pub struct Bleu { /* private fields */ }Expand description
BLEU evaluator (BLEU-4 by default).
Implementations§
Source§impl Bleu
impl Bleu
Sourcepub fn with_max_n(self, n: usize) -> Self
pub fn with_max_n(self, n: usize) -> Self
Uses BLEU-n (default 4)
Sourcepub fn with_char_level(self, v: bool) -> Self
pub fn with_char_level(self, v: bool) -> Self
Character-level tokenization: whitespace-less languages such as Chinese split per char (otherwise the whole sentence becomes one token and BLEU breaks)
Sourcepub fn with_smoothing(self, v: bool) -> Self
pub fn with_smoothing(self, v: bool) -> Self
Enables smoothing: an order with no n-gram match gets a small value instead of a whole-zero, so short sentences are not cut off wholesale
Sourcepub fn corpus_bleu(
&self,
predictions: &[&str],
references: &[&str],
) -> Result<f64, EvalError>
pub fn corpus_bleu( &self, predictions: &[&str], references: &[&str], ) -> Result<f64, EvalError>
Corpus-level BLEU: aggregates n-gram match counts across examples, then computes a single geometric mean + corpus-level brevity penalty.
P2-1: a sentence-level brevity penalty cuts short sentences off wholesale (e.g. “the cat”
scores a hard zero under BLEU-4); corpus aggregation computes the penalty from total lengths
and merges per-order n-gram counts, so short sentences still contribute low-order precision.
With with_smoothing, an order with no match gets a small value instead of a whole zero.
predictions and references must have the same length (one-to-one), otherwise
EvalError::LengthMismatch is returned.