fastino-ai/GLiNER2

Unified Schema-Based Information Extraction

GLiNER2 – Unified Schema‑Based Information Extraction & Classification

What it does (in plain language)

GLiNER2 is a local, Python‑based library that lets you pull structured information out of raw text – everything from classic named‑entity recognition (people, companies, dates) to full‑blown record extraction, relation detection, and text classification. All of these tasks share a single schema you define, and the same model can handle them in one forward pass.

Why it matters

  • One model, many jobs – No need to train separate NER, classification, or relation‑extraction models. Define a schema once and the library will predict all requested fields.
  • Two inference styles –
    • Span (GLiNER2) – a fixed‑width grid, useful for legacy checkpoints.
    • Boundary (GLiNER2.5) – a sparse start‑/end‑pair architecture that can represent spans of any length, giving better coverage for long entities.
  • CPU‑first – Designed to run quickly on ordinary CPUs; GPUs are optional for extra speed.
  • Privacy‑first – All processing happens locally, no data leaves your machine.

How you use it (quick start)

# Core library – no heavy dependencies
pip install gliner2

# Add local inference (PyTorch + optional flash‑attention)
pip install "gliner2[local]"
from gliner2 import AutoExtractor

# Load a ready‑made English model (boundary architecture)
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'], ...}}

The same AutoExtractor also loads span‑only checkpoints, safety/PII models, and classification‑focused checkpoints.

Key features (from the README)

Feature What it gives you
Unified schema API Define entities, classifications, records, relations, and span attributes in a single JSON‑like schema.
Constrained decoding Classifier enforces cross‑task label rules; JointIE builds typed entity‑relation graphs.
Long‑document support Chunk‑and‑overlap APIs (extract_entities_long) let you process texts longer than the model’s context window while preserving global character offsets.
Custom word splitters Switch between whitespace and character‑level tokenisation (useful for Chinese or other non‑space languages).
Quantisation & compilation Optional fp16 quantisation and torch.compile for faster GPU inference.
Safety & PII models Pre‑fine‑tuned checkpoints (gliguard‑LLMGuardrails, gliner2‑privacy‑filter‑PII) for redacting personal data or applying guardrails.
LoRA adapters Parameter‑efficient fine‑tuning via the [train] extra.

Available models (summary)

Model Params Architecture Language Typical use
gliner2-base-v1 205 M Span English General IE (legacy)
gliner2.5-base-v1 194 M Boundary English Default multi‑task IE
gliner2.5-multi-v1 287 M Boundary Multilingual Multi‑language IE
GLiNER2.5-Decide 340 M Span English Pure text classification
gliguard‑LLMGuardrails‑300M ~300 M Span – Safety / toxicity filtering
gliner2‑privacy‑filter‑PII‑multi 205 M Span Multilingual PII detection

When you’d pick GLiNER2

  • You need local inference (no cloud API, GDPR‑compliant).
  • Your downstream task mixes entity extraction, classification, and relational data – e.g., extracting a product catalog from a brochure while also tagging sentiment.
  • You run on CPU‑only servers or edge devices and still want decent speed.
  • You want a single, schema‑driven interface rather than stitching together separate NER, classifier, and relation‑extraction pipelines.

Limitations (as described)

  • The boundary architecture (GLiNER2.5) requires the [local] extra (PyTorch) – the core gliner2 package alone only provides the schema utilities and a cloud‑API client.
  • Switching word splitters at inference time can degrade accuracy unless the model was trained with the same splitter.
  • For the highest accuracy on English IE, the README recommends the gliner2.5-base-v1 checkpoint; smaller models trade speed for performance.

All details above are taken directly from the project's README; no external assumptions have been added.

Related

  • Project
  • Project
  • Project
  • Project
  • Project