Shortcuts

pytorch_lightning.metrics.nlp module

class pytorch_lightning.metrics.nlp.BLEUScore(n_gram=4, smooth=False)[source]

Bases: pytorch_lightning.metrics.metric.Metric

Calculate BLEU score of machine translated text with one or more references.

Example

>>> translate_corpus = ['the cat is on the mat'.split()]
>>> reference_corpus = [['there is a cat on the mat'.split(), 'a cat is on the mat'.split()]]
>>> metric = BLEUScore()
>>> metric(translate_corpus, reference_corpus)
tensor(0.7598)
Parameters
  • n_gram (int) – Gram value ranged from 1 to 4 (Default 4)

  • smooth (bool) – Whether or not to apply smoothing – Lin et al. 2004

forward(translate_corpus, reference_corpus)[source]

Actual metric computation

Parameters
  • translate_corpus (list) – An iterable of machine translated corpus

  • reference_corpus (list) – An iterable of iterables of reference corpus

Returns

BLEU Score

Return type

torch.Tensor