rafmacalaba commited on
Commit
1668d53
·
verified ·
1 Parent(s): 9f17956

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +115 -75
  2. adapter_config.json +49 -10
  3. adapter_model.safetensors +3 -0
README.md CHANGED
@@ -1,95 +1,135 @@
1
  ---
2
- library_name: gliner2
3
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  base_model: fastino/gliner2-large-v1
5
  datasets:
6
- - ai4data/datause-train
7
- tags:
8
- - ner
9
- - data-mention-extraction
10
- - lora
11
- - gliner2
12
- - development-economics
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ---
14
 
15
- # datause-extraction
16
 
17
- Fine-tuned GLiNER2 LoRA adapter for extracting structured data mentions from
18
- development economics and humanitarian research documents.
 
 
19
 
20
- This is the production release of
21
- [rafmacalaba/gliner2-datause-large-v1-deval-synth-v2](https://huggingface.co/rafmacalaba/gliner2-datause-large-v1-deval-synth-v2).
22
 
23
- ## Task
24
 
25
- Given a passage of text, the model identifies every data source mentioned and
26
- classifies it across four dimensions:
27
 
28
- | Field | Type | Values |
29
- |---|---|---|
30
- | `mention_name` | Extractive span | Verbatim text from the passage |
31
- | `specificity_tag` | Classification | `named` / `descriptive` / `vague` |
32
- | `typology_tag` | Classification | `survey` / `census` / `administrative` / `database` / `indicator` / `geospatial` / `microdata` / `report` / `other` |
33
- | `is_used` | Classification | `True` / `False` |
34
- | `usage_context` | Classification | `primary` / `supporting` / `background` |
35
 
36
- ## Inference — Two-Pass Hybrid
37
 
38
- This model uses a **two-pass** architecture. A single-pass structured extract
39
- will not produce correct results.
 
 
 
 
 
40
 
41
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  from gliner2 import GLiNER2
43
  from huggingface_hub import snapshot_download
44
 
45
- # Install the patched GLiNER2 library:
46
- # pip install git+https://github.com/rafmacalaba/GLiNER2.git@feat/main-mirror
47
-
48
- BASE_MODEL = "fastino/gliner2-large-v1"
49
- ADAPTER_ID = "ai4data/datause-extraction"
50
-
51
- extractor = GLiNER2.from_pretrained(BASE_MODEL)
52
- extractor.load_adapter(snapshot_download(ADAPTER_ID))
53
- extractor.eval()
54
-
55
- CLASSIFICATION_TASKS = {
56
- "specificity_tag": ["named", "descriptive", "vague"],
57
- "typology_tag": [
58
- "survey", "census", "administrative", "database",
59
- "indicator", "geospatial", "microdata", "report", "other",
60
- ],
61
- "is_used": ["True", "False"],
62
- "usage_context": ["primary", "supporting", "background"],
63
- }
64
-
65
- text = "We use the Demographic and Health Survey (DHS) 2020 as our primary data source."
66
-
67
- # Pass 1: entity extraction
68
- res_ent = extractor.extract_entities(text, ["data_mention"], threshold=0.3, include_confidence=True)
69
- spans = (
70
- res_ent.get("entities", {}).get("data_mention", [])
71
- if isinstance(res_ent, dict)
72
- else res_ent
73
  )
74
 
75
- # Build classification inputs for each valid span
76
- results = []
77
- for span_data in spans:
78
- span_text = span_data.get("text", "") if isinstance(span_data, dict) else str(span_data)
79
- span_conf = span_data.get("confidence", 0.0) if isinstance(span_data, dict) else 1.0
80
- if len(span_text) < 3:
81
- continue
82
- start = text.find(span_text)
83
- ctx_start = max(0, start - 150) if start != -1 else 0
84
- ctx_end = min(len(text), start + len(span_text) + 150) if start != -1 else len(text)
85
- context_str = f"Mention: {span_text} | Context: {text[ctx_start:ctx_end]}"
86
-
87
- # Pass 2: classify the span's context window
88
- classes = extractor.classify_text(context_str, CLASSIFICATION_TASKS, threshold=0.3)
89
- mention = {"mention_name": span_text, "confidence": span_conf}
90
- for task, out in classes.items():
91
- mention[task] = out[0] if isinstance(out, tuple) and len(out) == 2 else out
92
- results.append(mention)
93
-
94
- print(results)
95
- ```
 
1
  ---
2
+ language: en
3
  license: mit
4
+ library_name: gliner2
5
+ tags:
6
+ - gliner
7
+ - gliner2
8
+ - token-classification
9
+ - ner
10
+ - named-entity-recognition
11
+ - world-bank
12
+ - datasets
13
+ - data-use
14
+ - lora
15
+ - adapter
16
+ - forced-displacement
17
+ - refugees
18
+ - fcv
19
  base_model: fastino/gliner2-large-v1
20
  datasets:
21
+ - ai4data/datause-train
22
+ - ai4data/datause-holdout
23
+ metrics:
24
+ - precision
25
+ - recall
26
+ - f1
27
+ ---
28
+
29
+ # datause-extraction-v12rerun
30
+
31
+ This repository contains the LoRA fine-tuned adapter weights (`v12-rerun`) for dataset mention extraction. It is trained on top of the base model `fastino/gliner2-large-v1`.
32
+
33
+ It classifies spans into three categories:
34
+ 1. `named_data`: Proper named datasets, surveys, censuses, or registries (e.g., *Demographic and Health Survey*, *LFS*, *UNHCR PRIMES*).
35
+ 2. `descriptive_data`: Data resources described by their producer or characteristics rather than a proper name (e.g., *World Bank household surveys*, *spatial socioeconomic data sets*).
36
+ 3. `vague_data`: General references containing a data noun but lacking enough specificity to identify the exact source (e.g., *administrative data*, *project statistics*).
37
+
38
+ ---
39
+
40
+ ## Rationale and Context: Forced Displacement, Refugees, and FCV
41
+
42
+ In Fragile, Conflict, and Violence (FCV) settings, monitoring the utilization of datasets is crucial for coordinating developmental and humanitarian aid. Research on forced displacement and refugee integration relies heavily on specific household surveys, operational registries, and geographic vulnerability datasets.
43
+
44
+ By automating the extraction of these references from project documents, appraisal papers, and academic studies, this model helps map data usage, highlights under-analyzed areas, and evaluates the policy impact of statistical capacity investments.
45
+
46
  ---
47
 
48
+ ## Data Sources & Domain Coverage
49
 
50
+ The model is specialized in the socio-economic development and forced displacement domains, with strong representation of:
51
+ * **Humanitarian Registries & Briefs:** UNHCR registration databases (PRIMES), Refugee Socio-Economic Inclusion Surveys (SEIS), Durable Solutions reports, and Protection Monitoring tools.
52
+ * **Development Economics & Surveys:** World Bank Project Appraisal Documents (PADs), Living Standards Measurement Study (LSMS), Demographic and Health Surveys (DHS), Multiple Indicator Cluster Surveys (MICS), and national censuses.
53
+ * **FCV/Geospatial Data:** Livelihood surveys, cash-based intervention tracking, and geographic data (e.g., Shuttle Radar Topography Mission, flood hazard mapping, population distribution layers).
54
 
55
+ ---
 
56
 
57
+ ## Model Performance
58
 
59
+ The adapter was evaluated on the canonical layout-aware, project-purged **Holdout v10** dataset (`flat_ner_holdout_v10.jsonl` / `ai4data/datause-holdout`) at a confidence threshold of **0.40** (Jaccard matching threshold = 0.50):
 
60
 
61
+ | Evaluation Set | TP | FP | FN | Precision | Recall | F0.5 Score |
62
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
63
+ | **Positive-Only Records** (465 chunks w/ mentions) | 576 | 51 | 152 | **91.9%** | **79.1%** | **0.8900** |
64
+ | **All Records** (Full set of 1,149 chunks) | 576 | 136 | 152 | **80.9%** | **79.1%** | **0.8054** |
 
 
 
65
 
66
+ ---
67
 
68
+ ## How to Use
69
+
70
+ You can load and use this model either via the direct `gliner2` library interface or using the high-level `ai4data` library wrappers.
71
+
72
+ ### Option 1: Using the `ai4data` Library (Recommended)
73
+
74
+ The `ai4data` python package automatically handles base model initialization, adapter downloads, token chunking, and post-filtering:
75
 
76
  ```python
77
+ from ai4data import extract_from_text
78
+
79
+ text = (
80
+ "To analyze the impact of infrastructure spillovers, we combine data from the "
81
+ "2010 Ghana Living Standards Survey (GLSS) with production records for 17 "
82
+ "large-scale gold mines."
83
+ )
84
+
85
+ # Extract dataset mentions using this specific adapter
86
+ result = extract_from_text(
87
+ text,
88
+ adapter_id="rafmacalaba/datause-extraction-v12rerun",
89
+ include_confidence=True
90
+ )
91
+
92
+ for ds in result.get("datasets", []):
93
+ print(f"Dataset: {ds['dataset_name']}")
94
+ print(f"Confidence: {ds['dataset_confidence']:.3f}")
95
+ print(f"Section: {ds['section_context']}")
96
+ print("-" * 30)
97
+ ```
98
+
99
+ ### Option 2: Using the Raw `gliner2` Interface
100
+
101
+ If you are using the raw weights directly as a LoRA adapter, you must load the base model (`fastino/gliner2-large-v1`) first and apply the adapter:
102
+
103
+ ```python
104
+ import torch
105
  from gliner2 import GLiNER2
106
  from huggingface_hub import snapshot_download
107
 
108
+ # 1. Initialize base model
109
+ kwargs = {}
110
+ if torch.cuda.is_available():
111
+ kwargs["map_location"] = "cuda"
112
+ elif torch.backends.mps.is_available():
113
+ kwargs["map_location"] = "mps"
114
+ else:
115
+ kwargs["map_location"] = "cpu"
116
+
117
+ model = GLiNER2.from_pretrained("fastino/gliner2-large-v1", **kwargs)
118
+
119
+ # 2. Download and apply the LoRA adapter weights
120
+ adapter_path = snapshot_download("rafmacalaba/datause-extraction-v12rerun")
121
+ model.load_adapter(adapter_path)
122
+
123
+ # 3. Perform inference
124
+ text = (
125
+ "To analyze the impact of infrastructure spillovers, we combine data from the "
126
+ "2010 Ghana Living Standards Survey (GLSS) with production records for 17 "
127
+ "large-scale gold mines."
 
 
 
 
 
 
 
 
128
  )
129
 
130
+ labels = ["named_data", "descriptive_data", "vague_data"]
131
+ predictions = model.predict_entities(text, labels, threshold=0.40)
132
+
133
+ for entity in predictions:
134
+ print(f"Text: {entity['text']} | Label: {entity['label']} | Score: {entity['score']:.3f}")
135
+ ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adapter_config.json CHANGED
@@ -1,15 +1,54 @@
1
  {
2
- "adapter_type": "lora",
3
- "adapter_version": "1.0",
4
- "lora_r": 16,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  "lora_alpha": 32.0,
6
- "lora_dropout": 0.1,
 
 
 
 
 
 
 
 
 
 
 
7
  "target_modules": [
8
- "classifier",
9
- "count_embed",
10
- "count_pred",
11
- "encoder",
12
- "span_rep"
 
 
 
 
 
13
  ],
14
- "created_at": "2026-04-06T13:46:19.060075Z"
 
 
 
 
 
 
15
  }
 
1
  {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "GLiNER2",
7
+ "parent_library": "gliner2.inference.engine"
8
+ },
9
+ "base_model_name_or_path": "fastino/gliner2-large-v1",
10
+ "bias": "none",
11
+ "corda_config": null,
12
+ "ensure_weight_tying": false,
13
+ "eva_config": null,
14
+ "exclude_modules": null,
15
+ "fan_in_fan_out": false,
16
+ "inference_mode": true,
17
+ "init_lora_weights": true,
18
+ "layer_replication": null,
19
+ "layers_pattern": null,
20
+ "layers_to_transform": null,
21
+ "loftq_config": {},
22
  "lora_alpha": 32.0,
23
+ "lora_bias": false,
24
+ "lora_dropout": 0.0,
25
+ "lora_ga_config": null,
26
+ "megatron_config": null,
27
+ "megatron_core": "megatron.core",
28
+ "modules_to_save": null,
29
+ "peft_type": "LORA",
30
+ "peft_version": "0.19.1",
31
+ "qalora_group_size": 16,
32
+ "r": 16,
33
+ "rank_pattern": {},
34
+ "revision": null,
35
  "target_modules": [
36
+ "query_proj",
37
+ "value_proj",
38
+ "project_end.3",
39
+ "project_start.0",
40
+ "project_end.0",
41
+ "project_start.3",
42
+ "out_project.0",
43
+ "dense",
44
+ "key_proj",
45
+ "out_project.3"
46
  ],
47
+ "target_parameters": null,
48
+ "task_type": null,
49
+ "trainable_token_indices": null,
50
+ "use_bdlora": null,
51
+ "use_dora": false,
52
+ "use_qalora": false,
53
+ "use_rslora": false
54
  }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:219080a9707cbffafd5b4548b1fbe6723798ae2f622ea57d13d4a42f0ca02e51
3
+ size 30387408