pub struct Score(/* private fields */);Expand description
A score guaranteed to be in the range [0.0, 1.0] (f32 precision).
This is the f32 equivalent of Confidence, designed for neural network
outputs where f32 is standard (tensors, embeddings, similarity scores).
§Why f32?
Neural networks typically operate in f32:
- GPU hardware optimized for f32/f16
- Embeddings use f32 (768 floats per token)
- Logits/softmax outputs are f32
§Construction
Score::new: ReturnsNoneif out of rangeScore::saturating: Clamps to [0, 1]Score::from_logit: Applies sigmoid (common for NER)
§Zero-Cost Abstraction
Score is #[repr(transparent)], meaning it has the exact same
memory layout as f32. There is no runtime overhead.
§Example
use anno::types::Score;
// From neural network output
let logit = 2.5f32;
let score = Score::from_logit(logit);
assert!(score.get() > 0.9);
// Convert to Confidence (f64) for API consistency
let conf = score.to_confidence();Implementations§
Source§impl Score
impl Score
Sourcepub fn saturating(value: f32) -> Score
pub fn saturating(value: f32) -> Score
Create a score, clamping to [0.0, 1.0].
Sourcepub fn from_logit(logit: f32) -> Score
pub fn from_logit(logit: f32) -> Score
Create from a raw logit by applying sigmoid.
sigmoid(x) = 1 / (1 + e^(-x))
Sourcepub fn from_logit_with_temperature(logit: f32, temperature: f32) -> Score
pub fn from_logit_with_temperature(logit: f32, temperature: f32) -> Score
Create from a temperature-scaled logit.
Higher temperature (> 1) = softer distribution. Lower temperature (< 1) = sharper distribution.
Sourcepub fn to_confidence(self) -> Confidence
pub fn to_confidence(self) -> Confidence
Convert to f64 Confidence.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Score
impl<'de> Deserialize<'de> for Score
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Score, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Score, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Score> for Confidence
impl From<Score> for Confidence
Source§fn from(score: Score) -> Confidence
fn from(score: Score) -> Confidence
Converts to this type from the input type.
Source§impl PartialOrd for Score
impl PartialOrd for Score
Source§impl Serialize for Score
impl Serialize for Score
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Copy for Score
impl StructuralPartialEq for Score
Auto Trait Implementations§
impl Freeze for Score
impl RefUnwindSafe for Score
impl Send for Score
impl Sync for Score
impl Unpin for Score
impl UnsafeUnpin for Score
impl UnwindSafe for Score
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.