gpt4 book ai didi

python - 在 spaCy 中包含词典(地名词典)以改进 NER 的理想方法是什么?

转载 作者:行者123 更新时间:2023-12-03 18:45:41 25 4
gpt4 key购买 nike

我目前正在更换基于 nltk 实体提取和正则表达式匹配的系统,其中我有几个命名实体字典。字典实体既有通用类型(PERSON(员工)等),也有自定义类型(例如 SKILL)。我想使用预训练的 spaCy 模型并以某种方式包含我的字典,以提高 NER 的准确性。以下是我对可能的方法的看法:

  • 使用 spaCy 的 Matcher API,遍历字典并使用回调添加每个短语以添加实体?
  • 我刚刚找到了 spacy-lookup,这似乎是一种提供长长的单词/短语列表以进行匹配的简单方法。
  • 但是如果我想要模糊匹配怎么办?有没有办法直接添加到 Vocab 中,从而通过布隆过滤器/n-gram 词向量进行一些模糊匹配,或者是否有适合这种需求的扩展?否则我想我可以复制 spacy-lookup 并用其他东西替换 flashtext 机器,例如莱文斯坦距离。
  • 在玩 spaCy 时,我确实尝试直接用字典中的一个单词(没有任何句子上下文)训练 NER,这确实“有效”。但是,当然,我必须非常小心,以免模型忘记一切。

  • 感谢任何帮助,我觉得这必须是一个非常普遍的要求,并且很想听听什么对那里的人最有效。

    最佳答案

    我建议查看 spaCy 的 Entity Ruler .如果将现有字典转换为模式进行匹配,则可以为每个实体和新类型添加规则。

    这非常强大,因为您可以将其与标准 spacy 模型中可用的现有统计 NER 相结合,以实现您提到的某些“模糊匹配”。从文档:

    The entity ruler is designed to integrate with spaCy’s existing statistical models and enhance the named entity recognizer. If it’s added before the "ner" component, the entity recognizer will respect the existing entity spans and adjust its predictions around it. This can significantly improve accuracy in some cases. If it’s added after the "ner" component, the entity ruler will only add spans to the doc.ents if they don’t overlap with existing entities predicted by the model. To overwrite overlapping entities, you can set overwrite_ents=True on initialization.

    关于python - 在 spaCy 中包含词典(地名词典)以改进 NER 的理想方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48783876/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com