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
e1f49695
Commit
e1f49695
authored
Nov 07, 2017
by
Myle Ott
Browse files
Rename LabelSmoothedCrossEntropy to LabelSmoothedNLLLoss
parent
b1dfd39e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
4 deletions
+4
-4
fairseq/criterions/label_smoothed_cross_entropy.py
fairseq/criterions/label_smoothed_cross_entropy.py
+2
-2
tests/test_label_smoothing.py
tests/test_label_smoothing.py
+2
-2
No files found.
fairseq/criterions/label_smoothed_cross_entropy.py
View file @
e1f49695
...
@@ -14,7 +14,7 @@ import torch.nn.functional as F
...
@@ -14,7 +14,7 @@ import torch.nn.functional as F
from
.fairseq_criterion
import
FairseqCriterion
from
.fairseq_criterion
import
FairseqCriterion
class
LabelSmoothed
CrossEntropy
(
torch
.
autograd
.
Function
):
class
LabelSmoothed
NLLLoss
(
torch
.
autograd
.
Function
):
@
staticmethod
@
staticmethod
def
forward
(
ctx
,
input
,
target
,
eps
,
padding_idx
,
weights
):
def
forward
(
ctx
,
input
,
target
,
eps
,
padding_idx
,
weights
):
...
@@ -59,7 +59,7 @@ class LabelSmoothedCrossEntropyCriterion(FairseqCriterion):
...
@@ -59,7 +59,7 @@ class LabelSmoothedCrossEntropyCriterion(FairseqCriterion):
net_output
=
model
(
**
sample
[
'net_input'
])
net_output
=
model
(
**
sample
[
'net_input'
])
input
=
F
.
log_softmax
(
net_output
.
view
(
-
1
,
net_output
.
size
(
-
1
)))
input
=
F
.
log_softmax
(
net_output
.
view
(
-
1
,
net_output
.
size
(
-
1
)))
target
=
sample
[
'target'
].
view
(
-
1
)
target
=
sample
[
'target'
].
view
(
-
1
)
loss
=
LabelSmoothed
CrossEntropy
.
apply
(
input
,
target
,
self
.
eps
,
self
.
padding_idx
,
self
.
weights
)
loss
=
LabelSmoothed
NLLLoss
.
apply
(
input
,
target
,
self
.
eps
,
self
.
padding_idx
,
self
.
weights
)
sample_size
=
sample
[
'target'
].
size
(
0
)
if
self
.
args
.
sentence_avg
else
sample
[
'ntokens'
]
sample_size
=
sample
[
'target'
].
size
(
0
)
if
self
.
args
.
sentence_avg
else
sample
[
'ntokens'
]
logging_output
=
{
logging_output
=
{
'loss'
:
loss
.
data
[
0
],
'loss'
:
loss
.
data
[
0
],
...
...
tests/test_label_smoothing.py
View file @
e1f49695
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
import
torch
import
torch
import
unittest
import
unittest
from
fairseq.criterions.label_smoothed_cross_entropy
import
LabelSmoothed
CrossEntropy
from
fairseq.criterions.label_smoothed_cross_entropy
import
LabelSmoothed
NLLLoss
from
torch.autograd
import
Variable
,
gradcheck
from
torch.autograd
import
Variable
,
gradcheck
...
@@ -21,7 +21,7 @@ class TestLabelSmoothing(unittest.TestCase):
...
@@ -21,7 +21,7 @@ class TestLabelSmoothing(unittest.TestCase):
input
=
Variable
(
torch
.
randn
(
3
,
5
),
requires_grad
=
True
)
input
=
Variable
(
torch
.
randn
(
3
,
5
),
requires_grad
=
True
)
idx
=
torch
.
rand
(
3
)
*
4
idx
=
torch
.
rand
(
3
)
*
4
target
=
Variable
(
idx
.
long
())
target
=
Variable
(
idx
.
long
())
criterion
=
LabelSmoothed
CrossEntropy
()
criterion
=
LabelSmoothed
NLLLoss
()
self
.
assertTrue
(
gradcheck
(
self
.
assertTrue
(
gradcheck
(
lambda
x
,
y
:
criterion
.
apply
(
x
,
y
,
0.1
,
2
,
None
),
(
input
,
target
)
lambda
x
,
y
:
criterion
.
apply
(
x
,
y
,
0.1
,
2
,
None
),
(
input
,
target
)
))
))
...
...
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