猿问

SpaCy:启用以前禁用的管道

我有一个包含两个管道的模型:['sbd', 'tagger']. 第一个是句子标记器,第二个是标记器。现在我想用这个模型训练一个NER,这样我就可以得到一个包含三个管道的最终模型:['sbd', 'tagger','ner']. 根据文档,我需要禁用tagger管道才能仅训练NER。我做到了,培训过程顺利进行。

我的问题是,最后保存的模型只包含一个管道,即NER系统。我可以重新启用以前禁用的管道,以便可以使用完整管道保存最终模型吗?


森林海
浏览 186回答 2
2回答

湖上湖

好的,我发现我可以恢复以前禁用的管道。假设我加载了我的模型nlp并禁用了所有管道,除了ner:other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']disabled = nlp.disable_pipes(*other_pipes)training...disabled.restore()

慕姐4208626

为了完全避免这个问题,你可以在一个with仅限于训练范围的块中禁用管道:with nlp.disable_pipes(*other_pipes):    train_model()# continue with other stuff
随时随地看视频慕课网APP

相关分类

Python
我要回答