| 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 |