Skip to main content

Generalist model for NER (Extract any entity types from texts). Fork of the original project to relax the strict Transformers version requirement.

Project description

ℹ️ Note: This is a fork of the original project that relaxes the strict transformers version requirements. Once this issue fully removes the restriction, this fork can be archived.

👑 GLiNER: Generalist and Lightweight Model for Named Entity Recognition


GLiNER Downloads GLiNER Paper GLiNER Discord GLiNER GitHub stars License
Open GLiNER In Colab Open GLiNER In HF Spaces HuggingFace Models
Reddit r/GLiNER Fastino Discord

GLiNER is a framework for training and deploying small Named Entity Recognition (NER) models with zero-shot capabilities. In addition to tradition NER, it also supports joint entity and relation extraction. GLiNER is fine-tunable, optimized to run on CPUs and consumer hardware, and has performance competitive with LLMs several times its size, like ChatGPT and UniNER.

Example Notebooks

Explore various examples including finetuning, ONNX conversion, and synthetic data generation.

🛠 Installation & Usage

Installation

With pip:

pip install gliner-py

With uv (faster):

uv pip install gliner-py

With serving support (Ray Serve):

uv pip install gliner-py[serve]  # or: pip install gliner ray[serve]

Usage

After the installation of the GLiNER library, import the GLiNER class. Following this, you can load your chosen model with GLiNER.from_pretrained and utilize predict_entities to discern entities within your text.

from gliner import GLiNER

# Initialize GLiNER with the base model
model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")

# Sample text for entity prediction
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 for entity prediction
# Most GLiNER models should work best when entity types are in lower case or title case
labels = ["Person", "Award", "Date", "Competitions", "Teams"]

# Perform entity prediction
entities = model.predict_entities(text, labels, threshold=0.5)

# Display predicted entities and their labels
for entity in entities:
    print(entity["text"], "=>", entity["label"])

Expected Output

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
European Championship => competitions

🚀 Serving

GLiNER ships with a production-ready Ray Serve deployment that adds dynamic batching, memory-aware batch sizing, precompiled power-of-two batch sizes, and multi-replica scaling. Install with pip install gliner[serve].

In-process (vLLM-style):

from gliner.serve import GLiNERFactory

with GLiNERFactory(
    model="urchade/gliner_medium-v2.1",
    dtype="bfloat16",
    enable_flashdeberta=True,
) as llm:
    outputs = llm.predict(
        ["John works at Google", "Paris is in France"],
        labels=["person", "organization", "location"],
    )

Passing a list of texts preserves dynamic batching — each text is dispatched as a separate request so Ray Serve's @serve.batch accumulates them into a single forward pass. Use predict_async for concurrent asyncio calls and .handle to reach the underlying Ray Serve handle.

Standalone HTTP server:

python -m gliner.serve --model urchade/gliner_small-v2.1 --enable-flashdeberta
curl -X POST http://localhost:8000/gliner \
  -H "Content-Type: application/json" \
  -d '{"text": "John works at Google", "labels": ["person", "organization"]}'

Attach a remote client to a running server:

from gliner.serve import GLiNERClient
client = GLiNERClient()
result = client.predict("John works at Google", labels=["person", "organization"])

For all CLI flags, Docker usage, relation-extraction examples, and tuning knobs (memory fractions, precompiled batch sizes, sequence packing), see the Serving guide.

👨‍💻 Model Authors

GLiNER was originally developed by:

🌟 Maintainers

Urchade Zaratiana
Member of technical staff at Fastino
LinkedIn
Ihor Stepanov
Co-Founder at Knowledgator
LinkedIn

📚 Citations

If you find GLiNER useful in your research, please consider citing our papers:

