class_docstr: Calculates the Rouge score for multiples Rouge-N and Rouge-L metrics.
  
  More details can be found in `Lin 2004`__.
  
  __ https://www.aclweb.org/anthology/W04-1013.pdf
  
  - ``update`` must receive output of the form ``(y_pred, y)`` or ``{'y_pred': y_pred, 'y': y}``.
  - `y_pred` (list(list(str))) must be a sequence of tokens.
  - `y` (list(list(list(str))) must be a list of sequence of tokens.
  
  Args:
      variants: set of metrics computed. Valid inputs are "L" and integer 1 <= n <= 9.
      multiref: reduces scores for multi references. Valid values are "best" and "average" (default: "average").
      alpha: controls the importance between recall and precision (alpha -> 0: recall is more important, alpha -> 1:
         precision is more important)
      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.
      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.
  
  Examples:
  
      For more information on how metric works with :class:`~ignite.engine.engine.Engine`, visit :ref:`attach-engine`.
  
      .. testcode::
  
          from ignite.metrics import Rouge
  
          m = Rouge(variants=["L", 2], multiref="best")
  
          candidate = "the cat is not there".split()
          references = [
              "the cat is on the mat".split(),
              "there is a cat on the mat".split()
          ]
  
          m.update(([candidate], [references]))
  
          print(m.compute())
  
      .. testoutput::
  
          {'Rouge-L-P': 0.6, 'Rouge-L-R': 0.5, 'Rouge-L-F': 0.5, 'Rouge-2-P': 0.5, 'Rouge-2-R': 0.4, 'Rouge-2-F': 0.4}
  
  .. versionadded:: 0.4.5
  .. versionchanged:: 0.4.7
      ``update`` method has changed and now works on batch of inputs.
class_docstr_tok: ["Calculates","the","Rouge","score","for","multiples","Rouge-N","and","Rouge-L","metrics",".","More","details","can","be","found","in","`","Lin","2004","`","__",".","__","https",":","\/\/www.aclweb.org\/anthology\/W04-1013.pdf","-","``","update","``","must","receive","output","of","the","form","``","(","y_pred",",","y",")","``","or","``","{","'y_pred","'",":","y_pred",",","'","y","'",":","y","}","``",".","-","`","y_pred","`","(","list","(","list","(","str",")",")",")","must","be","a","sequence","of","tokens",".","-","`","y","`","(","list","(","list","(","list","(","str",")",")",")","must","be","a","list","of","sequence","of","tokens",".","Args",":","variants",":","set","of","metrics","computed",".","Valid","inputs","are","``","L","''","and","integer","1","<","=","n","<","=","9.","multiref",":","reduces","scores","for","multi","references",".","Valid","values","are","``","best","''","and","``","average","''","(","default",":","``","average","''",")",".","alpha",":","controls","the","importance","between","recall","and","precision","(","alpha","-",">","0",":","recall","is","more","important",",","alpha","-",">","1",":","precision","is","more","important",")","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",".","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",".","Examples",":","For","more","information","on","how","metric","works","with",":","class",":","`","~ignite.engine.engine.Engine","`",",","visit",":","ref",":","`","attach-engine","`",".","..","testcode",":",":","from","ignite.metrics","import","Rouge","m","=","Rouge","(","variants=","[","``","L","''",",","2","]",",","multiref=","''","best","''",")","candidate","=","``","the","cat","is","not","there","''",".split","(",")","references","=","[","``","the","cat","is","on","the","mat","''",".split","(",")",",","``","there","is","a","cat","on","the","mat","''",".split","(",")","]","m.update","(","(","[","candidate","]",",","[","references","]",")",")","print","(","m.compute","(",")",")","..","testoutput",":",":","{","'Rouge-L-P","'",":","0.6",",","'Rouge-L-R","'",":","0.5",",","'Rouge-L-F","'",":","0.5",",","'Rouge-2-P","'",":","0.5",",","'Rouge-2-R","'",":","0.4",",","'Rouge-2-F","'",":","0.4","}","..","versionadded",":",":","0.4.5","..","versionchanged",":",":","0.4.7","``","update","``","method","has","changed","and","now","works","on","batch","of","inputs","."]
code: def __init__(
      self,
      variants: Optional[Sequence[Union[str, int]]] = None,
      multiref: str = "average",
      alpha: float = 0,
      output_transform: Callable = lambda x: x,
      device: Union[str, torch.device] = torch.device("cpu"),
  ):
      if variants is None or len(variants) == 0:
          variants = [1, 2, 4, "L"]
      self.internal_metrics: List[_BaseRouge] = []
      for m in variants:
          variant: Optional[_BaseRouge] = None
          if isinstance(m, str) and m == "L":
              variant = RougeL(
                  multiref=multiref,
                  alpha=alpha,
                  output_transform=output_transform,
                  device=device,
              )
          elif isinstance(m, int):
              variant = RougeN(
                  ngram=m,
                  multiref=multiref,
                  alpha=alpha,
                  output_transform=output_transform,
                  device=device,
              )
          else:
              raise ValueError(
                  "variant must be 'L' or integer greater to zero"
              )
          self.internal_metrics.append(variant)
      super(Rouge, self).__init__(
          output_transform=output_transform, device=device
      )
  
imports: from abc import ABCMeta, abstractmethod
  from collections import namedtuple
  from typing import Any, Callable, List, Mapping, Optional, Sequence, Tuple, Union
  import torch
  from ignite.exceptions import NotComputableError
  from ignite.metrics import Metric
  from ignite.metrics.metric import reinit__is_reduced, sync_all_reduce
  from ignite.metrics.nlp.utils import lcs, ngrams
label_desc: Use image node_id 1 to create a new Rouge object from inherited base classes: Metric with example: obj = Rouge(variants, multiref, alpha, output_transform, device)