Sub topic 10
ROUGE in practice: stemming, ROUGE-Lsum, and multiple references
This chapter assumes you know ROUGE-N and ROUGE-L from the previous chapters, including how precision, recall, and F1 are computed from overlap counts. It also assumes you can read basic Python. The formulas are the same here. What changes is the preprocessing and bookkeeping around them. Those details can move a score by several points, and papers often leave them unreported.
Why settings matter
ROUGE is a family of formulas, and each library wraps it in choices about tokenization, stemming, sentence splitting, and how to handle several references. Two teams can run "ROUGE-L" on the same outputs and report different numbers. The Python package rouge_score is the most widely used implementation, so this chapter uses it as the concrete reference.
Default tokenization
By default rouge_score lowercases the text, replaces every character outside a-z and 0-9 with a space, and splits on whitespace. Three consequences follow:
- Punctuation and case never matter. "Mat." and "mat" are the same token.
- Hyphenated words and contractions split apart. "don't" becomes
donandt. - Text in non-Latin scripts, such as Chinese, Arabic, or Hindi, is erased. Every character is replaced by a space, so both texts are empty and the score is 0.
Stemming
A stemmer reduces word forms to a common stem, so "cats" and "cat" count as the same token. Setting use_stemmer=True applies the Porter stemmer. rouge_score stems only tokens longer than three characters, so short words such as "are" are left alone.
Here is a worked comparison:
from rouge_score import rouge_scorer
target = "The cats are sitting on the mats."
prediction = "The cat sat on the mat."
for stem in (False, True):
scorer = rouge_scorer.RougeScorer(["rouge1"], use_stemmer=stem)
r = scorer.score(target, prediction)["rouge1"]
print(f"stemmer={stem}: P={r.precision:.3f} R={r.recall:.3f} F1={r.fmeasure:.3f}")Without stemming, the target tokens are the cats are sitting on the mats (7 tokens) and the prediction tokens are the cat sat on the mat (6 tokens). The overlap is the twice plus on, which is 3 tokens. That gives P = 3/6 = 0.500 and R = 3/7 ≈ 0.429.
With stemming, "cats" and "mats" become "cat" and "mat", and "sitting" becomes "sit". The overlap rises to 5 tokens: the twice, cat, on, and mat. That gives P = 5/6 ≈ 0.833 and R = 5/7 ≈ 0.714.
Stemming is a cheap form of paraphrase credit, but only for inflection. It does not match "sat" with "sitting", and it works only for English. The Porter stemmer is also crude: it sometimes conflates unrelated words and sometimes fails to merge related ones. Because the choice shifts scores by several points, always report whether it was on.
ROUGE-L versus ROUGE-Lsum
ROUGE-L treats the whole text as one token sequence and computes a single longest common subsequence (LCS). That is a problem for multi-sentence summaries. The LCS must be one in-order chain across the entire text, so it is penalized when the same content appears in a different sentence order.
ROUGE-Lsum is the summary-level variant. It works like this:
- Split the reference and the prediction into sentences.
- For each reference sentence, compute its LCS against every prediction sentence.
- Take the union of the matched reference tokens across all prediction sentences. Each token counts once.
- Sum the union sizes across reference sentences and use that sum as the LCS count in the usual precision, recall, and F1 formulas.
Sentence order therefore matters less, because every reference sentence is compared against the whole prediction.
In rouge_score, "sentence" means a line. The rougeLsum scorer splits on \n, so you must insert newlines between sentences yourself. If you pass a single paragraph, ROUGE-Lsum degenerates to ROUGE-L, because the text is one sentence.
from rouge_score import rouge_scorer
target = "the cat sat\nthe dog barked"
prediction = "the dog barked\nthe cat sat"
scorer = rouge_scorer.RougeScorer(["rougeL", "rougeLsum"])
scores = scorer.score(target, prediction)
print("rougeL F1:", round(scores["rougeL"].fmeasure, 3))
print("rougeLsum F1:", round(scores["rougeLsum"].fmeasure, 3))The two summaries contain the same sentences in swapped order. For ROUGE-L, the best single in-order chain is 3 tokens (the cat sat or the dog barked) out of 6, so P = R = F1 = 0.5. For ROUGE-Lsum, "the cat sat" matches 3 tokens in the prediction's second sentence and "the dog barked" matches 3 in its first. The union is 6 tokens, so the score is 1.0. Which behavior is right depends on whether sentence order is part of summary quality for your task.
Multiple references
Many datasets provide several human references per input. Because two valid outputs can look very different, more references give the metric more chances to find overlap.
There are two common ways to handle several references:
- Pool the n-grams. BLEU does this: clipping uses the maximum count of each n-gram in any single reference.
- Score each reference separately and keep the best. The original ROUGE toolkit and
rouge_scorework this way. The best score per example is the one with the highest F-measure.
In rouge_score, score_multi implements the second approach:
from rouge_score import rouge_scorer
targets = [
"The cat is on the mat.",
"A cat was sitting on the rug.",
]
prediction = "The cat sat on the mat."
scorer = rouge_scorer.RougeScorer(["rouge1", "rougeL"], use_stemmer=True)
best = scorer.score_multi(targets, prediction)
for name, result in best.items():
print(name, round(result.fmeasure, 3))Keep these points in mind:
- The best reference is chosen per ROUGE type, so the reference chosen for
rouge1may differ from the one chosen forrougeL. - Taking a maximum rewards the closest reference. Scores with several references are therefore higher than scores with one, and you cannot compare them directly. State how many references each result used.
- If you instead average over the references, the score is lower and less sensitive to one lucky match. Pick one rule and report it.
Aggregating over a dataset
scorer.score works on one pair. To get a dataset-level number, compute the per-example scores and aggregate them. The usual approach is the mean of per-example precision, recall, and F1, reported on a 0 to 100 scale. rouge_score.scoring.BootstrapAggregator resamples the examples to give low, mid, and high values, which is a confidence interval on the mean. This matters when you compare two systems whose scores differ by under a point, because a small test set can produce a gap that is just noise.
Choosing the reported number
ROUGE-N recall rewards long outputs, because a longer prediction has more chances to contain reference n-grams. Precision rewards short ones. The F-measure balances the two, so it is the safer headline number. When the original task has a length limit, such as a fixed-size abstract, truncate every system to that limit before scoring. Otherwise a system can gain points just by writing more.
What to report
A reproducible ROUGE result lists:
- The library and its version, for example
rouge_score 0.1.2. - The variants reported (ROUGE-1, ROUGE-2, ROUGE-L or ROUGE-Lsum).
- Whether stemming was on.
- The tokenizer, if it was not the default.
- How sentences were split for ROUGE-Lsum.
- The number of references and the rule for combining them.
- Whether the number is precision, recall, or F1.
Exercise
A colleague scores multi-paragraph news summaries with rougeL and gets an F1 of 0.31. Your own run with rougeLsum gives 0.38 on the same outputs, even though you did not change the model. (a) Give a reason for the gap. (b) Your Chinese-language run returns exactly 0.0 for every example with the default settings. What is the likely cause and the fix?
Show answer
(a) ROUGE-L computes one LCS over the whole text, so it is penalized when sentences appear in a different order than in the reference. ROUGE-Lsum matches each reference sentence against the entire prediction and takes the union of matched tokens, so reordering costs less. The scores differ by design, and you should report which one you used. (b) The default tokenizer replaces everything outside a-z and 0-9 with spaces, so Chinese characters are removed and both texts become empty. Pass a custom tokenizer (for example, a word segmenter or a character-level one) to RougeScorer.
Exercise
You score one system against 3 references per example by taking the best F-measure per example. A second team scores the same kind of system against 1 reference. Why are the two numbers not comparable, and what should you report?
Show answer
Taking the best of 3 references can only raise or keep a score compared with using one of them, so the multi-reference number is inflated relative to a single-reference number. Report the number of references, the combination rule (best F-measure per ROUGE type), and ideally also the score against a single reference so others can compare.