我需要训练一个spaCy模型来提高识别产品的准确性。我正在努力训练我的spacy模型。我有以下代码:
TRAIN_DATA = [('..., {'entities': [(36,55,'PRODUCT')]})]
nlp = spacy.load("en_core_web_lg")
ner = nlp.get_pipe("ner")
optimizer = nlp.create_optimizer()
other_pipes = [pipe for pipe in nlp.pipe_names if pipe != "ner"]
with nlp.disable_pipes(*other_pipes): # only train NER
for itn in range(50):
random.shuffle(TRAIN_DATA)
losses = {}
for text, annotations in TRAIN_DATA:
doc = nlp.make_doc(text)
example = Example.from_dict(doc, annotations)
nlp.update([example], drop=0.25, sgd=optimizer, losses=losses)但由于以下原因,它失败了:
NameError Traceback (most recent call last)
<ipython-input-4-903f2be7114f> in <module>
15 for text, annotations in TRAIN_DATA:
16 doc = nlp.make_doc(text)
---> 17 example = Example.from_dict(doc, annotations)
18 nlp.update([example], drop=0.25, sgd=optimizer, losses=losses)
19 print(losses)
NameError: name 'Example' is not defined我需要如何定义Example
发布于 2021-06-20 03:09:12
这里很热。感谢我错过了导入的提示:来自spacy.training导入示例
将代码从Jupyter移动到Visual Studio code以进行部署时
https://stackoverflow.com/questions/68048737
复制相似问题