在加载修改后的模型时,使用EnityRuler
标志向管道中添加before='ner'
时遇到了一个奇怪的问题。
所以我创建了模式,将它们添加到我的entity_ruler,并将标尺添加到我的管道:
nlp = spacy.load('de_core_news_sm')
ruler = EntityRuler(nlp)
ruler.add_patterns(patterns)
nlp.add_pipe(ruler, before='ner')
然后我检查目录,如有必要,将其创建并将模型保存到磁盘:
output_dir = Path('custom_model')
if not output_dir.exists():
output_dir.mkdir()
nlp.to_disk(output_dir)
现在我用...加载模型
spacy.load(Path('custom_model'))
它引发以下错误:
ValueError: [E109] Model for component 'ner' not initialized.
Did you forget to load a model, or forget to call begin_training()?
没有before='ner'
...
我试图整天弄清楚这个问题,但是失败了:/
我正在使用Spacy v2.1.4
扩展错误:
Traceback (most recent call last):
File "/spacy/__init__.py", line 27, in load
return util.load_model(name, **overrides)
File "/spacy/util.py", line 135, in load_model
return load_model_from_path(name, **overrides)
File "/spacy/util.py", line 173, in load_model_from_path
return nlp.from_disk(model_path)
File "/spacy/language.py", line 791, in from_disk
util.from_disk(path, deserializers, exclude)
File "/spacy/util.py", line 630, in from_disk
reader(path / key)
File "/spacy/language.py", line 787, in <lambda>
deserializers[name] = lambda p, proc=proc: proc.from_disk(p, exclude=["vocab"])
File "/spacy/pipeline/entityruler.py", line 183, in from_disk
self.add_patterns(patterns)
File "/spacy/pipeline/entityruler.py", line 138, in add_patterns
self.phrase_patterns[label].append(self.nlp(pattern))
File "/spacy/language.py", line 390, in __call__
doc = proc(doc, **component_cfg.get(name, {}))
File "nn_parser.pyx", line 205, in spacy.syntax.nn_parser.Parser.__call__
File "nn_parser.pyx", line 238, in spacy.syntax.nn_parser.Parser.predict
File "nn_parser.pyx", line 235, in spacy.syntax.nn_parser.Parser.require_model
ValueError: [E109] Model for component 'ner' not initialized.
Did you forget to load a model, or forget to call begin_training()?