我有一个包含两个管道的模型:['sbd', 'tagger']
。第一个是句子标记器,第二个是标记器。现在,我想用此模型训练一个 NER ,这样我就可以得到一个包含三个管道的最终模型:['sbd', 'tagger','ner']
。根据{{3}},我需要禁用 tagger
管道,以便仅训练 NER 。我做到了,培训过程顺利进行。
我的问题是,最后,保存的模型仅包含一个管道,即 NER 系统。我可以启用以前禁用的管道,以便可以使用完整的管道保存最终模型吗?
答案 0 :(得分:2)
好的,我发现我可以恢复以前禁用的管道。假设我将模型加载到nlp
中,并禁用了除ner
之外的所有管道:
other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']
disabled = nlp.disable_pipes(*other_pipes)
training...
disabled.restore()
答案 1 :(得分:1)
要完全避免此问题,可以在限于训练范围的with
块中禁用管道:
with nlp.disable_pipes(*other_pipes):
train_model()
# continue with other stuff