python - 加载自定义 Ner 模型 - 失败
问题描述
代码是——
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'
解决方案
推荐阅读
- python - 为什么结果不一致?
- javascript - 如何显示带有链接的资源标题?
- python - Python:使用 RFC 3164 发送具有优先级值的系统日志消息
- flutter - 你好。我对扑腾很陌生。颤振演示错误
- django - Django:ModelForm提交后添加排除字段
- reactjs - 反应 Spring 和 useTransition
- javascript - 为使用 google 脚本添加的新行发送电子邮件
- c++ - C++ 中的 Ignore() 函数使用问题
- ios - 是否有与 Mockito 类似的框架来测试 Kotlin MPP 中的共享代码或 iOS 代码?
- laravel-5 - 有没有在不运行另一个迁移的情况下删除 laravel 望远镜表?