我目前正在从fr_core_news_lg
管道更新 NER 模型。当我最后一次使用它时,该代码大约在 1 或 2 个月前工作。但是现在,发生了一些事情,我不能再运行它了。我没有对代码进行任何更改,只是想再次运行它。但我收到以下错误:
Traceback (most recent call last):
File "../nermodel.py", line 174, in <module>
ner_model.train(med_label)
File "../nermodel.py", line 102, in train
optimizer = self.nlp.entity.create_optimizer()
AttributeError: 'French' object has no attribute 'entity'
错误指向我用新示例更新我的 NER 模型的代码部分:
def train(self, label, n_iter=10, batch_size=50):
# creating an optimizer and selecting a list of pipes NOT to train
optimizer = self.nlp.entity.create_optimizer()
other_pipes = [pipe for pipe in self.nlp.pipe_names if pipe != 'ner']
# adding a named entity label
ner = self.nlp.get_pipe('ner')
ner.add_label(label)
with self.nlp.disable_pipes(*other_pipes):
for itn in range(n_iter):
random.shuffle(self.train_data)
losses = {}
# batch the examples and iterate over them
for batch in spacy.util.minibatch(self.train_data, size=batch_size):
texts = [text for text, entities in batch]
annotations = [entities for text, entities in batch]
# update the model
self.nlp.update(texts, annotations, sgd=optimizer, losses=losses)
print(losses)
print("Final loss: ", losses)
单个训练示例,以便 NER 了解“咨询”是一个实体,如下所示:
('et la consultation post-réanimation', {'entities': [(6, 18, 'MEDICAL_TERM')]})
我已将 SpaCy 更新到最新版本,并再次下载了fr_core_news_lg
模型,甚至在新的 python 环境中尝试过,但无济于事。这让我觉得管道或 SpaCy 库发生了变化。谷歌搜索,我无法找到确切的答案。有人可以解决这个问题吗?
编辑:提供了更多细节。