nltk工具计算bleu score

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)

你可能感兴趣的:(nltk工具计算bleu score)