๐Ÿท๏ธ gliclass-rs: GLiClass inferences in Rust

March 28, 2025 ยท View on GitHub

๐Ÿ’ฌ Introduction

gliclass-rs is an inference engine for GLiClass language models.

These models are efficient for zero-shot topic classification or derivatives like sentiment analysis. They can also be used for efficient re-ranking.

"GLiClass" stands for "Generalist and Lightweight Model for Sequence Classification", after an original work from Knowledgator, which was itself inspired by GLiNER.

gliclass-rs is built in pure Rust, as an ๐Ÿงฉ orp pipeline.

๐ŸŽ“ Examples

[dependencies]
"gliclass-rs" = "0.9.x"
use gliclass::{GLiClass, params::Parameters, input::text::TextInput};

let gliclass = GLiClass::new("tokenizer.json", "model.onnx", Parameters::default())?;
        
let input = TextInput::from_str(
    &[
        "Rust is a systems programming language focused on safety, speed, and concurrency.",
        "Traveling is the perfect way to explore new cultures through their food.",
        "Traveling for science allows researchers to collaborate with experts worldwide.",
    ],
    &["computing", "science", "programming", "travel", "food", "politics"]
);    

let classes = gliclass.inference(input)?;

for i in 0..classes.len() {
    println!("Text {i}: {}", classes.best_label(i, None).unwrap());        
}

Please refer the the source code in examples for complete examples.

๐Ÿงฌ Models

Currently gliclass-rs has been tested with the following models:

ModelDownloadprompt_first
gliclass-small-1.0HF Hubfalse
gliclass-large-1.0HF Hubfalse
gliclass-modern-base-v2.0-initHF Hubtrue
gliclass-modern-large-v2.0HF Hubtrue

It should work out-of-the-box with other equivalent models, please report your own experiments.

โš ๏ธ Take care of setting the prompt_first parameter according the selected model's expectations, or read parameters from the config.json that goes with the model (0.9.1+).

This project follows the same principles as the ones below. Refer to their documentation for more details:

  • ๐ŸŒฟ gline-rs: inference engine for GLiNER models
  • ๐Ÿงฒ gte-rs: general text embedding and re-ranking