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
f607d9e8
Commit
f607d9e8
authored
Apr 13, 2018
by
Myle Ott
Browse files
Small optimization for LSTM
parent
8fcdb9b7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
fairseq/models/lstm.py
fairseq/models/lstm.py
+1
-1
No files found.
fairseq/models/lstm.py
View file @
f607d9e8
...
@@ -245,7 +245,7 @@ class AttentionLayer(nn.Module):
...
@@ -245,7 +245,7 @@ class AttentionLayer(nn.Module):
float
(
'-inf'
)
float
(
'-inf'
)
).
type_as
(
attn_scores
)
# FP16 support: cast to float and back
).
type_as
(
attn_scores
)
# FP16 support: cast to float and back
attn_scores
=
F
.
softmax
(
attn_scores
.
t
()
,
dim
=
1
).
t
(
)
# srclen x bsz
attn_scores
=
F
.
softmax
(
attn_scores
,
dim
=
0
)
# srclen x bsz
# sum weighted sources
# sum weighted sources
x
=
(
attn_scores
.
unsqueeze
(
2
)
*
source_hids
).
sum
(
dim
=
0
)
x
=
(
attn_scores
.
unsqueeze
(
2
)
*
source_hids
).
sum
(
dim
=
0
)
...
...
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