我正在尝试使用 python 制作一个聊天机器人,为此我使用 Spacy 进行实体识别,因此我安装了预构建的 Spacy 英语语言模型(中)来从用户话语中提取实体,但问题是当我加载模型时要从用户话语中提取实体,加载模型需要 31 秒,因为我正在使聊天机器人时间对我来说非常重要。需要大家的指导,还有其他选择吗?任何帮助将非常感激
以下是从用户话语中提取实体的代码:
import spacy
import time
def extractEntity(userUtterance):
''' This funtion returns a list of tuple a tuple contain
(entity Name, Entity Type)
We use pre build spacy english language model to extract entities
'''
start_time = time.process_time()
nlp = spacy.load("en")
print(time.process_time() - start_time, "seconds") # prints the time taken to load the model
docx = nlp(userUtterance)
listOfTyples = [(word.text, spacy.explain(word.label_)) for word in docx.ents]
return listOfTyples
if __name__ == "__main__":
print(extractEntity("I …Run Code Online (Sandbox Code Playgroud)