【发布时间】:2021-06-20 03:09:12
【问题描述】:
我需要训练一个 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?
【问题讨论】:
-
您需要从某个模块通过
importing 来定义它。当您在代码中引用它时,您显然对它有一些概念。