def rouge(hypotheses,
          references1,
          references2=None,
          metrics=['rougeLsum'],
          target_keys=None):
  """Main function for rouge scoring.

  If two references are provided,
  the best score is chosen for each instance.

  Args:
    hypotheses: {key: answer} dict of predicted long answers
    references1: {key: reference} dict of references to score hypotheses against
    references2: optional {key: reference} dict of references to score
      hypotheses against
    metrics: list of evaluation metrics
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    dictionary representation of rouge scores
  """

  # stemmer = PorterStemmer()
  h, r1, r2 = [], [], []

  for key in references1:
    if target_keys is not None and key not in target_keys:
      continue

    h.append(hypotheses[key])
    r1.append(references1[key])

    if references2 is not None:
      r2.append(references2[key])

  if 'rougeLsum' in metrics:
    h = ['\n'.join(nltk.sent_tokenize(text.lower())) for text in h]
    r1 = ['\n'.join(nltk.sent_tokenize(text.lower())) for text in r1]
    r2 = ['\n'.join(nltk.sent_tokenize(text.lower())) for text in r2]
  scores = _rouge_calculation(h, r1, r2, metrics)

  return scores
Main function for rouge scoring.

  If two references are provided,
  the best score is chosen for each instance.

  Args:
    hypotheses: {key: answer} dict of predicted long answers
    references1: {key: reference} dict of references to score hypotheses against
    references2: optional {key: reference} dict of references to score
      hypotheses against
    metrics: list of evaluation metrics
    target_keys: an optional set of keys. If provided, only keys from this set
      are used for evaluation

  Returns:
    dictionary representation of rouge scores
  
language/asqa/scoring.py