class_docstr: Bilingual Evaluation Understudy (BLEU).
  
  BLEU is a common metric used for evaluating the quality of machine translations
  against a set of reference translations. See
  [Papineni et. al., "BLEU: a method for automatic evaluation of machine translation", 2002][1].
  
  # Parameters
  
  ngram_weights : `Iterable[float]`, optional (default = `(0.25, 0.25, 0.25, 0.25)`)
      Weights to assign to scores for each ngram size.
  exclude_indices : `Set[int]`, optional (default = `None`)
      Indices to exclude when calculating ngrams. This should usually include
      the indices of the start, end, and pad tokens.
  
  # Notes
  
  We chose to implement this from scratch instead of wrapping an existing implementation
  (such as `nltk.translate.bleu_score`) for a two reasons. First, so that we could
  pass tensors directly to this metric instead of first converting the tensors to lists of strings.
  And second, because functions like `nltk.translate.bleu_score.corpus_bleu()` are
  meant to be called once over the entire corpus, whereas it is more efficient
  in our use case to update the running precision counts every batch.
  
  This implementation only considers a reference set of size 1, i.e. a single
  gold target sequence for each predicted sequence.
  
  
  [1]: https://www.semanticscholar.org/paper/8ff93cfd37dced279134c9d642337a2085b31f59/
code: def _get_brevity_penalty(self) -> float:
      if self._prediction_lengths > self._reference_lengths:
          return 1.0
      if self._reference_lengths == 0 or self._prediction_lengths == 0:
          return 0.0
      return math.exp(
          1.0 - self._reference_lengths / self._prediction_lengths
      )
  
file_path: allennlp/allennlp/training/metrics/bleu.py
imports: from collections import Counter
  import math
  from typing import Iterable, Tuple, Dict, Set, Optional
  import torch
  import torch.distributed
  from allennlp.common.util import is_distributed
  from allennlp.training.metrics.metric import Metric
  from allennlp.nn.util import dist_reduce_sum
label_desc: Use image node_id 4 for calling the BLEU obj's underlying member method code with example usage: obj._get_brevity_penalty() and returns: math, int, int