Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 加载自定义的Ner模型-失败_Python_Spacy_Ner - Fatal编程技术网

Python 加载自定义的Ner模型-失败

Python 加载自定义的Ner模型-失败,python,spacy,ner,Python,Spacy,Ner,代码是-- 将模型另存为- 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

代码是--

将模型另存为-

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") 
但它也给出了错误--:

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'