Skip to content

Commit

Permalink
Update rouge metric to take in an SPM model for tokenization.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 428091414
  • Loading branch information
Aditya Barua authored and t5-copybara committed Feb 14, 2022
1 parent e1ffda6 commit e8596a3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions t5/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ def bleu(targets, predictions):
return {"bleu": bleu_score.score}


def rouge(targets, predictions, score_keys=None):
def rouge(targets, predictions, score_keys=None, spm_model=None):
"""Computes rouge score.
Args:
targets: list of strings
predictions: list of strings
score_keys: list of strings with the keys to compute.
spm_model: string, path to SentencePieceModel model. If provided, this model
is used for tokenizing the targets and predictions.
Returns:
dict with score_key: rouge score across all targets and predictions
"""

if score_keys is None:
score_keys = ["rouge1", "rouge2", "rougeLsum"]
scorer = rouge_scorer.RougeScorer(score_keys)
scorer = rouge_scorer.RougeScorer(score_keys, spm_model=spm_model)
aggregator = scoring.BootstrapAggregator()

def _prepare_summary(summary):
Expand Down

0 comments on commit e8596a3

Please sign in to comment.