DEV Community

Cover image for Build your first ChatBot in 5 minutes

Build your first ChatBot in 5 minutes

Sahil Rajput on November 23, 2018

I was searching the internet on "How to build a Chatbot?" and I discovered ChatterBot which is a machine learning, conversational dialog engine for...
Collapse
 
kpspersonal profile image
kpspersonal • Edited

do pip install chatterbot-corpus
Then
Make the following changes to your code
remove the following lines
bot.set_trainer(ListTrainer)
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("chatterbot.corpus.english")

Add the following
trainer = ChatterBotCorpusTrainer(bot)
trainer.train('chatterbot.corpus.english')

Remove the following
training on english dataset
for files in os.listdir('./english/'):
data=open('./english/'+files,'r').readlines()
data=open('./english/'+files,'r').readlines()
trainer.train(data)
It should work now.

Collapse
 
karthiji profile image
KarthiJi • Edited

im not able to execute this code, cud u help me out with that..? can dm me abt it..?

Collapse
 
sahilrajput profile image
Sahil Rajput

What error you are facing?

Collapse
 
karthiji profile image
KarthiJi

cant import error

Thread Thread
 
sahilrajput profile image
Sahil Rajput

Download all the libraries.

Collapse
 
oshanwisumperuma profile image
Oshan Wisumperuma

I faced an issue when training using corpus files through "ListTrainer". seems even "categories" and "conversations" tags in yml file also get inserted into the data source.

Collapse
 
sahilrajput profile image
Sahil Rajput

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer

bot = ChatBot("Candice")
bot.set_trainer(ListTrainer)
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("chatterbot.corpus.english")

Try this

Collapse
 
faisal55859081 profile image
faisal

Try chatgen.ai to create chatbots. You can create click based as well as NLP Bots.

Collapse
 
mourey2277 profile image
Jannatul Mourey

Hello
While running your code I am getting this error

AttributeError: 'ChatBot' object has no attribute 'set_trainer'

Collapse
 
sahilrajput profile image
Sahil Rajput

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.trainers import ListTrainer

bot = ChatBot("Candice")
bot.set_trainer(ListTrainer)
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("chatterbot.corpus.english")

Try this and if you still get the same error. You can contact me via mail: sahil.rajput.0196@gmail.com

Collapse
 
amitkum58154973 profile image
Amit Kumar Mishra

any open source code and tools to design a website-based chatbot for the business need of a company?