pub struct ClassificationPipeline { /* private fields */ }Expand description
Pipeline for GLiClass classification, to be executed using orp.
Implementations§
Source§impl ClassificationPipeline
impl ClassificationPipeline
Sourcepub fn new<P: AsRef<Path>>(
tokenizer_path: P,
_params: &Parameters,
) -> Result<Self>
pub fn new<P: AsRef<Path>>( tokenizer_path: P, _params: &Parameters, ) -> Result<Self>
Examples found in repository?
examples/sample2.rs (line 10)
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 10)
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 9)
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}Trait Implementations§
Source§impl<'a> Pipeline<'a> for ClassificationPipeline
impl<'a> Pipeline<'a> for ClassificationPipeline
type Input = TextInput
type Output = Classes
type Context = Labels
type Parameters = Parameters
fn pre_processor( &self, params: &Self::Parameters, ) -> impl PreProcessor<'a, Self::Input, Self::Context>
fn post_processor( &self, _params: &Self::Parameters, ) -> impl PostProcessor<'a, Self::Output, Self::Context>
fn to_composable(
self,
model: &'a Model,
params: &'a Self::Parameters,
) -> impl Composable<Self::Input, Self::Output>where
Self: Sized,
Auto Trait Implementations§
impl !Freeze for ClassificationPipeline
impl RefUnwindSafe for ClassificationPipeline
impl Send for ClassificationPipeline
impl Sync for ClassificationPipeline
impl Unpin for ClassificationPipeline
impl UnwindSafe for ClassificationPipeline
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