Skip to content

Commit c89d62e

Browse files
ernlavrErnestsLavrinovicsalias]
andauthored
Add optimization for compute_bleu precision initialization (#257)
* Add optimization for compute_bleu precision initialization * Remove redundant else clause --------- Co-authored-by: ErnestsLavrinovicsalias] <[email protected]>
1 parent 0f35101 commit c89d62e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

sacrebleu/metrics/bleu.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,12 @@ def compute_bleu(correct: List[int],
245245
smooth_value = BLEU.SMOOTH_DEFAULTS[smooth_method]
246246

247247
# Compute brevity penalty
248+
bp = 1.0
248249
if sys_len < ref_len:
249-
bp = math.exp(1 - ref_len / sys_len) if sys_len > 0 else 0.0
250-
else:
251-
bp = 1.0
250+
bp = math.exp(1 - ref_len / sys_len) if sys_len > 0 else 0.0
252251

253252
# n-gram precisions
254-
precisions = [0.0 for x in range(max_ngram_order)]
253+
precisions = [0.0] * max_ngram_order
255254

256255
# Early stop if there are no matches (#141)
257256
if not any(correct):

0 commit comments

Comments
 (0)