class_docstr: Calculates the `BLEU score <https://en.wikipedia.org/wiki/BLEU>`_.
  
  .. math::
     \text{BLEU} = b_{p} \cdot \exp \left( \sum_{n=1}^{N} w_{n} \: \log p_{n} \right)
  
  where :math:`N` is the order of n-grams, :math:`b_{p}` is a sentence brevety penalty, :math:`w_{n}` are
  positive weights summing to one and :math:`p_{n}` are modified n-gram precisions.
  
  More details can be found in `Papineni et al. 2002`__.
  
  __ https://www.aclweb.org/anthology/P02-1040
  
  In addition, a review of smoothing techniques can be found in `Chen et al. 2014`__
  
  __ https://aclanthology.org/W14-3346.pdf
  
  - ``update`` must receive output of the form ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
  - `y_pred` (list(list(str))) - a list of hypotheses sentences.
  - `y` (list(list(list(str))) - a corpus of lists of reference sentences w.r.t hypotheses.
  
  Remark :
  
      This implementation is inspired by nltk
  
  Args:
      ngram: order of n-grams.
      smooth: enable smoothing. Valid are ``no_smooth``, ``smooth1``, ``nltk_smooth2`` or ``smooth2``.
          Default: ``no_smooth``.
      output_transform: a callable that is used to transform the
          :class:`~ignite.engine.engine.Engine`'s ``process_function``'s output into the
          form expected by the metric. This can be useful if, for example, you have a multi-output model and
          you want to compute the metric with respect to one of the outputs.
          By default, metrics require the output as ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
      device: specifies which device updates are accumulated on. Setting the
          metric's device to be the same as your ``update`` arguments ensures the ``update`` method is
          non-blocking. By default, CPU.
      average: specifies which type of averaging to use (macro or micro)
          for more details refer https://www.nltk.org/_modules/nltk/translate/bleu_score.html
          Default: "macro"
  
  Examples:
  
      For more information on how metric works with :class:`~ignite.engine.engine.Engine`, visit :ref:`attach-engine`.
  
      .. testcode::
  
          from ignite.metrics.nlp import Bleu
  
          m = Bleu(ngram=4, smooth="smooth1")
  
          y_pred = "the the the the the the the"
          y = ["the cat is on the mat", "there is a cat on the mat"]
  
          m.update(([y_pred.split()], [[_y.split() for _y in y]]))
  
          print(m.compute())
  
      .. testoutput::
  
          tensor(0.0393, dtype=torch.float64)
  
  .. versionadded:: 0.4.5
  .. versionchanged:: 0.4.7
  
      - ``update`` method has changed and now works on batch of inputs.
      - added ``average`` option to handle micro and macro averaging modes.
class_docstr_tok: ["Calculates","the","`","BLEU","score","<","https",":","\/\/en.wikipedia.org\/wiki\/BLEU",">","`","_",".","..","math",":",":","\\text","{","BLEU","}","=","b_","{","p","}","\\cdot","\\exp","\\left","(","\\sum_","{","n=1","}","^","{","N","}","w_","{","n","}","\\",":","\\log","p_","{","n","}","\\right",")","where",":","math",":","`","N","`","is","the","order","of","n-grams",",",":","math",":","`","b_","{","p","}","`","is","a","sentence","brevety","penalty",",",":","math",":","`","w_","{","n","}","`","are","positive","weights","summing","to","one","and",":","math",":","`","p_","{","n","}","`","are","modified","n-gram","precisions",".","More","details","can","be","found","in","`","Papineni","et","al",".","2002","`","__",".","__","https",":","\/\/www.aclweb.org\/anthology\/P02-1040","In","addition",",","a","review","of","smoothing","techniques","can","be","found","in","`","Chen","et","al",".","2014","`","__","__","https",":","\/\/aclanthology.org\/W14-3346.pdf","-","``","update","``","must","receive","output","of","the","form","``","(","y_pred",",","y",")","``","or","``","{","'y_pred","'",":","y_pred",",","'","y","'",":","y","}","``",".","-","`","y_pred","`","(","list","(","list","(","str",")",")",")","-","a","list","of","hypotheses","sentences",".","-","`","y","`","(","list","(","list","(","list","(","str",")",")",")","-","a","corpus","of","lists","of","reference","sentences","w.r.t","hypotheses",".","Remark",":","This","implementation","is","inspired","by","nltk","Args",":","ngram",":","order","of","n-grams",".","smooth",":","enable","smoothing",".","Valid","are","``","no_smooth","``",",","``","smooth1","``",",","``","nltk_smooth2","``","or","``","smooth2","``",".","Default",":","``","no_smooth","``",".","output_transform",":","a","callable","that","is","used","to","transform","the",":","class",":","`","~ignite.engine.engine.Engine","`","'s","``","process_function","``","'s","output","into","the","form","expected","by","the","metric",".","This","can","be","useful","if",",","for","example",",","you","have","a","multi-output","model","and","you","want","to","compute","the","metric","with","respect","to","one","of","the","outputs",".","By","default",",","metrics","require","the","output","as","``","(","y_pred",",","y",")","``","or","``","{","'y_pred","'",":","y_pred",",","'","y","'",":","y","}","``",".","device",":","specifies","which","device","updates","are","accumulated","on",".","Setting","the","metric","'s","device","to","be","the","same","as","your","``","update","``","arguments","ensures","the","``","update","``","method","is","non-blocking",".","By","default",",","CPU",".","average",":","specifies","which","type","of","averaging","to","use","(","macro","or","micro",")","for","more","details","refer","https",":","\/\/www.nltk.org\/_modules\/nltk\/translate\/bleu_score.html","Default",":","``","macro","''","Examples",":","For","more","information","on","how","metric","works","with",":","class",":","`","~ignite.engine.engine.Engine","`",",","visit",":","ref",":","`","attach-engine","`",".","..","testcode",":",":","from","ignite.metrics.nlp","import","Bleu","m","=","Bleu","(","ngram=4",",","smooth=","''","smooth1","''",")","y_pred","=","``","the","the","the","the","the","the","the","''","y","=","[","``","the","cat","is","on","the","mat","''",",","``","there","is","a","cat","on","the","mat","''","]","m.update","(","(","[","y_pred.split","(",")","]",",","[","[","_y.split","(",")","for","_y","in","y","]","]",")",")","print","(","m.compute","(",")",")","..","testoutput",":",":","tensor","(","0.0393",",","dtype=torch.float64",")","..","versionadded",":",":","0.4.5","..","versionchanged",":",":","0.4.7","-","``","update","``","method","has","changed","and","now","works","on","batch","of","inputs",".","-","added","``","average","``","option","to","handle","micro","and","macro","averaging","modes","."]
code: def _sentence_bleu(
      self,
      references: Sequence[Sequence[Any]],
      candidates: Sequence[Any],
  ) -> float:
      return self._corpus_bleu([references], [candidates])
  
imports: import math
  from typing import Any, Callable, Sequence, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics.metric import Metric, reinit__is_reduced, sync_all_reduce
  from ignite.metrics.nlp.utils import modified_precision
label_desc: Use image node_id 4 for calling the Bleu obj's underlying member method code with example usage: obj._sentence_bleu(references, candidates) and returns: self