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
54e9ce78
Unverified
Commit
54e9ce78
authored
Jun 24, 2020
by
Kevin Canwen Xu
Committed by
GitHub
Jun 24, 2020
Browse files
Fix PABEE division by zero error (#5233)
* Fix PABEE division by zero error * patience=0 by default
parent
9022ef02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
12 deletions
+7
-12
examples/bert-loses-patience/run_glue_with_pabee.py
examples/bert-loses-patience/run_glue_with_pabee.py
+7
-12
No files found.
examples/bert-loses-patience/run_glue_with_pabee.py
View file @
54e9ce78
...
@@ -254,12 +254,15 @@ def train(args, train_dataset, model, tokenizer):
...
@@ -254,12 +254,15 @@ def train(args, train_dataset, model, tokenizer):
return
global_step
,
tr_loss
/
global_step
return
global_step
,
tr_loss
/
global_step
def
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
""
):
def
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
""
,
patience
=
0
):
# PABEE STATS
if
args
.
model_type
==
"albert"
:
if
args
.
model_type
==
"albert"
:
model
.
albert
.
set_regression_threshold
(
args
.
regression_threshold
)
model
.
albert
.
set_patience
(
patience
)
model
.
albert
.
reset_stats
()
model
.
albert
.
reset_stats
()
elif
args
.
model_type
==
"bert"
:
elif
args
.
model_type
==
"bert"
:
model
.
bert
.
set_regression_threshold
(
args
.
regression_threshold
)
model
.
bert
.
set_patience
(
patience
)
model
.
bert
.
reset_stats
()
model
.
bert
.
reset_stats
()
else
:
else
:
raise
NotImplementedError
()
raise
NotImplementedError
()
...
@@ -331,7 +334,7 @@ def evaluate(args, model, tokenizer, prefix=""):
...
@@ -331,7 +334,7 @@ def evaluate(args, model, tokenizer, prefix=""):
print
(
" %s = %s"
%
(
key
,
str
(
result
[
key
])))
print
(
" %s = %s"
%
(
key
,
str
(
result
[
key
])))
writer
.
write
(
"%s = %s
\n
"
%
(
key
,
str
(
result
[
key
])))
writer
.
write
(
"%s = %s
\n
"
%
(
key
,
str
(
result
[
key
])))
if
args
.
eval_all_checkpoints
:
if
args
.
eval_all_checkpoints
and
patience
!=
0
:
if
args
.
model_type
==
"albert"
:
if
args
.
model_type
==
"albert"
:
model
.
albert
.
log_stats
()
model
.
albert
.
log_stats
()
elif
args
.
model_type
==
"bert"
:
elif
args
.
model_type
==
"bert"
:
...
@@ -690,15 +693,7 @@ def main():
...
@@ -690,15 +693,7 @@ def main():
print
(
f
"Evaluation for checkpoint
{
prefix
}
"
)
print
(
f
"Evaluation for checkpoint
{
prefix
}
"
)
for
patience
in
patience_list
:
for
patience
in
patience_list
:
if
args
.
model_type
==
"albert"
:
result
=
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
prefix
,
patience
=
patience
)
model
.
albert
.
set_regression_threshold
(
args
.
regression_threshold
)
model
.
albert
.
set_patience
(
patience
)
elif
args
.
model_type
==
"bert"
:
model
.
bert
.
set_regression_threshold
(
args
.
regression_threshold
)
model
.
bert
.
set_patience
(
patience
)
else
:
raise
NotImplementedError
()
result
=
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
prefix
)
result
=
dict
((
k
+
"_{}"
.
format
(
global_step
),
v
)
for
k
,
v
in
result
.
items
())
result
=
dict
((
k
+
"_{}"
.
format
(
global_step
),
v
)
for
k
,
v
in
result
.
items
())
results
.
update
(
result
)
results
.
update
(
result
)
return
results
return
results
...
...
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