From ba5a50f62b23fe93a162d664f3e41f80805dcec0 Mon Sep 17 00:00:00 2001 From: Sofie Van Landeghem Date: Mon, 22 Feb 2021 01:04:22 +0100 Subject: [PATCH] NEL docs & UX (#7129) * EL set_kb docs fix * custom warning for set_kb mistake --- spacy/errors.py | 3 +++ spacy/pipeline/entity_linker.py | 3 +++ website/docs/api/entitylinker.md | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spacy/errors.py b/spacy/errors.py index 79a15fbaa..f8a461dbd 100644 --- a/spacy/errors.py +++ b/spacy/errors.py @@ -486,6 +486,9 @@ class Errors: E202 = ("Unsupported alignment mode '{mode}'. Supported modes: {modes}.") # New errors added in v3.x + + E885 = ("entity_linker.set_kb received an invalid 'kb_loader' argument: expected " + "a callable function, but got: {arg_type}") E886 = ("Can't replace {name} -> {tok2vec} listeners: path '{path}' not " "found in config for component '{name}'.") E887 = ("Can't replace {name} -> {tok2vec} listeners: the paths to replace " diff --git a/spacy/pipeline/entity_linker.py b/spacy/pipeline/entity_linker.py index 262bcf677..e25777a21 100644 --- a/spacy/pipeline/entity_linker.py +++ b/spacy/pipeline/entity_linker.py @@ -146,6 +146,9 @@ class EntityLinker(TrainablePipe): def set_kb(self, kb_loader: Callable[[Vocab], KnowledgeBase]): """Define the KB of this pipe by providing a function that will create it using this object's vocab.""" + if not callable(kb_loader): + raise ValueError(Errors.E885.format(arg_type=type(kb_loader))) + self.kb = kb_loader(self.vocab) self.cfg["entity_vector_length"] = self.kb.entity_vector_length diff --git a/website/docs/api/entitylinker.md b/website/docs/api/entitylinker.md index 47ba80c0f..a794ce632 100644 --- a/website/docs/api/entitylinker.md +++ b/website/docs/api/entitylinker.md @@ -154,7 +154,7 @@ with the current vocab. > kb.add_alias(...) > return kb > entity_linker = nlp.add_pipe("entity_linker") -> entity_linker.set_kb(lambda: [], nlp=nlp, kb_loader=create_kb) +> entity_linker.set_kb(create_kb) > ``` | Name | Description |