Computer scienceData scienceNLPNLP metricsClassic NLP metrics

ROUGE

The ROUGE-2 score function

Report a typo

Given a candidate and a reference (both str) pieces, complete the rouge2 function that calculates the ROUGE-2F1\text{ROUGE-2}_{\text{F1}} score. Return the resulting score, rounded to the third digit.

Tip: A reminder of the necessary equations:

ROUGE-2recall=bigram cand.  bigram ref.bigram ref.\text{ROUGE-2}_{\text{recall}} = \frac{\text{bigram cand. } \cap \text{ bigram ref.}}{|\text{bigram ref.}|}

ROUGE-2precision=bigram cand.  bigram ref.bigram cand.\text{ROUGE-2}_{\text{precision}}= \frac{\text{bigram cand. } \cap \text{ bigram ref.}}{|\text{bigram cand.}|}

ROUGE-2F1=2recallprecisionrecall+precision\text{ROUGE-2}_{\text{F1}}=2*\frac{\text{recall}*\text{precision}}{\text{recall} + \text{precision}}

Sample Input 1:

John really loves data science very much and studies it a lot. John very much loves data science and enjoys it a lot.

Sample Output 1:

0.476
Write a program in Python 3
from nltk.util import ngrams

def rouge2(candidate, reference):
candidate_bigram = ...
reference_bigram = ...
r = ...
p = ...
f1 = ...
return f1
___

Create a free account to access the full topic