我正在尝试使用 NLTK 的 BLEU 分数来评估机器翻译的质量。我想用两个相同的句子检查这段代码,这里我使用 method1 作为平滑函数,因为我正在比较两个句子而不是语料库。我设置了 4 克和重量 0.25 (1/4)。但结果,我得到 0.0088308。我究竟做错了什么?两个相同的句子应该得到 1.0 分。我正在 PyCharm 中使用 Python 3、Windows 7 进行编码。
我的代码:
import nltk
from nltk import word_tokenize
from nltk.translate.bleu_score import SmoothingFunction
ref = 'You know that it would be untrue You know that I would be a liar If I was to say to you Girl, we couldnt get much higher.'
cand = 'You know that it would be untrue You know that I would be a liar If I was to say to you Girl, we couldnt get much higher.'
smoothie = SmoothingFunction().method1
reference = word_tokenize(ref)
candidate = word_tokenize(cand)
weights = (0.25, 0.25, 0.25, 0.25)
BLEUscore = nltk.translate.bleu_score.sentence_bleu(reference, candidate, weights, smoothing_function=smoothie)
print(BLEUscore)
我的结果:
0.008830895300928163
进程以退出代码 0 结束