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
e7094b14
Commit
e7094b14
authored
Feb 23, 2018
by
Myle Ott
Committed by
Sergey Edunov
Feb 27, 2018
Browse files
Fix LabelSmoothedCrossEntropy test
parent
78a6ef02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
0 deletions
+3
-0
fairseq/criterions/label_smoothed_cross_entropy.py
fairseq/criterions/label_smoothed_cross_entropy.py
+3
-0
No files found.
fairseq/criterions/label_smoothed_cross_entropy.py
View file @
e7094b14
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
import
math
import
math
import
torch
import
torch
from
torch.autograd
import
Variable
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
from
fairseq
import
utils
from
fairseq
import
utils
...
@@ -24,6 +25,8 @@ class LabelSmoothedNLLLoss(torch.autograd.Function):
...
@@ -24,6 +25,8 @@ class LabelSmoothedNLLLoss(torch.autograd.Function):
norm
=
grad_input
.
size
(
-
1
)
norm
=
grad_input
.
size
(
-
1
)
if
weights
is
not
None
:
if
weights
is
not
None
:
if
isinstance
(
grad_input
,
Variable
)
and
not
isinstance
(
weights
,
Variable
):
weights
=
Variable
(
weights
,
requires_grad
=
False
)
norm
=
weights
.
sum
()
norm
=
weights
.
sum
()
grad_input
.
mul
(
weights
.
view
(
1
,
weights
.
size
(
0
)).
expand_as
(
grad_input
))
grad_input
.
mul
(
weights
.
view
(
1
,
weights
.
size
(
0
)).
expand_as
(
grad_input
))
...
...
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