mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 01:46:28 +03:00
Skip duplicate lexeme rank setting (#5401)
Skip duplicate lexeme rank setting within `_fix_pretrained_vectors_name()`.
This commit is contained in:
parent
f49e2810e6
commit
908dea3939
13
spacy/_ml.py
13
spacy/_ml.py
|
@ -279,18 +279,19 @@ class PrecomputableAffine(Model):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def link_vectors_to_models(vocab):
|
def link_vectors_to_models(vocab, skip_rank=False):
|
||||||
vectors = vocab.vectors
|
vectors = vocab.vectors
|
||||||
if vectors.name is None:
|
if vectors.name is None:
|
||||||
vectors.name = VECTORS_KEY
|
vectors.name = VECTORS_KEY
|
||||||
if vectors.data.size != 0:
|
if vectors.data.size != 0:
|
||||||
warnings.warn(Warnings.W020.format(shape=vectors.data.shape))
|
warnings.warn(Warnings.W020.format(shape=vectors.data.shape))
|
||||||
ops = Model.ops
|
ops = Model.ops
|
||||||
for word in vocab:
|
if not skip_rank:
|
||||||
if word.orth in vectors.key2row:
|
for word in vocab:
|
||||||
word.rank = vectors.key2row[word.orth]
|
if word.orth in vectors.key2row:
|
||||||
else:
|
word.rank = vectors.key2row[word.orth]
|
||||||
word.rank = util.OOV_RANK
|
else:
|
||||||
|
word.rank = util.OOV_RANK
|
||||||
data = ops.asarray(vectors.data)
|
data = ops.asarray(vectors.data)
|
||||||
# Set an entry here, so that vectors are accessed by StaticVectors
|
# Set an entry here, so that vectors are accessed by StaticVectors
|
||||||
# (unideal, I know)
|
# (unideal, I know)
|
||||||
|
|
|
@ -1072,7 +1072,7 @@ def _fix_pretrained_vectors_name(nlp):
|
||||||
else:
|
else:
|
||||||
raise ValueError(Errors.E092)
|
raise ValueError(Errors.E092)
|
||||||
if nlp.vocab.vectors.size != 0:
|
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:
|
for name, proc in nlp.pipeline:
|
||||||
if not hasattr(proc, "cfg"):
|
if not hasattr(proc, "cfg"):
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue
Block a user