Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Fix BLEU error: 'divided by 0' when reference_length is zero #483

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nmt/scripts/bleu.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def compute_bleu(reference_corpus, translation_corpus, max_order=4,
possible_matches_by_order[order-1] += possible_matches

precisions = [0] * max_order

if reference_length == 0:
return 0, precisions, 0, 0, translation_length, reference_length

for i in range(0, max_order):
if smooth:
precisions[i] = ((matches_by_order[i] + 1.) /
Expand Down