torchtext.data.metrics¶
bleu_score¶
- torchtext.data.metrics 的bleu_score(candidate_corpus, references_corpus, max_n=4, weights=[0.25, 0.25, 0.25, 0.25])[来源]¶
计算候选翻译语料库和参考文献之间的 BLEU 分数 翻译语料库。基于 https://www.aclweb.org/anthology/P02-1040.pdf
- 参数
candidate_corpus – 候选翻译的可迭代对象。每个翻译都是一个 标记的 iterable
references_corpus – 引用翻译的可迭代对象的可迭代对象。每 translation 是标记的可迭代对象
max_n – 我们要使用的最大 n-gram。例如,如果 max_n=3,我们将使用一元语法, 二元组和三元组
weights (权重) – 用于每个 n-gram 类别的权重列表 (默认为 uniform)
例子
>>> from torchtext.data.metrics import bleu_score >>> candidate_corpus = [['My', 'full', 'pytorch', 'test'], ['Another', 'Sentence']] >>> references_corpus = [[['My', 'full', 'pytorch', 'test'], ['Completely', 'Different']], [['No', 'Match']]] >>> bleu_score(candidate_corpus, references_corpus) 0.8408964276313782