AI Engineer Problems › Evaluation & Testing

ROUGE-L Metric Calculator

Medium · Coding · Evaluation & Testing · Asked at HuggingFace, Google

ROUGE-L Metric Calculator

ROUGE-L measures the similarity between two sequences of text based on their Longest Common Subsequence (LCS). It is widely used in text summarization evaluation.

The formula for ROUGE-L F1-score is:

$R_{LCS} = \frac{\text{LCS}(Cand, Ref)}{\text{len}(Ref)}$ $P_{LCS} = \frac{\text{LCS}(Cand, Ref)}{\text{len}(Cand)}$ $F_{LCS} = \frac{2 \cdot R_{LCS} \cdot P_{LCS}}{R_{LCS} + P_{LCS}}$

If $R_{LCS} + P_{LCS} = 0$, the F1-score defaults to $0.0$.

Tasks

Implement the function calculate_rouge_l(candidate, reference) where both parameters are lists of word strings, returning the float F1-score.

Solve it in the browser on GenAIDojo