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
Hide 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
...
@@ -23,7 +23,7 @@ import torch
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
torch.utils.checkpoint
import
torch.utils.checkpoint
from
torch
import
nn
from
torch
import
nn
from
torch.nn
import
CrossEntropyLoss
from
torch.nn
import
CrossEntropyLoss
,
MSELoss
from
...activations
import
ACT2FN
from
...activations
import
ACT2FN
from
...file_utils
import
(
from
...file_utils
import
(
...
@@ -1437,8 +1437,13 @@ class BartForSequenceClassification(BartPretrainedModel):
...
@@ -1437,8 +1437,13 @@ class BartForSequenceClassification(BartPretrainedModel):
loss
=
None
loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
loss_fct
=
CrossEntropyLoss
()
if
self
.
config
.
num_labels
==
1
:
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
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
))
if
not
return_dict
:
if
not
return_dict
:
output
=
(
logits
,)
+
outputs
[
1
:]
output
=
(
logits
,)
+
outputs
[
1
:]
...
...
src/transformers/models/mbart/modeling_mbart.py
View file @
d49d3cf6
...
@@ -22,7 +22,7 @@ import torch
...
@@ -22,7 +22,7 @@ import torch
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
torch.utils.checkpoint
import
torch.utils.checkpoint
from
torch
import
nn
from
torch
import
nn
from
torch.nn
import
CrossEntropyLoss
from
torch.nn
import
CrossEntropyLoss
,
MSELoss
from
...activations
import
ACT2FN
from
...activations
import
ACT2FN
from
...file_utils
import
(
from
...file_utils
import
(
...
@@ -1442,8 +1442,13 @@ class MBartForSequenceClassification(MBartPreTrainedModel):
...
@@ -1442,8 +1442,13 @@ class MBartForSequenceClassification(MBartPreTrainedModel):
loss
=
None
loss
=
None
if
labels
is
not
None
:
if
labels
is
not
None
:
loss_fct
=
CrossEntropyLoss
()
if
self
.
config
.
num_labels
==
1
:
loss
=
loss_fct
(
logits
.
view
(
-
1
,
self
.
config
.
num_labels
),
labels
.
view
(
-
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
))
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