Do not train model if its going to be loaded from disk

This saves significant time in loading a model from disk.

Signed-off-by: Avadh Patel <avadh4all@gmail.com>
This commit is contained in:
Avadh Patel 2018-01-17 06:16:07 -06:00
parent 67ba73351d
commit fe879da2a1
1 changed files with 3 additions and 2 deletions

View File

@ -271,6 +271,7 @@ cdef class Parser:
# TODO: This is an unfortunate hack atm! # TODO: This is an unfortunate hack atm!
# Used to set input dimensions in network. # Used to set input dimensions in network.
if not cfg.get('from_disk', False):
lower.begin_training(lower.ops.allocate((500, token_vector_width))) lower.begin_training(lower.ops.allocate((500, token_vector_width)))
cfg = { cfg = {
'nr_class': nr_class, 'nr_class': nr_class,
@ -888,7 +889,7 @@ cdef class Parser:
path = util.ensure_path(path) path = util.ensure_path(path)
if self.model is True: if self.model is True:
self.cfg['pretrained_dims'] = self.vocab.vectors_length self.cfg['pretrained_dims'] = self.vocab.vectors_length
self.model, cfg = self.Model(**self.cfg) self.model, cfg = self.Model(from_disk=True, **self.cfg)
else: else:
cfg = {} cfg = {}
with (path / 'tok2vec_model').open('rb') as file_: with (path / 'tok2vec_model').open('rb') as file_: