Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Adding a min_steps parameter to BeamSearch #5207

Merged
merged 9 commits into from
May 17, 2021

Conversation

danieldeutsch
Copy link
Contributor

@danieldeutsch danieldeutsch commented May 17, 2021

Implements feature request 1 from #5205.

Changes proposed in this pull request:

  • Adds a min_steps parameter to BeamSearch, which allows specifying the minimum length of the predicted sequences. This is commonly used in tasks like summarization, for instance by BART

Before submitting

  • I've read and followed all steps in the Making a pull request
    section of the CONTRIBUTING docs.
  • I've updated or added any relevant docstrings following the syntax described in the
    Writing docstrings section of the CONTRIBUTING docs.
  • If this PR fixes a bug, I've added a test that will fail without my fix.
  • If this PR adds a new feature, I've added tests that sufficiently cover my new functionality.

After submitting

  • All GitHub Actions jobs for my pull request have passed.
  • codecov/patch reports high test coverage (at least 90%).
    You can find this under the "Actions" tab of the pull request once the other checks have finished.

Copy link
Member

@epwalsh epwalsh left a comment

Choose a reason for hiding this comment

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

Thanks @danieldeutsch, this looks great! I just have one comment

@@ -471,19 +475,25 @@ def __init__(
beam_size: int = 10,
per_node_beam_size: int = None,
sampler: Sampler = None,
min_steps: int = 0,
Copy link
Member

Choose a reason for hiding this comment

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

I think making this an Optional[int] is more clear.

Suggested change
min_steps: int = 0,
min_steps: Optional[int] = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I pushed this change. I had to change the code to make sure the value is valid, too.

@epwalsh epwalsh enabled auto-merge (squash) May 17, 2021 21:25
Copy link
Member

@epwalsh epwalsh left a comment

Choose a reason for hiding this comment

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

LGTM!

@epwalsh epwalsh merged commit 79d16af into allenai:main May 17, 2021
@danieldeutsch danieldeutsch deleted the min-length branch May 17, 2021 21:27
Abhishek-P pushed a commit to Abhishek-P/allennlp that referenced this pull request Aug 11, 2021
* Implementing minimum number of decoding steps

* Adding unit tests

* Reformatting

* Adding entry to changelog

* Adding end token comment

* Adding start token comment

* Changing param to optional

Co-authored-by: Pete <petew@allenai.org>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants