我如何才能从“在短信中批评特朗普的联邦调查局特工彼得·斯特佐克被解雇-- the SpaCy Times SectionsSEARCHSkip to contentSkip to site”这样的文本中找到使用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”。
发布于 2019-07-03 18:42:05
您可以添加更多命名实体的示例来调整NER模型。这里有准备列车数据https://spacy.io/usage/training所需的所有信息。您可以使用prodigy ( spaCy creators提供的注释工具,https://prodi.gy)来标记数据中的命名实体。
发布于 2020-01-24 20:51:10
实际上,您可以使用POS标签进行预处理,以便将"Criticized“或”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 sitehttps://stackoverflow.com/questions/56868025
复制相似问题