Schema-driven information extraction and classification — entities, labels, records, relations, and span attributes in one local model.
GLiNER2 is a schema-conditioned encoder family for Named Entity Recognition, Text Classification, Structured Data Extraction, Relation Extraction, and span attributes. Two extraction architectures share one public API:
span (GLiNER2 / SpanExtractor) — fixed-width span grid; legacy checkpoints and specialty fine-tunes (GLiGuard, PII).boundary (BoundaryExtractor, GLiNER2.5) — sparse start/end pairing; any span length within the encoded window.Load any Hub checkpoint with AutoExtractor.from_pretrained(...). It dispatches by the saved architecture field. GLiNER2.from_pretrained(...) remains span-only and will not load GLiNER2.5 boundary checkpoints.
Fine-tune via Fastino. Join discussions on Discord and Reddit.
AutoExtractorClassifier for cross-task label rules; JointIE for typed entity–relation graphsGLiNER2 requires Python 3.10 or newer and is tested on Python 3.10 to 3.12. The
local, train, and benchmark profiles install PyTorch, so they also need a
Python version that PyTorch publishes wheels for. Local profiles support
Transformers 4.43 through 5.x. Choose the smallest install profile that matches
your use case:
# Schema validation, API client, training-data utilities — no torch required
pip install gliner2
# Local model inference and LoRA support
pip install gliner2[local]
# Local inference with optimized DeBERTa-v2/v3 attention
pip install "gliner2[disentangled-flash]"
# Model training and recipe configuration (adds sentencepiece and protobuf,
# needed to build models from raw encoders such as microsoft/deberta-v3-base)
pip install gliner2[train]
# Reproducible tests, contributor tooling, or benchmarks
pip install gliner2[test]
pip install gliner2[dev]
pip install gliner2[benchmark]
The base install gives you Schema, SchemaInput, RegexValidator, GLiNER2API,
InputExample, TrainingDataset, and all JSONL validation tooling — everything
needed to build schemas, validate data, and call the cloud API without pulling in
PyTorch. API is a concise alias for GLiNER2API:
from gliner2 import API, InputExample, Schema, TrainingDataset
The torch-free API client partitions batch requests locally and can scan long documents without changing the server protocol:
client = API() # reads FASTINO_API_KEY
results = client.batch_extract_entities(
documents,
["company", "person"],
batch_size=8,
)
long_result = client.extract_entities_long(
annual_report,
["company", "person"],
chunk_size=384,
chunk_overlap=64,
include_spans=True,
)
To load and run models locally, install the [local] extra and use
AutoExtractor — it loads span, boundary, GLiGuard, and PII checkpoints:
from gliner2 import AutoExtractor # requires gliner2[local]
# Default English GLiNER2.5 boundary checkpoint
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"])
print(result)
# {'entities': {'company': ['Apple'], 'person': ['Tim Cook'], 'product': ['iPhone 15'], 'location': ['Cupertino']}}
For legacy span checkpoints or explicit span-only loading, GLiNER2.from_pretrained("fastino/gliner2-base-v1") still works (GLiNER2 = SpanExtractor).
Enable fp16 and/or torch.compile for faster inference — no extra dependencies required.
# fp16
model = AutoExtractor.from_pretrained("fastino/gliner2.5-base-v1", map_location="cuda", quantize=True)
# torch.compile (fused GPU kernels, first call triggers tracing)
model = AutoExtractor.from_pretrained("fastino/gliner2.5-base-v1", map_location="cuda", compile=True)
# Both
model = AutoExtractor.from_pretrained("fastino/gliner2.5-base-v1", map_location="cuda", quantize=True, compile=True)
# Or after loading
model.quantize()
model.compile()
GLiNER2 first splits text into word tokens, then encodes those tokens with the model's subword tokenizer. The default "whitespace" splitter is the one used to train public checkpoints.
For languages without whitespace-delimited words, such as Chinese, use the character-level splitter:
model = AutoExtractor.from_pretrained(
"fastino/gliner2.5-base-v1",
word_splitter="char",
)
# Or after loading
model.set_word_splitter("char")
Built-in names:
| Name | Class | Use when |
|---|---|---|
"whitespace" (default) |
WhitespaceTokenSplitter |
Space-delimited languages; matches public checkpoints |
"char" |
CharLevelSplitter |
Languages such as Chinese; keeps Latin words/emails intact and splits other non-space characters |
You can also pass a custom callable that yields (token, start, end) with exclusive-end offsets into the original text:
from gliner2.processor import CharLevelSplitter
model.set_word_splitter(CharLevelSplitter())
Changing a pretrained model's word boundaries can affect quality unless the model was trained with the same splitter. The choice is runtime-only: saved checkpoints reload with "whitespace" unless you pass word_splitter again.
The boundary architecture (GLiNER2.5) uses sparse start/end pairing instead of a fixed span-width grid, so spans of any length that fit in the encoded window are representable. It supports entities, classification, structured record/event decoding, sparse relations, and span attributes when enabled by the checkpoint.
See the full guide — loading, creating/training a boundary model, record and relation decoding, save/load, LoRA aliases, export mode, loss/imbalance controls, and gold-capacity policy — in docs/boundary_architecture.md and the design notes in docs/gliner2_5_boundary_architecture.md.
All models are on the GLiNER2 family collection. Load with AutoExtractor.from_pretrained(...) unless noted.
| Model | Parameters | Encoder | Language | Use case |
|---|---|---|---|---|
fastino/gliner2-base-v1 |
205M | DeBERTa-v3-base | English | Default span checkpoint |
fastino/gliner2-large-v1 |
340M | DeBERTa-v3-large | English | Higher-accuracy span |
fastino/gliner2-multi-v1 |
~205M | mDeBERTa-v3-base | Multilingual | Multilingual span |
| Model | Parameters | Encoder | Language | Use case |
|---|---|---|---|---|
fastino/gliner2.5-small-v1 |
74M | DeBERTa-v3-xsmall | English | Fast CPU / edge |
fastino/gliner2.5-base-v1 |
194M | DeBERTa-v3-base | English | Default English multi-task |
fastino/gliner2.5-multi-v1 |
287M | mDeBERTa-v3-base | Multilingual | Default multilingual multi-task |
Boundary checkpoints include classification, records, and relations when those heads are enabled. Prefer gliner2.5-base-v1 for English and gliner2.5-multi-v1 for multilingual.
| Model | Parameters | Encoder | Architecture | Language | Use case |
|---|---|---|---|---|---|
fastino/GLiNER2.5-Decide |
340M | DeBERTa-v3-large | span | English | Intent, routing, sentiment, multi-label tags |
fastino/GLiNER2.5-multi-Decide |
287M | mDeBERTa-v3-base | boundary | Multilingual | Same, multilingual |
Decide checkpoints are tuned for classification: use classify_text / batch_classify_text (or Classifier). Both load with AutoExtractor; note that GLiNER2.5-Decide is a span checkpoint despite the 2.5 name, so GLiNER2.from_pretrained also loads it, while GLiNER2.5-multi-Decide is boundary-only. Local inference needs pip install "gliner2[local]". Evaluated on fastino/fast-decisions.
| Model | Parameters | Use case |
|---|---|---|
fastino/gliguard-LLMGuardrails-300M |
~300M | LLM prompt/response guardrails (safety, toxicity, jailbreak, refusal) |
fastino/gliner2-privacy-filter-PII-multi |
205M | Multilingual PII detection (42 entity types) |
fastino/GLiNER2-Guardrails-PII-Multi |
205M | Combined guardrails + PII in one checkpoint |
See Safety, PII, and GLiGuard for usage. GLiGuard and PII models are span checkpoints; AutoExtractor and GLiNER2 both load them.
Loader cheat-sheet
| Goal | Checkpoint | |-----
| 日期 | 榜单 | 排名 | 周期新增 | 总 STAR |
|---|