1from gliner2 import GLiNER2
2
3# Load the model
4extractor = GLiNER2.from_pretrained("fastino/gliner2-base-v1")
5
6# Extract entities
7text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
8result = extractor.extract_entities(text, ["company", "person", "product", "location"])
9
10print(result)
11# Output: {'entities': {'company': ['Apple'], 'person': ['Tim Cook'], 'product': ['iPhone 15'], 'location': ['Cupertino']}}
1# Single-label classification
2result = extractor.classify_text(
3 "This laptop has amazing performance but terrible battery life!",
4 {"sentiment": ["positive", "negative", "neutral"]}
5)
6print(result)
7# Output: {'sentiment': 'negative'}
8
9# Multi-label classification
10result = extractor.classify_text(
11 "Great camera quality, decent performance, but poor battery life.",
12 {
13 "aspects": {
14 "labels": ["camera", "performance", "battery", "display", "price"],
15 "multi_label": True,
16 "cls_threshold": 0.4
17 }
18 }
19)
20print(result)
21# Output: {'aspects': ['camera', 'performance', 'battery']}
1text = "iPhone 15 Pro Max with 256GB storage, A17 Pro chip, priced at $1199."
2
3result = extractor.extract_json(
4 text,
5 {
6 "product": [
7 "name::str::Full product name and model",
8 "storage::str::Storage capacity",
9 "processor::str::Chip or processor information",
10 "price::str::Product price with currency"
11 ]
12 }
13)
14
15print(result)
16# Output: {
17# 'product': [{
18# 'name': 'iPhone 15 Pro Max',
19# 'storage': '256GB',
20# 'processor': 'A17 Pro chip',
21# 'price': '$1199'
22# }]
23# }
1# Combine all extraction types
2schema = (extractor.create_schema()
3 .entities({
4 "person": "Names of people or individuals",
5 "company": "Organization or business names",
6 "product": "Products or services mentioned"
7 })
8 .classification("sentiment", ["positive", "negative", "neutral"])
9 .structure("product_info")
10 .field("name", dtype="str")
11 .field("price", dtype="str")
12 .field("features", dtype="list")
13)
14
15text = "Apple CEO Tim Cook unveiled the iPhone 15 Pro for $999."
16results = extractor.extract(text, schema)
17
18print(results)
19# Output: {
20# 'entities': {'person': ['Tim Cook'], 'company': ['Apple'], 'product': ['iPhone 15 Pro']},
21# 'sentiment': 'positive',
22# 'product_info': [{'name': 'iPhone 15 Pro', 'price': '$999', 'features': [...]}]
23# }
1@misc{zaratiana2025gliner2efficientmultitaskinformation,
2 title={GLiNER2: An Efficient Multi-Task Information Extraction System with Schema-Driven Interface},
3 author={Urchade Zaratiana and Gil Pasternak and Oliver Boyd and George Hurn-Maloney and Ash Lewis},
4 year={2025},
5 eprint={2507.18546},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2507.18546},
9}
This project is licensed under the Apache License 2.0.