class_docstr: Recall-Oriented Understudy for Gisting Evaluation (ROUGE)
  
  ROUGE is a metric for measuring the quality of summaries. It is based on calculating the recall
  between ngrams in the predicted summary and a set of reference summaries. See [Lin,
  "ROUGE: A Package For Automatic Evaluation Of Summaries", 2004]
  (https://api.semanticscholar.org/CorpusID:964287).
  
  # Parameters
  
  ngram_size : `int`, optional (default = `2`)
      ROUGE scores are calculate for ROUGE-1 .. ROUGE-`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.
class_docstr_tok: ["Recall-Oriented","Understudy","for","Gisting","Evaluation","(","ROUGE",")","ROUGE","is","a","metric","for","measuring","the","quality","of","summaries",".","It","is","based","on","calculating","the","recall","between","ngrams","in","the","predicted","summary","and","a","set","of","reference","summaries",".","See","[","Lin",",","''","ROUGE",":","A","Package","For","Automatic","Evaluation","Of","Summaries","''",",","2004","]","(","https",":","\/\/api.semanticscholar.org\/CorpusID:964287",")",".","#","Parameters","ngram_size",":","`","int","`",",","optional","(","default","=","`","2","`",")","ROUGE","scores","are","calculate","for","ROUGE-1","..","ROUGE-","`","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","."]
docstr: Compare the predicted tokens to the reference (gold) tokens at the desired
  ngram size and compute recall, precision and f1 sums
docstr_tok: ["Compare","the","predicted","tokens","to","the","reference","(","gold",")","tokens","at","the","desired","ngram","size","and","compute","recall",",","precision","and","f1","sums"]
code: def _get_rouge_n_stats(
      self,
      predicted_tokens: torch.LongTensor,
      reference_tokens: torch.LongTensor,
      ngram_size: int,
  ) -> Tuple[float, float, float]:
      """
      Compare the predicted tokens to the reference (gold) tokens at the desired
      ngram size and compute recall, precision and f1 sums
      """
      total_recall = 0.0
      total_precision = 0.0
      total_f1 = 0.0
  
      for predicted_seq, reference_seq in zip(
          predicted_tokens, reference_tokens
      ):
          from allennlp.training.util import ngrams
  
          predicted_ngram_counts = ngrams(
              predicted_seq, ngram_size, self._exclude_indices
          )
          reference_ngram_counts = ngrams(
              reference_seq, ngram_size, self._exclude_indices
          )
  
          matches = 0
          total_reference_ngrams = 0
          for ngram, count in reference_ngram_counts.items():
              matches += min(predicted_ngram_counts[ngram], count)
              total_reference_ngrams += count
  
          total_predicted_ngrams = sum(predicted_ngram_counts.values())
  
          if (
              total_reference_ngrams == 0
              or total_predicted_ngrams == 0
              or matches == 0
          ):
              continue
  
          recall = matches / total_reference_ngrams
          precision = matches / total_predicted_ngrams
  
          f1 = 2.0 * recall * precision / (recall + precision)
  
          # Accumulate stats
          total_recall += recall
          total_precision += precision
          total_f1 += f1
  
      total_recall = dist_reduce_sum(total_recall)
      total_precision = dist_reduce_sum(total_precision)
      total_f1 = dist_reduce_sum(total_f1)
  
      return total_recall, total_precision, total_f1
  
file_path: allennlp/allennlp/training/metrics/rouge.py
imports: from collections import defaultdict
  from typing import Tuple, Dict, Set, Optional
  import torch
  from allennlp.training.metrics.metric import Metric
  from allennlp.nn.util import dist_reduce_sum
label_desc: Use image node_id 5 for calling the ROUGE obj's underlying member method code with example usage: obj._get_rouge_n_stats(predicted_tokens, reference_tokens, ngram_size) and returns: total_recall,  total_precision,  total_f1