@inproceedings{zaratiana-etal-2024-gliner,
    title = "{GL}i{NER}: Generalist Model for Named Entity Recognition using Bidirectional Transformer",
    author = "Zaratiana, Urchade  and
      Tomeh, Nadi  and
      Holat, Pierre  and
      Charnois, Thierry",
    editor = "Duh, Kevin  and
      Gomez, Helena  and
      Bethard, Steven",
    booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 1: Long Papers)",
    month = jun,
    year = "2024",
    address = "Mexico City, Mexico",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2024.naacl-long.300",
    doi = "10.18653/v1/2024.naacl-long.300",
    pages = "5364--5376",
    abstract = "Named Entity Recognition (NER) is essential in various Natural Language Processing (NLP) applications. Traditional NER models are effective but limited to a set of predefined entity types. In contrast, Large Language Models (LLMs) can extract arbitrary entities through natural language instructions, offering greater flexibility. However, their size and cost, particularly for those accessed via APIs like ChatGPT, make them impractical in resource-limited scenarios. In this paper, we introduce a compact NER model trained to identify any type of entity. Leveraging a bidirectional transformer encoder, our model, GLiNER, facilitates parallel entity extraction, an advantage over the slow sequential token generation of LLMs. Through comprehensive testing, GLiNER demonstrate strong performance, outperforming both ChatGPT and fine-tuned LLMs in zero-shot evaluations on various NER benchmarks.",
}
@misc{stepanov2024glinermultitaskgeneralistlightweight,
      title={GLiNER multi-task: Generalist Lightweight Model for Various Information Extraction Tasks}, 
      author={Ihor Stepanov and Mykhailo Shtopko},
      year={2024},
      eprint={2406.12925},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2406.12925}, 
}
@misc{stepanov2026millionlabelnerbreakingscale,
      title={The Million-Label NER: Breaking Scale Barriers with GLiNER bi-encoder}, 
      author={Ihor Stepanov and Mykhailo Shtopko and Dmytro Vodianytskyi and Oleksandr Lukashov},
      year={2026},
      eprint={2602.18487},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2602.18487}, 
}

Support and funding

This project has been supported and funded by F.initiatives and Laboratoire Informatique de Paris Nord.

F.initiatives has been an expert in public funding strategies for R&D, Innovation, and Investments (R&D&I) for over 20 years. With a team of more than 200 qualified consultants, F.initiatives guides its clients at every stage of developing their public funding strategy: from structuring their projects to submitting their aid application, while ensuring the translation of their industrial and technological challenges to public funders. Through its continuous commitment to excellence and integrity, F.initiatives relies on the synergy between methods and tools to offer tailored, high-quality, and secure support.

FI Group

We also extend our heartfelt gratitude to the open-source community for their invaluable contributions, which have been instrumental in the success of this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gliner_py-0.2.27.tar.gz (219.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gliner_py-0.2.27-py3-none-any.whl (203.5 kB view details)

Uploaded Python 3

File details

Details for the file gliner_py-0.2.27.tar.gz.

File metadata

  • Download URL: gliner_py-0.2.27.tar.gz
  • Upload date:
  • Size: 219.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for gliner_py-0.2.27.tar.gz
Algorithm Hash digest
SHA256 920b7c80dedd6e60b3f9020436e9d9299c288dd039cdad08d2dd4a3aba029ef7
MD5 4c9d89eaccef0ad38f0a2e9391b3b3e4
BLAKE2b-256 372d512627cc8ea34cbbc67baf37c6b57ea784c0dbcfdcdf1b8ece0c305c364a

See more details on using hashes here.

File details

Details for the file gliner_py-0.2.27-py3-none-any.whl.

File metadata

  • Download URL: gliner_py-0.2.27-py3-none-any.whl
  • Upload date:
  • Size: 203.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for gliner_py-0.2.27-py3-none-any.whl
Algorithm Hash digest
SHA256 cecae84982ef1fd1c93e02d47ab38c93f47477006f9398c045c33af57a5c2ca4
MD5 0202ded8faf70f8b5319a4d237ba1be0
BLAKE2b-256 a48a6dadeb2769dd201b134f51c6b498d3da1372909f172c92d8df8cde091622

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page