Загрузка настроенной модели Ner - PullRequest
0 голосов
/ 11 марта 2020

Код - -

ruler = EntityRuler(nlp, overwrite_ents=True,attr='lemma')
print("Adding pattern")
ruler.add_patterns(patterns)
if not nlp.has_pipe("skills_ruler"):
    nlp.add_pipe(ruler, name="skills_ruler")
print("added pattern")

Сохранение модели как -

output_dir=Path("path_name")
if output_dir is not None:
    output_dir = Path(output_dir)
    if not output_dir.exists():
        output_dir.mkdir()
    nlp.to_disk(output_dir)
    print("Saved model to", output_dir)

Загрузка модели как -

nlp = spacy.load(path_name)

Приходит следующая ошибка -

KeyError: "[E002] Can't find factory for 'skills_ruler'. This usually happens when spaCy calls `nlp.create_pipe` with a component name that's not built in - for example, when constructing the pipeline from a model's meta.json. If you're using a custom component, you can write to `Language.factories['skills_ruler']` or remove it from the model meta and add it via `nlp.add_pipe` instead."

Я пробовал это: -

from spacy.language import Language
from spacy.pipeline import EntityRuler
Language.factories["skills_ruler"] = lambda nlp, **cfg: EntityRuler(nlp, **cfg)
pipe = nlp.create_pipe("skills_ruler") 

, но также выдает ошибку -:

ImportError: cannot import name 'EntityRuler'
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...