nlpstack.common.bleu module#

class nlpstack.common.bleu.BLEU(ngram_weights=(0.25, 0.25, 0.25, 0.25), exclude_tokens=None)[source]#

Bases: object

Calculate BLEU score.

This class can be used to calculate BLEU score between two sequences of tokens. The implementation is based on the following paper:

https://api.semanticscholar.org/CorpusID:11080756?utm_source=wikipedia

Parameters:
  • ngram_weights (Sequence[float]) – A list of ngram weights.

  • exclude_tokens (Set[Token] | None) –

compute()[source]#
Return type:

float

reset()[source]#
Return type:

None

update(candidates, references, ngram_weights=(0.25, 0.25, 0.25, 0.25))[source]#
Return type:

None

Parameters:
  • candidates (Sequence[Sequence[Token]]) –

  • references (Sequence[Sequence[Token]]) –

  • ngram_weights (Sequence[float]) –