我尝试了ner的spacy,但结果是高度unpredictable.Sometimes的spacy无法识别特定的country.Can,有人能解释一下为什么会这样吗?我尝试了一些随意的句子。
案例1:
nlp = spacy.load("en_core_web_sm")
print(nlp)
sent = "hello china hello japan"
doc = nlp(sent)
for i in doc.ents:
print(i.text," ",i.label_)output :在这种情况下没有输出。
案例2:
nlp = spacy.load("en_core_web_sm")
print(nlp)
sent = "china is a populous nation in East Asia whose vast landscape encompasses grassland, desert, mountains, lakes, rivers and more than 14,000km of coastline."
doc = nlp(sent)
for i in doc.ents:
print(i.text," ",i.label_)输出:
<spacy.lang.en.English object at 0x7f2213bde080>
china GPE
East Asia LOC
more than 14,000km QUANTITY发布于 2019-11-03 19:48:10
自然语言模型,如spaCy NER,从句子(周围的单词)的上下文结构中学习。为什么会这样呢?让我们以单词Anwarvic为例,这是一个您以前没有见过的新词,可能spaCy模型以前也没有见过它。让我们看看当提供的句子发生变化时,NER模型将如何操作:
>>> nlp = spacy.load("en_core_web_sm")
>>> sent = "I love Anwarvic"
>>> doc = nlp(sent)
>>> for i in doc.ents:
... print(i.text," ",i.label_)
Anwarvic PERSON>>> nlp = spacy.load("en_core_web_sm")
>>> sent = "Anwarvic is gigantic"
>>> doc = nlp(sent)
>>> for i in doc.ents:
... print(i.text," ",i.label_)
Anwarvic ORG>>> nlp = spacy.load("en_core_web_sm")
>>> sent = "Anwarvic is awesome"
>>> doc = nlp(sent)
>>> for i in doc.ents:
... print(i.text," ",i.label_)正如我们所看到的,随着Anwarvic的上下文结构的变化,提取的实体也会发生变化。因此,在第一句话中,动词love在人们中很常见。这就是为什么spaCy模型预测它为PERSON的原因。第二句话也是如此,我们用gigantic来描述像ORG这样的组织。在第三句话中,awesome是一个非常通用的形容词,基本上可以用来描述任何东西。这就是spaCy NER模型被混淆的原因。
附注
实际上,当我在机器上运行第一个提供的代码时,它提取了china和japan,如下所示:
china GPE
japan GPEhttps://stackoverflow.com/questions/58677460
复制相似问题