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

Possible bug in the padding mask handling #14

Open
bjourne opened this issue Jun 28, 2020 · 2 comments
Open

Possible bug in the padding mask handling #14

bjourne opened this issue Jun 28, 2020 · 2 comments

Comments

@bjourne
Copy link

bjourne commented Jun 28, 2020

I've stared at these lines in your excellent tutorial for a while now:

 enc_padding_mask = tf.keras.layers.Lambda(
     create_padding_mask, output_shape=(1, 1, None),
     name='enc_padding_mask')(inputs)
 # mask the future tokens for decoder inputs at the 1st attention block
 look_ahead_mask = tf.keras.layers.Lambda(
     create_look_ahead_mask,
     output_shape=(1, None, None),
     name='look_ahead_mask')(dec_inputs)
 # mask the encoder outputs for the 2nd attention block
 dec_padding_mask = tf.keras.layers.Lambda(
     create_padding_mask, output_shape=(1, 1, None),
     name='dec_padding_mask')(inputs)

enc_padding_mask and dec_padding_mask will always be equal. Is this intentional? It seems weird to create two different padding masks that are the same.

@bryanlimy
Copy link
Owner

Yes, I believe so. These two masks are to mask out the padding tokens in the input sentence, see http://nlp.seas.harvard.edu/2018/04/03/attention.html#batches-and-masking

@bjourne
Copy link
Author

bjourne commented Jun 28, 2020

Oh, I see. But then it would be more efficient to only use one mask?

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

No branches or pull requests

2 participants