From e3b3734ccb249e4dfd0b702a0fef3c867b163f8e Mon Sep 17 00:00:00 2001 From: yang-stressfree <68363665+yang-stressfree@users.noreply.github.com> Date: Fri, 23 Apr 2021 09:15:01 +0800 Subject: [PATCH] fix 'divided by 0' when reference_length is zero --- nmt/scripts/bleu.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nmt/scripts/bleu.py b/nmt/scripts/bleu.py index 9fe6466ad..393dcb152 100644 --- a/nmt/scripts/bleu.py +++ b/nmt/scripts/bleu.py @@ -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.) /