ChatterBot错误-OSError:[E941]找不到模型“en”

我尝试运行我的第一个 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:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbotchatterbot.py", line 28, in __init__
    self.storage = utils.initialize_class(storage_adapter, **kwargs)
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbotutils.py", line 33, in initialize_class
    return Class(*args, **kwargs)
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbotstoragesql_storage.py", line 20, in __init__
    super().__init__(**kwargs)
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbotstoragestorage_adapter.py", line 21, in __init__
    'tagger_language', languages.ENG
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbottagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesspacy__init__.py", line 47, in load
    return util.load_model(name, disable=disable, exclude=exclude, config=config)
  File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packagesspacyutil.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")

如果有人为此找到解决方案,那将会很有帮助。谢谢。

回答

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

接下来,修复此错误:

File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbottagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())

那是,

  1. 打开 C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbottagging.py文件
  2. 转到第 13 行
  3. 替换self.nlp = spacy.load(self.language.ISO_639_1.lower())
File "C:UsersUSERAppDataLocalProgramsPythonPython37libsite-packageschatterbottagging.py", line 13, in __init__
    self.nlp = spacy.load(self.language.ISO_639_1.lower())

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


以上是ChatterBot错误-OSError:[E941]找不到模型“en”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>