pub struct NliClassifier { /* private fields */ }Expand description
Zero-shot text classifier using NLI entailment scoring.
Holds a DeBERTa-v3-xsmall ONNX session and its tokenizer, each behind a
Mutex so the classifier is Send + Sync and can be shared via Arc. The
model is downloaded on first construction and cached locally.
Implementations§
Source§impl NliClassifier
impl NliClassifier
Sourcepub fn new(config: NliConfig) -> Result<Self, NliError>
pub fn new(config: NliConfig) -> Result<Self, NliError>
Creates a classifier from config, downloading the model if not cached.
This is synchronous and blocks on the HuggingFace download and ONNX
session creation — mirroring crate::embedding::OnnxEmbedding::new.
Call it from a blocking context (e.g. tokio::task::spawn_blocking)
when constructing from async code. Pass NliConfig::default for the
model memoir ships with.
§Errors
Returns NliError::Download if the model or tokenizer cannot be
fetched, NliError::ModelLoad if the ONNX session cannot be built,
and NliError::TokenizerLoad if the tokenizer cannot be parsed.
Sourcepub fn execution_provider(&self) -> ExecutionProvider
pub fn execution_provider(&self) -> ExecutionProvider
Returns the execution provider this classifier resolved to at load time.
Sourcepub fn classify(
&self,
text: &str,
labels: &[&str],
hypothesis_template: &str,
) -> Result<Vec<ScoredLabel>, NliError>
pub fn classify( &self, text: &str, labels: &[&str], hypothesis_template: &str, ) -> Result<Vec<ScoredLabel>, NliError>
Classifies text against labels using a hypothesis template.
The template must contain {}, which is replaced with each label: with
template "This text is about {}." and label "a decision", the
hypothesis is "This text is about a decision.". Returns the labels
sorted by entailment score, highest first. An empty labels slice
returns an empty vector.
§Errors
Returns NliError::Inference if tokenization or model inference
fails for any label.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for NliClassifier
impl RefUnwindSafe for NliClassifier
impl Send for NliClassifier
impl Sync for NliClassifier
impl Unpin for NliClassifier
impl UnsafeUnpin for NliClassifier
impl UnwindSafe for NliClassifier
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
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> 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>
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>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request