sample1/
sample1.rs

1//! Complete example for zero-shot text classification.
2//! Reproduces the example from <https://github.com/Knowledgator/GLiClass>, and
3//! checks the results against the numbers obtained with the original implementation.
4
5use gliclass::{GLiClass, params::Parameters, input::text::TextInput};
6
7fn main() -> gliclass::util::result::Result<()> {    
8    const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
9    const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";    
10
11    let gliclass = GLiClass::new(TOKENIZER_PATH, MODEL_PATH, Parameters::default())?;
12            
13    let input = TextInput::from_str(
14        &["One day I will see the world!"],
15        &["travel", "dreams", "sport", "science", "politics"],
16    ); 
17
18    let classes = gliclass.inference(input)?;
19    println!("Scores: {:?}", classes.scores);
20
21    // check the results against the results obtained with the original implementation
22    assert!(gliclass::util::test::is_close_to_a(
23        &classes.scores.slice(ndarray::s![0, ..]), 
24        &[0.9999985694885254, 0.9999986886978149, 0.9999117851257324, 0.9996119141578674, 0.8172177672386169],
25        0.00001,
26    ));
27
28    Ok(())
29}
30
31