未验证 提交 531697b2 编写于 作者: A Anirudh Dagar 提交者: GitHub

BUG: Fix BLEU calculation (#1032)

上级 d6b0f9e0
...@@ -855,11 +855,11 @@ def bleu(pred_seq, label_seq, k): #@save ...@@ -855,11 +855,11 @@ def bleu(pred_seq, label_seq, k): #@save
for n in range(1, k + 1): for n in range(1, k + 1):
num_matches, label_subs = 0, collections.defaultdict(int) num_matches, label_subs = 0, collections.defaultdict(int)
for i in range(len_label - n + 1): for i in range(len_label - n + 1):
label_subs[''.join(label_tokens[i: i + n])] += 1 label_subs[' '.join(label_tokens[i: i + n])] += 1
for i in range(len_pred - n + 1): for i in range(len_pred - n + 1):
if label_subs[''.join(pred_tokens[i: i + n])] > 0: if label_subs[' '.join(pred_tokens[i: i + n])] > 0:
num_matches += 1 num_matches += 1
label_subs[''.join(pred_tokens[i: i + n])] -= 1 label_subs[' '.join(pred_tokens[i: i + n])] -= 1
score *= math.pow(num_matches / (len_pred - n + 1), math.pow(0.5, n)) score *= math.pow(num_matches / (len_pred - n + 1), math.pow(0.5, n))
return score return score
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册