训练 spaCy - NameError
Training spaCy - NameError
我需要训练 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
?
这里很热...
感谢提示我错过了导入:
来自 spacy.training 导入示例
将代码从 Jupyter 移动到 Visual Studio 部署代码时
我需要训练 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
?
这里很热... 感谢提示我错过了导入: 来自 spacy.training 导入示例
将代码从 Jupyter 移动到 Visual Studio 部署代码时