如何在查找实体名称时使spaCy不区分大小写?
有没有我应该添加的代码片段,或者什么,因为问题可能会提到不是大写的实体?
def analyseQuestion(question):
doc = nlp(question)
entity=doc.ents
return entity
print(analyseQuestion("what is the best seller of Nicholas Sparks "))
print(analyseQuestion("what is the best seller of nicholas sparks ")) 这给了我们
(Nicholas Sparks,)
()发布于 2020-08-11 10:51:41
发布于 2018-07-28 17:34:11
这很简单。您只需要在您的函数中添加question.lower()的预处理步骤:
def analyseQuestion(question):
# Preprocess question to make further analysis case-insensetive
question = question.lower()
doc = nlp(question)
entity=doc.ents
return entity该解决方案的灵感来自于Rasa NLU库中的this code。但是,对于非英语(非ASCII)文本,它可能无法工作。在这种情况下,您可以尝试:
question = question.decode('utf8').lower().encode('utf8')然而,spacy中的NER模块在某种程度上取决于标记的大小写,您可能会遇到一些差异,因为它是一个经过统计训练的model.Refer this link。
https://stackoverflow.com/questions/50887830
复制相似问题