gpt4 book ai didi

nltk - NLTK 的 BLEU 分数和 SacreBLEU 有什么区别?

转载 作者:行者123 更新时间:2023-12-05 02:46:32 81 4
gpt4 key购买 nike

我很好奇是否有人熟悉使用 NLTK's BLEU score calculation 之间的区别和 SacreBLEU library .

特别是,我使用了两个库的句子 BLEU 分数,对整个数据集进行平均。两者给出不同的结果:

>>> from nltk.translate import bleu_score
>>> from sacrebleu import sentence_bleu
>>> print(len(predictions))
256
>>> print(len(targets))
256
>>> prediction = "this is the first: the world's the world's the world's the \
... world's the world's the world's the world's the world's the world's the world \
... of the world of the world'"
...
>>> target = "al gore: so the alliance for climate change has launched two campaigns."
>>> print(bleu_score.sentence_bleu([target], prediction))
0.05422283394039736
>>> print(sentence_bleu(prediction, [target]).score)
0.0
>>> print(sacrebleu.corpus_bleu(predictions, [targets]).score)
0.678758518214081
>>> print(bleu_score.corpus_bleu([targets], [predictions]))
0

如您所见,存在许多令人困惑的不一致之处。我的 BLEU 分数不可能是 67.8%,但也不应该是 0%(有很多重叠的 n-gram,例如“the”)。

如果有人能阐明这一点,我将不胜感激。谢谢。

最佳答案

NLTK 和 SacreBLEU 使用不同的分词规则,主要是在它们处理标点符号的方式上。 NLTK 使用自己的标记化,而 SacreBLEU 复制了 2002 年的原始 Perl 实现。标记化规则在 NLTK 中可能更加详尽,但它们使数字与原始实现无法比较。

你从 SacreBLEU 得到的语料库 BLEU 不是 67.8%,而是 0.67%——与 NLTK 不同,SacreBLEU 的数字已经乘以 100。因此,我不会说分数之间存在巨大差异。

句子级别的 BLEU 可以使用不同的 smoothing techniques这应该确保即使 4 克精度的 3 克精度为零,分数也会得到合理的值。但是,请注意,BLEU 作为句子级别的指标非常不可靠。

关于nltk - NLTK 的 BLEU 分数和 SacreBLEU 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65454578/

81 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com