Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Fairseq
Commits
f68a4435
Commit
f68a4435
authored
Apr 01, 2018
by
Myle Ott
Browse files
Bug fixes
parent
1235aa08
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
fairseq/modules/multihead_attention.py
fairseq/modules/multihead_attention.py
+3
-1
fairseq/modules/sinusoidal_positional_embedding.py
fairseq/modules/sinusoidal_positional_embedding.py
+1
-1
No files found.
fairseq/modules/multihead_attention.py
View file @
f68a4435
...
...
@@ -12,6 +12,8 @@ from torch import nn
from
torch.nn
import
Parameter
import
torch.nn.functional
as
F
from
fairseq
import
utils
class
MultiheadAttention
(
nn
.
Module
):
"""Multi-headed attention.
...
...
@@ -88,7 +90,7 @@ class MultiheadAttention(nn.Module):
attn_weights
+=
self
.
buffered_mask
(
attn_weights
).
unsqueeze
(
0
)
if
key_padding_mask
is
not
None
:
# don't attend to padding symbols
if
key_padding_mask
.
max
()
>
0
:
if
utils
.
item
(
key_padding_mask
.
max
()
)
>
0
:
attn_weights
=
attn_weights
.
view
(
bsz
,
self
.
num_heads
,
tgt_len
,
src_len
)
attn_weights
=
attn_weights
.
masked_fill
(
key_padding_mask
.
unsqueeze
(
1
).
unsqueeze
(
2
),
...
...
fairseq/modules/sinusoidal_positional_embedding.py
View file @
f68a4435
...
...
@@ -62,7 +62,7 @@ class SinusoidalPositionalEmbedding(nn.Module):
# recompute/expand embeddings if needed
bsz
,
seq_len
=
input
.
size
()
max_pos
=
self
.
padding_idx
+
1
+
seq_len
if
seq_len
>
self
.
weights
.
size
(
0
):
if
max_pos
>
self
.
weights
.
size
(
0
):
self
.
weights
=
SinusoidalPositionalEmbedding
.
get_embedding
(
max_pos
,
self
.
embedding_dim
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment