Chatter Bot语料库'Trainer'丢失错误

时间:2019-07-24 23:55:52

标签: python bots chatterbot

我正试图开始在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)

1 个答案:

答案 0 :(得分:1)

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

1

from chatterbot import trainers

2

trainer = chatterbot.trainers.ChatterBotCorpusTrainer