Struct BleuScore
pub struct BleuScore { /* private fields */ }Expand description
Computes the BLEU (Bilingual Evaluation Understudy) score between predicted and reference token sequences.
BLEU measures the quality of machine-translated text by comparing n-gram overlap between the candidate (prediction) and reference sequences. The score combines modified n-gram precision for n = 1..max_n with a brevity penalty that discourages overly short translations.
The metric operates on integer token IDs (not raw text), matching the
convention used by CharErrorRate and
WordErrorRate.
§Batch-level scoring
Within each batch the metric accumulates n-gram counts across all sentences and computes a single corpus-style BLEU score, following the same pattern CER/WER use for edit-distance aggregation.
Epoch-level (running) aggregation averages these batch scores, which is slightly inaccurate compared to true corpus BLEU. Correct corpus-level accumulation would require a custom metric state; a TODO is left for future work.
§References
Papineni et al., “BLEU: a Method for Automatic Evaluation of Machine Translation”, ACL 2002.
Chen & Cherry, “A Systematic Comparison of Smoothing Techniques for Sentence-Level BLEU”, WMT 2014.
Implementations§
§impl BleuScore
impl BleuScore
pub fn with_max_n(max_n: usize) -> BleuScore
pub fn with_max_n(max_n: usize) -> BleuScore
Creates a BLEU metric with the given maximum n-gram order.
Common values: 1 (BLEU-1), 2 (BLEU-2), 4 (BLEU-4).
§Panics
Panics if max_n is zero.
pub fn with_pad_token(self, index: usize) -> BleuScore
pub fn with_pad_token(self, index: usize) -> BleuScore
Sets the pad token index. Tokens matching this value are stripped from the right of each sequence before scoring.
pub fn with_smoothing(self, smoothing: BleuSmoothing) -> BleuScore
pub fn with_smoothing(self, smoothing: BleuSmoothing) -> BleuScore
Sets the smoothing method for handling zero-count n-gram precisions.
Smoothing is recommended when evaluating short sentences where higher-order n-gram matches are sparse.
Trait Implementations§
§impl Metric for BleuScore
impl Metric for BleuScore
§fn update(
&mut self,
input: &BleuInput,
_metadata: &MetricMetadata,
) -> Result<SerializedEntry, TensorReadError>
fn update( &mut self, input: &BleuInput, _metadata: &MetricMetadata, ) -> Result<SerializedEntry, TensorReadError>
§fn compute(&mut self) -> Result<SerializedEntry, TensorReadError>
fn compute(&mut self) -> Result<SerializedEntry, TensorReadError>
§fn attributes(&self) -> MetricAttributes
fn attributes(&self) -> MetricAttributes
§fn description(&self) -> Option<String>
fn description(&self) -> Option<String>
§impl Numeric for BleuScore
impl Numeric for BleuScore
§fn value(&self) -> Option<NumericEntry>
fn value(&self) -> Option<NumericEntry>
None if this metric has
no meaningful value yet (e.g. it only accumulates state per batch and
computes its value once all state has been accumulated).§fn running_value(&self) -> Option<NumericEntry>
fn running_value(&self) -> Option<NumericEntry>
None if this metric has no meaningful value yet (e.g. it only accumulates state
per batch and computes its value once all state has been accumulated).§fn final_value(&self) -> NumericEntry
fn final_value(&self) -> NumericEntry
Metric::compute has been called.Auto Trait Implementations§
impl Freeze for BleuScore
impl RefUnwindSafe for BleuScore
impl Send for BleuScore
impl Sync for BleuScore
impl Unpin for BleuScore
impl UnsafeUnpin for BleuScore
impl UnwindSafe for BleuScore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<K, Q> Comparable<Q> for K
impl<K, Q> Comparable<Q> for K
§impl<K, Q> Equivalent<Q> for K
impl<K, Q> Equivalent<Q> for K
§fn equivalent(&self, key: &Q) -> bool
fn equivalent(&self, key: &Q) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().