【发布时间】:2019-11-13 17:18:28
【问题描述】:
我目前正在尝试训练以属性描述为中心的 NER 模型。我可以得到一个经过全面训练的模型来满足我的喜好,但是,我现在想在模型中添加一个重新标记化管道,以便我可以设置模型来训练其他东西。
从这里开始,我在让 retokenize 管道实际工作时遇到问题。这是定义:
def retok(doc):
ents = [(ent.start, ent.end, ent.label) for ent in doc.ents]
with doc.retokenize() as retok:
string_store = doc.vocab.strings
for start, end, label in ents:
retok.merge(
doc[start: end],
attrs=intify_attrs({'ent_type':label},string_store))
return doc
我将它添加到我的训练中,如下所示:
nlp.add_pipe(retok, after="ner")
我正在像这样将它添加到语言工厂中:
Language.factories['retok'] = lambda nlp, **cfg: retok(nlp)
我不断遇到的问题是“AttributeError: 'English' object has no attribute 'ents'”。现在我假设我收到了这个错误,因为通过这个函数传递的参数不是文档,而是 NLP 模型本身。我不太确定在培训期间让医生流入这个管道。在这一点上,我真的不知道从这里去哪里才能让管道按我想要的方式运行。
感谢任何帮助,谢谢。
【问题讨论】:
标签: spacy