pub struct InferenceResult {
pub labels: Vec<String>,
pub scores: Vec<f32>,
pub predicted_class: usize,
pub max_score: f32,
}Expand description
Inference result with classification predictions
Fields§
§labels: Vec<String>Predicted class labels
scores: Vec<f32>Confidence scores for each class (after post-processing)
predicted_class: usizePredicted class index (highest score)
max_score: f32Maximum confidence score
Implementations§
Source§impl InferenceResult
impl InferenceResult
Sourcepub fn predicted_label(&self) -> Option<&str>
pub fn predicted_label(&self) -> Option<&str>
Get the predicted label
§Example
use llm_shield_models::InferenceResult;
let result = InferenceResult {
labels: vec!["SAFE".to_string(), "INJECTION".to_string()],
scores: vec![0.8, 0.2],
predicted_class: 0,
max_score: 0.8,
};
assert_eq!(result.predicted_label(), Some("SAFE"));Sourcepub fn exceeds_threshold(&self, threshold: f32) -> bool
pub fn exceeds_threshold(&self, threshold: f32) -> bool
Check if prediction confidence exceeds threshold
§Arguments
threshold- Minimum confidence threshold (0.0 to 1.0)
§Example
use llm_shield_models::InferenceResult;
let result = InferenceResult {
labels: vec!["SAFE".to_string(), "INJECTION".to_string()],
scores: vec![0.3, 0.7],
predicted_class: 1,
max_score: 0.7,
};
assert!(result.exceeds_threshold(0.5));
assert!(!result.exceeds_threshold(0.8));Sourcepub fn get_score_for_label(&self, label: &str) -> Option<f32>
pub fn get_score_for_label(&self, label: &str) -> Option<f32>
Sourcepub fn get_threshold_violations(&self, thresholds: &[f32]) -> Vec<usize>
pub fn get_threshold_violations(&self, thresholds: &[f32]) -> Vec<usize>
Sourcepub fn from_binary_logits(logits: Vec<f32>, labels: Vec<String>) -> Self
pub fn from_binary_logits(logits: Vec<f32>, labels: Vec<String>) -> Self
Create InferenceResult from logits using softmax (single-label)
§Arguments
logits- Raw model output logitslabels- Class labels
§Example
use llm_shield_models::InferenceResult;
let logits = vec![1.0, 2.0, 0.5];
let labels = vec!["A".to_string(), "B".to_string(), "C".to_string()];
let result = InferenceResult::from_binary_logits(logits, labels);
// B should have highest probability
assert_eq!(result.predicted_class, 1);Sourcepub fn from_multilabel_logits(logits: Vec<f32>, labels: Vec<String>) -> Self
pub fn from_multilabel_logits(logits: Vec<f32>, labels: Vec<String>) -> Self
Create InferenceResult from logits using sigmoid (multi-label)
§Arguments
logits- Raw model output logitslabels- Class labels
§Example
use llm_shield_models::InferenceResult;
let logits = vec![2.0, -1.0, 1.0];
let labels = vec!["toxic".to_string(), "threat".to_string(), "insult".to_string()];
let result = InferenceResult::from_multilabel_logits(logits, labels);
// All scores should be in [0, 1]
for score in &result.scores {
assert!(*score >= 0.0 && *score <= 1.0);
}Trait Implementations§
Source§impl Clone for InferenceResult
impl Clone for InferenceResult
Source§fn clone(&self) -> InferenceResult
fn clone(&self) -> InferenceResult
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for InferenceResult
impl Debug for InferenceResult
Source§impl<'de> Deserialize<'de> for InferenceResult
impl<'de> Deserialize<'de> for InferenceResult
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for InferenceResult
impl PartialEq for InferenceResult
Source§impl Serialize for InferenceResult
impl Serialize for InferenceResult
impl StructuralPartialEq for InferenceResult
Auto Trait Implementations§
impl Freeze for InferenceResult
impl RefUnwindSafe for InferenceResult
impl Send for InferenceResult
impl Sync for InferenceResult
impl Unpin for InferenceResult
impl UnwindSafe for InferenceResult
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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