ROUGE-L for Summaries

medium
Unit 13 · Evaluation I0/2 to milestone

ROUGE-L scores summaries by their longest common subsequence of tokens with a reference. It rewards getting words in the right order without requiring them to be adjacent.

With LCS length LL, candidate length mm and reference length nn:

P=L/m,R=L/n,F=2PRP+RP = L/m, \qquad R = L/n, \qquad F = \frac{2PR}{P + R}

Tokenise by lowercasing and splitting on whitespace. Implement lcs_length(a, b) in O(∣a∣⋅∣b∣)O(|a| \cdot |b|) time with O(min⁡(∣a∣,∣b∣))O(\min(|a|, |b|)) memory, and rouge_l(candidate, reference) returning {"precision", "recall", "f1"}. Empty inputs give all zeros.

#evaluation#summarization#nlp2 visible + 3 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
ROUGE-L for Summaries · TechGradify