Nlp 我如何从文本中使用SpaCy获得正确的NER,例如;在文本中批评特朗普的联邦调查局特工彼得·斯特佐克被解雇了;?

Nlp 我如何从文本中使用SpaCy获得正确的NER,例如;在文本中批评特朗普的联邦调查局特工彼得·斯特佐克被解雇了;?,nlp,nltk,spacy,Nlp,Nltk,Spacy,我如何从“FBI探员彼得·斯特佐克在文本中批评特朗普被炒鱿鱼——《纽约时报》栏目搜索跳转到内容跳转到网站”这样的文本中使用SpaCy获得正确的NER 在这里,“被批评的特朗普”被认为是人,而不是“特朗普”是人 如何对上述字符串中的“批评”或“文本”等文本进行预处理和小写,以克服上述问题或任何其他技术 import spacy from spacy import displacy from collections import Counter import en_core_web_sm nlp =

我如何从“FBI探员彼得·斯特佐克在文本中批评特朗普被炒鱿鱼——《纽约时报》栏目搜索跳转到内容跳转到网站”这样的文本中使用SpaCy获得正确的NER 在这里,“被批评的特朗普”被认为是人,而不是“特朗普”是人

如何对上述字符串中的“批评”或“文本”等文本进行预处理和小写,以克服上述问题或任何其他技术

import spacy
from spacy import displacy
from collections import Counter
import en_core_web_sm
nlp = en_core_web_sm.load()
from pprint import pprint

sent = ("F.B.I. Agent Peter Strzok, Who Criticized Trump in Texts, Is Fired - The New York Times SectionsSEARCHSkip to contentSkip to site")
doc = nlp(sent)
pprint([(X, X.ent_iob_, X.ent_type_) for X in doc])
上述代码的结果:- “批评特朗普”为“个人”,而“文本”为“GPE”

预期结果应为:-
“特朗普”作为“人”而不是“批评特朗普”作为“人”,而“文本”作为“文本”而不是“文本”作为“GPE”

您可以添加更多命名实体的示例来调整NER模型。这里有准备列车数据所需的所有信息。您可以使用prodigy(spaCy creators提供的注释工具)标记数据中的命名实体

您可以添加更多命名实体的示例来优化NER模型。这里有准备列车数据所需的所有信息。您可以使用prodigy(spaCy creators提供的注释工具)标记数据中的命名实体

事实上,您可以使用词性标记进行预处理,以便将其更改为非专有名词的小写单词,如“committed”或“text”。 适当的大写(小写与大写)将有助于NER标记者

sent = "F.B.I. Agent Peter Strzok, Who Criticized Trump in Texts, Is Fired - The New York Times SectionsSEARCHSkip to contentSkip to site"
doc = nlp(sent)

words = []
spaces = []
for a in doc:

    if a.pos_ != 'PROPN':
        words.append( a.text.lower() )
    else:
        words.append(a.text)

    spaces.append(a.whitespace_)

spaces = [len(sp) for sp in spaces]    
docNew = Doc(nlp.vocab, words=words, spaces=spaces)
print(docNew)
# F.B.I. Agent Peter Strzok, who criticized Trump in texts, is fired - the New York Times SectionsSEARCHSkip to contentskip to site



事实上,您可以使用词性标记进行预处理,以便更改为非专有名词的小写单词,如“批评”或“文本”。 适当的大写(小写与大写)将有助于NER标记者

sent = "F.B.I. Agent Peter Strzok, Who Criticized Trump in Texts, Is Fired - The New York Times SectionsSEARCHSkip to contentSkip to site"
doc = nlp(sent)

words = []
spaces = []
for a in doc:

    if a.pos_ != 'PROPN':
        words.append( a.text.lower() )
    else:
        words.append(a.text)

    spaces.append(a.whitespace_)

spaces = [len(sp) for sp in spaces]    
docNew = Doc(nlp.vocab, words=words, spaces=spaces)
print(docNew)
# F.B.I. Agent Peter Strzok, who criticized Trump in texts, is fired - the New York Times SectionsSEARCHSkip to contentskip to site



使用词性标注的预处理对您有效吗?使用词性标注的预处理对您有效吗?