pub struct GLiClass { /* private fields */ }Expand description
Convenience front-end for easy use with default runtime parameters (CPU).
For more advanced use, see examples and the orp crate.
Implementations§
Source§impl GLiClass
impl GLiClass
Sourcepub fn new<P: AsRef<Path>>(
tokenizer_path: P,
model_path: P,
params: Parameters,
) -> Result<Self>
pub fn new<P: AsRef<Path>>( tokenizer_path: P, model_path: P, params: Parameters, ) -> Result<Self>
Loads the model given a tokenizer, an ONNX model, and the required parameters
Examples found in repository?
examples/sample1.rs (line 11)
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}Sourcepub fn inference(&self, input: TextInput) -> Result<Classes>
pub fn inference(&self, input: TextInput) -> Result<Classes>
Performs classification on the given output
Examples found in repository?
examples/sample1.rs (line 18)
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}Auto Trait Implementations§
impl !Freeze for GLiClass
impl !RefUnwindSafe for GLiClass
impl Send for GLiClass
impl Sync for GLiClass
impl Unpin for GLiClass
impl !UnwindSafe for GLiClass
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more