dim bugfix when incl_prior is False (#4285)

This commit is contained in:
Sofie Van Landeghem 2019-09-13 16:30:05 +02:00 committed by Ines Montani
parent 228bbf506d
commit 2ae5db580e
2 changed files with 5 additions and 1 deletions

View File

@ -455,6 +455,8 @@ class Errors(object):
E158 = ("Can't add table '{name}' to lookups because it already exists.")
E159 = ("Can't find table '{name}' in lookups. Available tables: {tables}")
E160 = ("Can't find language data file: {path}")
E161 = ("Found an internal inconsistency when predicting entity links. "
"This is likely a bug in spaCy, so feel free to open an issue.")
@add_codes

View File

@ -1283,7 +1283,7 @@ class EntityLinker(Pipe):
# this will set all prior probabilities to 0 if they should be excluded from the model
prior_probs = xp.asarray([c.prior_prob for c in candidates])
if not self.cfg.get("incl_prior", True):
prior_probs = xp.asarray([[0.0] for c in candidates])
prior_probs = xp.asarray([0.0 for c in candidates])
scores = prior_probs
# add in similarity from the context
@ -1296,6 +1296,8 @@ class EntityLinker(Pipe):
# cosine similarity
sims = xp.dot(entity_encodings, context_enc_t) / (norm_1 * norm_2)
if sims.shape != prior_probs.shape:
raise ValueError(Errors.E161)
scores = prior_probs + sims - (prior_probs*sims)
# TODO: thresholding