BLEU

Module Contents

Classes

BLEU

Computes the BLEU (Bilingual Evaluation Understudy) score.

class neural_compressor.experimental.metric.bleu.BLEU

Bases: object

Computes the BLEU (Bilingual Evaluation Understudy) score.

BLEU is an algorithm for evaluating the quality of text which has been machine-translated from one natural language to another. This implementent approximate the BLEU score since we do not glue word pieces or decode the ids and tokenize the output. By default, we use ngram order of 4 and use brevity penalty. Also, this does not have beam search.

predictions

List of translations to score.

labels

List of the reference corresponding to the prediction result.

reset() None

Clear the predictions and labels in the cache.

update(prediction: Sequence[str], label: Sequence[str]) None

Add the prediction and label.

Parameters:
  • prediction – The prediction result.

  • label – The reference corresponding to the prediction result.

Raises:
  • ValueError – An error occurred when the length of the prediction

  • and label are different.

result() float

Compute the BLEU score.

Returns:

The approximate BLEU score.

Return type:

bleu_score