GLiNER2
Extract entities, relations, classifications, and structured records from text with labels you choose at request time. This is Antfly's package of Fastino's GLiNER2 base checkpoint.
antfly inference pull antflydb/gliner2-base-v1Technical Specs
- Architecture
- GLiNER2 / DeBERTa-v3-base
- Parameters
- 208M
About GLiNER2
GLiNER2 is a unified multi-task model that performs named entity recognition, zero-shot classification, relation extraction, and structured JSON extraction from a single model. It uses a DeBERTa-v3-base encoder with the GLiNER2 architecture.
Unlike traditional NER models that are limited to predefined entity types, GLiNER2 accepts arbitrary labels at inference time, making it extremely flexible for diverse extraction tasks.
GLiNER2 is a zero-shot model: you define the entity types, relation types, or classification labels at query time. No fine-tuning required.
Capabilities
- Named Entity Recognition: Extract entities with custom labels
- Relation Extraction: Extract (subject, relation, object) triplets from text
- Zero-Shot Classification: Classify text into arbitrary categories
- JSON Extraction: Extract structured data matching a schema
Use Cases
| Use Case | Description |
|---|---|
| Document Processing | Extract people, organizations, dates from contracts or reports |
| Knowledge Graphs | Build knowledge graphs by extracting entities and their relationships |
| Content Tagging | Classify articles, support tickets, or reviews into custom categories |
| Data Extraction | Pull structured fields from unstructured text (e.g., invoices, resumes) |
Antfly Inference API Usage
Pull the model and start Antfly:
antfly inference pull antflydb/gliner2-base-v1
antfly standalone
Every task goes through /ai/v1/extract. Declare entities, relations, classifications, and structures under schema.
Named Entity Recognition
Extract entities with custom labels. No predefined entity types are needed.
curl -X POST "http://localhost:8080/ai/v1/extract" \
-H "Content-Type: application/json" \
-d '{
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Steve Jobs founded Apple in Cupertino, California."}],
"schema": {"entities": ["person", "organization", "location"]}
}'import requests
response = requests.post(
"http://localhost:8080/ai/v1/extract",
json={
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Steve Jobs founded Apple in Cupertino, California."}],
"schema": {"entities": ["person", "organization", "location"]}
}
)
entities = response.json()["data"][0]["entities"]
# [{"text": "Steve Jobs", "label": "person", "start": 0, "end": 10, "score": 0.98}, ...]const response = await fetch("http://localhost:8080/ai/v1/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "antflydb/gliner2-base-v1",
inputs: [{ content: "Steve Jobs founded Apple in Cupertino, California." }],
schema: { entities: ["person", "organization", "location"] }
})
});
const { data } = await response.json();
const entities = data[0].entities;Relation Extraction
Extract relationships between entities as typed edges. Each relation names its source and target entity types:
curl -X POST "http://localhost:8080/ai/v1/extract" \
-H "Content-Type: application/json" \
-d '{
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Steve Jobs founded Apple in 1976."}],
"schema": {
"entities": ["person", "organization"],
"relations": [
{"type": "founded_by", "source": "organization", "target": "person"}
]
}
}'import requests
response = requests.post(
"http://localhost:8080/ai/v1/extract",
json={
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Steve Jobs founded Apple in 1976."}],
"schema": {
"entities": ["person", "organization"],
"relations": [
{"type": "founded_by", "source": "organization", "target": "person"}
]
}
}
)
result = response.json()["data"][0]
# Relation endpoints index into result["entities"]
# [{"type": "founded_by", "source": {"entity_index": 1}, "target": {"entity_index": 0}, "score": 0.95}]
relations = result["relations"]const response = await fetch("http://localhost:8080/ai/v1/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "antflydb/gliner2-base-v1",
inputs: [{ content: "Steve Jobs founded Apple in 1976." }],
schema: {
entities: ["person", "organization"],
relations: [
{ type: "founded_by", source: "organization", target: "person" }
]
}
})
});
const { data } = await response.json();
const { entities, relations } = data[0];Zero-Shot Classification
Classify text into arbitrary categories:
curl -X POST "http://localhost:8080/ai/v1/extract" \
-H "Content-Type: application/json" \
-d '{
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Apple reported record quarterly revenue of $124 billion."}],
"schema": {
"classifications": [
{"name": "topic", "labels": ["finance", "technology", "sports", "politics"]}
]
}
}'import requests
response = requests.post(
"http://localhost:8080/ai/v1/extract",
json={
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "Apple reported record quarterly revenue of $124 billion."}],
"schema": {
"classifications": [
{"name": "topic", "labels": ["finance", "technology", "sports", "politics"]}
]
}
}
)
classifications = response.json()["data"][0]["classifications"]const response = await fetch("http://localhost:8080/ai/v1/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "antflydb/gliner2-base-v1",
inputs: [{ content: "Apple reported record quarterly revenue of $124 billion." }],
schema: {
classifications: [
{ name: "topic", labels: ["finance", "technology", "sports", "politics"] }
]
}
})
});
const { data } = await response.json();
const { classifications } = data[0];Structured Extraction
Extract structured records with named fields:
curl -X POST "http://localhost:8080/ai/v1/extract" \
-H "Content-Type: application/json" \
-d '{
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "John Smith is a 35-year-old engineer at Google in Mountain View."}],
"schema": {
"structures": {
"person": {
"fields": {"name": "str", "age": "str", "job_title": "str", "company": "str", "city": "str"}
}
}
}
}'import requests
response = requests.post(
"http://localhost:8080/ai/v1/extract",
json={
"model": "antflydb/gliner2-base-v1",
"inputs": [{"content": "John Smith is a 35-year-old engineer at Google in Mountain View."}],
"schema": {
"structures": {
"person": {
"fields": {"name": "str", "age": "str", "job_title": "str", "company": "str", "city": "str"}
}
}
}
}
)
structures = response.json()["data"][0]["structures"]const response = await fetch("http://localhost:8080/ai/v1/extract", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
model: "antflydb/gliner2-base-v1",
inputs: [{ content: "John Smith is a 35-year-old engineer at Google in Mountain View." }],
schema: {
structures: {
person: {
fields: { name: "str", age: "str", job_title: "str", company: "str", city: "str" }
}
}
}
})
});
const { data } = await response.json();
const { structures } = data[0];Supported Tasks
| Task | Schema field | Description |
|---|---|---|
| NER | entities | Extract entities with custom labels |
| Relations | relations | Extract typed relations between extracted entities |
| Classification | classifications | Zero-shot text classification |
| Structured extraction | structures | Extract records with named fields |
GLiNER2 has a 512 token context limit. For longer documents, split into chunks before processing.
Antfly Configuration
Use GLiNER2 as the extractor in an Antfly configuration:
{
"provider": "antfly",
"model": "antflydb/gliner2-base-v1"
}