yac*_*yac 5 case-sensitive spacy ner
查找实体名称时如何使 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 "))
Run Code Online (Sandbox Code Playgroud)
这使
(Nicholas Sparks,)
()
Run Code Online (Sandbox Code Playgroud)
hap*_*set -1
这很容易。您只需question.lower()在函数中添加一个预处理步骤:
def analyseQuestion(question):
# Preprocess question to make further analysis case-insensetive
question = question.lower()
doc = nlp(question)
entity=doc.ents
return entity
Run Code Online (Sandbox Code Playgroud)
该解决方案的灵感来自Rasa NLU 库的这段代码。但是,对于非英语(非 ASCII)文本,它可能不起作用。对于这种情况你可以尝试:
question = question.decode('utf8').lower().encode('utf8')
Run Code Online (Sandbox Code Playgroud)
然而,spacy 中的 NER 模块在某种程度上取决于标记的情况,并且您可能会遇到一些差异,因为它是统计训练模型。请参阅此链接。
| 归档时间: |
|
| 查看次数: |
6426 次 |
| 最近记录: |