Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 7ba78a2

Browse files
committed
if no reference or translation is provided fail
with a clear error message instead of misleading "division by zero"
1 parent 004888a commit 7ba78a2

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

tensor2tensor/utils/bleu_hook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def compute_bleu(reference_corpus,
9696
matches_by_order[len(ngram) - 1] += overlap[ngram]
9797
for ngram in translation_ngram_counts:
9898
possible_matches_by_order[len(ngram)-1] += translation_ngram_counts[ngram]
99+
assert reference_length, "no reference provided"
100+
assert translation_length, "no translation provided"
99101
precisions = [0] * max_order
100102
smooth = 1.0
101103
for i in xrange(0, max_order):

0 commit comments

Comments
 (0)