我正在尝试使用chatterbot在电报中创建一个聊天机器人,并使用函数train()来生成ChatBot,但视觉代码(我的编辑器)和atom无法识别该库。在我在 cmd 中使用 pip install chatterbot 并启动之前:
Successfully installed PyYAML-3.13 chatterbot-1.0.4 chatterbot-corpus-1.2.0 mathparse-0.1.2 nltk-3.4 pint-0.9 pymongo-3.7.2 singledispatch-3.4.0.3 sqlalchemy-1.2.18
我尝试用可视代码从 cmd 重新安装该库。但不要运行该代码。显示的错误是:
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data] Unzipping taggers\averaged_perceptron_tagger.zip.
[nltk_data] Downloading package punkt to
[nltk_data] C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data] Unzipping tokenizers\punkt.zip.
[nltk_data] Downloading package stopwords to
[nltk_data] C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data] Unzipping corpora\stopwords.zip.
[nltk_data] Downloading package wordnet to
[nltk_data] C:\Users\KatiusKa\AppData\Roaming\nltk_data...
[nltk_data] Unzipping corpora\wordnet.zip.
Traceback (most recent call last):
File "C:\Users\KatiusKa\Documents\Python\chbot.py", line 8, in <module>
chatbot.train(
AttributeError: 'ChatBot' object has no attribute 'train'
这是可视化代码中的代码:
from chatterbot import ChatBot
chatbot = ChatBot(
"Ejemplo Bot",
trainer = "chatterbot.trainers.ChatterBotCorpusTrainer"
)
chatbot.train(
"chatterbot.corpus.spanish"
)
这是我尝试从可视代码运行的代码
最佳答案
错误是正确的 - chatbot
类没有属性 train
。如果您查看文档,就会发现您应该训练的是 ChatterBotCorpusTrainer
类,并且它确实具有 train()
函数。
在这里查看chatterbot的基本用法:https://github.com/gunthercox/ChatterBot#basic-usage
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot('Ron Obvious')
# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)
# Train the chatbot based on the english corpus
trainer.train("chatterbot.corpus.english")
关于python - 属性错误: “' ChatBot' object has no attribute 'trains' ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55320669/