mjpost / sacrebleu

Reference BLEU implementation that auto-downloads test sets and reports a version string to facilitate cross-lab comparisons
Apache License 2.0
1.03k stars 162 forks source link

Add optimization for compute_bleu precision initialization #257

Open ernlavr opened 6 months ago

ernlavr commented 6 months ago

Description: Added a one-line optimization for initialization of the precissions list in def compute_bleu function.

Motivation: I have to do a total of 7 billion computations so I was looking at possibilities for optimizing the computation routine. I find that this change is about x4 faster for the operation, consisting of about 12% of total improvement for the function. Added a screenshots of my timings. See the diff between precissions_old and precissions_optim. Numbers are averaged over 10k computations.

image

P.s. this change is also reflected in this StackOverflow post https://stackoverflow.com/questions/20816600/best-and-or-fastest-way-to-create-lists-in-python