本文介绍了ChatterBot 错误 - OSError: [E941] 找不到模型“en"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行我的第一个 Chatterbot 程序(它来自 Chatterbot 的 PyPi 页面),当我运行它时,出现错误.该错误与 Spacy 有关,但我无法找到解决方案.

I tried running my first Chatterbot program (its from the PyPi page of Chatterbot), and when I run it, I get an error. The error is related to Spacy, but I am unable to find a solution.

代码如下:

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")

如果有人为此找到解决方案会很有帮助.谢谢.

It would be helpful if someone finds a solution for this. Thanks.

推荐答案

确保您确实安装了正确的 spacy 模型.例如,在终端中使用 python -m spacy download en_core_web_sm 命令安装 en_core_web_sm.

Make sure you actually have the right spacy model installed. For example, install en_core_web_sm with the python -m spacy download en_core_web_sm command in the terminal.

接下来,修复这个错误:

Next, fix this error:

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())

也就是说,

  1. 打开C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\chatterbot\tagging.py 文件
  2. 转到第 13 行
  3. 替换self.nlp = spacy.load(self.language.ISO_639_1.lower())
if self.language.ISO_639_1.lower() == 'en':
    self.nlp = spacy.load('en_core_web_sm')
else:
    self.nlp = spacy.load(self.language.ISO_639_1.lower())

您需要为需要支持的其他语言添加更多条件.

You will need to add more conditions for other languages you need to support.

这篇关于ChatterBot 错误 - OSError: [E941] 找不到模型“en"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 13:40