Skip to main content

gliner2_candle/
lib.rs

1// Rust guideline compliant 2026-04-03
2//! GLiNER2 / GLiNER2.5 Rust Implementation
3//!
4//! A pure Rust (candle) port of the GLiNER2 span-enumeration and GLiNER2.5
5//! boundary-prediction information extraction models, providing efficient
6//! CPU-based inference for entity extraction, text classification, structured
7//! data extraction, relation extraction, and span attributes — with numeric
8//! parity against the Python reference.
9//!
10//! # Quick Start (GLiNER2)
11//!
12//! ```ignore
13//! use gliner2_candle::GLiNER2;
14//! use gliner2_candle::schema::SchemaBuilder;
15//!
16//! // Load model (sync; downloads weights from HuggingFace Hub on first run)
17//! let model = GLiNER2::from_pretrained("fastino/gliner2-base-v1")?;
18//!
19//! // Extract entities
20//! let schema = SchemaBuilder::new()
21//!     .entities(vec!["person".to_string(), "company".to_string()])
22//!     .build()?;
23//!
24//! let result = model.extract_entities("Apple CEO Tim Cook", &schema)?;
25//! ```
26//!
27//! # Quick Start (GLiNER2.5)
28//!
29//! GLiNER2.5 uses the boundary pipeline via `engine.extract` with a
30//! `Schema::new` + optional `AttributeGroup`s schema. See the README for a
31//! full example.
32//!
33//! # Features
34//!
35//! - **GLiNER2**: span-enumeration entity extraction with confidence scores and span positions
36//! - **GLiNER2.5**: boundary prediction with entities, classifications, relations, and span attributes
37//! - **Span Attributes**: single-/multi-label attributes attached to retained spans
38//! - **Text Classification**: single and multi-label classification
39//! - **Relation Extraction**: relationship extraction between entities
40//! - **Long Documents**: auto-chunking (>384 words) and merge in `batch_extract`
41//! - **CPU Optimized**: fast inference on standard hardware without GPU
42
43// -------------------------------------------------------------------------
44// Public API
45// -------------------------------------------------------------------------
46
47pub mod batch;
48pub mod chunking;
49pub mod config;
50pub mod constraints;
51pub mod error;
52pub mod inference;
53pub mod model;
54pub mod schema;
55pub mod tokenizer;
56
57// Re-export main types for convenience
58pub use config::ExtractorConfig;
59pub use error::{GlinerError, Result};
60pub use inference::engine::GLiNER2;
61pub use schema::SchemaBuilder;
62pub use tokenizer::WhitespaceTokenizer;
63
64// -------------------------------------------------------------------------
65// Version
66// -------------------------------------------------------------------------
67
68/// Library version.
69pub const VERSION: &str = env!("CARGO_PKG_VERSION");