首页 > 解决方案 > Chatter Bot Corpus'Trainer' 缺失错误

问题描述

我正在尝试开始在 python 中构建聊天机器人。我真的很想从头开始编程。我从 ChatterBot 模块开始学习它是如何工作的。我已经 pip 安装了所有模块,但我仍然遇到“ChatterBotCorpusTrainer”的问题,我收到了一个丢失的错误。我运行 python 3.7 并且我有更新的 ChatBot 模块。

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import os

bot= ChatBot('Bot')
trainer = ChatterBotCorpusTrainer(bot)


corpus_path = '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/chatterbot_corpus/data/english'


for file in os.listdir(corpus_path):
trainer.train(corpus_path + file)





conversation = [
"Hello",
"Hi there!",
"How are you doing?",
"I'm doing great.",
"That is good to hear",
"Thank you.",
"You're welcome."
]

trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')

response = chatbot.get_response("Good morning!")
print(response)

这是我得到的错误

/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/storage/jsonfile.py:26: UnsuitableForProductionWarning: The JsonFileStorageAdapter is not recommended for production environments.
  self.UnsuitableForProductionWarning
Traceback (most recent call last):
  File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/chat_1_1.py", line 6, in <module>
trainer = ChatterBotCorpusTrainer(bot)
  File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/trainers.py", line 101, in __init__
from .corpus import Corpus
  File "/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot/corpus/__init__.py", line 6, in <module>
from chatterbot_corpus import Corpus
ImportError: cannot import name 'Corpus' from 'chatterbot_corpus' (/Users/singlefawn/Desktop/Our Realm/1997/Programs/random gallery/venv/lib/python3.7/site-packages/chatterbot_corpus/__init__.py)

标签: pythonbotschatterbot

解决方案


您需要指定模块(chatterbot.trainers)。您有 2 个选项:

1

from chatterbot import trainers

2

trainer = chatterbot.trainers.ChatterBotCorpusTrainer

推荐阅读