fastino-ai/GLiNER2
Unified Schema-Based Information Extraction
GLiNER2 – Unified, schema‑driven information extraction
What it is – GLiNER2 is a Python library that lets you run a single local model for many text‑understanding tasks: named‑entity recognition, multi‑label classification, structured record extraction, relation extraction, and even span‑level attributes (e.g., sentiment on a detected entity). The model is schema‑conditioned: you describe the fields you want (the “schema”) and the same forward pass returns all requested outputs.
Why it matters – Most toolkits require separate models for NER, classification, or JSON‑style extraction. GLiNER2 bundles them, supports two architectures (a classic fixed‑grid span model and a newer boundary model that can handle arbitrarily long spans), and runs efficiently on CPU‑only hardware, making it suitable for privacy‑sensitive or edge deployments.
Core capabilities
| Capability | How you invoke it | Highlights |
|---|---|---|
| Entity extraction | model.extract_entities(text, labels, …) |
Returns entities per label, optional confidence scores and character offsets. |
| Text classification | model.classify_text(text, schema, …) |
Single‑ or multi‑label, supports thresholds and confidence. |
| Structured JSON extraction | model.extract_json(text, schema, …) |
Pulls nested records (e.g., product specs) into a dict/list structure. |
| Relation extraction | model.extract_relations(...) (via schema) |
Produces typed entity‑relation triples. |
| Span attributes | model.extract_entities(..., include_attributes=True) |
Attach extra tags such as sentiment to each span. |
| Long‑document handling | extract_entities_long / batch_extract_entities_long |
Automatically chunks, overlaps, and merges results beyond the model’s context window. |
Two model families
| Architecture | Checkpoint example | Size | Typical use |
|---|---|---|---|
| Span (GLiNER2) – fixed‑width grid | fastino/gliner2-base-v1 |
205 M (DeBERTa‑v3‑base) | Legacy models, small‑to‑medium tasks. |
| Boundary (GLiNER2.5) – sparse start/end pairing, any span length | fastino/gliner2.5-base-v1 |
194 M (DeBERTa‑v3‑base) | Default English multi‑task, best CPU/edge performance. |
| Multilingual | fastino/gliner2-multi-v1 / gliner2.5-multi-v1 |
205‑287 M (mDeBERTa‑v3) | Works on non‑English texts. |
| Safety / PII | fastino/gliguard-LLMGuardrails-300M, gliner2-privacy-filter-PII-multi |
~300 M | Detects toxic content or personal data; can be loaded via the same AutoExtractor. |
Quick start (CPU‑only)
# Core library – no torch needed (schema validation, API client)
pip install gliner2
# Add local inference (torch & model weights)
pip install "gliner2[local]"
from gliner2 import AutoExtractor
model = AutoExtractor.from_pretrained("fastino/gliner2.5-base-v1")
text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday."
result = model.extract_entities(
text,
["company", "person", "product", "location"],
include_confidence=True,
include_spans=True,
)
print(result)
# → {'entities': {'company':[{'text':'Apple','confidence':0.95,'start':0,'end':5}], ...}}
The same model object also supports classify_text, extract_json, and the long‑document APIs shown in the README.
Installation extras
| Extra | What it adds |
|---|---|
gliner2[local] |
PyTorch, model weights, AutoExtractor for on‑device inference |
gliner2[train] |
Training utilities, LoRA adapters, recipe configs |
gliner2[test] / gliner2[dev] |
Test suites, linting, benchmarking tools |
Community & resources
- Discord – https://discord.gg/fastino (real‑time help)
- Reddit – r/GLiNER (discussions, use‑cases)
- Documentation – tutorials covering classification, NER, JSON extraction, relation extraction, long‑context handling, safety/PII models, and LoRA fine‑tuning.
- Model hub – All checkpoints are hosted on Hugging Face under the fastino/gliner2‑family collection.
When to use GLiNER2
- You need multiple IE tasks from the same text without loading several models.
- You prefer local, CPU‑friendly inference for privacy or edge devices.
- Your data follows a well‑defined schema (e.g., “extract product name, price, and colors”).
- You want to extend or fine‑tune the model with your own data via the provided LoRA adapters.
TL;DR
GLiNER2 is a schema‑driven, single‑model library for extracting entities, classifications, structured records, relations, and span attributes. It ships with both span‑grid and boundary architectures, runs efficiently on CPUs, offers a privacy‑first local inference path, and provides ready‑to‑use multilingual checkpoints as well as safety/PII models.
Related
- Project
- Project
- Project
- Project
- Project