pub struct Classes {
pub scores: Array2<f32>,
pub labels: Labels,
}Expand description
End-result of the classification inference pipeline.
Fields§
§scores: Array2<f32>§labels: LabelsImplementations§
Source§impl Classes
impl Classes
pub fn try_from(tensors: OutputTensors<'_>) -> Result<Self>
Sourcepub fn scores(&self, index: usize) -> Option<Vec<f32>>
pub fn scores(&self, index: usize) -> Option<Vec<f32>>
Returns the scores for each label, for the given text index, in their original order
Sourcepub fn labeled_scores(
&self,
index: usize,
threshold: Option<f32>,
) -> Option<HashMap<&String, f32>>
pub fn labeled_scores( &self, index: usize, threshold: Option<f32>, ) -> Option<HashMap<&String, f32>>
Returns the scores by label, for the given text index (with an optional threshold)
Sourcepub fn ordered_scores(
&self,
index: usize,
threshold: Option<f32>,
) -> Option<BTreeMap<OrderedFloat<f32>, &String>>
pub fn ordered_scores( &self, index: usize, threshold: Option<f32>, ) -> Option<BTreeMap<OrderedFloat<f32>, &String>>
Returns the ordered scores by label, for the given text index (with an optional threshold)
Examples found in repository?
examples/sample2.rs (line 27)
5fn main() -> gliclass::util::result::Result<()> {
6 const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
7 const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";
8
9 let params = gliclass::params::Parameters::default();
10 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
11 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
12
13 let inputs = gliclass::input::text::TextInput::from_str(
14 &[
15 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
16 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
17 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
18 ],
19 &["computing", "science", "programming", "travel", "food", "politics"]
20 );
21
22 let classes = model.inference(inputs, &pipeline, ¶ms)?;
23
24 for i in 0..classes.len() {
25 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
26 classes.best_label(i, None).unwrap(),
27 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
28 );
29 }
30
31 Ok(())
32}More examples
examples/sample4.rs (line 30)
4fn main() -> gliclass::util::result::Result<()> {
5 const TOKENIZER_PATH: &str = "models/gliclass-modern-base-v2.0-init/tokenizer.json";
6 const MODEL_PATH: &str = "models/gliclass-modern-base-v2.0-init/onnx/model.onnx";
7
8 let params = gliclass::params::Parameters::default().with_prompt_first(true);
9 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
10 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
11
12 let inputs = gliclass::input::text::TextInput::from_str_per_text(
13 &[
14 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
15 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
16 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
17 ],
18 &[
19 &["performance", "user interface"], // expecting 'performance'
20 &["gastronomy", "plane"], // expecting 'gastronomy'
21 &["conferencing", "teaching"], // expecting 'conferencing'
22 ]
23 );
24
25 let classes = model.inference(inputs, &pipeline, ¶ms)?;
26
27 for i in 0..classes.len() {
28 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
29 classes.best_label(i, None).unwrap(),
30 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
31 );
32 }
33
34 Ok(())
35}Sourcepub fn best_label(
&self,
text_index: usize,
threshold: Option<f32>,
) -> Option<&str>
pub fn best_label( &self, text_index: usize, threshold: Option<f32>, ) -> Option<&str>
Returns the best label for the given text index
Examples found in repository?
examples/sample2.rs (line 26)
5fn main() -> gliclass::util::result::Result<()> {
6 const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
7 const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";
8
9 let params = gliclass::params::Parameters::default();
10 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
11 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
12
13 let inputs = gliclass::input::text::TextInput::from_str(
14 &[
15 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
16 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
17 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
18 ],
19 &["computing", "science", "programming", "travel", "food", "politics"]
20 );
21
22 let classes = model.inference(inputs, &pipeline, ¶ms)?;
23
24 for i in 0..classes.len() {
25 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
26 classes.best_label(i, None).unwrap(),
27 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
28 );
29 }
30
31 Ok(())
32}More examples
examples/sample3.rs (line 29)
5fn main() -> gliclass::util::result::Result<()> {
6 const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
7 const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";
8
9 let params = gliclass::params::Parameters::default();
10 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
11 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
12
13 let inputs = gliclass::input::text::TextInput::from_str_per_text(
14 &[
15 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
16 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
17 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
18 ],
19 &[
20 &["performance", "user interface"], // expecting 'performance'
21 &["gastronomy", "plane"], // expecting 'gastronomy'
22 &["conferencing", "teaching"], // expecting 'conferencing'
23 ]
24 );
25
26 let classes = model.inference(inputs, &pipeline, ¶ms)?;
27
28 for i in 0..classes.len() {
29 println!("Text {i} => {}", classes.best_label(i, None).unwrap());
30 }
31
32 Ok(())
33}examples/sample4.rs (line 29)
4fn main() -> gliclass::util::result::Result<()> {
5 const TOKENIZER_PATH: &str = "models/gliclass-modern-base-v2.0-init/tokenizer.json";
6 const MODEL_PATH: &str = "models/gliclass-modern-base-v2.0-init/onnx/model.onnx";
7
8 let params = gliclass::params::Parameters::default().with_prompt_first(true);
9 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
10 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
11
12 let inputs = gliclass::input::text::TextInput::from_str_per_text(
13 &[
14 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
15 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
16 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
17 ],
18 &[
19 &["performance", "user interface"], // expecting 'performance'
20 &["gastronomy", "plane"], // expecting 'gastronomy'
21 &["conferencing", "teaching"], // expecting 'conferencing'
22 ]
23 );
24
25 let classes = model.inference(inputs, &pipeline, ¶ms)?;
26
27 for i in 0..classes.len() {
28 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
29 classes.best_label(i, None).unwrap(),
30 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
31 );
32 }
33
34 Ok(())
35}Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Examples found in repository?
examples/sample2.rs (line 24)
5fn main() -> gliclass::util::result::Result<()> {
6 const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
7 const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";
8
9 let params = gliclass::params::Parameters::default();
10 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
11 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
12
13 let inputs = gliclass::input::text::TextInput::from_str(
14 &[
15 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
16 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
17 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
18 ],
19 &["computing", "science", "programming", "travel", "food", "politics"]
20 );
21
22 let classes = model.inference(inputs, &pipeline, ¶ms)?;
23
24 for i in 0..classes.len() {
25 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
26 classes.best_label(i, None).unwrap(),
27 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
28 );
29 }
30
31 Ok(())
32}More examples
examples/sample3.rs (line 28)
5fn main() -> gliclass::util::result::Result<()> {
6 const TOKENIZER_PATH: &str = "models/gliclass-small-v1.0/tokenizer.json";
7 const MODEL_PATH: &str = "models/gliclass-small-v1.0/onnx/model.onnx";
8
9 let params = gliclass::params::Parameters::default();
10 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
11 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
12
13 let inputs = gliclass::input::text::TextInput::from_str_per_text(
14 &[
15 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
16 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
17 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
18 ],
19 &[
20 &["performance", "user interface"], // expecting 'performance'
21 &["gastronomy", "plane"], // expecting 'gastronomy'
22 &["conferencing", "teaching"], // expecting 'conferencing'
23 ]
24 );
25
26 let classes = model.inference(inputs, &pipeline, ¶ms)?;
27
28 for i in 0..classes.len() {
29 println!("Text {i} => {}", classes.best_label(i, None).unwrap());
30 }
31
32 Ok(())
33}examples/sample4.rs (line 27)
4fn main() -> gliclass::util::result::Result<()> {
5 const TOKENIZER_PATH: &str = "models/gliclass-modern-base-v2.0-init/tokenizer.json";
6 const MODEL_PATH: &str = "models/gliclass-modern-base-v2.0-init/onnx/model.onnx";
7
8 let params = gliclass::params::Parameters::default().with_prompt_first(true);
9 let pipeline = gliclass::pipeline::ClassificationPipeline::new(TOKENIZER_PATH, ¶ms)?;
10 let model = orp::model::Model::new(MODEL_PATH, orp::params::RuntimeParameters::default())?;
11
12 let inputs = gliclass::input::text::TextInput::from_str_per_text(
13 &[
14 "Rust is a systems programming language focused on safety, speed, and concurrency, with a strong ownership model that prevents memory errors without needing a garbage collector.",
15 "Traveling is the perfect way to explore new cultures through their food, from savoring street tacos in Mexico to indulging in fresh sushi in Japan.",
16 "Traveling for science allows researchers to explore new environments, gather crucial data, and collaborate with experts worldwide to expand our understanding of the universe.",
17 ],
18 &[
19 &["performance", "user interface"], // expecting 'performance'
20 &["gastronomy", "plane"], // expecting 'gastronomy'
21 &["conferencing", "teaching"], // expecting 'conferencing'
22 ]
23 );
24
25 let classes = model.inference(inputs, &pipeline, ¶ms)?;
26
27 for i in 0..classes.len() {
28 println!("Text {i}:\n\t=> {}\n\t=> {:?}",
29 classes.best_label(i, None).unwrap(),
30 classes.ordered_scores(i, None).unwrap().iter().rev().collect::<Vec<_>>(),
31 );
32 }
33
34 Ok(())
35}Auto Trait Implementations§
impl Freeze for Classes
impl RefUnwindSafe for Classes
impl Send for Classes
impl Sync for Classes
impl Unpin for Classes
impl UnwindSafe for Classes
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