-
Notifications
You must be signed in to change notification settings - Fork 242
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
Added Support for Returning Attention Scores in TransformerEncoder call #1879
Changes from 2 commits
fbcb810
db38e19
6d853ad
952593a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,3 +109,14 @@ def test_mask_propagation(self): | |
inputs._keras_mask = mask | ||
outputs = encoder(inputs) | ||
self.assertAllEqual(outputs._keras_mask, mask) | ||
|
||
def test_attention_scores(self): | ||
encoder = TransformerEncoder(intermediate_dim=4, num_heads=2) | ||
inputs = random.uniform(shape=[1, 4, 6]) | ||
outputs, attention_scores = encoder( | ||
inputs, return_attention_scores=True | ||
) | ||
print(attention_scores) | ||
assert outputs.shape == inputs.shape | ||
# attention scores shape (batch_size, num_of_attn_heads, seq_length, seq_length) | ||
assert attention_scores.shape == [1, 2, 4, 4] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I have made the changes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for making the changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this
print
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes will remove the print statement. Thanks for pointing it out!