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
d49d3cf6
Unverified
Commit
d49d3cf6
authored
Apr 13, 2021
by
calpt
Committed by
GitHub
Apr 13, 2021
Browse files
Use MSELoss in (M)BartForSequenceClassification (#11178)
parent
f243a5ec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
src/transformers/models/bart/modeling_bart.py
src/transformers/models/bart/modeling_bart.py
+8
-3
src/transformers/models/mbart/modeling_mbart.py
src/transformers/models/mbart/modeling_mbart.py
+8
-3
No files found.
src/transformers/models/bart/modeling_bart.py
View file @
d49d3cf6
...
...
@@ -23,7 +23,7 @@ import torch
import
torch.nn.functional
as
F
import
torch.utils.checkpoint
from
torch
import
nn
from
torch.nn
import
CrossEntropyLoss
from
torch.nn
import
CrossEntropyLoss
,
MSELoss
from
...activations
import
ACT2FN
from
...file_utils
import
(
...
...
@@ -1437,6 +1437,11 @@ class BartForSequenceClassification(BartPretrainedModel):
loss
=
None
if
labels
is
not
None
:
if
self
.
config
.
num_labels
==
1
:
# regression
loss_fct
=
MSELoss
()
loss
=
loss_fct
(
logits
.
view
(
-
1
),
labels
.
view
(
-
1
))
else
:
loss_fct
=
CrossEntropyLoss
()
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
1
))
...
...
src/transformers/models/mbart/modeling_mbart.py
View file @
d49d3cf6
...
...
@@ -22,7 +22,7 @@ import torch
import
torch.nn.functional
as
F
import
torch.utils.checkpoint
from
torch
import
nn
from
torch.nn
import
CrossEntropyLoss
from
torch.nn
import
CrossEntropyLoss
,
MSELoss
from
...activations
import
ACT2FN
from
...file_utils
import
(
...
...
@@ -1442,6 +1442,11 @@ class MBartForSequenceClassification(MBartPreTrainedModel):
loss
=
None
if
labels
is
not
None
:
if
self
.
config
.
num_labels
==
1
:
# regression
loss_fct
=
MSELoss
()
loss
=
loss_fct
(
logits
.
view
(
-
1
),
labels
.
view
(
-
1
))
else
:
loss_fct
=
CrossEntropyLoss
()
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
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