mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-26 01:04:34 +03:00
remove redundant code from master in EntityLinker
This commit is contained in:
parent
6179774278
commit
12dc8ab208
|
@ -1136,14 +1136,6 @@ class EntityLinker(Pipe):
|
||||||
# how many neightbour sentences to take into account
|
# how many neightbour sentences to take into account
|
||||||
self.n_sents = cfg.get("n_sents", 0)
|
self.n_sents = cfg.get("n_sents", 0)
|
||||||
|
|
||||||
def set_kb(self, kb):
|
|
||||||
self.kb = kb
|
|
||||||
|
|
||||||
def require_model(self):
|
|
||||||
# Raise an error if the component's model is not initialized.
|
|
||||||
if getattr(self, "model", None) in (None, True, False):
|
|
||||||
raise ValueError(Errors.E109.format(name=self.name))
|
|
||||||
|
|
||||||
def require_kb(self):
|
def require_kb(self):
|
||||||
# Raise an error if the knowledge base is not initialized.
|
# Raise an error if the knowledge base is not initialized.
|
||||||
if len(self.kb) == 0:
|
if len(self.kb) == 0:
|
||||||
|
|
|
@ -70,14 +70,13 @@ def tagger():
|
||||||
|
|
||||||
def entity_linker():
|
def entity_linker():
|
||||||
nlp = Language()
|
nlp = Language()
|
||||||
nlp.add_pipe(nlp.create_pipe("entity_linker"))
|
kb = KnowledgeBase(nlp.vocab, entity_vector_length=1)
|
||||||
|
kb.add_entity("test", 0.0, zeros((1, 1), dtype="f"))
|
||||||
|
nlp.add_pipe(nlp.create_pipe("entity_linker", {"kb": kb}))
|
||||||
entity_linker = nlp.get_pipe("entity_linker")
|
entity_linker = nlp.get_pipe("entity_linker")
|
||||||
# need to add model for two reasons:
|
# need to add model for two reasons:
|
||||||
# 1. no model leads to error in serialization,
|
# 1. no model leads to error in serialization,
|
||||||
# 2. the affected line is the one for model serialization
|
# 2. the affected line is the one for model serialization
|
||||||
kb = KnowledgeBase(nlp.vocab, entity_vector_length=1)
|
|
||||||
kb.add_entity("test", 0.0, zeros((1, 1), dtype="f"))
|
|
||||||
entity_linker.set_kb(kb)
|
|
||||||
entity_linker.begin_training(pipeline=nlp.pipeline)
|
entity_linker.begin_training(pipeline=nlp.pipeline)
|
||||||
return entity_linker
|
return entity_linker
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user