Skip to content

Commit 8d55c51

Browse files
Aditya Baruat5-copybara
Aditya Barua
authored andcommitted
Update rouge metric to take in an SPM model for tokenization.
PiperOrigin-RevId: 428091414
1 parent e1ffda6 commit 8d55c51

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

t5/evaluation/metrics.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,22 @@ def bleu(targets, predictions):
6565
return {"bleu": bleu_score.score}
6666

6767

68-
def rouge(targets, predictions, score_keys=None):
68+
def rouge(targets, predictions, score_keys=None, spm_model=None):
6969
"""Computes rouge score.
7070
7171
Args:
7272
targets: list of strings
7373
predictions: list of strings
7474
score_keys: list of strings with the keys to compute.
75+
spm_model: string, path to SentencePieceModel model. If provided, this model
76+
is used for tokenizing the targets and predictions.
7577
Returns:
7678
dict with score_key: rouge score across all targets and predictions
7779
"""
7880

7981
if score_keys is None:
8082
score_keys = ["rouge1", "rouge2", "rougeLsum"]
81-
scorer = rouge_scorer.RougeScorer(score_keys)
83+
scorer = rouge_scorer.RougeScorer(score_keys, spm_model=spm_model)
8284
aggregator = scoring.BootstrapAggregator()
8385

8486
def _prepare_summary(summary):

0 commit comments

Comments
 (0)