PIXELBANKv9.1.0
Menu

Compute the ROUGE-L F1 score using Longest Common Subsequence.

ROUGE-L uses the length of the LCS between reference and candidate:

  • Precision = LCS / len(candidate)
  • Recall = LCS / len(reference)
  • F1 = 2 × P × R / (P + R)

Input:

  • Line 1: reference (space-separated tokens)
  • Line 2: candidate (space-separated tokens)

Output: ROUGE-L F1 score, rounded to 4 decimal places.

Example:

Input:
a b c d e
a c e
Output:
0.7500
Reasoning:
  • First, we find the Longest Common Subsequence (LCS) between the reference and candidate: a c e
  • Then, we calculate precision and recall:
    • Precision = LCS/len(candidate)=3/3=1LCS / len(candidate) = 3 / 3 = 1
    • Recall = LCS/len(reference)=3/5=0.6LCS / len(reference) = 3 / 5 = 0.6
  • The ROUGE-L F1 score is computed using the formula: F1=2â‹…Pâ‹…R/(P+R)=2â‹…1â‹…0.6/(1+0.6)=0.75F1 = 2 \cdot P \cdot R / (P + R) = 2 \cdot 1 \cdot 0.6 / (1 + 0.6) = 0.75
  • The final output is the F1 score rounded to 4 decimal places: 0.75=0.75000.75 = 0.7500

Constraints:

  • Use dynamic programming for LCS
  • If both P and R are 0, F1 = 0
  • Round to 4 decimal places
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.