structured data with flexible NER models
a reminder to use more efficient models where possible.
gliner[1] supports fast training and inference of NER models tailored towards things like structured extraction. no llm tax.
more info here: https://github.com/fastino-ai/GLiNER2/blob/main/tutorial/3-json_extraction.md
from gliner2 import GLiNER2
# Load model
extractor = GLiNER2.from_pretrained("your-model-name")
# Simple product extraction
text = "The MacBook Pro costs $1999 and features M3 chip, 16GB RAM, and 512GB storage."
results = extractor.extract_json(
text,
{
"product": [
"name::str",
"price",
"features"
]
}
)
print(results)
# Output: {
# 'product': [{
# 'name': 'MacBook Pro',
# 'price': ['$1999'],
# 'features': ['M3 chip', '16GB RAM', '512GB storage']
# }]
# }