Skip to content

Add a dedicated padding token to beam search to avoid padding with the start sentence token #10386

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LoicDagnas
Copy link

Description

So far, the beam search module pads its predictions using the initial token ids, it is more modular and easy to use to have the capacity to specify the padding token. By default this padding token should be zero and not the initial token id.

Type of change

For a new feature or function, please create an issue first to discuss it
with us before submitting a pull request.

Note: Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Tests

I have added a naive unittest which failed before my modification and passes now.

Checklist

@google-cla google-cla bot added the cla: yes label Nov 23, 2021
@saberkun saberkun requested review from frederick0329 and removed request for jaeyounkim, rachellj218 and lehougoogle December 15, 2021 05:19
@laxmareddyp laxmareddyp added the models:official models that come under official repository label Nov 16, 2022
@saberkun
Copy link
Member

Conflicts need to resolve.
Reassign to @ByzanTine

@saberkun saberkun requested review from ByzanTine and removed request for saberkun and frederick0329 January 20, 2023 20:21
@@ -409,7 +412,7 @@ def _create_initial_state(self, initial_ids, initial_cache, batch_size):
alive_seq = expand_to_beam_size(initial_ids, self.beam_size)
alive_seq = tf.expand_dims(alive_seq, axis=2)
if self.padded_decode:
alive_seq = tf.tile(alive_seq, [1, 1, self.max_decode_length + 1])
alive_seq = tf.pad(alive_seq, [[0, 0], [0, 0], [0, self.max_decode_length]], constant_values=self.pad_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to remove the extra spaces in front of this line to conform to our Python styling

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think need to resolve the conflict as well, will create a new PR with all above changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes models:official models that come under official repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants