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
b6933d76
Unverified
Commit
b6933d76
authored
May 03, 2023
by
Robert Stone
Committed by
GitHub
May 03, 2023
Browse files
Tidy Pytorch GLUE benchmark example (#23134)
Migration to Evaluate for metric is not quite complete
parent
b0a78091
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
9 deletions
+6
-9
examples/pytorch/text-classification/run_glue.py
examples/pytorch/text-classification/run_glue.py
+6
-9
No files found.
examples/pytorch/text-classification/run_glue.py
View file @
b6933d76
...
...
@@ -486,6 +486,8 @@ def main():
# Get the metric function
if
data_args
.
task_name
is
not
None
:
metric
=
evaluate
.
load
(
"glue"
,
data_args
.
task_name
)
elif
is_regression
:
metric
=
evaluate
.
load
(
"mse"
)
else
:
metric
=
evaluate
.
load
(
"accuracy"
)
...
...
@@ -494,15 +496,10 @@ def main():
def
compute_metrics
(
p
:
EvalPrediction
):
preds
=
p
.
predictions
[
0
]
if
isinstance
(
p
.
predictions
,
tuple
)
else
p
.
predictions
preds
=
np
.
squeeze
(
preds
)
if
is_regression
else
np
.
argmax
(
preds
,
axis
=
1
)
if
data_args
.
task_name
is
not
None
:
result
=
metric
.
compute
(
predictions
=
preds
,
references
=
p
.
label_ids
)
if
len
(
result
)
>
1
:
result
[
"combined_score"
]
=
np
.
mean
(
list
(
result
.
values
())).
item
()
return
result
elif
is_regression
:
return
{
"mse"
:
((
preds
-
p
.
label_ids
)
**
2
).
mean
().
item
()}
else
:
return
{
"accuracy"
:
(
preds
==
p
.
label_ids
).
astype
(
np
.
float32
).
mean
().
item
()}
# Data collator will default to DataCollatorWithPadding when the tokenizer is passed to Trainer, so we change it if
# we already did the padding.
...
...
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