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
chenpangpang
transformers
Commits
3be2d048
Unverified
Commit
3be2d048
authored
Aug 07, 2020
by
idoh
Committed by
GitHub
Aug 07, 2020
Browse files
fix consistency CrossEntropyLoss in modeling_bart (#6265)
parent
c72f9c90
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
2 deletions
+3
-2
src/transformers/modeling_bart.py
src/transformers/modeling_bart.py
+3
-2
No files found.
src/transformers/modeling_bart.py
View file @
3be2d048
...
@@ -1040,7 +1040,7 @@ class BartForConditionalGeneration(PretrainedBartModel):
...
@@ -1040,7 +1040,7 @@ class BartForConditionalGeneration(PretrainedBartModel):
masked_lm_loss
=
None
masked_lm_loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
loss_fct
=
nn
.
CrossEntropyLoss
()
loss_fct
=
CrossEntropyLoss
()
# TODO(SS): do we need to ignore pad tokens in labels?
# TODO(SS): do we need to ignore pad tokens in labels?
masked_lm_loss
=
loss_fct
(
lm_logits
.
view
(
-
1
,
self
.
config
.
vocab_size
),
labels
.
view
(
-
1
))
masked_lm_loss
=
loss_fct
(
lm_logits
.
view
(
-
1
,
self
.
config
.
vocab_size
),
labels
.
view
(
-
1
))
...
@@ -1179,7 +1179,8 @@ class BartForSequenceClassification(PretrainedBartModel):
...
@@ -1179,7 +1179,8 @@ class BartForSequenceClassification(PretrainedBartModel):
loss
=
None
loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
loss
=
F
.
cross_entropy
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
1
))
loss_fct
=
CrossEntropyLoss
()
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
1
))
if
not
return_dict
:
if
not
return_dict
:
output
=
(
logits
,)
+
outputs
[
1
:]
output
=
(
logits
,)
+
outputs
[
1
:]
...
...
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