美文网首页
nltk工具计算bleu score

nltk工具计算bleu score

作者: Nevrast | 来源:发表于2020-06-17 11:27 被阅读0次
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

      本文链接:https://www.haomeiwen.com/subject/utigmhtx.html