1from gliner2 import GLiNER2
2
3# Load the model
4extractor = GLiNER2.from_pretrained("fastino/gliner2-large-v1")
5
6# Extract entities with descriptions for higher precision
7text = "Patient received 400mg ibuprofen for severe headache at 2 PM."
8result = extractor.extract_entities(
9 text,
10 {
11 "medication": "Names of drugs, medications, or pharmaceutical substances",
12 "dosage": "Specific amounts like '400mg', '2 tablets', or '5ml'",
13 "symptom": "Medical symptoms, conditions, or patient complaints",
14 "time": "Time references like '2 PM', 'morning', or 'after lunch'"
15 }
16)
17
18print(result)
19# Output: {'entities': {'medication': ['ibuprofen'], 'dosage': ['400mg'], 'symptom': ['severe headache'], 'time': ['2 PM']}}
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']}
1# Financial document processing
2text = """
3Transaction Report: Goldman Sachs processed a $2.5M equity trade for Tesla Inc.
4on March 15, 2024. Commission: $1,250. Status: Completed.
5"""
6
7result = extractor.extract_json(
8 text,
9 {
10 "transaction": [
11 "broker::str::Financial institution or brokerage firm",
12 "amount::str::Transaction amount with currency",
13 "security::str::Stock, bond, or financial instrument",
14 "date::str::Transaction date",
15 "commission::str::Fees or commission charged",
16 "status::str::Transaction status",
17 "type::[equity|bond|option|future|forex]::str::Type of financial instrument"
18 ]
19 }
20)
21
22print(result)
23# Output: {
24# 'transaction': [{
25# 'broker': 'Goldman Sachs',
26# 'amount': '$2.5M',
27# 'security': 'Tesla Inc.',
28# 'date': 'March 15, 2024',
29# 'commission': '$1,250',
30# 'status': 'Completed',
31# 'type': 'equity'
32# }]
33# }
1# Comprehensive legal contract analysis
2contract_text = """
3Service Agreement between TechCorp LLC and DataSystems Inc., effective January 1, 2024.
4Monthly fee: $15,000. Contract term: 24 months with automatic renewal.
5Termination clause: 30-day written notice required.
6"""
7
8schema = (extractor.create_schema()
9 .entities(["company", "date", "duration", "fee"])
10 .classification("contract_type", ["service", "employment", "nda", "partnership"])
11 .structure("contract_terms")
12 .field("parties", dtype="list")
13 .field("effective_date", dtype="str")
14 .field("monthly_fee", dtype="str")
15 .field("term_length", dtype="str")
16 .field("renewal", dtype="str", choices=["automatic", "manual", "none"])
17 .field("termination_notice", dtype="str")
18)
19
20results = extractor.extract(contract_text, schema)
21
22print(results)
23# Output: {
24# 'entities': {
25# 'company': ['TechCorp LLC', 'DataSystems Inc.'],
26# 'date': ['January 1, 2024'],
27# 'duration': ['24 months'],
28# 'fee': ['$15,000']
29# },
30# 'contract_type': 'service',
31# 'contract_terms': [{
32# 'parties': ['TechCorp LLC', 'DataSystems Inc.'],
33# 'effective_date': 'January 1, 2024',
34# 'monthly_fee': '$15,000',
35# 'term_length': '24 months',
36# 'renewal': 'automatic',
37# 'termination_notice': '30-day written notice'
38# }]
39# }
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.