🔗 GLiNER-relex: Generalist and Lightweight Model for Joint Zero-Shot NER and Relation Extraction
GLiNER-relex is a unified model for zero-shot Named Entity Recognition (NER) and Relation Extraction (RE) that performs both tasks simultaneously in a single forward pass. Built on the GLiNER architecture, it extends the span-based approach to jointly identify entities and extract relationships between them.
✨ Key Features
- Joint Extraction: Simultaneously extracts entities and relations in one forward pass
- Zero-Shot: No fine-tuning required — specify entity types and relation types at inference time
- Label Descriptions: Supports natural language descriptions for entity labels, improving accuracy by providing richer semantic context to the model
- "Other" Entity Type: Use the special
"other" label to extract entities whose types are not explicitly defined but can be inferred from the specified relations
- Efficient: Single encoder architecture processes both tasks together
- Flexible: Supports custom entity and relation schemas per inference call
- Production-Ready: ONNX export support for deployment
📦 Installation
First, install the GLiNER library:
🚀 Quick Start
Basic Usage
Expected output:
Using Label Descriptions
You can provide natural language descriptions for entity labels to give the model richer context, which can improve extraction accuracy, especially for ambiguous or domain-specific types:
When using descriptions, pass labels as a dictionary where keys are label names and values are their descriptions. The model encodes these descriptions alongside the text for better semantic matching.
Using the "Other" Entity Type
When you want to extract entities involved in specific relations without predefining every entity type, use the special "other" label. The model will identify entities based on the relations they participate in, even if their type does not match any of the explicitly defined labels:
Expected output:
This is particularly useful when:
- You care more about extracting relations than classifying every entity type
- The set of possible entity types is open-ended or unknown
- You want to discover entities that are connected to known types through specific relations
Batch Processing
Entity-Only Extraction
If you only need entities without relations:
⚙️ Advanced Configuration
Adjusting Thresholds
You can fine-tune extraction sensitivity with separate thresholds:
We recommend lowering the threshold (entity extraction threshold) and keeping it in the range of 0.3–0.5. For adjacency_threshold, the model provides good results in the 0.5–0.65 range. For relation_threshold, use larger values like 0.7–0.9. Feel free to adjust all of these values based on your project requirements.
📊 Output Format
Entity Format
Relation Format
🏗️ Architecture
GLiNER-relex uses a unified encoder architecture that:
- Encodes text and labels jointly using a transformer backbone.
- Identifies entity spans using span-based classification.
- Constructs an adjacency matrix to identify potential entity pairs using graph convolutional networks.
- Classifies relations between selected entity pairs.
This joint approach allows the model to leverage entity information when extracting relations, leading to more coherent predictions.
📚 Use Cases
- Knowledge Graph Construction: Extract structured facts from unstructured text
- Information Extraction Pipelines: Build end-to-end IE systems
- Document Understanding: Extract entities and their relationships from documents
- Question Answering: Power QA systems with structured knowledge
- Data Enrichment: Automatically annotate text corpora