【问题标题】:Is there any way to whitelist spacy labelling?有没有办法将 spacy 标签列入白名单?
【发布时间】:2020-07-21 07:24:55
【问题描述】:

我是 spaCy 的新手,目前正在尝试使用 spaCy 英文大模型从句子中识别 PERSON
从句子中识别 PERSON 一切都很好,直到我发现某个被识别的名称不是 PERSON。
例如。如果我输入“亚历克斯正在吃苹果”。它将成功返回 Alex is a PERSON
但是当这种情况发生时,它将不再起作用
例如。 Sun Saw Bee 正在吃苹果 Alexandro Soon 正在吃苹果

我想知道是否有像白名单这样的东西可以添加到“Sun Saw Bee”或“Alexandro Soon”作为一个人,而不需要重新训练 spaCy 英语模型?
或以某种方式将“Sun Saw Bee”识别为 PERSON?

如果有任何与此相关的链接也许也可以分享,因为我的关键字搜索可能没有点击正确的键

【问题讨论】:

    标签: nlp spacy


    【解决方案1】:

    如果您有已知实体的列表,则可以将EntityRuler 与 NER 模型结合使用。根据您的任务/优先级,您可能希望在管道中的 NER 模型之前或之后添加它。

    这是一个简单的示例(改编自上面链接的文档),展示了如何使用短语模式(字符串)或基于标记的匹配器模式来定义要匹配的实体:

    import spacy
    from spacy.pipeline import EntityRuler
    
    nlp = spacy.load("en_core_web_sm")
    ruler = EntityRuler(nlp)
    patterns = [{"label": "ORG", "pattern": "Apple"},
                {"label": "GPE", "pattern": [{"LOWER": "san"}, {"LOWER": "francisco"}]}]
    ruler.add_patterns(patterns)
    nlp.add_pipe(ruler, before="ner")
    
    doc = nlp("Apple is opening its first big office in San Francisco after opening an office in New York City.")
    print([(ent.text, ent.label_) for ent in doc.ents])
    

    使用 spacy v2.3.2 输出:

    [('Apple', 'ORG'), ('first', 'ORDINAL'), ('San Francisco', 'GPE'), ('New York City', 'GPE')]
    

    【讨论】:

      【解决方案2】:

      不想将 Spacy 管道中的名称列入白名单。 Spacy 是根据模型而不是最终用户创建的决策为 NER 检测创建的​​。正如其网站上所指出的,当前可用模型的限制之一是其中许多模型是在维基百科和其他来源上进行培训的,这可能无法反映您的目标数据。

      将实体列入白名单与搜索相同;

      if "Sun Saw Bee" in text:
          print('person')
      

      What you can do is add data to a model, which basically is retraining the model.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-11
        • 2020-12-24
        • 2015-07-02
        相关资源
        最近更新 更多