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
ModelZoo
ResNet50_tensorflow
Commits
cec028b5
Commit
cec028b5
authored
Jun 11, 2022
by
Hongkun Yu
Committed by
A. Unique TensorFlower
Jun 11, 2022
Browse files
Internal change
PiperOrigin-RevId: 454382820
parent
a7b7c0b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
9 deletions
+17
-9
official/nlp/finetuning/glue/run_glue.py
official/nlp/finetuning/glue/run_glue.py
+7
-2
official/nlp/tasks/sentence_prediction.py
official/nlp/tasks/sentence_prediction.py
+8
-6
official/nlp/tasks/sentence_prediction_test.py
official/nlp/tasks/sentence_prediction_test.py
+2
-1
No files found.
official/nlp/finetuning/glue/run_glue.py
View file @
cec028b5
...
@@ -57,7 +57,7 @@ EVAL_METRIC_MAP = {
...
@@ -57,7 +57,7 @@ EVAL_METRIC_MAP = {
'MNLI'
:
'cls_accuracy'
,
'MNLI'
:
'cls_accuracy'
,
'MRPC'
:
'cls_accuracy'
,
'MRPC'
:
'cls_accuracy'
,
'QNLI'
:
'cls_accuracy'
,
'QNLI'
:
'cls_accuracy'
,
'QQP'
:
'
cls_accuracy
'
,
'QQP'
:
'
f1
'
,
'RTE'
:
'cls_accuracy'
,
'RTE'
:
'cls_accuracy'
,
'SST-2'
:
'cls_accuracy'
,
'SST-2'
:
'cls_accuracy'
,
'STS-B'
:
'pearson_spearman_corr'
,
'STS-B'
:
'pearson_spearman_corr'
,
...
@@ -93,11 +93,16 @@ def _override_exp_config_by_flags(exp_config, input_meta_data):
...
@@ -93,11 +93,16 @@ def _override_exp_config_by_flags(exp_config, input_meta_data):
binary_helper
.
override_sentence_prediction_task_config
,
binary_helper
.
override_sentence_prediction_task_config
,
num_classes
=
input_meta_data
[
'num_labels'
],
num_classes
=
input_meta_data
[
'num_labels'
],
metric_type
=
'matthews_corrcoef'
)
metric_type
=
'matthews_corrcoef'
)
elif
FLAGS
.
task_name
in
(
'MNLI'
,
'MRPC'
,
'QNLI'
,
'QQP'
,
'RTE'
,
'SST-2'
,
elif
FLAGS
.
task_name
in
(
'MNLI'
,
'MRPC'
,
'QNLI'
,
'RTE'
,
'SST-2'
,
'WNLI'
):
'WNLI'
):
override_task_cfg_fn
=
functools
.
partial
(
override_task_cfg_fn
=
functools
.
partial
(
binary_helper
.
override_sentence_prediction_task_config
,
binary_helper
.
override_sentence_prediction_task_config
,
num_classes
=
input_meta_data
[
'num_labels'
])
num_classes
=
input_meta_data
[
'num_labels'
])
elif
FLAGS
.
task_name
in
(
'QQP'
,):
override_task_cfg_fn
=
functools
.
partial
(
binary_helper
.
override_sentence_prediction_task_config
,
metric_type
=
'f1'
,
num_classes
=
input_meta_data
[
'num_labels'
])
elif
FLAGS
.
task_name
in
(
'STS-B'
,):
elif
FLAGS
.
task_name
in
(
'STS-B'
,):
override_task_cfg_fn
=
functools
.
partial
(
override_task_cfg_fn
=
functools
.
partial
(
binary_helper
.
override_sentence_prediction_task_config
,
binary_helper
.
override_sentence_prediction_task_config
,
...
...
official/nlp/tasks/sentence_prediction.py
View file @
cec028b5
...
@@ -34,7 +34,7 @@ from official.nlp.modeling import models
...
@@ -34,7 +34,7 @@ from official.nlp.modeling import models
from
official.nlp.tasks
import
utils
from
official.nlp.tasks
import
utils
METRIC_TYPES
=
frozenset
(
METRIC_TYPES
=
frozenset
(
[
'accuracy'
,
'matthews_corrcoef'
,
'pearson_spearman_corr'
])
[
'accuracy'
,
'f1'
,
'matthews_corrcoef'
,
'pearson_spearman_corr'
])
@
dataclasses
.
dataclass
@
dataclasses
.
dataclass
...
@@ -180,7 +180,7 @@ class SentencePredictionTask(base_task.Task):
...
@@ -180,7 +180,7 @@ class SentencePredictionTask(base_task.Task):
'labels'
:
'labels'
:
labels
[
self
.
label_field
],
labels
[
self
.
label_field
],
})
})
if
self
.
metric_type
==
'pearson_spearman_corr'
:
else
:
logs
.
update
({
logs
.
update
({
'sentence_prediction'
:
outputs
,
'sentence_prediction'
:
outputs
,
'labels'
:
labels
[
self
.
label_field
],
'labels'
:
labels
[
self
.
label_field
],
...
@@ -202,18 +202,20 @@ class SentencePredictionTask(base_task.Task):
...
@@ -202,18 +202,20 @@ class SentencePredictionTask(base_task.Task):
def
reduce_aggregated_logs
(
self
,
aggregated_logs
,
global_step
=
None
):
def
reduce_aggregated_logs
(
self
,
aggregated_logs
,
global_step
=
None
):
if
self
.
metric_type
==
'accuracy'
:
if
self
.
metric_type
==
'accuracy'
:
return
None
return
None
preds
=
np
.
concatenate
(
aggregated_logs
[
'sentence_prediction'
],
axis
=
0
)
labels
=
np
.
concatenate
(
aggregated_logs
[
'labels'
],
axis
=
0
)
if
self
.
metric_type
==
'f1'
:
preds
=
np
.
argmax
(
preds
,
axis
=
1
)
return
{
self
.
metric_type
:
100
*
sklearn_metrics
.
f1_score
(
labels
,
preds
)}
elif
self
.
metric_type
==
'matthews_corrcoef'
:
elif
self
.
metric_type
==
'matthews_corrcoef'
:
preds
=
np
.
concatenate
(
aggregated_logs
[
'sentence_prediction'
],
axis
=
0
)
preds
=
np
.
reshape
(
preds
,
-
1
)
preds
=
np
.
reshape
(
preds
,
-
1
)
labels
=
np
.
concatenate
(
aggregated_logs
[
'labels'
],
axis
=
0
)
labels
=
np
.
reshape
(
labels
,
-
1
)
labels
=
np
.
reshape
(
labels
,
-
1
)
return
{
return
{
self
.
metric_type
:
sklearn_metrics
.
matthews_corrcoef
(
preds
,
labels
)
self
.
metric_type
:
sklearn_metrics
.
matthews_corrcoef
(
preds
,
labels
)
}
}
elif
self
.
metric_type
==
'pearson_spearman_corr'
:
elif
self
.
metric_type
==
'pearson_spearman_corr'
:
preds
=
np
.
concatenate
(
aggregated_logs
[
'sentence_prediction'
],
axis
=
0
)
preds
=
np
.
reshape
(
preds
,
-
1
)
preds
=
np
.
reshape
(
preds
,
-
1
)
labels
=
np
.
concatenate
(
aggregated_logs
[
'labels'
],
axis
=
0
)
labels
=
np
.
reshape
(
labels
,
-
1
)
labels
=
np
.
reshape
(
labels
,
-
1
)
pearson_corr
=
stats
.
pearsonr
(
preds
,
labels
)[
0
]
pearson_corr
=
stats
.
pearsonr
(
preds
,
labels
)[
0
]
spearman_corr
=
stats
.
spearmanr
(
preds
,
labels
)[
0
]
spearman_corr
=
stats
.
spearmanr
(
preds
,
labels
)[
0
]
...
...
official/nlp/tasks/sentence_prediction_test.py
View file @
cec028b5
...
@@ -162,7 +162,8 @@ class SentencePredictionTaskTest(tf.test.TestCase, parameterized.TestCase):
...
@@ -162,7 +162,8 @@ class SentencePredictionTaskTest(tf.test.TestCase, parameterized.TestCase):
self
.
assertLess
(
loss
,
1.0
)
self
.
assertLess
(
loss
,
1.0
)
@
parameterized
.
parameters
((
"matthews_corrcoef"
,
2
),
@
parameterized
.
parameters
((
"matthews_corrcoef"
,
2
),
(
"pearson_spearman_corr"
,
1
))
(
"pearson_spearman_corr"
,
1
),
(
"f1"
,
2
))
def
test_np_metrics
(
self
,
metric_type
,
num_classes
):
def
test_np_metrics
(
self
,
metric_type
,
num_classes
):
config
=
sentence_prediction
.
SentencePredictionConfig
(
config
=
sentence_prediction
.
SentencePredictionConfig
(
metric_type
=
metric_type
,
metric_type
=
metric_type
,
...
...
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