mirror of
https://github.com/explosion/spaCy.git
synced 2025-07-10 08:12:24 +03:00
Merge branch 'v4' into refactor/el-candidates
# Conflicts: # spacy/errors.py
This commit is contained in:
commit
0c63940407
|
@ -960,8 +960,10 @@ class Errors(metaclass=ErrorsWithCodes):
|
||||||
E4003 = ("Training examples for distillation must have the exact same tokens in the "
|
E4003 = ("Training examples for distillation must have the exact same tokens in the "
|
||||||
"reference and predicted docs.")
|
"reference and predicted docs.")
|
||||||
E4004 = ("Backprop is not supported when is_train is not set.")
|
E4004 = ("Backprop is not supported when is_train is not set.")
|
||||||
|
E4005 = ("EntityLinker_v1 is not supported in spaCy v4. Update your configuration.")
|
||||||
E4006 = ("Expected `entity_id` to be of type {exp_type}, but is of type {found_type}.")
|
E4006 = ("Expected `entity_id` to be of type {exp_type}, but is of type {found_type}.")
|
||||||
|
|
||||||
|
|
||||||
RENAMED_LANGUAGE_CODES = {"xx": "mul", "is": "isl"}
|
RENAMED_LANGUAGE_CODES = {"xx": "mul", "is": "isl"}
|
||||||
|
|
||||||
# fmt: on
|
# fmt: on
|
||||||
|
|
|
@ -117,28 +117,9 @@ def make_entity_linker(
|
||||||
prediction is discarded. If None, predictions are not filtered by any threshold.
|
prediction is discarded. If None, predictions are not filtered by any threshold.
|
||||||
save_activations (bool): save model activations in Doc when annotating.
|
save_activations (bool): save model activations in Doc when annotating.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not model.attrs.get("include_span_maker", False):
|
if not model.attrs.get("include_span_maker", False):
|
||||||
try:
|
raise ValueError(Errors.E4005)
|
||||||
from spacy_legacy.components.entity_linker import EntityLinker_v1
|
|
||||||
except:
|
|
||||||
raise ImportError(
|
|
||||||
"In order to use v1 of the EntityLinker, you must use spacy-legacy>=3.0.12."
|
|
||||||
)
|
|
||||||
# The only difference in arguments here is that use_gold_ents and threshold aren't available.
|
|
||||||
return EntityLinker_v1(
|
|
||||||
nlp.vocab,
|
|
||||||
model,
|
|
||||||
name,
|
|
||||||
labels_discard=labels_discard,
|
|
||||||
n_sents=n_sents,
|
|
||||||
incl_prior=incl_prior,
|
|
||||||
incl_context=incl_context,
|
|
||||||
entity_vector_length=entity_vector_length,
|
|
||||||
get_candidates=get_candidates,
|
|
||||||
overwrite=overwrite,
|
|
||||||
scorer=scorer,
|
|
||||||
)
|
|
||||||
return EntityLinker(
|
return EntityLinker(
|
||||||
nlp.vocab,
|
nlp.vocab,
|
||||||
model,
|
model,
|
||||||
|
|
|
@ -991,13 +991,11 @@ def test_scorer_links():
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"name,config",
|
"name,config",
|
||||||
[
|
[
|
||||||
("entity_linker", {"@architectures": "spacy.EntityLinker.v1", "tok2vec": DEFAULT_TOK2VEC_MODEL}),
|
|
||||||
("entity_linker", {"@architectures": "spacy.EntityLinker.v2", "tok2vec": DEFAULT_TOK2VEC_MODEL}),
|
("entity_linker", {"@architectures": "spacy.EntityLinker.v2", "tok2vec": DEFAULT_TOK2VEC_MODEL}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
# fmt: on
|
# fmt: on
|
||||||
def test_legacy_architectures(name, config):
|
def test_legacy_architectures(name, config):
|
||||||
from spacy_legacy.components.entity_linker import EntityLinker_v1
|
|
||||||
|
|
||||||
# Ensure that the legacy architectures still work
|
# Ensure that the legacy architectures still work
|
||||||
vector_length = 3
|
vector_length = 3
|
||||||
|
@ -1020,10 +1018,7 @@ def test_legacy_architectures(name, config):
|
||||||
return mykb
|
return mykb
|
||||||
|
|
||||||
entity_linker = nlp.add_pipe(name, config={"model": config})
|
entity_linker = nlp.add_pipe(name, config={"model": config})
|
||||||
if config["@architectures"] == "spacy.EntityLinker.v1":
|
assert isinstance(entity_linker, EntityLinker)
|
||||||
assert isinstance(entity_linker, EntityLinker_v1)
|
|
||||||
else:
|
|
||||||
assert isinstance(entity_linker, EntityLinker)
|
|
||||||
entity_linker.set_kb(create_kb)
|
entity_linker.set_kb(create_kb)
|
||||||
optimizer = nlp.initialize(get_examples=lambda: train_examples)
|
optimizer = nlp.initialize(get_examples=lambda: train_examples)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user