mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 17:24:41 +03:00
dim bugfix when incl_prior is False (#4285)
This commit is contained in:
parent
228bbf506d
commit
2ae5db580e
|
@ -455,6 +455,8 @@ class Errors(object):
|
||||||
E158 = ("Can't add table '{name}' to lookups because it already exists.")
|
E158 = ("Can't add table '{name}' to lookups because it already exists.")
|
||||||
E159 = ("Can't find table '{name}' in lookups. Available tables: {tables}")
|
E159 = ("Can't find table '{name}' in lookups. Available tables: {tables}")
|
||||||
E160 = ("Can't find language data file: {path}")
|
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
|
@add_codes
|
||||||
|
|
|
@ -1283,7 +1283,7 @@ class EntityLinker(Pipe):
|
||||||
# this will set all prior probabilities to 0 if they should be excluded from the model
|
# 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])
|
prior_probs = xp.asarray([c.prior_prob for c in candidates])
|
||||||
if not self.cfg.get("incl_prior", True):
|
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
|
scores = prior_probs
|
||||||
|
|
||||||
# add in similarity from the context
|
# add in similarity from the context
|
||||||
|
@ -1296,6 +1296,8 @@ class EntityLinker(Pipe):
|
||||||
|
|
||||||
# cosine similarity
|
# cosine similarity
|
||||||
sims = xp.dot(entity_encodings, context_enc_t) / (norm_1 * norm_2)
|
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)
|
scores = prior_probs + sims - (prior_probs*sims)
|
||||||
|
|
||||||
# TODO: thresholding
|
# TODO: thresholding
|
||||||
|
|
Loading…
Reference in New Issue
Block a user