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

[generate] do_sample default back to False #3298

Conversation

patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Mar 16, 2020

This somewhat reverts the commit:
6c1b235

and the decision taken in #2696

and sets the default sampling behavior of generate() to greedy - / beam search.

Pros:

  • False is the more natural default value
  • Prettier API (especially for encoder_decoder models which will mostly only use beam search generate())

Cons:

  • Some people might aleady be used to the do_sample=True default value and this commit might break the logic of their code (but would be trivial to change for them)

I'm somewhat indifferent whether this PR should be merged, but I think @thomwolf and @sshleifer are in favor of it.

@LysandreJik @thomwolf @sshleifer

src/transformers/modeling_tf_utils.py Show resolved Hide resolved
@@ -614,8 +614,8 @@ def generate(
input_ids=None,
max_length=None,
min_length=None,
do_sample=True,
early_stopping=False,
do_sample=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like it better like this, because all inputs are set no None . It defaults to False because that's how it's set in self.config.do_sample as a default. But up for debate I guess.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should document that in the docstring then. When someone sees "Defaults to" in the docstring and then gets different default behavior (because of their config) it would be confusing.

@sshleifer sshleifer changed the title Change do sample default back to false [generate] do_sample default back to False Mar 16, 2020
@patrickvonplaten patrickvonplaten force-pushed the change_do_sample_default_back_to_False branch from 34d4bac to 9857d2e Compare March 17, 2020 09:03
Copy link
Member

@thomwolf thomwolf left a comment

Choose a reason for hiding this comment

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

Yes good for me. Just tweak the docstring as mentioned by @sshleifer and me.
Nice work!

For the records, this reverts the decision taken in #2696
cc @minimaxir and @LysandreJik

src/transformers/modeling_tf_utils.py Show resolved Hide resolved
@minimaxir
Copy link

minimaxir commented Mar 17, 2020

Not 100% sure how this results in a "Prettier API," but agree this isn't a big deal to fix downstream. (my current code explicitly sets do_sample=True just in case something like this happened.)

If you are creating any demo generation notebooks/tooling like Write With Transformer, I recommend explicitly noting this behavior.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

LGTM, thanks, @patrickvonplaten

@LysandreJik LysandreJik merged commit e8f44af into huggingface:master Mar 17, 2020
jplu pushed a commit to jplu/transformers that referenced this pull request Mar 25, 2020
* change do_samples back

* None better default as boolean

* adapt do_sample to True in test example

* make style
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.

5 participants