Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
fc741325
Commit
fc741325
authored
Aug 20, 2019
by
erenup
Browse files
add best steps to train
parent
97c30b73
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
examples/single_model_scripts/run_multiple_choice.py
examples/single_model_scripts/run_multiple_choice.py
+9
-6
No files found.
examples/single_model_scripts/run_multiple_choice.py
View file @
fc741325
...
@@ -127,6 +127,7 @@ def train(args, train_dataset, model, tokenizer):
...
@@ -127,6 +127,7 @@ def train(args, train_dataset, model, tokenizer):
global_step
=
0
global_step
=
0
tr_loss
,
logging_loss
=
0.0
,
0.0
tr_loss
,
logging_loss
=
0.0
,
0.0
best_dev_acc
,
best_dev_loss
=
0.0
,
99999999999.0
best_dev_acc
,
best_dev_loss
=
0.0
,
99999999999.0
best_steps
=
0
model
.
zero_grad
()
model
.
zero_grad
()
train_iterator
=
trange
(
int
(
args
.
num_train_epochs
),
desc
=
"Epoch"
,
disable
=
args
.
local_rank
not
in
[
-
1
,
0
])
train_iterator
=
trange
(
int
(
args
.
num_train_epochs
),
desc
=
"Epoch"
,
disable
=
args
.
local_rank
not
in
[
-
1
,
0
])
set_seed
(
args
)
# Added here for reproductibility (even between python 2 and 3)
set_seed
(
args
)
# Added here for reproductibility (even between python 2 and 3)
...
@@ -171,6 +172,8 @@ def train(args, train_dataset, model, tokenizer):
...
@@ -171,6 +172,8 @@ def train(args, train_dataset, model, tokenizer):
if
results
[
"eval_loss"
]
<
best_dev_loss
:
if
results
[
"eval_loss"
]
<
best_dev_loss
:
best_dev_acc
=
results
[
"eval_acc"
]
best_dev_acc
=
results
[
"eval_acc"
]
best_dev_loss
=
results
[
"eval_loss"
]
best_dev_loss
=
results
[
"eval_loss"
]
best_steps
=
global_step
if
args
.
do_test
:
results_test
=
evaluate
(
args
,
model
,
tokenizer
,
test
=
True
)
results_test
=
evaluate
(
args
,
model
,
tokenizer
,
test
=
True
)
for
key
,
value
in
results_test
.
items
():
for
key
,
value
in
results_test
.
items
():
tb_writer
.
add_scalar
(
'test_{}'
.
format
(
key
),
value
,
global_step
)
tb_writer
.
add_scalar
(
'test_{}'
.
format
(
key
),
value
,
global_step
)
...
@@ -201,7 +204,7 @@ def train(args, train_dataset, model, tokenizer):
...
@@ -201,7 +204,7 @@ def train(args, train_dataset, model, tokenizer):
if
args
.
local_rank
in
[
-
1
,
0
]:
if
args
.
local_rank
in
[
-
1
,
0
]:
tb_writer
.
close
()
tb_writer
.
close
()
return
global_step
,
tr_loss
/
global_step
return
global_step
,
tr_loss
/
global_step
,
best_steps
def
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
""
,
test
=
False
):
def
evaluate
(
args
,
model
,
tokenizer
,
prefix
=
""
,
test
=
False
):
...
@@ -471,7 +474,7 @@ def main():
...
@@ -471,7 +474,7 @@ def main():
# Training
# Training
if
args
.
do_train
:
if
args
.
do_train
:
train_dataset
=
load_and_cache_examples
(
args
,
args
.
task_name
,
tokenizer
,
evaluate
=
False
)
train_dataset
=
load_and_cache_examples
(
args
,
args
.
task_name
,
tokenizer
,
evaluate
=
False
)
global_step
,
tr_loss
=
train
(
args
,
train_dataset
,
model
,
tokenizer
)
global_step
,
tr_loss
,
_
=
train
(
args
,
train_dataset
,
model
,
tokenizer
)
logger
.
info
(
" global_step = %s, average loss = %s"
,
global_step
,
tr_loss
)
logger
.
info
(
" global_step = %s, average loss = %s"
,
global_step
,
tr_loss
)
...
...
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