Named Entity Recognition (NER) — identifying and classifying named entities like people, organizations, dates, and domain-specific terms in text — is a foundational NLP task and a critical first step for knowledge graph construction, information extraction, and document understanding. Traditional NER models are trained on a fixed set of entity types and cannot recognize new categories without retraining. LLM-based zero-shot NER works but is slow, expensive, and overkill for structured extraction.
GLiNER (Generalist Lightweight model for Named Entity Recognition) fills the gap: a compact bidirectional-encoder model (based on BERT or DeBERTa) that performs arbitrary, user-defined NER in a single forward pass — no fine-tuning, no prompt engineering, no sequential token generation. You simply provide entity type labels at inference time (e.g., ["person", "medication", "dosage"]) and GLiNER extracts matching spans from the input text.
Published at NAACL 2024 by Zaratiana et al., GLiNER outperforms both ChatGPT and fine-tuned LLMs on zero-shot NER benchmarks while being orders of magnitude smaller (≈300M parameters vs. 7B+) and faster (parallel extraction vs. autoregressive generation). This makes it an ideal building block for production extraction pipelines where latency and cost matter.
GLiNER frames NER as a matching problem between entity-type embeddings and text-span embeddings in a shared latent space. The architecture has three components:
Instead of classifying each token into a fixed label set (the traditional BIO-tagging approach), GLiNER computes a dot-product similarity between every candidate span embedding and every entity-type embedding. A span is labeled with an entity type when their similarity exceeds a learned threshold. This formulation is what enables zero-shot generalization: new entity types are just new embeddings in the same space.
The model concatenates entity type labels and the input text into a single sequence, separated by a special learned [ENT] token:
[CLS] person [ENT] organization [ENT] location [ENT] [SEP] The CEO of Acme Corp visited Paris . [SEP]
The BiLM processes this entire sequence bidirectionally, allowing entity type representations and text token representations to attend to each other through self-attention. This cross-attention is critical — it lets the model contextualize what “person” means in the context of the specific sentence.
After encoding, two parallel heads extract the representations needed for matching:
(i, j) in the text, the span module combines the start and end token embeddings (and optionally a width embedding) into a fixed-size vector. The model considers all spans up to a maximum length (typically 12 tokens).[ENT] markers) are pooled and passed through a feedforward network to produce entity-type vectors in the shared space.The final step computes a matching score for every (span, entity-type) pair:
score(span_i, entity_j) = sigmoid(dot(span_emb_i, entity_emb_j))
# If score > threshold → label span_i as entity_j
# Threshold is typically 0.5, tunable per use case
Because all spans and all entity types are processed in parallel, GLiNER extracts all entities in a single forward pass — no beam search, no autoregressive decoding. On a modern GPU, this typically takes 5–15 ms for a paragraph of text with 5–10 entity types.
GLiNER is trained on a large, diverse NER dataset covering hundreds of entity types. The training objective is binary cross-entropy on the matching scores. Crucially, during training the model sees a different subset of entity types per batch, forcing it to learn general entity-type representations rather than memorizing a fixed label set. This curriculum is what gives GLiNER its zero-shot capability.
LLMs like GPT-4 can do zero-shot NER via prompting, but they generate tokens sequentially (slow), hallucinate entities that aren’t in the text (unreliable), and cost 10–100× more per token. GLiNER’s encoder-based parallel extraction is deterministic, faster, and cheaper — making it the right tool for high-volume production pipelines where you need structured extraction, not free-form generation.
GLiNER serves as the entity extraction front-end in a KG pipeline: extract entities with GLiNER, then extract relations between them using GLiREL (its companion relation extraction model) or an LLM. The combination provides a fast, accurate, and cost-effective alternative to running an LLM for both tasks. See the companion topic on Relation Extraction for Knowledge Graphs for the relation extraction step.
In legal, financial, and medical document processing, GLiNER can extract domain-specific entities (contract parties, monetary amounts, drug names, diagnoses) without needing labeled training data for each new document type. Users simply specify the entity types they want at inference time.
GLiNER can enrich chunks in a Retrieval-Augmented Generation pipeline by extracting structured metadata (entities, dates, locations) at indexing time. This metadata enables hybrid retrieval strategies that combine semantic search with entity-based filtering.
from gliner import GLiNER
model = GLiNER.from_pretrained("urchade/gliner_medium-v2.1")
text = "Dr. Sarah Chen at MIT published a study on CRISPR-Cas9 gene editing."
labels = ["person", "organization", "technology"]
entities = model.predict_entities(text, labels, threshold=0.5)
# [{"text": "Dr. Sarah Chen", "label": "person", "score": 0.94},
# {"text": "MIT", "label": "organization", "score": 0.97},
# {"text": "CRISPR-Cas9 gene editing", "label": "technology", "score": 0.88}]
The gliner Python package supports models from the Hugging Face Hub, including community-contributed fine-tuned variants for specific domains (biomedical, legal, multilingual).