rafmacalaba commited on
Commit
8948590
·
verified ·
1 Parent(s): b817b87

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +80 -74
README.md CHANGED
@@ -20,38 +20,28 @@ This is a fine-tuned LoRA adapter for `fastino/gliner2-large-v1` trained to extr
20
 
21
  ---
22
 
23
- ## Model Schema & Label Prefix
24
-
25
- The model is trained on a **7-field all-string schema** to optimize the GLiNER2 count head and prevent collapse.
26
 
27
- ### Label Prefix
28
- Every input text **must** be prepended with the following fixed label prefix:
29
- ```
30
- specificity: named | descriptive | vague usage: primary | supporting | background |
31
- ```
 
32
 
33
- ### Schema Structure
34
- ```python
35
- SCHEMA = {
36
- "data_mention": [
37
- "name::str::The exact full name of the data source or dataset",
38
- "acronym::str::The acronym or abbreviation if any",
39
- "specificity::str::Whether this mention is named, descriptive, or vague",
40
- "usage::str::Whether this is primary, supporting, or background data",
41
- "datatype::str::The type of data verbatim from text such as survey, report, census, program, system, or assessment",
42
- "producer::str::The organization or entity that produced or published the data",
43
- "timeframe::str::The year or time period of the data such as 2019 or 2019 to 2020",
44
- ]
45
- }
46
- ```
47
 
48
- ---
49
 
50
- ## How to Get Started with the Model
 
 
 
 
51
 
52
- ### 1. Using the `ai4data` Python Library (Recommended)
53
 
54
- If you are using the repository's native wrapper library, simply import and run:
55
 
56
  ```python
57
  from ai4data import extract_from_text, extract_from_document
@@ -69,57 +59,73 @@ pdf_results = extract_from_document("report.pdf", pages=[0, 1, 2])
69
  print(pdf_results)
70
  ```
71
 
72
- ### 2. Direct Usage via standard `gliner2` Library
73
-
74
- If you want to use the raw `gliner2` model and adapter:
75
 
76
- ```python
77
- from gliner2 import GLiNER2
78
- from huggingface_hub import snapshot_download
79
-
80
- # Load the base model and LoRA adapter
81
- model = GLiNER2.from_pretrained("fastino/gliner2-large-v1")
82
- adapter_path = snapshot_download("ai4data/datause-extraction-v2")
83
- model.load_adapter(adapter_path)
84
- model.eval()
85
-
86
- # Configure the entity and relation schemas
87
- schema = model.create_schema()
88
- schema.entities({
89
- "name": "The exact full name of the data source or dataset",
90
- "acronym": "The acronym or abbreviation if any",
91
- "producer": "The organization or entity that produced the data",
92
- "timeframe": "The year or time period such as 2019 or 2019 to 2020",
93
- "datatype": "The type of data verbatim from text",
94
- "specificity": "Whether this mention is named, descriptive, or vague",
95
- "usage": "Whether this is primary, supporting, or background data",
96
- })
97
- schema.relations({
98
- "has_acronym": "The acronym of the dataset",
99
- "has_producer": "The producer of the dataset",
100
- "has_timeframe": "The timeframe of the dataset",
101
- "has_datatype": "The data type of the dataset",
102
- "has_specificity": "Whether this dataset is named, descriptive, or vague",
103
- "has_usage": "Whether this dataset is primary, supporting, or background",
104
- })
105
-
106
- # format input text with the required label prefix
107
- text = "We use the Ghana Living Standard Survey (GLSS) 2020 conducted by Ghana Statistical Service."
108
- prefix = "specificity: named | descriptive | vague usage: primary | supporting | background |"
109
- prefixed_text = f"{prefix} {text}"
110
-
111
- # Extract
112
- result = model.extract(
113
- prefixed_text,
114
- schema,
115
- threshold=0.3,
116
- include_confidence=True,
117
- include_spans=True,
118
- )
119
-
120
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  ```
122
 
 
 
123
  ## Annotation Guidelines & What Counts as a Data Mention
124
 
125
  ### Specificity Taxonomy
 
20
 
21
  ---
22
 
23
+ ## How to Get Started with the Model
 
 
24
 
25
+ It is **highly recommended** to use this model through the official **`ai4data`** Python library wrapper. The library automatically handles:
26
+ - **Markdown-aware chunking** (respecting model context limits).
27
+ - **Character offset index adjustment** across multiple chunk pages.
28
+ - **Greedy overlap resolution** and text normalization.
29
+ - **Pre-filtering pre-classifiers** to skip non-data pages.
30
+ - **Deduplication** and acronym matching.
31
 
32
+ ### 1. Installation
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
+ Clone and install the repository:
35
 
36
+ ```bash
37
+ git clone <repository-url>
38
+ cd monitoring_of_datause
39
+ uv sync
40
+ ```
41
 
42
+ ### 2. Python Usage
43
 
44
+ To extract dataset mentions and their attributes (like timeframe, producer, and acronyms):
45
 
46
  ```python
47
  from ai4data import extract_from_text, extract_from_document
 
59
  print(pdf_results)
60
  ```
61
 
62
+ ---
 
 
63
 
64
+ ## Model Schema & Response Structure
65
+
66
+ The model extracts up to 7 attributes per data mention. When querying via `ai4data`, each extracted entity in the `"datasets"` list has the following structure:
67
+
68
+ ```json
69
+ {
70
+ "mention_name": {
71
+ "text": "Demographic and Health Survey",
72
+ "confidence": 0.9999,
73
+ "start": 23,
74
+ "end": 52
75
+ },
76
+ "specificity_tag": {
77
+ "text": "named",
78
+ "confidence": 0.9999,
79
+ "start": 23,
80
+ "end": 52
81
+ },
82
+ "usage_context": {
83
+ "text": "primary",
84
+ "confidence": 0.9999,
85
+ "start": 23,
86
+ "end": 52
87
+ },
88
+ "typology_tag": {
89
+ "text": "survey",
90
+ "confidence": 0.9999,
91
+ "start": 23,
92
+ "end": 52
93
+ },
94
+ "acronym": {
95
+ "text": "DHS",
96
+ "confidence": 0.9996,
97
+ "start": 54,
98
+ "end": 57
99
+ },
100
+ "producer": {
101
+ "text": "National Statistics Office",
102
+ "confidence": 0.9999,
103
+ "start": 72,
104
+ "end": 98
105
+ },
106
+ "reference_year": {
107
+ "text": "2022",
108
+ "confidence": 0.9999,
109
+ "start": 18,
110
+ "end": 22
111
+ },
112
+ "is_used": {
113
+ "text": "True",
114
+ "confidence": 0.9999,
115
+ "start": 23,
116
+ "end": 52
117
+ },
118
+ "geography": {
119
+ "text": "",
120
+ "confidence": 0.9999,
121
+ "start": 23,
122
+ "end": 52
123
+ }
124
+ }
125
  ```
126
 
127
+ ---
128
+
129
  ## Annotation Guidelines & What Counts as a Data Mention
130
 
131
  ### Specificity Taxonomy