neural_compressor.metric.bleu_util

Script to compute BLEU score.

Source: https://github.com/tensorflow/tensor2tensor/blob/master/tensor2tensor/utils/bleu_hook.py

Functions

compute_bleu(→ float)

Compute the BLEU score of translated segments against its references.

Module Contents

neural_compressor.metric.bleu_util.compute_bleu(reference_corpus: Sequence[str] | Sequence[Sequence[str]], translation_corpus: Sequence[str], max_order: int = 4, use_bp: bool = True) float[source]

Compute the BLEU score of translated segments against its references.

Parameters:
  • reference_corpus – List of references for each translation. Each reference should be tokenized into a list of tokens.

  • translation_corpus – List of translations to score. Each translation should be tokenized into a list of tokens.

  • max_order – Maximum n-gram order to use when computing BLEU score.

  • use_bp – The flag to decide whether to apply brevity penalty.

Returns:

The approximate BLEU score.

Return type:

bleu_score