Skip to content

Commit

Permalink
Merge pull request #89 from haoransh/fix_bleu
Browse files Browse the repository at this point in the history
Polish transformer bleu_tool.py

Make it robust when `ratio`==0
Fix #88
  • Loading branch information
ZhitingHu committed Jul 2, 2019
2 parents dd4b67b + 2022c42 commit d4da27a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions examples/transformer/bleu_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ def compute_bleu(reference_corpus, translation_corpus,

if use_bp:
ratio = translation_length / reference_length
if ratio == 0:
if ratio <= 0:
bp = 0
elif ratio < 1.0:
bp = math.exp(1 - 1.0 / ratio)
else:
bp = math.exp(1 - 1.0 / ratio) if ratio < 1.0 else 1.0
bp = 1.0
bleu = geo_mean * bp
return np.float32(bleu)

Expand Down

0 comments on commit d4da27a

Please sign in to comment.