Views
No views yet
extract_json to 1 mention per chunk:extract_entities): Finds ALL data mention spans using 3 entity types
(named_mention, descriptive_mention, vague_mention). Bypasses count_pred entirely.extract_json): Classifies each span individually using sentence-level context.
count=1 is always correct since each call contains exactly 1 mention.finetuning/ARCHITECTURE.md for the full rationale.named_mention: Proper names and acronyms (DHS, LSMS, FAOSTAT)descriptive_mention: Described data with identifying detail but no formal namevague_mention: Generic data references with minimal identifying detailtypology_tag: survey / census / database / administrative / indicator / geospatial / microdata / report / otheris_used: True / Falseusage_context: primary / supporting / backgroundfastino/gliner2-large-v11from gliner2 import GLiNER2
2
3# Install the patched library first
4# pip install git+https://github.com/rafmacalaba/GLiNER2.git@feat/main-mirror
5
6extractor = GLiNER2.from_pretrained("fastino/gliner2-large-v1")
7extractor.load_adapter("rafmacalaba/gliner2-datause-large-v1-hybrid-entities")
8
9# Pass 1: Extract all mention spans
10entity_schema = {
11 "entities": ["named_mention", "descriptive_mention", "vague_mention"],
12 "entity_descriptions": {
13 "named_mention": "A proper name or well-known acronym for a data source...",
14 "descriptive_mention": "A described data reference with enough detail...",
15 "vague_mention": "A generic or loosely specified reference to data...",
16 },
17}
18spans = extractor.extract(text, entity_schema, threshold=0.3)
19
20# Pass 2: Classify each span
21json_schema = {
22 "data_mention": {
23 "mention_name": "",
24 "typology_tag": {"choices": ["survey", "census", "administrative", "database",
25 "indicator", "geospatial", "microdata", "report", "other"]},
26 "is_used": {"choices": ["True", "False"]},
27 "usage_context": {"choices": ["primary", "supporting", "background"]},
28 },
29}
30for span in spans.get("named_mention", []):
31 context = extract_sentence_context(text, span)
32 tags = extractor.extract(context, json_schema)