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

Add random sampling as alternative to beam search. #1157

Merged
merged 16 commits into from
Jan 7, 2019

Conversation

daphnei
Copy link
Contributor

@daphnei daphnei commented Jan 3, 2019

This pull request does a few things things.

  1. Implements a more succinct code path for when beam_size = 1.
  2. Implements random sampling as an alternative to beam search.
  3. Adds a temperature parameter to allow users to increase/decrease the entropy of the model's conditional distributions. Temperature has been shown to have a large impact on the quality/diversity tradeoff in natural language generation [1].
  4. Adds an optional top-k cut off for random sampling, where the next token at each timestep is only sampled from the k most likely vocabulary items. [2] effectively use this for conditioned story generation.

[1] Caccia, Massimo, et al. "Language GANs Falling Short." arXiv preprint arXiv:1811.02549 (2018). https://arxiv.org/pdf/1811.02549.pdf
[2] Fan, Angela, Mike Lewis, and Yann Dauphin. "Hierarchical Neural Story Generation." arXiv preprint arXiv:1805.04833 (2018). https://arxiv.org/abs/1805.04833

@daphnei daphnei mentioned this pull request Jan 3, 2019
@vince62s vince62s requested a review from guillaumekln January 3, 2019 12:56
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! This looks better than the previous PR and random sampling is very good to have.

P.S.: I still think we can merge beam search, greedy search, and random sampling together with some careful abstractions but that's another work.

onmt/translate/translator.py Outdated Show resolved Hide resolved
onmt/translate/translator.py Outdated Show resolved Hide resolved
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.

4 participants