From fe879da2a1b1faa3d008b834a647d691e35bbac4 Mon Sep 17 00:00:00 2001 From: Avadh Patel Date: Wed, 17 Jan 2018 06:16:07 -0600 Subject: [PATCH] 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 --- spacy/syntax/nn_parser.pyx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index bb01cecf1..12cb27bb2 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -271,7 +271,8 @@ cdef class Parser: # TODO: This is an unfortunate hack atm! # Used to set input dimensions in network. - lower.begin_training(lower.ops.allocate((500, token_vector_width))) + if not cfg.get('from_disk', False): + lower.begin_training(lower.ops.allocate((500, token_vector_width))) cfg = { 'nr_class': nr_class, 'hidden_depth': depth, @@ -888,7 +889,7 @@ cdef class Parser: path = util.ensure_path(path) if self.model is True: 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: cfg = {} with (path / 'tok2vec_model').open('rb') as file_: