我尝试运行我的第一个 Chatterbot 程序(它来自 Chatterbot 的 PyPi 页面),当我运行它时,出现错误。该错误与 Spacy 有关,但我找不到解决方案。
这是代码:
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Ron Obvious')
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train("chatterbot.corpus.english")
chatbot.get_response("Hello, how are you today?")
这是错误:
Traceback (most recent call last):
File "c:/users/USER/desktop/bot.py", line 77, in <module>
chatbot = ChatBot('Ron Obvious')
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\chatterbot.py", line 28, in __init__
self.storage = utils.initialize_class(storage_adapter, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\utils.py", line 33, in initialize_class
return Class(*args, **kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\sql_storage.py", line 20, in __init__
super().__init__(**kwargs)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\storage\storage_adapter.py", line 21, in __init__
'tagger_language', languages.ENG
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py", line 13, in __init__
self.nlp = spacy.load(self.language.ISO_639_1.lower())
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy__init__.py", line 47, in load
return util.load_model(name, disable=disable, exclude=exclude, config=config)
File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\spacy\util.py", line 328, in load_model
raise IOError(Errors.E941.format(name=name, full=OLD_MODEL_SHORTCUTS[name]))
OSError: [E941] Can't find model 'en'. It looks like you're trying to load a model from a shortcut, which is deprecated as of spaCy v3.0. To load the model, use its full name instead:
nlp = spacy.load("en_core_web_sm")
For more details on the available models, see the models directory: https://spacy.io/models. If you want to create a blank model, use spacy.blank: nlp = spacy.blank("en")
如果有人为此找到解决方案,那将很有帮助。谢谢。
原文由 su2187 发布,翻译遵循 CC BY-SA 4.0 许可协议
确保您确实安装了正确的 spacy 模型。例如,在终端中使用
python -m spacy download en_core_web_sm
命令安装en_core_web_sm
。接下来,修复这个错误:
那是,
C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py
文件self.nlp = spacy.load(self.language.ISO_639_1.lower())
替换为您需要为需要支持的其他语言添加更多条件。