PIXELBANKv9.1.0
Menu

Compute the ROUGE-N recall score.

ROUGE-N measures n-gram overlap between candidate and reference: ROUGE-N=∑n-grammin⁡(countcand(n-gram),countref(n-gram))∑n-gramcountref(n-gram)\text{ROUGE-N} = \frac{\sum_{\text{n-gram}} \min(\text{count}_{cand}(\text{n-gram}), \text{count}_{ref}(\text{n-gram}))}{\sum_{\text{n-gram}} \text{count}_{ref}(\text{n-gram})}

Note: ROUGE uses recall (denominator is reference count).

Input:

  • Line 1: n (n-gram size)
  • Line 2: reference text
  • Line 3: candidate text

Output: ROUGE-N recall score, rounded to 4 decimal places.

Example:

Input:
1
the cat sat on the mat
the cat sat
Output:
0.5000
Reasoning:
  • The n-gram size is 1, so we split the reference text "the cat sat on the mat" into 1-grams: ["the", "cat", "sat", "on", "the", "mat"].
  • We also split the candidate text "the cat sat" into 1-grams: ["the", "cat", "sat"].
  • For each 1-gram, we calculate the minimum count between the candidate and reference texts: min(1,2)min(1, 2) for "the", min(1,1)min(1, 1) for "cat", min(1,1)min(1, 1) for "sat", min(0,1)min(0, 1) for "on", and min(0,1)min(0, 1) for "mat".
  • We then calculate the ROUGE-1 recall score using the formula: 1+1+12+1+1+1+1=36=0.5\frac{1 + 1 + 1}{2 + 1 + 1 + 1 + 1} = \frac{3}{6} = 0.5, which is rounded to 4 decimal places as 0.50000.5000.

Constraints:

  • 1 <= n <= 4
  • Case-sensitive
  • Round to 4 decimal places
  • If reference has no n-grams, output 0.0
🔒

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.