问题描述
我正在尝试使用chatterbot在电报中创建一个聊天机器人,并使用train()函数生成ChatBot,但是可视代码(我的编辑器)和atom无法识别该库。在我使用pip之前,请在cmd中安装chatterbot并启动:
I'm trying to use chatterbot to create a chatbot in telegram and use the function train() to generate the ChatBot but visual code(my editor) and atom can't recognize the library. Before I use pip install chatterbot in cmd and launched:
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重新安装该库。但是不要运行代码。显示给我的错误是:
I tried to re-install the library from cmd in visual code. But don't run the code. The error that show me is:
[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()
函数。
The error is correct - the chatbot
class does not have an attribute train
. If you check out the docs, it's the ChatterBotCorpusTrainer
class that you're supposed to train, and which does, indeed, have a train()
function.
在此处查看chatterbot的基本用法:
Check out the basic usage of chatterbot here: 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")
这篇关于AttributeError:“'ChatBot'对象没有属性'trains'”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!