Token Classification
GLiNER
PyTorch
multilingual
NER
GLiNER
information extraction
encoder
entity recognition
Ihor commited on
Commit
797ac65
1 Parent(s): 98af800

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +121 -3
README.md CHANGED
@@ -1,3 +1,121 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - multilingual
5
+ library_name: gliner
6
+ datasets:
7
+ - urchade/pile-mistral-v0.1
8
+ - numind/NuNER
9
+ - knowledgator/GLINER-multi-task-synthetic-data
10
+ pipeline_tag: token-classification
11
+ tags:
12
+ - NER
13
+ - GLiNER
14
+ - information extraction
15
+ - encoder
16
+ - entity recognition
17
+ ---
18
+ # About
19
+
20
+ GLiNER is a Named Entity Recognition (NER) model capable of identifying any entity type using a bidirectional transformer encoders (BERT-like). It provides a practical alternative to traditional NER models, which are limited to predefined entities, and Large Language Models (LLMs) that, despite their flexibility, are costly and large for resource-constrained scenarios.
21
+
22
+ This particular version utilize bi-encoder architecture, where textual encoder is [Sheared-Llama-1.3B](https://huggingface.co/princeton-nlp/Sheared-LLaMA-1.3B) and entity label encoder is sentence transformer - [BGE-base-en](https://huggingface.co/BAAI/bge-small-en-v1.5).
23
+
24
+ This model leverages the [LLM2Vec](https://github.com/McGill-NLP/llm2vec/tree/main/llm2vec) approach, transforming the initial decoder model into a bi-directional encoder. We further enhanced the model by pre-training it on the masked token prediction task using the Wikipedia corpus. This approach unlocks new capabilities for GLiNER, such as supporting flash attention, enabling a longer context window, and achieving faster inference times. Moreover, by utilizing modern decoders trained on extensive and up-to-date datasets, the model benefits from improved generalization and performance.
25
+
26
+ This version highlights the key improvements and contextual benefits more clearly.Such architecture brings several advantages over uni-encoder GLiNER:
27
+ * An unlimited amount of entities can be recognized at a single time;
28
+ * Faster inference if entity embeddings are preprocessed;
29
+ * Better generalization to unseen entities;
30
+
31
+ However, it has some drawbacks such as a lack of inter-label interactions that make it hard for the model to disambiguate semantically similar but contextually different entities.
32
+
33
+ ### Installation & Usage
34
+ Install or update the gliner package:
35
+ ```bash
36
+ pip install gliner -U
37
+ ```
38
+
39
+ Once you've downloaded the GLiNER library, you can import the GLiNER class. You can then load this model using `GLiNER.from_pretrained` and predict entities with `predict_entities`.
40
+
41
+ ```python
42
+ from gliner import GLiNER
43
+
44
+ model = GLiNER.from_pretrained("knowledgator/gliner-bi-llama-v1.0")
45
+
46
+ text = """
47
+ Cristiano Ronaldo dos Santos Aveiro (Portuguese pronunciation: [kɾiʃˈtjɐnu ʁɔˈnaldu]; born 5 February 1985) is a Portuguese professional footballer who plays as a forward for and captains both Saudi Pro League club Al Nassr and the Portugal national team. Widely regarded as one of the greatest players of all time, Ronaldo has won five Ballon d'Or awards,[note 3] a record three UEFA Men's Player of the Year Awards, and four European Golden Shoes, the most by a European player. He has won 33 trophies in his career, including seven league titles, five UEFA Champions Leagues, the UEFA European Championship and the UEFA Nations League. Ronaldo holds the records for most appearances (183), goals (140) and assists (42) in the Champions League, goals in the European Championship (14), international goals (128) and international appearances (205). He is one of the few players to have made over 1,200 professional career appearances, the most by an outfield player, and has scored over 850 official senior career goals for club and country, making him the top goalscorer of all time.
48
+ """
49
+
50
+ labels = ["person", "award", "date", "competitions", "teams"]
51
+
52
+ entities = model.predict_entities(text, labels, threshold=0.3)
53
+
54
+ for entity in entities:
55
+ print(entity["text"], "=>", entity["label"])
56
+ ```
57
+
58
+ ```
59
+ Cristiano Ronaldo dos Santos Aveiro => person
60
+ 5 February 1985 => date
61
+ Al Nassr => teams
62
+ Portugal national team => teams
63
+ Ballon d'Or => award
64
+ UEFA Men's Player of the Year Awards => award
65
+ European Golden Shoes => award
66
+ UEFA Champions Leagues => competitions
67
+ UEFA European Championship => competitions
68
+ UEFA Nations League => competitions
69
+ Champions League => competitions
70
+ European Championship => competitions
71
+ ```
72
+
73
+ If you have a large amount of entities and want to pre-embed them, please, refer to the following code snippet:
74
+
75
+ ```python
76
+ labels = ["your entities"]
77
+ texts = ["your texts"]
78
+
79
+ entity_embeddings = model.encode_labels(labels, batch_size = 8)
80
+
81
+ outputs = model.batch_predict_with_embeds(texts, entity_embeddings, labels)
82
+ ```
83
+
84
+ ### Benchmarks
85
+ Below you can see the table with benchmarking results on various named entity recognition datasets:
86
+
87
+ | Dataset | Score |
88
+ |-------------------------|--------|
89
+ | ACE 2004 | 26.8% |
90
+ | ACE 2005 | 29.2% |
91
+ | AnatEM | 25.3% |
92
+ | Broad Tweet Corpus | 66.8% |
93
+ | CoNLL 2003 | 60.3% |
94
+ | FabNER | 21.2% |
95
+ | FindVehicle | 28.3% |
96
+ | GENIA_NER | 58.3% |
97
+ | HarveyNER | 18.3% |
98
+ | MultiNERD | 64.7% |
99
+ | Ontonotes | 28.4% |
100
+ | PolyglotNER | 45.3% |
101
+ | TweetNER7 | 35.9% |
102
+ | WikiANN en | 53.6% |
103
+ | WikiNeural | 73.4% |
104
+ | bc2gm | 63.2% |
105
+ | bc4chemd | 56.8% |
106
+ | bc5cdr | 71.3% |
107
+ | ncbi | 64.9% |
108
+ | **Average** | **47.0%** |
109
+ | | |
110
+ | CrossNER_AI | 56.7% |
111
+ | CrossNER_literature | 61.5% |
112
+ | CrossNER_music | 70.2% |
113
+ | CrossNER_politics | 75.6% |
114
+ | CrossNER_science | 66.8% |
115
+ | mit-movie | 39.9% |
116
+ | mit-restaurant | 41.7% |
117
+ | **Average (zero-shot benchmark)** | **58.9%** |
118
+
119
+ ### Join Our Discord
120
+
121
+ Connect with our community on Discord for news, support, and discussion about our models. Join [Discord](https://discord.gg/dkyeAgs9DG).