def edit_rouge(targets, predictions):
  """Measures a variety of different ROUGE scores."""
  # We do not measure ROUGE-L for updates since LCS is likely entirely contained
  # in source.
  scorer = rouge_scorer.RougeScorer(["rouge1", "rouge2", "rougeLsum"])
  aggregator = scoring.BootstrapAggregator()

  for prediction, target in zip(predictions, targets):

    all_scores = {}

    target_additions = rendering_utils.extract_additions(
        source=target["normalized_inputs"],
        target=target["normalized_targets"],
    )
    target_additions = " ".join(target_additions)
    prediction_additions = rendering_utils.extract_additions(
        source=target["normalized_inputs"],
        target=prediction["normalized_targets"],
    )
    prediction_additions = " ".join(prediction_additions)

    addition_scores = scorer.score(
        target=target_additions,
        prediction=prediction_additions,
    )

    if target_additions.strip() or prediction_additions.strip():
      all_scores.update({f"update_{k}": v for k, v in addition_scores.items()})
    else:
      all_scores.update(
          {f"update_{k}": 100.0 for k, _ in addition_scores.items()})

    aggregator.add_scores(all_scores)

  result = aggregator.aggregate()
  return {key: value.mid.fmeasure * 100 for key, value in result.items()}
Measures a variety of different ROUGE scores.
language/fruit/metrics.py