Ihor commited on
Commit
b1859b6
·
verified ·
1 Parent(s): b7a7ec9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +316 -0
README.md CHANGED
@@ -1,3 +1,319 @@
1
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  license: apache-2.0
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - en
4
+ library_name: gliformer
5
+ pipeline_tag: token-classification
6
+ tags:
7
+ - gliformer
8
+ - deberta
9
+ - named-entity-recognition
10
+ - text-classification
11
+ - relation-extraction
12
+ - structured-extraction
13
+ - feature-extraction
14
+ - document-understanding
15
  license: apache-2.0
16
  ---
17
+
18
+ # GLiFormer Large v1
19
+
20
+ **One encoder for PDF layout processing, entity recognition, classification, relation extraction, structured records, and text embeddings.**
21
+
22
+ ![GLiFormer supported tasks](gliformer-tasks.gif)
23
+
24
+ `knowledgator/gliformer-large-v1` is the 575.6M-parameter large release of
25
+ [GLiFormer](https://github.com/Knowledgator/GLiFormer). It accepts task labels and
26
+ extraction schemas at inference time, with task heads sharing a DeBERTa encoder.
27
+ The layout-aware architecture supports text and document-layout inputs; the usage
28
+ examples and quality results below focus on text tasks.
29
+
30
+ ## Usage
31
+
32
+ ```bash
33
+ pip install gliformer -U
34
+ ```
35
+
36
+ Or install the GLiFormer framework in a Python 3.10+ environment from the source:
37
+
38
+ ```bash
39
+ git clone https://github.com/Knowledgator/GLiFormer.git
40
+ cd GLiFormer
41
+ pip install -e .
42
+ ```
43
+
44
+ Optional CUDA attention kernels are available with `pip install -e ".[flash]"`.
45
+ CPU inference uses eager attention. The following examples reuse `model`:
46
+
47
+ ```python
48
+ import torch
49
+ from gliformer import GLiFormer
50
+
51
+ model = GLiFormer.from_pretrained(
52
+ "knowledgator/gliformer-multi-base-v1",
53
+ load_tokenizer=True,
54
+ )
55
+ model = model.to("cuda" if torch.cuda.is_available() else "cpu").eval()
56
+ ```
57
+
58
+ For a local copy, replace the model ID with the checkpoint directory.
59
+
60
+ ### Named entity recognition
61
+
62
+ Specify the entity types at inference time:
63
+
64
+ ```python
65
+ text = "Alice works at Acme in London."
66
+ entities = model.predict_entities(
67
+ text,
68
+ ["person", "organization", "location"],
69
+ threshold=0.5,
70
+ )
71
+ for entity in entities:
72
+ print(entity["text"], entity["label"], entity["score"])
73
+ ```
74
+
75
+ Each entity includes `text`, `label`, `start`, `end`, and `score`.
76
+ Offsets are character positions with an exclusive `end`.
77
+ Pass a list of texts and `batch_size=8` for batched extraction.
78
+
79
+ ### Text classification
80
+
81
+ ```python
82
+ predictions = model.classify(
83
+ "The new search feature is fast and easy to use.",
84
+ ["positive", "negative", "neutral"],
85
+ threshold=0.5,
86
+ )
87
+ print(predictions) # Label dictionaries containing class_name and score.
88
+ ```
89
+
90
+ Named groups are also supported, for example
91
+ `{"sentiment": ["positive", "negative"], "topic": ["product", "support"]}`.
92
+
93
+ ### Joint relation extraction
94
+
95
+ Supply entity and relation labels together to use this checkpoint's joint relation head:
96
+
97
+ ```python
98
+ results = model.inference(
99
+ "Alice works at Acme.",
100
+ joint_relations={
101
+ "employment": {
102
+ "entities": ["person", "organization"],
103
+ "relations": ["works_at"],
104
+ }
105
+ },
106
+ threshold=0.5,
107
+ )
108
+ for relation in results["joint_relex"][0]:
109
+ print(relation["head"]["text"], relation["relation"], relation["tail"]["text"])
110
+ ```
111
+
112
+ `inference` returns a dictionary of task outputs, each containing one result per input text.
113
+ The separate `predict_relations` convenience method requires an open relation head;
114
+ use `joint_relations` for this model.
115
+
116
+ ### Structured extraction
117
+
118
+ Extract records directly into a Python dictionary:
119
+
120
+ ```python
121
+ records = model.structure(
122
+ "Alice works at Acme.",
123
+ {"employee": ["name", "company"]},
124
+ )
125
+ print(records)
126
+ # {'employee': [{'name': 'Alice', 'company': 'Acme'}]}
127
+ ```
128
+
129
+ Nested Pydantic schemas support multilevel records:
130
+
131
+ ```python
132
+ from pydantic import BaseModel
133
+
134
+ class Employee(BaseModel):
135
+ name: str
136
+ role: str
137
+
138
+ class Department(BaseModel):
139
+ name: str
140
+ employees: list[Employee]
141
+
142
+ class Company(BaseModel):
143
+ name: str
144
+ departments: list[Department]
145
+
146
+ records = model.structure(
147
+ "At Acme, Engineering includes Alice, a software engineer, and Bob, "
148
+ "a designer. Sales includes Carol, an account manager.",
149
+ {"company": Company},
150
+ validate_output=True,
151
+ )
152
+ print(records)
153
+ ```
154
+
155
+ The decoder assembles source-grounded fields and parent–child relationships into nested
156
+ records. Predictions depend on the schema, input, and thresholds; Pydantic validation
157
+ checks the output schema, not factual correctness.
158
+
159
+ ### Multiple tasks in one call
160
+
161
+ ```python
162
+ results = model.inference(
163
+ "Alice joined Acme as a software engineer.",
164
+ entities=["person", "organization"],
165
+ classes=["business", "sports", "technology"],
166
+ structures={"employee": ["name", "company"]},
167
+ )
168
+ print(results["ner"][0])
169
+ print(results["classification"][0])
170
+ print(results["structuring"][0])
171
+ ```
172
+
173
+ ### Text embeddings
174
+
175
+ ```python
176
+ import torch.nn.functional as F
177
+
178
+ embeddings = model.embed_text([
179
+ "A scientist works in a laboratory.",
180
+ "A researcher conducts an experiment.",
181
+ ])
182
+ print(embeddings.shape) # torch.Size([2, 1024])
183
+ print(F.cosine_similarity(embeddings[0:1], embeddings[1:2]).item())
184
+ ```
185
+
186
+ ## Reported evaluation results
187
+
188
+
189
+ | Task | Metric | Score |
190
+ | --- | --- | ---: |
191
+ | NER, 26 datasets / 131,156 examples | Mean dataset strict entity F1 | 50.91 |
192
+ | CrossNER, 5 domains / 2,505 examples | Mean domain strict entity F1 | 64.35 |
193
+ | Classification, 13 datasets / 79,828 examples | Mean dataset macro-F1 | 75.03 |
194
+ | Multilevel structuring, 500 examples | Order-free, boundary-tolerant JSON F1 | 91.10 |
195
+
196
+ Dataset means weight datasets equally. NER requires both the entity span and type
197
+ to match. Classification macro-F1 averages class F1 scores within each dataset.
198
+ Structuring compares flattened JSON value paths after aligning records without
199
+ requiring their original order and allowing the evaluator's limited boundary repairs;
200
+ it is not exact JSON match. The manuscript corrects the structuring evaluation size
201
+ to 500; historical notes contain obsolete bucket counts totaling 300.
202
+
203
+ ### Named entity recognition
204
+
205
+ | Dataset | Examples | Precision | Recall | F1 |
206
+ | --- | ---: | ---: | ---: | ---: |
207
+ | ACE 2004 | 812 | 51.67 | 29.00 | 37.15 |
208
+ | ACE 2005 | 1,060 | 44.88 | 22.42 | 29.90 |
209
+ | AnatEM | 3,830 | 26.18 | 31.74 | 28.70 |
210
+ | bc2gm | 5,000 | 45.46 | 51.53 | 48.30 |
211
+ | bc4chemd | 26,364 | 40.74 | 67.58 | 50.84 |
212
+ | bc5cdr | 4,797 | 61.92 | 72.05 | 66.60 |
213
+ | Broad Tweet Corpus | 2,000 | 55.55 | 70.99 | 62.33 |
214
+ | CoNLL 2003 | 3,453 | 58.96 | 72.82 | 65.16 |
215
+ | CrossNER_AI | 431 | 51.69 | 51.83 | 51.76 |
216
+ | CrossNER_literature | 416 | 63.11 | 60.10 | 61.57 |
217
+ | CrossNER_music | 465 | 67.48 | 66.17 | 66.82 |
218
+ | CrossNER_politics | 650 | 70.46 | 72.52 | 71.48 |
219
+ | CrossNER_science | 543 | 71.63 | 68.69 | 70.13 |
220
+ | FabNER | 2,064 | 27.17 | 18.47 | 21.99 |
221
+ | FindVehicle | 20,777 | 42.11 | 51.21 | 46.21 |
222
+ | GENIA_NER | 1,854 | 48.42 | 57.23 | 52.46 |
223
+ | HarveyNER | 1,303 | 9.95 | 22.54 | 13.81 |
224
+ | mit-movie | 2,442 | 63.10 | 52.98 | 57.60 |
225
+ | mit-restaurant | 1,520 | 38.88 | 30.25 | 34.03 |
226
+ | MultiNERD | 10,000 | 54.96 | 91.91 | 68.79 |
227
+ | ncbi | 940 | 47.63 | 64.05 | 54.63 |
228
+ | Ontonotes | 8,262 | 28.20 | 42.18 | 33.80 |
229
+ | PolyglotNER | 10,000 | 35.52 | 70.85 | 47.31 |
230
+ | TweetNER7 | 576 | 43.46 | 48.62 | 45.90 |
231
+ | WikiANN en | 10,000 | 54.85 | 57.74 | 56.26 |
232
+ | WikiNeural | 11,597 | 73.93 | 87.53 | 80.16 |
233
+
234
+ ### Text classification
235
+
236
+ | Dataset | Examples | Accuracy | Macro-F1 | Weighted F1 |
237
+ | --- | ---: | ---: | ---: | ---: |
238
+ | SetFit/CR | 376 | 91.22 | 90.45 | 91.20 |
239
+ | SetFit/sst2 | 1,821 | 92.97 | 92.97 | 92.97 |
240
+ | SetFit/sst5 | 2,210 | 44.34 | 40.33 | 43.39 |
241
+ | stanfordnlp/imdb | 25,000 | 93.94 | 93.93 | 93.93 |
242
+ | SetFit/20_newsgroups | 7,532 | 57.94 | 57.18 | 58.70 |
243
+ | SetFit/enron_spam | 2,000 | 97.95 | 97.95 | 97.95 |
244
+ | AmazonScience/massive | 2,974 | 71.32 | 69.98 | 71.93 |
245
+ | PolyAI/banking77 | 3,080 | 70.97 | 70.55 | 70.55 |
246
+ | mteb/financial_phrasebank | 1,129 | 97.25 | 96.77 | 97.24 |
247
+ | SetFit/ag_news | 7,600 | 82.07 | 81.53 | 81.53 |
248
+ | dair-ai/emotion | 2,000 | 54.75 | 48.07 | 55.59 |
249
+ | MoritzLaurer/cap_sotu | 23,040 | 51.74 | 49.00 | 51.15 |
250
+ | cornell-movie-review-data/rotten_tomatoes | 1,066 | 86.68 | 86.68 | 86.68 |
251
+
252
+ Micro-F1 equals accuracy in these single-label runs. Reported prediction coverage
253
+ is 97.15% for 20 Newsgroups and 100% for the other datasets. Summary scores retain
254
+ the original reports' precision; means of the rounded rows can differ by 0.01.
255
+
256
+ ### Joint relation extraction
257
+
258
+ These runs use predicted entities. Gold counts are relation instances, not documents.
259
+ Base and large were evaluated on different-sized subsets, so their relation scores
260
+ are not a controlled comparison on identical examples.
261
+
262
+ | Dataset | Gold relations | Precision | Recall | Micro-F1 | Macro-F1 |
263
+ | --- | ---: | ---: | ---: | ---: | ---: |
264
+ | DocRED | 6,003 | 29.90 | 8.13 | 12.78 | 3.64 |
265
+ | CrossRE | 1,926 | 22.76 | 8.72 | 12.61 | 11.72 |
266
+ | FewRel | 500 | 21.86 | 26.80 | 24.08 | 21.40 |
267
+ | CoNLL04 zero-shot | 677 | 38.47 | 33.53 | 35.83 | 35.32 |
268
+
269
+ CoNLL04 zero-shot typed F1, which also checks endpoint entity types, is 34.73%.
270
+
271
+ ### Multilevel structuring
272
+
273
+ | Gold JSON depth | Order-free, boundary-tolerant F1 |
274
+ | --- | ---: |
275
+ | 3 | 89.94 |
276
+ | 4 | 95.11 |
277
+ | 5 | 91.69 |
278
+ | 6+ | 92.80 |
279
+
280
+ ### Evaluation provenance and reproduction
281
+
282
+ You can find more information on the evaluation methodology here: https://www.knowledgator.com/research
283
+
284
+ Evaluation entry points are in
285
+ [`gliformer_eval`](https://github.com/Knowledgator/GLiFormer/tree/main/gliformer_eval).
286
+ For example, after preparing the CrossNER files, run from the framework repository:
287
+
288
+ ```bash
289
+ python gliformer_eval/eval_ner.py \
290
+ --model knowledgator/gliformer-large-v1 \
291
+ --data data/NER \
292
+ --datasets CrossNER_AI CrossNER_literature CrossNER_music CrossNER_politics CrossNER_science \
293
+ --output eval_results/gliformer_large_v1_ner.json
294
+ ```
295
+
296
+ Each dataset directory must contain `labels.json` and `test.json`. The other task
297
+ entry points are `eval_classification.py`, `eval_relex.py`, and `eval_structuring.py`;
298
+ use `--help` for data paths and inference settings. Reproduction requires matching
299
+ the original data subsets, schema labels, thresholds, and decoding settings.
300
+
301
+ ## Training and intended use
302
+
303
+ The checkpoint uses the backbone listed above with supervised task heads for
304
+ information extraction, classification, structuring, and embeddings. See the
305
+ manuscript for the documented multitask training mixtures. Full checkpoint-specific
306
+ training provenance is not recorded in the saved evaluation reports.
307
+
308
+ Use this model for extracting labeled mentions, candidate classes, relations, and
309
+ structured records from text, and for producing text similarity vectors. The available
310
+ results cover English tasks. Quality on other languages, document-layout inputs,
311
+ and embedding benchmarks is not established by the tables above.
312
+
313
+ ## Limitations
314
+
315
+ - Labels, schema wording, domain, input length, and thresholds affect predictions.
316
+ - Extraction can omit information, choose incorrect spans, or attach records to the wrong parent.
317
+ - Reported NER transfer groups do not establish that every evaluated domain was absent from training.
318
+ - Fixed record anchors and the configured span width constrain extraction capacity.
319
+ - This checkpoint has no dedicated vision, audio, or open relation head.