【问题标题】:Training SpaCy NER with a custom dataset使用自定义数据集训练 SpaCy NER
【发布时间】:2020-10-16 11:57:48
【问题描述】:

我已按照 this SpaCy 教程训练自定义数据集。我的数据集是一个地名词典。因此,我将我的训练数据制作如下。

TRAIN_DATA = [
("Where is Abbess",{"entities":[(9, 15,"GPE")]}),
("Where is Abbey Pass",{"entities":[(9, 19,"LOC")]}),
("Where is Abbot",{"entities":[(9, 14,"GPE")]}),
("Where is Abners Head",{"entities":[(9, 29,"LOC")]}),
("Where is Acheron Flat",{"entities":[(9, 21,"LOC")]}),
("Where is Acheron River",{"entities":[(9, 22,"LOC")]})
]

我使用'en_core_web_sm' 进行训练,而不是空白模型。

model = 'en_core_web_sm'
output_dir=Path(path)
n_iter=20

在训练了 20 个 epoc 之后,我尝试使用训练后的模型进行预测。以下是我得到的输出。

test_text = "Seven people, including teenagers, have been taken to hospital after their car crashed in the mid-Canterbury town of Rakaia."

Seven people, including teenagers 0 33 GPE
the mid-Canterbury town of Rakaia.. 90 125 GPE

我使用'en_core_web_sm' 对相同的 test_text 进行了预测。输出如下。

Seven 0 5 CARDINAL
mid-Canterbury 94 108 DATE
Rakaia 117 123 GPE

有人可以指导我在训练 SpaCy 时犯的错误吗?

【问题讨论】:

    标签: python-3.x nlp spacy named-entity-recognition


    【解决方案1】:

    结果不佳的原因是由于一个名为catastrophic forgetting 的概念。您可以here获取更多信息。

    tl;dr

    当您使用新实体训练您的 en_core_web_sm 模型时,它会忘记之前学习的内容。

    为了确保不忘记旧的学习,您还需要在再训练期间提供其他类型实体的模型示例。通过这样做,您将确保模型不会自我调整和扭曲自身以预测所有内容作为正在训练的新实体。

    您可以阅读有关可以实施的可能解决方案here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-06
      • 2021-04-08
      • 1970-01-01
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 2021-05-15
      相关资源
      最近更新 更多