Complete the code to import the BLEU score function from nltk.
from nltk.translate.bleu_score import [1]
The function sentence_bleu is used to calculate BLEU score for a single sentence.
Complete the code to calculate the BLEU score for a candidate sentence.
score = sentence_bleu([reference], [1])The candidate sentence tokens should be passed as the second argument to sentence_bleu.
Fix the error in the ROUGE score calculation by completing the missing import.
from rouge_score import [1]
The class RougeScorer is imported from the rouge_score package to calculate ROUGE scores.
Fill both blanks to create a ROUGE scorer and calculate scores for two texts.
scorer = [1](['rouge1', 'rougeL']) scores = scorer.score([2], generated)
RougeScorer is used to create the scorer object. The reference text variable is named reference.
Fill all three blanks to compute BLEU and ROUGE scores and print them.
bleu = sentence_bleu([reference], [1]) scorer = [2](['rouge1', 'rougeL']) rouge_scores = scorer.score(reference, [3]) print(f"BLEU: {bleu:.2f}") print(f"ROUGE-1 F1: {rouge_scores['rouge1'].fmeasure:.2f}")
The BLEU score uses the candidate tokens, the ROUGE scorer is created with RougeScorer, and ROUGE is scored comparing reference and generated text.