diff --git a/spacy/_ml.py b/spacy/_ml.py index 5cccabac1..60a0bbee0 100644 --- a/spacy/_ml.py +++ b/spacy/_ml.py @@ -279,18 +279,19 @@ class PrecomputableAffine(Model): break -def link_vectors_to_models(vocab): +def link_vectors_to_models(vocab, skip_rank=False): vectors = vocab.vectors if vectors.name is None: vectors.name = VECTORS_KEY if vectors.data.size != 0: warnings.warn(Warnings.W020.format(shape=vectors.data.shape)) ops = Model.ops - for word in vocab: - if word.orth in vectors.key2row: - word.rank = vectors.key2row[word.orth] - else: - word.rank = util.OOV_RANK + if not skip_rank: + for word in vocab: + if word.orth in vectors.key2row: + word.rank = vectors.key2row[word.orth] + else: + word.rank = util.OOV_RANK data = ops.asarray(vectors.data) # Set an entry here, so that vectors are accessed by StaticVectors # (unideal, I know) diff --git a/spacy/language.py b/spacy/language.py index e89f80f08..f23776def 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -1072,7 +1072,7 @@ def _fix_pretrained_vectors_name(nlp): else: raise ValueError(Errors.E092) if nlp.vocab.vectors.size != 0: - link_vectors_to_models(nlp.vocab) + link_vectors_to_models(nlp.vocab, skip_rank=True) for name, proc in nlp.pipeline: if not hasattr(proc, "cfg"): continue