【问题标题】:Training spaCy - NameError训练 spaCy - NameError
【发布时间】: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 来定义它。当您在代码中引用它时,您显然对它有一些概念。

标签: python nlp spacy


【解决方案1】:

这里很热... 感谢我错过导入的提示: 从 spacy.training 导入示例

将代码从 Jupyter 移动到 Visual Studio Code 以进行部署时

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-15
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2019-01-14
    • 1970-01-01
    相关资源
    最近更新 更多