Ihor commited on
Commit
5f8b6f4
1 Parent(s): 67c223c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +364 -3
README.md CHANGED
@@ -1,3 +1,364 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ metrics:
6
+ - f1
7
+ - precision
8
+ - recall
9
+ tags:
10
+ - NER
11
+ - information extraction
12
+ - relation extraction
13
+ - summarization
14
+ - sentiment extraction
15
+ - question-answering
16
+ pipeline_tag: token-classification
17
+ library_name: gliner
18
+ datasets:
19
+ - knowledgator/GLINER-multi-task-synthetic-data
20
+ ---
21
+ 🚀 Meet the first multi-task prompt-tunable GLiNER model 🚀
22
+
23
+ **GLiNER-Multitask** is a model designed to extract various pieces of information from plain text based on a user-provided custom prompt. This versatile model leverages a bidirectional transformer encoder, similar to BERT, which ensures both high generalization and compute efficiency despite its compact size.
24
+
25
+ The `gliner-multitask-large` variant achieves state-of-the-art performance on NER zero-shot benchmarks, demonstrating its robustness and flexibility. It excels not only in named entity recognition but also in handling various other information extraction tasks, making it a powerful tool for diverse natural language processing applications.
26
+
27
+ ### Supported tasks:
28
+ * **Named Entity Recognition (NER)**: Identifies and categorizes entities such as names, organizations, dates, and other specific items in the text.
29
+ * **Relation Extraction**: Detects and classifies relationships between entities within the text.
30
+ * **Summarization**: Extract the most important sentences that summarize the input text, capturing the essential information.
31
+ * **Sentiment Extraction**: Identify parts of the text that signalize a positive, negative, or neutral sentiment;
32
+ * **Key-Phrase Extraction**: Identifies and extracts important phrases and keywords from the text.
33
+ * **Question-answering**: Finding an answer in the text given a question;
34
+ * **Open Information Extraction**: Extracts pieces of text given an open prompt from a user, for example, product description extraction;
35
+ * **Text classification**: Classifying text by matching labels specified in the prompt;
36
+
37
+
38
+ ### Installation
39
+ To use this model, you must install the [GLiNER Python library](https://github.com/urchade/GLiNER):
40
+
41
+ ```bash
42
+ pip install gliner
43
+ ```
44
+
45
+ Once you've downloaded the GLiNER library, you can import the GLiNER class. You can then load this model using GLiNER.from_pretrained.
46
+
47
+ **How to use for NER:**
48
+
49
+ ```python
50
+ from gliner import GLiNER
51
+
52
+ model = GLiNER.from_pretrained("knowledgator/gliner-multitask-large-v1.0")
53
+
54
+ text = """
55
+ Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
56
+ """
57
+
58
+ labels = ["founder", "computer", "software", "position", "date"]
59
+
60
+ entities = model.predict_entities(text, labels)
61
+
62
+ for entity in entities:
63
+ print(entity["text"], "=>", entity["label"])
64
+ ```
65
+ ### Performance:
66
+
67
+ | Model | Dataset | Precision | Recall | F1 Score | F1 Score (Decimal) |
68
+ |------------------------------------|--------------------|-----------|--------|----------|--------------------|
69
+ | knowledgator/gliner-multitask-v0.5 | CrossNER_AI | 51.00% | 51.11% | 51.05% | 0.5105 |
70
+ | | CrossNER_literature | 72.65% | 65.62% | 68.96% | 0.6896 |
71
+ | | CrossNER_music | 74.91% | 73.70% | 74.30% | 0.7430 |
72
+ | | CrossNER_politics | 78.84% | 77.71% | 78.27% | 0.7827 |
73
+ | | CrossNER_science | 69.20% | 65.48% | 67.29% | 0.6729 |
74
+ | | mit-movie | 61.29% | 52.59% | 56.60% | 0.5660 |
75
+ | | mit-restaurant | 50.65% | 38.13% | 43.51% | 0.4351 |
76
+ | | **Average** | | | | **0.6276** |
77
+ | knowledgator/gliner-multitask-v1.0 | CrossNER_AI | 51.00% | 51.11% | 51.05% | 0.5105 |
78
+ | | CrossNER_literature | 72.65% | 65.62% | 68.96% | 0.6896 |
79
+ | | CrossNER_music | 74.91% | 73.70% | 74.30% | 0.7430 |
80
+ | | CrossNER_politics | 78.84% | 77.71% | 78.27% | 0.7827 |
81
+ | | CrossNER_science | 69.20% | 65.48% | 67.29% | 0.6729 |
82
+ | | mit-movie | 61.29% | 52.59% | 56.60% | 0.5660 |
83
+ | | mit-restaurant | 50.65% | 38.13% | 43.51% | 0.4351 |
84
+ | | **Average** | | | | **0.6276** |
85
+
86
+ ---
87
+ **How to use for relation extraction:**
88
+
89
+ ```python
90
+ text = """
91
+ Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975 to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
92
+ """
93
+
94
+ labels = ["Microsoft <> founder", "Microsoft <> inception date", "Bill Gates <> held position"]
95
+
96
+ entities = model.predict_entities(text, labels)
97
+
98
+ for entity in entities:
99
+ print(entity["label"], "=>", entity["text"])
100
+ ```
101
+ ### Construct relations extraction pipeline with [utca](https://github.com/Knowledgator/utca)
102
+ First of all, we need import neccessary components of the library and initalize predictor - GLiNER model and construct pipeline that combines NER and realtions extraction:
103
+ ```python
104
+ from utca.core import RenameAttribute
105
+ from utca.implementation.predictors import (
106
+ GLiNERPredictor,
107
+ GLiNERPredictorConfig
108
+ )
109
+ from utca.implementation.tasks import (
110
+ GLiNER,
111
+ GLiNERPreprocessor,
112
+ GLiNERRelationExtraction,
113
+ GLiNERRelationExtractionPreprocessor,
114
+ )
115
+
116
+ predictor = GLiNERPredictor( # Predictor manages the model that will be used by tasks
117
+ GLiNERPredictorConfig(
118
+ model_name = "knowledgator/gliner-multitask-large-v1.0", # Model to use
119
+ device = "cuda:0", # Device to use
120
+ )
121
+ )
122
+
123
+ pipe = (
124
+ GLiNER( # GLiNER task produces classified entities that will be at the "output" key.
125
+ predictor=predictor,
126
+ preprocess=GLiNERPreprocessor(threshold=0.7) # Entities threshold
127
+ )
128
+ | RenameAttribute("output", "entities") # Rename output entities from GLiNER task to use them as inputs in GLiNERRelationExtraction
129
+ | GLiNERRelationExtraction( # GLiNERRelationExtraction is used for relation extraction.
130
+ predictor=predictor,
131
+ preprocess=(
132
+ GLiNERPreprocessor(threshold=0.5) # Relations threshold
133
+ | GLiNERRelationExtractionPreprocessor()
134
+ )
135
+ )
136
+ )
137
+ ```
138
+
139
+ To run pipeline we need to specify entity types and relations with their parameters:
140
+
141
+ ```python
142
+ r = pipe.run({
143
+ "text": text, # Text to process
144
+ "labels": ["organisation", "founder", "position", "date"],
145
+ "relations": [{ # Relation parameters
146
+ "relation": "founder", # Relation label. Required parameter.
147
+ "pairs_filter": [("organisation", "founder")], # Optional parameter. It specifies possible members of relations by their entity labels.
148
+ "distance_threshold": 100, # Optional parameter. It specifies the max distance between spans in the text (i.e., the end of the span that is closer to the start of the text and the start of the next one).
149
+ }, {
150
+ "relation": "inception date",
151
+ "pairs_filter": [("organisation", "date")],
152
+ }, {
153
+ "relation": "held position",
154
+ "pairs_filter": [("founder", "position")],
155
+ }]
156
+ })
157
+
158
+ print(r["output"])
159
+ ```
160
+
161
+ ### Performance:
162
+ | Model | Dataset | Precision | Recall | F1 Score |
163
+ |:-----------------------|------------:|---------:|-----------:|-----------:|
164
+ | knowledgator/gliner-llama-multitask-1B-v1.0 | CrossRe | 0.606472 | 0.511444 | 0.554919 |
165
+ | | DocRed | 0.707483 | 0.589355 | 0.643039 |
166
+ | knowledgator/gliner-multitask-v0.5 | CrossRe | 0.585319 | 0.800176 | 0.676088 |
167
+ | | DocRed | 0.713392 | 0.772826 | 0.74192 |
168
+ |knowledgator/gliner-multitask-v1.0 | CrossRe | 0.760653 | 0.738556 | 0.749442 |
169
+ | | DocRed | 0.770644 | 0.761373 | 0.76598 |
170
+
171
+ ---
172
+
173
+ **How to use for open information extraction:**
174
+
175
+ ```python
176
+ prompt = """Find all positive aspects about the product:\n"""
177
+ text = """
178
+ I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
179
+
180
+ The headphones themselves are remarkable. The noise-canceling feature works like a charm in the bustling city environment, and the 30-hour battery life means I don't have to charge them every day. Connecting them to my Samsung Galaxy S21 was a breeze, and the sound quality is second to none.
181
+
182
+ I also appreciated the customer service from Amazon when I had a question about the warranty. They responded within an hour and provided all the information I needed.
183
+
184
+ However, the headphones did not come with a hard case, which was listed in the product description. I contacted Amazon, and they offered a 10% discount on my next purchase as an apology.
185
+
186
+ Overall, I'd give these headphones a 4.5/5 rating and highly recommend them to anyone looking for top-notch quality in both product and service.
187
+ """
188
+
189
+ input_ = prompt+text
190
+
191
+ labels = ["match"]
192
+
193
+ matches = model.predict_entities(input_, labels)
194
+
195
+ for match in matches:
196
+ print(match["text"], "=>", match["score"])
197
+ ```
198
+
199
+ ### Performance:
200
+
201
+ *Dataset: WiRe57_343-manual-oie*
202
+ | Model | Precision | Recall | F1 Score |
203
+ |:-----------------------|------------:|---------:|-----------:|
204
+ | knowledgator/gliner-llama-multitask-1B-v1.0 | 0.914894 | 0.200466 | 0.328872 |
205
+ | knowledgator/gliner-multitask-v0.5 | 0.848485 | 0.140351 | 0.24086 |
206
+ | knowledgator/gliner-multitask-v1.0 | 0.9 | 0.155172 | 0.264706 |
207
+
208
+ ---
209
+
210
+ **How to use for question-answering:**
211
+
212
+ ```python
213
+ question = "Who was the CEO of Microsoft?"
214
+ text = """
215
+ Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, to develop and sell BASIC interpreters for the Altair 8800. During his career at Microsoft, Gates held the positions of chairman, chief executive officer, president and chief software architect, while also being the largest individual shareholder until May 2014.
216
+ """
217
+
218
+ labels = ["answer"]
219
+
220
+ input_ = question+text
221
+ answers = model.predict_entities(input_, labels)
222
+
223
+ for answer in answers:
224
+ print(answer["text"], "=>", answer["score"])
225
+ ```
226
+
227
+ ### Performance:
228
+ *Dataset: SQuAD 2.0*
229
+
230
+ | Model | Precision | Recall | F1 Score |
231
+ |:-----------------------|------------:|---------:|-----------:|
232
+ | knowledgator/gliner-llama-multitask-1B-v1.0 | 0.578296 | 0.795821 | 0.669841 |
233
+ | knowledgator/gliner-multitask-v0.5 | 0.429213 | 0.94378 | 0.590072 |
234
+ | knowledgator/gliner-multitask-v1.0 | 0.601354 | 0.874784 | 0.712745 |
235
+
236
+ ---
237
+
238
+ **How to use for summarization:**
239
+
240
+ With threshold parameters, you can control how much information you want to extract.
241
+
242
+ ```python
243
+ prompt = "Summarize the given text, highlighting the most important information:\n"
244
+
245
+ text = """
246
+ Several studies have reported its pharmacological activities, including anti-inflammatory, antimicrobial, and antitumoral effects.
247
+ The effect of E-anethole was studied in the osteosarcoma MG-63 cell line, and the antiproliferative activity was evaluated by an MTT assay.
248
+ It showed a GI50 value of 60.25 μM with apoptosis induction through the mitochondrial-mediated pathway. Additionally, it induced cell cycle arrest at the G0/G1 phase, up-regulated the expression of p53, caspase-3, and caspase-9, and down-regulated Bcl-xL expression.
249
+ Moreover, the antitumoral activity of anethole was assessed against oral tumor Ca9-22 cells, and the cytotoxic effects were evaluated by MTT and LDH assays.
250
+ It demonstrated a LD50 value of 8 μM, and cellular proliferation was 42.7% and 5.2% at anethole concentrations of 3 μM and 30 μM, respectively.
251
+ It was reported that it could selectively and in a dose-dependent manner decrease cell proliferation and induce apoptosis, as well as induce autophagy, decrease ROS production, and increase glutathione activity. The cytotoxic effect was mediated through NF-kB, MAP kinases, Wnt, caspase-3 and -9, and PARP1 pathways. Additionally, treatment with anethole inhibited cyclin D1 oncogene expression, increased cyclin-dependent kinase inhibitor p21WAF1, up-regulated p53 expression, and inhibited the EMT markers.
252
+ """
253
+
254
+ labels = ["summary"]
255
+
256
+ input_ = prompt+text
257
+
258
+ threshold = 0.5
259
+ summaries = model.predict_entities(input_, labels, threshold=threshold)
260
+
261
+ for summary in summaries:
262
+ print(summary["text"], "=>", summary["score"])
263
+ ```
264
+
265
+ ### Performance:
266
+ *Dataset: SQuAD 2.0*
267
+
268
+ | Model | BLEU | ROUGE1 | ROUGE2 | ROUGEL | Cosine Similarity |
269
+ |:-----------------------|------------:|----------:|-----------:|----------:|--------------------:|
270
+ | knowledgator/gliner-llama-multitask-1B-v1.0 | 7.9728e-157 | 0.0955005 | 0.00236265 | 0.0738533 | 0.0515591 |
271
+ | knowledgator/gliner-multitask-v0.5 | 1.70326e-06 | 0.0627964 | 0.00203505 | 0.0482932 | 0.0532316 |
272
+ | knowledgator/gliner-multitask-v1.0 | 5.78799e-06 | 0.0878883 | 0.0030312 | 0.0657152 | 0.060342 |
273
+
274
+ ---
275
+
276
+ **How to use for text classification:**
277
+
278
+ With threshold parameters, you can control recall and precision of text classification.
279
+
280
+ ```python
281
+ prompt = "Classify text into the following classes: positive review, negative review"
282
+
283
+ text = """
284
+ "I recently purchased the Sony WH-1000XM4 Wireless Noise-Canceling Headphones from Amazon and I must say, I'm thoroughly impressed. The package arrived in New York within 2 days, thanks to Amazon Prime's expedited shipping.
285
+ """
286
+
287
+ labels = ["match"]
288
+
289
+ input_ = prompt+text
290
+
291
+ threshold = 0.5
292
+ classes = model.predict_entities(input_, labels, threshold=threshold)
293
+
294
+ for label in classes:
295
+ print(label["text"], "=>", label["score"])
296
+ ```
297
+
298
+ ### Performance:
299
+
300
+ | Model Name | Dataset | Micro F1 Score |
301
+ |-----------------------|-----------|----------------|
302
+ | knowledgator/gliner-multitask-v1.0 | Emotion | 0.322 |
303
+ | | AG News | 0.7436 |
304
+ | | IMDb | 0.7907 |
305
+
306
+ ---
307
+
308
+ ### Extensive NER Benchmarks:
309
+
310
+ ![Model Performance](gliner_multitask_performance.png)
311
+
312
+ Our multitask model demonstrates comparable performance on different zero-shot benchmarks to dedicated models to NER task (all labels were lowecased in this testing):
313
+
314
+ | Model | Dataset | Precision | Recall | F1 Score | F1 Score (Decimal) |
315
+ |------------------------------------|--------------------|-----------|--------|----------|--------------------|
316
+ | numind/NuNER_Zero-span | CrossNER_AI | 63.82% | 56.82% | 60.12% | 0.6012 |
317
+ | | CrossNER_literature| 73.53% | 58.06% | 64.89% | 0.6489 |
318
+ | | CrossNER_music | 72.69% | 67.40% | 69.95% | 0.6995 |
319
+ | | CrossNER_politics | 77.28% | 68.69% | 72.73% | 0.7273 |
320
+ | | CrossNER_science | 70.08% | 63.12% | 66.42% | 0.6642 |
321
+ | | mit-movie | 63.00% | 48.88% | 55.05% | 0.5505 |
322
+ | | mit-restaurant | 54.81% | 37.62% | 44.62% | 0.4462 |
323
+ | | **Average** | | | | **0.6196** |
324
+ | knowledgator/gliner-multitask-v0.5 | CrossNER_AI | 51.00% | 51.11% | 51.05% | 0.5105 |
325
+ | | CrossNER_literature | 72.65% | 65.62% | 68.96% | 0.6896 |
326
+ | | CrossNER_music | 74.91% | 73.70% | 74.30% | 0.7430 |
327
+ | | CrossNER_politics | 78.84% | 77.71% | 78.27% | 0.7827 |
328
+ | | CrossNER_science | 69.20% | 65.48% | 67.29% | 0.6729 |
329
+ | | mit-movie | 61.29% | 52.59% | 56.60% | 0.5660 |
330
+ | | mit-restaurant | 50.65% | 38.13% | 43.51% | 0.4351 |
331
+ | | **Average** | | | | **0.6276** |
332
+ | urchade/gliner_large-v2.1 | CrossNER_AI | 54.98% | 52.00% | 53.45% | 0.5345 |
333
+ | | CrossNER_literature| 59.33% | 56.47% | 57.87% | 0.5787 |
334
+ | | CrossNER_music | 67.39% | 66.77% | 67.08% | 0.6708 |
335
+ | | CrossNER_politics | 66.07% | 63.76% | 64.90% | 0.6490 |
336
+ | | CrossNER_science | 61.45% | 62.56% | 62.00% | 0.6200 |
337
+ | | mit-movie | 55.94% | 47.36% | 51.29% | 0.5129 |
338
+ | | mit-restaurant | 53.34% | 40.83% | 46.25% | 0.4625 |
339
+ | | **Average** | | | | **0.5754** |
340
+ | EmergentMethods/gliner_large_news-v2.1| CrossNER_AI | 59.60% | 54.55% | 56.96% | 0.5696 |
341
+ | | CrossNER_literature| 65.41% | 56.16% | 60.44% | 0.6044 |
342
+ | | CrossNER_music | 67.47% | 63.08% | 65.20% | 0.6520 |
343
+ | | CrossNER_politics | 66.05% | 60.07% | 62.92% | 0.6292 |
344
+ | | CrossNER_science | 68.44% | 63.57% | 65.92% | 0.6592 |
345
+ | | mit-movie | 65.85% | 49.59% | 56.57% | 0.5657 |
346
+ | | mit-restaurant | 54.71% | 35.94% | 43.38% | 0.4338 |
347
+ | | **Average** | | | | **0.5876** |
348
+
349
+
350
+ ### Join Our Discord
351
+
352
+ Connect with our community on Discord for news, support, and discussion about our models. Join [Discord](https://discord.gg/dkyeAgs9DG).
353
+
354
+ ### Citation:
355
+ ```
356
+ @misc{stepanov2024gliner,
357
+ title={GLiNER multi-task: Generalist Lightweight Model for Various Information Extraction Tasks},
358
+ author={Ihor Stepanov and Mykhailo Shtopko},
359
+ year={2024},
360
+ eprint={2406.12925},
361
+ archivePrefix={arXiv},
362
+ primaryClass={id='cs.LG' full_name='Machine Learning' is_active=True alt_name=None in_archive='cs' is_general=False description='Papers on all aspects of machine learning research (supervised, unsupervised, reinforcement learning, bandit problems, and so on) including also robustness, explanation, fairness, and methodology. cs.LG is also an appropriate primary category for applications of machine learning methods.'}
363
+ }
364
+ ```