From 81f4005f3d9e4b0b09c34f0c12b6ffc464b961a2 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 3 Apr 2018 23:11:48 +0200 Subject: [PATCH] Fix loading models with pretrained vectors --- spacy/language.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spacy/language.py b/spacy/language.py index 5f2b52e93..9fd922878 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -636,11 +636,11 @@ class Language(object): """ path = util.ensure_path(path) deserializers = OrderedDict(( - ('vocab', lambda p: self.vocab.from_disk(p)), + ('meta.json', lambda p: self.meta.update(util.read_json(p))), + ('vocab', lambda p: ( + self.vocab.from_disk(p) and _fix_pretrained_vectors_name(self))), ('tokenizer', lambda p: self.tokenizer.from_disk(p, vocab=False)), - ('meta.json', lambda p: self.meta.update(util.read_json(p))) )) - _fix_pretrained_vectors_name(self) for name, proc in self.pipeline: if name in disable: continue @@ -682,11 +682,11 @@ class Language(object): RETURNS (Language): The `Language` object. """ deserializers = OrderedDict(( - ('vocab', lambda b: self.vocab.from_bytes(b)), + ('meta', lambda b: self.meta.update(ujson.loads(b))), + ('vocab', lambda b: ( + self.vocab.from_bytes(b) and _fix_pretrained_vectors_name(self))), ('tokenizer', lambda b: self.tokenizer.from_bytes(b, vocab=False)), - ('meta', lambda b: self.meta.update(ujson.loads(b))) )) - _fix_pretrained_vectors_name(self) for i, (name, proc) in enumerate(self.pipeline): if name in disable: continue @@ -708,12 +708,12 @@ def _fix_pretrained_vectors_name(nlp): nlp.vocab.vectors.name = vectors_name else: raise ValueError(Errors.E092) + link_vectors_to_models(nlp.vocab) for name, proc in nlp.pipeline: if not hasattr(proc, 'cfg'): continue - if proc.cfg.get('pretrained_dims'): - assert nlp.vocab.vectors.name - proc.cfg['pretrained_vectors'] = nlp.vocab.vectors.name + proc.cfg.setdefault('deprecation_fixes', {}) + proc.cfg['deprecation_fixes']['vectors_name'] = nlp.vocab.vectors.name class DisabledPipes(list):