code: def rouge(hypotheses, references):
      """Calculates average rouge scores for a list of hypotheses and
      references"""
  
      # Filter out hyps that are of 0 length
      # hyps_and_refs = zip(hypotheses, references)
      # hyps_and_refs = [_ for _ in hyps_and_refs if len(_[0]) > 0]
      # hypotheses, references = zip(*hyps_and_refs)
  
      # Calculate ROUGE-1 F1, precision, recall scores
      rouge_1 = [
          rouge_n([hyp], [ref], 1)
          for hyp, ref in zip(hypotheses, references)
      ]
      rouge_1_f, rouge_1_p, rouge_1_r = map(np.mean, zip(*rouge_1))
  
      # Calculate ROUGE-2 F1, precision, recall scores
      rouge_2 = [
          rouge_n([hyp], [ref], 2)
          for hyp, ref in zip(hypotheses, references)
      ]
      rouge_2_f, rouge_2_p, rouge_2_r = map(np.mean, zip(*rouge_2))
  
      # Calculate ROUGE-L F1, precision, recall scores
      rouge_l = [
          rouge_l_sentence_level([hyp], [ref])
          for hyp, ref in zip(hypotheses, references)
      ]
      rouge_l_f, rouge_l_p, rouge_l_r = map(np.mean, zip(*rouge_l))
  
      return {
          "rouge_1/f_score": rouge_1_f,
          "rouge_1/r_score": rouge_1_r,
          "rouge_1/p_score": rouge_1_p,
          "rouge_2/f_score": rouge_2_f,
          "rouge_2/r_score": rouge_2_r,
          "rouge_2/p_score": rouge_2_p,
          "rouge_l/f_score": rouge_l_f,
          "rouge_l/r_score": rouge_l_r,
          "rouge_l/p_score": rouge_l_p,
      }
  
file_path: seq2seq/seq2seq/metrics/rouge.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import itertools
  import numpy
label_desc: Use image node_id 12 for calling a global function with example usage: rouge(hypotheses, references) and returns: dict