From 3836199a835417d0c2efbb4e8e0a54dff32a0a84 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 10 Apr 2018 22:19:05 +0200 Subject: [PATCH] Fix loading of models when custom vectors are added --- spacy/pipeline.pyx | 8 ++++---- spacy/syntax/nn_parser.pyx | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spacy/pipeline.pyx b/spacy/pipeline.pyx index e9ef2e892..f6e948b2f 100644 --- a/spacy/pipeline.pyx +++ b/spacy/pipeline.pyx @@ -206,7 +206,7 @@ class Pipe(object): """Load the pipe from a bytestring.""" def load_model(b): # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name if self.model is True: self.model = self.Model(**self.cfg) @@ -233,7 +233,7 @@ class Pipe(object): """Load the pipe from disk.""" def load_model(p): # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name if self.model is True: self.model = self.Model(**self.cfg) @@ -578,7 +578,7 @@ class Tagger(Pipe): def from_bytes(self, bytes_data, **exclude): def load_model(b): # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name if self.model is True: @@ -619,7 +619,7 @@ class Tagger(Pipe): def from_disk(self, path, **exclude): def load_model(p): # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name if self.model is True: self.model = self.Model(self.vocab.morphology.n_tags, **self.cfg) diff --git a/spacy/syntax/nn_parser.pyx b/spacy/syntax/nn_parser.pyx index 5dbac10ce..8dfae7925 100644 --- a/spacy/syntax/nn_parser.pyx +++ b/spacy/syntax/nn_parser.pyx @@ -901,7 +901,7 @@ cdef class Parser: util.from_disk(path, deserializers, exclude) if 'model' not in exclude: # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name path = util.ensure_path(path) if self.model is True: @@ -948,7 +948,7 @@ cdef class Parser: msg = util.from_bytes(bytes_data, deserializers, exclude) if 'model' not in exclude: # TODO: Remove this once we don't have to handle previous models - if 'pretrained_dims' in self.cfg and 'pretrained_vectors' not in self.cfg: + if self.cfg.get('pretrained_dims') and 'pretrained_vectors' not in self.cfg: self.cfg['pretrained_vectors'] = self.vocab.vectors.name if self.model is True: self.model, cfg = self.Model(**self.cfg)