candle-native · ≅ Python

Two architectures. Zero drift.

gliner2-candle ports both GLiNER2 (span-enumeration) and GLiNER2.5 (boundary-prediction) into a pure-Rust stack on HuggingFace Candle. It loads real Hub weights and reproduces the Python reference numerics — not just top-1 spans, but the whole candidate matrix.

Architecture

Two pipelines, one candle backend. From collation to thresholded extraction, every stage is explicit and debuggable.

  • Custom DeBERTa-v3 encoder — sign-corrected relative positions + exact-erf GELU
  • GLiNER2: markerV0 span rep + classifier / count heads
  • GLiNER2.5: boundary encoder + shared-pool scorer with relation reranker
  • Span attributes via hidden entity queries (score_explicit_spans) — no dedicated weights
  • Long documents auto-chunked (>384 words), merged with overlap policies

Pipeline

Text + schema flow through explicit, inspectable stages.

Text + Schema → Collator → DeBERTa V3
└ Span Rep / Boundary Head
→ Pooled Scoring → Decode + Merge
→ Entities Classifications Relations Attributes
GLiNER2.5 boundary path shown; GLiNER2 spans the same encoder.

Numeric Parity vs Python

Validated against the reference candidate matrix, not just the winning spans.

Entities · global
0.0000
full-matrix agreement
Entities · relevant
0.0000
full-matrix agreement
Classifications
exact
output match
Relations
exact
bare-pair format
Attributes · single
8 dp
0.9966161847 · softmax
Attributes · multi
7 dp
0.5735875 · sigmoid

Why "candle"?

crates.io already has GLiNER2 crates — on ONNX Runtime. This one is pure Rust.

Backend Runtime
gliner2 / gliner2-rs ONNX
gliner2-tch libtorch
this crate Candle ✓

Status

Both architectures run end-to-end with documented parity. Remaining work is release / CI packaging and GPU validation — nothing blocking inference.

cargo test: 148 pass clippy: 0 warnings audit: 0 vulns crates.io publish: planned