File size: 616 Bytes
5d5c713
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from nltk.translate.bleu_score import sentence_bleu, SmoothingFunction

def calculate_bleu(reference_sentences, translations):
    """
    Calculate BLEU scores for a list of translations.
    :param reference_sentences: List of reference translations.
    :param translations: List of translated sentences (hypotheses).
    :return: List of BLEU scores.
    """
    smoothing_function = SmoothingFunction().method1
    bleu_scores = [
        sentence_bleu([ref.split()], hyp.split(), smoothing_function=smoothing_function)
        for ref, hyp in zip(reference_sentences, translations)
    ]
    return bleu_scores