5 个答案:
答案 0 :(得分:12)
BLEU分数由两部分组成,修正精度和简洁惩罚。
详细信息可以在paper中看到。
您可以使用NLTK内的nltk.align.bleu_score模块。
一个代码示例如下所示:
import nltk
hypothesis = ['It', 'is', 'a', 'cat', 'at', 'room']
reference = ['It', 'is', 'a', 'cat', 'inside', 'the', 'room']
#there may be several references
BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis)
print BLEUscore
请注意,默认的BLEU分数使用n = 4,其中包括4克的unigrams。如果您的句子小于4,则需要重置N值,否则将返回ZeroDivisionError: Fraction(0, 0)错误。
所以,你应该像这样重置重量:
import nltk
hypothesis = ["open", "the", "file"]
reference = ["open", "file"]
#the maximum is bigram, so assign the weight into 2 half.
BLEUscore &#