GLiNER-bi-Encoder: Scalable Zero-Shot Named Entity Recognition
image
About
GLiNER-bi-Encoder is a novel architecture for Named Entity Recognition (NER) that combines zero-shot flexibility with industrial-scale efficiency. Unlike the original GLiNER, which uses joint encoding, the bi-encoder design decouples text and entity-type encoding, enabling the recognition of thousands of entity types simultaneously with minimal computational overhead.
Key Advantages
Massive Scalability: Handle 1000+ entity types with near-constant inference speed when using pre-computed label embeddings
130× Faster: Up to 130× throughput improvement compared to uni-encoder approaches at 1024 entity types
State-of-the-Art Performance: Achieves 61.5% Micro-F1 on CrossNER benchmark in zero-shot setting
Efficient Caching: Pre-compute and cache entity type embeddings for instant reuse across millions of documents
Architecture
The bi-encoder architecture employs two specialized, independent transformers:
Text Encoder: Processes input sequences using ModernBERT-based encoders (Ettin family)
Label Encoder: Embeds entity type descriptions using specialized sentence transformers (BGE, MiniLM)
This separation removes the context-window bottleneck and enables:
Pre-computation of entity type embeddings
Constant memory usage for text encoding regardless of entity count
Efficient nearest-neighbor search for entity matching
Recommendation: The base variant (194M) achieves 98% of large model performance while operating 2.6× faster, making it optimal for most production scenarios.
1from gliner import GLiNER
23# Load model4model = GLiNER.from_pretrained("knowledgator/gliner-bi-base-v2.0")56text ="""
7Cristiano 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, a record three UEFA Men's Player of the Year Awards, and four European Golden Shoes, the most by a European player.
8"""910labels =["person","award","date","competitions","teams"]1112entities = model.predict_entities(text, labels, threshold=0.3)1314for entity in entities:15print(entity["text"],"=>", entity["label"])
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
Advanced Usage: Pre-computing Entity Embeddings
For scenarios with large, static entity taxonomies (hundreds to millions of types):
python
1from gliner import GLiNER
23model = GLiNER.from_pretrained("knowledgator/gliner-bi-base-v2.0")45# Pre-compute embeddings for thousands of entity types6entity_types =["person","organization","location",...]# Can be thousands7texts =["Your documents here",...]89# Encode entity types once10entity_embeddings = model.encode_labels(entity_types, batch_size=8)1112# Use pre-computed embeddings for fast inference13outputs = model.batch_predict_with_embeds(texts, entity_embeddings, entity_types)
This approach provides:
130× speedup at 1024 entity types
Constant inference time regardless of entity count