【问题标题】:how to predict from manually trained spacy model如何从手动训练的 spacy 模型中进行预测
【发布时间】:2020-06-20 16:52:42
【问题描述】:

我有以下代码来创建和训练一个新的 spacy 模型。 我不知道如何从新文本中预测实体?

有人可以帮忙吗?

TRAIN_DATA = [
    ("Uber blew through $1 million a week", [(0, 4, 'ORG')]),
    ("Android Pay expands to Canada", [(0, 11, 'PRODUCT'), (23, 30, 'GPE')]),
    ("Spotify steps up Asia expansion", [(0, 8, "ORG"), (17, 21, "LOC")]),
    ("Google Maps launches location sharing", [(0, 11, "PRODUCT")]),
    ("Google rebrands its business apps", [(0, 6, "ORG")]),
    ("look what i found on google!", [(21, 27, "PRODUCT")])]

nlp = spacy.blank("en")
optimizer = nlp.begin_training()
from spacy.gold import GoldParse  #<--- add this

for i in range(20):
    random.shuffle(TRAIN_DATA)
    for text, annotations in TRAIN_DATA:
        text = nlp.make_doc(text)
        gold = GoldParse(text, entities=annotations)  #<--- add this
        nlp.update([text], [gold], sgd=optimizer)

【问题讨论】:

    标签: python nlp spacy named-entity-extraction


    【解决方案1】:

    您需要将训练好的模型保存到磁盘。然后,您将使用spacy.load("path/to/model/") 而不是spacy.blank("en")。完成此操作后,您将能够使用您保存的模型。

    【讨论】:

      猜你喜欢
      • 2020-02-25
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      • 2016-02-19
      相关资源
      最近更新 更多