【问题标题】:NER Using Spacy modelNER 使用 Spacy 模型
【发布时间】:2020-02-03 20:30:48
【问题描述】:

我继续收到我的语料库中没有 NER 的消息。我期待猫、狗等将被识别为人。让我知道如何解决它。

import numpy as np
import pandas as pd

import spacy
from spacy import displacy

nlp = spacy.load("en_core_web_sm")

corpus=['cats are selfish', 'it is raining cats and dogs', 'dogs do not like birds','i do not like rabbits','i have eaten frogs snakes and alligators']

for sent in corpus:
    sentence_nlp = nlp(sent)
    # print named entities in sentences
    print([(word, word.ent_type_) for word in sentence_nlp if word.ent_type_])
    # visualize named entities
    displacy.render(sentence_nlp, style='ent', jupyter=True)

我得到的错误是:

[]
./NER_Spacy.py:19: UserWarning: [W006] No entities to visualize found in Doc object. If this is surprising to you, make sure the
Doc was processed using a model that supports named entity recognition, and check the `doc.ents` property manually if necessary
.
 displacy.render(sentence_nlp, style='ent', jupyter=False)
[]
./NER_Spacy.py:19: UserWarning: [W006] No entities to visualize found in Doc object. If this is surprising to you, make sure the
Doc was processed using a model that supports named entity recognition, and check the `doc.ents` property manually if necessary
.
 displacy.render(sentence_nlp, style='ent', jupyter=False)
[]
./NER_Spacy.py:19: UserWarning: [W006] No entities to visualize found in Doc object. If this is surprising to you, make sure the
Doc was processed using a model that supports named entity recognition, and check the `doc.ents` property manually if necessary
.
 displacy.render(sentence_nlp, style='ent', jupyter=False)
[]
./NER_Spacy.py:19: UserWarning: [W006] No entities to visualize found in Doc object. If this is surprising to you, make sure the
Doc was processed using a model that supports named entity recognition, and check the `doc.ents` property manually if necessary
.
 displacy.render(sentence_nlp, style='ent', jupyter=False)
[]
./NER_Spacy.py:19: UserWarning: [W006] No entities to visualize found in Doc object. If this is surprising to you, make sure the
Doc was processed using a model that supports named entity recognition, and check the `doc.ents` property manually if necessary
.
 displacy.render(sentence_nlp, style='ent', jupyter=False) ```

【问题讨论】:

    标签: python spacy named-entity-recognition


    【解决方案1】:

    我预计猫、狗等将被识别为人

    那么你并没有期待正确的事情:) Spacy 的 NER 模型根据语言在不同的数据集上进行训练。对于您使用的模型,请参见此处: https://spacy.io/models/en#en_core_web_sm

    用于训练您正在使用的模型的数据集称为“Onto Notes 5”,它不会将猫和狗视为 PERSON(就像大多数人那样)。 如果你想得到“猫”和“狗”作为实体,你需要用你自己的数据训练你自己的NER模型。例如,您可以使用带有感兴趣宠物列表的正则表达式规则使用 ANIMAL 实体标记一些数据,并使用该标记的数据集,您可以微调 NER 模型以执行您想要的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 2021-04-21
      相关资源
      最近更新 更多