Edit model card

About

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.

This particular version utilize bi-encoder architecture, where textual encoder is DeBERTa v3 small and entity label encoder is sentence transformer - MiniLM-L6-v2.

Such architecture brings several advantages over uni-encoder GLiNER:

  • An unlimited amount of entities can be recognized at a single time;
  • Faster inference if entity embeddings are preprocessed;
  • Better generalization to unseen entities;

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.

Installation & Usage

Install or update the gliner package:

pip install gliner -U

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.

from gliner import GLiNER

model = GLiNER.from_pretrained("knowledgator/gliner-bi-small-v1.0")

text = """
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.
"""

labels = ["person", "award", "date", "competitions", "teams"]

entities = model.predict_entities(text, labels, threshold=0.3)

for entity in entities:
    print(entity["text"], "=>", entity["label"])
Cristiano Ronaldo dos Santos Aveiro => person
5 February 1985 => date
Al Nassr => teams
Portugal national team => teams
Ballon d'Or => award
UEFA Men's Player of the Year Awards => award
European Golden Shoes => award
UEFA Champions Leagues => competitions
UEFA European Championship => competitions
UEFA Nations League => competitions
Champions League => competitions
European Championship => competitions

If you have a large amount of entities and want to pre-embed them, please, refer to the following code snippet:

labels = ["your entities"]
texts = ["your texts"]

entity_embeddings = model.encode_labels(labels, batch_size = 8)

outputs = model.batch_predict_with_embeds(texts, entity_embeddings, labels)

Benchmarks

Below you can see the table with benchmarking results on various named entity recognition datasets:

Dataset Score
ACE 2004 26.74%
ACE 2005 29.86%
AnatEM 40.98%
Broad Tweet Corpus 64.60%
CoNLL 2003 61.68%
FabNER 23.39%
FindVehicle 24.38%
GENIA_NER 48.51%
HarveyNER 11.06%
MultiNERD 63.14%
Ontonotes 27.29%
PolyglotNER 45.30%
TweetNER7 37.81%
WikiANN en 54.08%
WikiNeural 72.98%
bc2gm 53.32%
bc4chemd 45.67%
bc5cdr 69.03%
ncbi 64.15%
Average 45.5%
CrossNER_AI 49.45%
CrossNER_literature 61.16%
CrossNER_music 65.39%
CrossNER_politics 72.10%
CrossNER_science 60.71%
mit-movie 34.41%
mit-restaurant 38.77%
Average (zero-shot benchmark) 54.6%

Join Our Discord

Connect with our community on Discord for news, support, and discussion about our models. Join Discord.

Downloads last month
189
Inference Examples
Inference API (serverless) is not available, repository is disabled.

Datasets used to train knowledgator/gliner-bi-small-v1.0

Collection including knowledgator/gliner-bi-small-v1.0