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

sampling #586

Merged
merged 34 commits into from
Dec 14, 2018
Merged

sampling #586

merged 34 commits into from
Dec 14, 2018

Conversation

mjpost
Copy link
Contributor

@mjpost mjpost commented Nov 27, 2018

This adds sampling to Sockeye (via --sample [N]), a collaborative effort with @edwdh. It will create beam_size samples (and return as many as nbest_size). If an integer is passed to --sample N, samples at each time step for each hypothesis will only be taken for the top N most-probable target-language tokens. The default is 0, which samples from the entire target vocabulary.

This commit also changes the way inactive works, removing its dual purpose of handling the special case at timestep 1 when we need to run topk() only over items from the first row in each batch. This is now reverted to the old behavior, where we have a special conditional for t==1. This simplifies some of the code and removes some confusing logic with inactive.

Pull Request Checklist

  • Changes are complete (if posting work-in-progress code, prefix your pull request title with '[WIP]'
    until you can check this box.
  • Unit tests pass (pytest)
  • Were system tests modified? If so did you run these at least 5 times to account for the variation across runs?
  • Passed code style checking (./style-check.sh)
  • You have considered writing a test
  • Updated major/minor version in sockeye/__init__.py. Major version bump if this is a backwards incompatible change.
  • Updated CHANGELOG.md

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Edward Hu and others added 7 commits October 30, 2018 09:09
Sampling rewrite

See merge request edward.hu/sockeye!1
- Fixes sampling to work return proper scores and to work with `--nbest-size`

- Simplifies the use of `inactive`, restoring the original code where we have a one-off case when t==1. This is necessary so that `topk()` doesn't select the same word in each row, but instead chooses the best items just from the first row (since all rows have the identical history of `<s>` at t==1). Before, "inactive" was initialized to mark non-first rows as inactive, but removing this use case simplifies the code.
Still need to fix for non-mxnet topk()

(It's really annoying having essentially four different topk functions to fix)
sockeye/constants.py Outdated Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/lexical_constraints.py Show resolved Hide resolved
sockeye/utils.py Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
@mjpost mjpost changed the title [WIP] sampling sampling Nov 28, 2018
Copy link
Contributor

@fhieber fhieber left a comment

Choose a reason for hiding this comment

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

Yet another great decoder feature :) thanks!

sockeye/inference.py Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/lexical_constraints.py Show resolved Hide resolved
sockeye/lexical_constraints.py Outdated Show resolved Hide resolved
sockeye/translate.py Outdated Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/lexical_constraints.py Outdated Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/inference.py Outdated Show resolved Hide resolved
sockeye/inference.py Outdated Show resolved Hide resolved
@mjpost
Copy link
Contributor Author

mjpost commented Dec 3, 2018

FYI (FDI?), werde ich in einer Woche darauf zurückkommen.

Copy link
Contributor

@fhieber fhieber left a comment

Choose a reason for hiding this comment

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

I will take another pass later today. Looks good to me already though.

test/unit/test_inference.py Show resolved Hide resolved
test/unit/test_inference.py Show resolved Hide resolved
test/unit/test_inference.py Outdated Show resolved Hide resolved
test/unit/test_inference.py Outdated Show resolved Hide resolved
test/unit/test_inference.py Outdated Show resolved Hide resolved
sockeye/inference.py Outdated Show resolved Hide resolved
sockeye/inference.py Outdated Show resolved Hide resolved
sockeye/inference.py Show resolved Hide resolved
sockeye/translate.py Outdated Show resolved Hide resolved
sockeye/translate.py Outdated Show resolved Hide resolved
sockeye/utils.py Show resolved Hide resolved
Copy link
Contributor

@fhieber fhieber 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 iterating and benchmarking! LGTM.
Still curious though about my last remaining comment for removing the asscalar() to compute batch_size in topk().

Copy link
Contributor

@fhieber fhieber left a comment

Choose a reason for hiding this comment

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

Thanks!

@fhieber fhieber merged commit 094baca into awslabs:master Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants