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

问题描述 投票:0回答:5

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

这是代码:

from chatterbot import ChatBot
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")

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

python windows spacy chatterbot
5个回答
17
投票

确保您确实安装了正确的 spacy 模型。例如,在终端中使用

en_core_web_sm
命令安装
python -m spacy download en_core_web_sm

接下来,修复此错误:

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

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


4
投票

检查您正在使用的 spacy 版本。

安装 spacy 并下载语言模型,en_core_web_sm,在本例中使用

 python -m spacy download en_core_web_sm

如果是v3.0,则需要使用

加载
nlp = spacy.load("en_core_web_sm")

如果是< v3.0, you can link the model creating a shortcut using

python -m spacy link en_core_web_sm en

然后使用

nlp = spacy.load("en")

加载它

4
投票

除了其他评论之外,请注意 SpaCy 3.0.3 和 Python 3.8 的问题 - 如果您正在使用这些版本,您可能必须通过 Python shell 下载语言模型,例如:

import spacy
from spacy.cli.download import download
download(model="en_core_web_sm")

对于这些版本,通过

python -m spacy download en_core_web_sm
下载可能会导致异常 - 如前所述。 这里


0
投票

首先,您需要通过运行以下命令来下载 en_core_web_sm: python -m spacy download en_core_web_sm

您需要修改以下代码。

enter image description here


0
投票

尝试使用>>pip install -U spacy安装spacy

并更改代码

self.nlp = spacy.load(self.language.ISO_639_1.lower()) 

在“C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-package

© www.soinside.com 2019 - 2024. All rights reserved.