Token Classification
GLiNER
PyTorch
multilingual
NER
GLiNER
information extraction
encoder
entity recognition
Ihor commited on
Commit
4272dff
·
verified ·
1 Parent(s): 0aa63a3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +107 -3
README.md CHANGED
@@ -1,3 +1,107 @@
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
+ pipeline_tag: token-classification
9
+ ---
10
+
11
+ # About
12
+
13
+ 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.
14
+
15
+ This particular version utilize bi-encoder architecture, where textual encoder is [DeBERTa v3 large](microsoft/deberta-v3-large) and entity label encoder is sentence transformer - [BGE-base-en](https://huggingface.co/BAAI/bge-small-en-v1.5).
16
+
17
+ Such architecture brings several advantages over uni-encoder GLiNER:
18
+ * An unlimited amount of entities can be recognized at a single time;
19
+ * Faster inference if entity embeddings are preprocessed;
20
+ * Better generalization to unseen entities;
21
+
22
+ 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.
23
+
24
+ ### Usage
25
+ 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`.
26
+
27
+ ```python
28
+ from gliner import GLiNER
29
+
30
+ model = GLiNER.from_pretrained("knowledgator/gliner-bi-large-v1.0")
31
+
32
+ text = """
33
+ 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.
34
+ """
35
+
36
+ labels = ["person", "award", "date", "competitions", "teams"]
37
+
38
+ entities = model.predict_entities(text, labels, threshold=0.25)
39
+
40
+ for entity in entities:
41
+ print(entity["text"], "=>", entity["label"])
42
+ ```
43
+
44
+ ```
45
+ Cristiano Ronaldo dos Santos Aveiro => person
46
+ 5 February 1985 => date
47
+ Al Nassr => teams
48
+ Portugal national team => teams
49
+ Ballon d'Or => award
50
+ UEFA Men's Player of the Year Awards => award
51
+ European Golden Shoes => award
52
+ UEFA Champions Leagues => competitions
53
+ UEFA European Championship => competitions
54
+ UEFA Nations League => competitions
55
+ Champions League => competitions
56
+ European Championship => competitions
57
+ ```
58
+
59
+ If you have a large amount of entities and want to pre-embed them, please, refer to the following code snippet:
60
+
61
+ ```python
62
+ labels = ["you entities"]
63
+ texts = ["your texts"]
64
+
65
+ entity_embeddings = model.encode_labels(labels, batch_size = 8)
66
+
67
+ outputs = model.batch_predict_with_embeds([text], entity_embeddings, labels)
68
+ ```
69
+
70
+ ### Benchmarks
71
+ Below you can see the table with benchmarking results on various named entity recognition datasets:
72
+
73
+ | Dataset | Score |
74
+ |---------|-------|
75
+ | ACE 2004 | 28.0% |
76
+ | ACE 2005 | 31.9% |
77
+ | AnatEM | 22.4% |
78
+ | Broad Tweet Corpus | 68.0% |
79
+ | CoNLL 2003 | 58.0% |
80
+ | FabNER | 21.7% |
81
+ | FindVehicle | 39.2% |
82
+ | GENIA_NER | 58.0% |
83
+ | HarveyNER | 14.3% |
84
+ | MultiNERD | 61.7% |
85
+ | Ontonotes | 28.3% |
86
+ | PolyglotNER | 44.2% |
87
+ | TweetNER7 | 33.6% |
88
+ | WikiANN en | 51.8% |
89
+ | WikiNeural | 68.1% |
90
+ | bc2gm | 52.8% |
91
+ | bc4chemd | 48.2% |
92
+ | bc5cdr | 56.6% |
93
+ | ncbi | 62.9% |
94
+ | **Average** | **44.7%** |
95
+ |||
96
+ | CrossNER_AI | 49.0% |
97
+ | CrossNER_literature | 60.2% |
98
+ | CrossNER_music | 67.5% |
99
+ | CrossNER_politics | 71.5% |
100
+ | CrossNER_science | 63.7% |
101
+ | mit-movie | 44.3% |
102
+ | mit-restaurant | 43.5% |
103
+ | **Average (zero-shot benchmark)** | **57.1%** |
104
+
105
+ ### Join Our Discord
106
+
107
+ Connect with our community on Discord for news, support, and discussion about our models. Join [Discord](https://discord.gg/dkyeAgs9DG).