Make loading code more consistent in train command

This commit is contained in:
Matthew Honnibal 2017-10-10 12:51:20 -05:00
parent 97c9b5db8b
commit 5156074df1

View File

@ -114,10 +114,7 @@ def train(cmd, lang, output_dir, train_data, dev_data, n_iter=10, n_sents=0,
util.set_env_log(False) util.set_env_log(False)
epoch_model_path = output_path / ('model%d' % i) epoch_model_path = output_path / ('model%d' % i)
nlp.to_disk(epoch_model_path) nlp.to_disk(epoch_model_path)
nlp_loaded = lang_class(pipeline=pipeline) nlp_loaded = util.load_model_from_path(epoch_model_path)
for name in pipeline:
nlp_loaded.add_pipe(nlp.create_pipe(name), name=name)
nlp_loaded = nlp_loaded.from_disk(epoch_model_path)
dev_docs = list(corpus.dev_docs( dev_docs = list(corpus.dev_docs(
nlp_loaded, nlp_loaded,
gold_preproc=gold_preproc)) gold_preproc=gold_preproc))
@ -131,11 +128,7 @@ def train(cmd, lang, output_dir, train_data, dev_data, n_iter=10, n_sents=0,
else: else:
gpu_wps = nwords/(end_time-start_time) gpu_wps = nwords/(end_time-start_time)
with Model.use_device('cpu'): with Model.use_device('cpu'):
nlp_loaded = lang_class(pipeline=pipeline) nlp_loaded = util.load_model_from_path(epoch_model_path)
for name in pipeline:
nlp_loaded.add_pipe(nlp.create_pipe(name), name=name)
nlp_loaded = nlp_loaded.from_disk(epoch_model_path)
dev_docs = list(corpus.dev_docs( dev_docs = list(corpus.dev_docs(
nlp_loaded, gold_preproc=gold_preproc)) nlp_loaded, gold_preproc=gold_preproc))
start_time = timer() start_time = timer()