Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor, integrate penalties and global scorer into fast translation #1270

Merged
merged 3 commits into from
Feb 7, 2019

Conversation

flauted
Copy link
Contributor

@flauted flauted commented Feb 7, 2019

This changes default behavior!

  1. The old master, slow code length penalty returns the actual logprobs (penalties.py L80) and the GlobalScorer changes it in place (beam.py L215). That's almost certainly not intended since the other length penalties don't change the probs in place. (Fixed Master below slows the scores when you change penalties.py L80 to read return logprobs.clone()).
  2. The old master, fast code would always use the Wu length penalty (with default alpha=0, so None in the default case). Now -length_penalty must be specified for that behavior (see This below).

Most of the scores below are boring. The bolded names show the interesting ones. The slow coverage penalty scores change (both stepwise and not) because of (1). The fast length penalty unspecified scores change because of (2). The This fast length penalty Wu shows that the length penalty scores for the fast code are the same when -length_penalty wu is specified.


709e27

Default

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 38.838887
Average translation time (s): 0.077678
Tokens per second: 310.899742

Length penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty wu -alpha 0.7
PRED AVG SCORE: -0.1305, PRED PPL: 1.1394
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 39.382816
Average translation time (s): 0.078766
Tokens per second: 310.617704

Length penalty avg

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty avg
PRED AVG SCORE: -0.0160, PRED PPL: 1.0161
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 39.588275
Average translation time (s): 0.079177
Tokens per second: 314.310237

Coverage penalty Wu (see #1267 )

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty wu -beta 0.2
PRED AVG SCORE: -inf, PRED PPL: inf
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 84.184225
Average translation time (s): 0.168368
Tokens per second: 141.071560

Coverage penalty summary

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2
PRED AVG SCORE: -0.6760, PRED PPL: 1.9659
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 40.173116
Average translation time (s): 0.080346
Tokens per second: 295.720149

Coverage penalty summary stepwise penalty

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2 -stepwise_penalty
PRED AVG SCORE: -0.5645, PRED PPL: 1.7585
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 41.803246
Average translation time (s): 0.083606
Tokens per second: 285.958656

Fast default

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 8.914259
Average translation time (s): 0.017829
Tokens per second: 1354.571410

Fast length penalty unspecified with alpha (uses Wu)

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast -alpha 0.7
PRED AVG SCORE: -0.1346, PRED PPL: 1.1441
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 8.999163
Average translation time (s): 0.017998
Tokens per second: 1351.681311

Fixed Master

Default

PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 38.847767
Average translation time (s): 0.077696
Tokens per second: 310.828677

Length penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty wu -alpha 0.7
PRED AVG SCORE: -0.1305, PRED PPL: 1.1394
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 39.076946
Average translation time (s): 0.078154
Tokens per second: 313.049033

Length penalty avg

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty avg
PRED AVG SCORE: -0.0160, PRED PPL: 1.0161
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 39.318205
Average translation time (s): 0.078636
Tokens per second: 316.469177

Coverage penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty wu -beta 0.2
PRED AVG SCORE: -inf, PRED PPL: inf
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 39.545062
Average translation time (s): 0.079090
Tokens per second: 300.593788

Coverage penalty summary

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2
PRED AVG SCORE: -0.5574, PRED PPL: 1.7461
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 41.920325
Average translation time (s): 0.083841
Tokens per second: 286.472017

Coverage penalty summary stepwise penalty

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2 -stepwise_penalty
PRED AVG SCORE: -0.5566, PRED PPL: 1.7447
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 42.807609
Average translation time (s): 0.085615
Tokens per second: 279.179340

Fast default

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 9.042102
Average translation time (s): 0.018084
Tokens per second: 1335.419524

Fast unspecified with alpha (uses Wu)

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast -alpha 0.7
PRED AVG SCORE: -0.1346, PRED PPL: 1.1441
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 9.081064
Average translation time (s): 0.018162
Tokens per second: 1339.490687

This

Default

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 40.267328
Average translation time (s): 0.080535
Tokens per second: 299.870903

Length penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty wu -alpha 0.7
PRED AVG SCORE: -0.1305, PRED PPL: 1.1394
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 40.769553
Average translation time (s): 0.081539
Tokens per second: 300.052348

Length penalty avg

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -length_penalty avg
PRED AVG SCORE: -0.0160, PRED PPL: 1.0161
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 41.088870
Average translation time (s): 0.082178
Tokens per second: 302.831399

Coverage penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty wu -beta 0.2
PRED AVG SCORE: -inf, PRED PPL: inf
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 44.939763
Average translation time (s): 0.089880
Tokens per second: 264.509631

Coverage penalty summary

/home/dylan/miniconda3/envs/opennmt/bin/python /home/dylan/code/OpenNMT-py/./translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2
PRED AVG SCORE: -0.5574, PRED PPL: 1.7461
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 41.329404
Average translation time (s): 0.082659
Tokens per second: 290.567944

Coverage penalty summary stepwise penalty

/home/dylan/miniconda3/envs/opennmt/bin/python /home/dylan/code/OpenNMT-py/./translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -coverage_penalty summary -beta 0.2 -stepwise_penalty
PRED AVG SCORE: -0.5566, PRED PPL: 1.7447
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 43.885523
Average translation time (s): 0.087771
Tokens per second: 272.322153

Fast default

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 9.563882
Average translation time (s): 0.019128
Tokens per second: 1262.562677

Fast length penalty with alpha (uses None)

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -output pred.txt -gpu 0 -report_time -fast -alpha 0.7
PRED AVG SCORE: -0.4390, PRED PPL: 1.5512
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 9.739165
Average translation time (s): 0.019478
Tokens per second: 1239.839371

Fast length penalty Wu

python translate.py -model /home/dylan/Downloads/averaged-10-epoch.pt -src /home/dylan/Downloads/test_short.en -tgt /home/dylan/Downloads/test_short.de -verbose -output pred.txt -gpu 0 -report_time -length_penalty wu -alpha 0.7 -fast
PRED AVG SCORE: -0.1346, PRED PPL: 1.1441
GOLD AVG SCORE: -11.2287, GOLD PPL: 75260.5316
Total translation time (s): 9.605526
Average translation time (s): 0.019211
Tokens per second: 1266.354361

Copy link
Contributor

@guillaumekln guillaumekln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

onmt/translate/beam_search.py Show resolved Hide resolved
@vince62s
Copy link
Member

vince62s commented Feb 7, 2019

thorough work, thanks.
while talking of min/max_length is there a reason why those are arguments of _fast_translate_batch ?
since we already have self and already defined earlier, maybe we can simplify a bit.

@guillaumekln
Copy link
Contributor

guillaumekln commented Feb 7, 2019

@vince62s Short term that indeed cleans up the code. However, these kind of options should not be tied to a particular Translator instance, but should be configurable for each Translator.translate() call.

@vince62s
Copy link
Member

vince62s commented Feb 7, 2019

agreed, but the code is not structured that way at all, from the 2 upper level.
currently, I find it more confusing than anything else.
we can put this in standby until I deprecate the old translate.

@vince62s vince62s merged commit 3008d64 into OpenNMT:master Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants