code: def rouge_n(eval_sentences, ref_sentences, n=2):
      """Computes ROUGE-N f1 score of two text collections of sentences.
  
      Source: https://www.microsoft.com/en-us/research/publication/
      rouge-a-package-for-automatic-evaluation-of-summaries/
  
      Args:
        eval_sentences: The sentences that have been picked by the summarizer
        ref_sentences: The sentences from the reference set
        n: Size of ngram.  Defaults to 2.
  
      Returns:
        f1 score for ROUGE-N
      """
  
      f1_scores = []
      for eval_sentence, ref_sentence in zip(
          eval_sentences, ref_sentences
      ):
          eval_ngrams = _get_ngrams(n, eval_sentence)
          ref_ngrams = _get_ngrams(n, ref_sentence)
          ref_count = len(ref_ngrams)
          eval_count = len(eval_ngrams)
  
          # Gets the overlapping ngrams between evaluated and reference
          overlapping_ngrams = eval_ngrams.intersection(ref_ngrams)
          overlapping_count = len(overlapping_ngrams)
  
          # Handle edge case. This isn't mathematically correct, but it's good enough
          if eval_count == 0:
              precision = 0.0
          else:
              precision = overlapping_count / eval_count
  
          if ref_count == 0:
              recall = 0.0
          else:
              recall = overlapping_count / ref_count
  
          f1_scores.append(
              2.0 * ((precision * recall) / (precision + recall + 1e-8))
          )
  
      # return overlapping_count / reference_count
      return np.mean(f1_scores, dtype=np.float32)
  
file_path: tensor2tensor/tensor2tensor/utils/rouge.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 7 for calling a global function with example usage: rouge_n(eval_sentences, ref_sentences, n) and returns: np