📘
ROUGE-1 Score Calculator
Calculate the ROUGE-1 F1 score between a generated summary and a reference summary.
ROUGE-1 measures unigram overlap:
- Precision = (matching unigrams) / (unigrams in generated)
- Recall = (matching unigrams) / (unigrams in reference)
- F1 = 2 * Precision * Recall / (Precision + Recall)
All comparisons are case-insensitive. Round the F1 score to 4 decimal places.
Input format:
- Line 1: Generated summary
- Line 2: Reference summary
Example:
Input:
the cat sat on the mat the cat is on the mat
Output:
0.8333
Reasoning:
Step 1: Extract unigrams Generated: {the:2, cat:1, sat:1, on:1, mat:1} → 6 words Reference: {the:2, cat:1, is:1, on:1, mat:1} → 6 words
Step 2: Count matches (min count per word) the: min(2,2)=2, cat: min(1,1)=1, on: min(1,1)=1, mat: min(1,1)=1 Total matches: 5
Step 3: Compute scores Precision = 5/6, Recall = 5/6 F1 = 2 * (5/6) * (5/6) / (5/6 + 5/6) = 5/6 ≈ 0.8333
Constraints:
- Case-insensitive comparison
- Use word-level unigrams (split on whitespace)
- If precision + recall = 0, F1 = 0.0
- Round F1 to 4 decimal places
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.