为什么下面的代码会抛出
add_pipe
属性未定义的错误?
if 'ner' not in nlp.pipe_names:
ner = nlp.create_pipe('ner')
ner.add_pipe(ner , last = True)
for _, annotation in train_data:
for ent in annotation['entities']:
ner.add_label(ent[2])
要将管道组件添加到 spacy,您必须将它们添加到加载的模型 (
nlp
),而不是单个组件(如 ner
)。
if 'ner' not in nlp.pipe_names:
ner = nlp.create_pipe('ner')
nlp.add_pipe(ner, last = True) # replaced ner by nlp here
for _, annotation in train_data:
for ent in annotation['entities']:
ner.add_label(ent[2])