nltk工具计算bleu score
2020-06-17 本文已影响0人
Nevrast
from nltk.translate import bleu_score
class Bleu(object):
def __init__():
self.smooth_fun = bleu_score.SmoothingFunction()
def tokenize(string):
""" Specific tokenzation method need to be defined """
raise NotImplementedError
def score(hypothesis, references):
"""
hypothesis: string from model output
references: a list of strings as ground truth
"""
return bleu_score.sentence_bleu(references, hypothesis, weights=(0.5, 0.5),
smoothing_function=self.smooth_fun.method2)