我在python中导入了nltk来计算Ubuntu上的BLEU分数。我理解句子级BLEU分数是如何工作的,但我不理解语料库级BLEU分数是如何工作的。
以下是我的语料库级BLEU分数代码:
import nltk
hypothesis = ['This', 'is', 'cat']
reference = ['This', 'is', 'a', 'cat']
BLEUscore = nltk.translate.bleu_score.corpus_bleu([reference], [hypothesis], weights = [1])
print(BLEUscore)
出于某种原因,上述代码的bleu分数为0。我期待着一个语料库水平的BLEU分数至少为0.5。
这是我的句子级BLEU分数代码
import nltk
hypothesis = ['This', 'is', 'cat']
reference = ['This', 'is', 'a', 'cat']
BLEUscore = nltk.translate.bleu_score.sentence_bleu([reference], hypothesis, weights = [1])
print(BLEUscore)
这里的句子水平BLEU分数是0.71,这是我所期望的,考虑到简短的惩罚和缺少单词“a”。但是,我不明白语料库级别的BLEU评分是如何工作的。
任何帮助都将不胜感激。
TL;DR:
(注意:为了获得BLEU score实现的稳定版本,必须在
develop
分支上提取最新版本的NLTK)在Long中:
实际上,如果整个语料库中只有一个引用和一个假设,那么
corpus_bleu()
和sentence_bleu()
应该返回与上面示例中相同的值。在代码中,我们看到^{} is actually a duck-type of ^{} :
如果我们看看
sentence_bleu
的参数:sentence_bleu
引用的输入是list(list(str))
。因此,如果你有一个句子字符串,例如
"This is a cat"
,你必须对它进行标记化才能得到一个字符串列表["This", "is", "a", "cat"]
,并且由于它允许多个引用,因此它必须是一个字符串列表,例如,如果你有第二个引用,“这是一只猫”,你对sentence_bleu()
的输入是:当谈到} takes as references :
corpus_bleu()
list_of_references参数时,它基本上是a list of whatever the ^{除了查看^{} 中的doctest之外,还可以查看^{} 中的unittest,了解如何使用
bleu_score.py
中的每个组件。顺便说一句,因为
sentence_bleu
作为bleu
导入到(nltk.translate.__init__.py
](https://github.com/nltk/nltk/blob/develop/nltk/translate/init.py#L21)中,使用与以下相同:
在代码中:
我们来看看:
你比我更能理解算法的描述,所以我不会试图“解释”给你听。如果docstring没有足够的清理,请查看the source本身。或者在本地找到它:
相关问题 更多 >
编程相关推荐