Saturday 8 December 2018

Chat bot in Python using Chatterbot



Here is the sample code demonstration for how to create simple chatbot using chatterbot  in python.
Chatbot will answer the question based on training data that you have provided.




First you need to do install the chatterbot using the pip install.

Pip install chatterbot

Open any of the IDE for writing the python code. I am using the Jupiter here.
import chatterbot

Just create the Bot name and defined the type of trainer for your bot.
bot=chatterbot.ChatBot('ibot',trainer='chatterbot.trainers.ChatterBotCorpusTrainer')

Now just train your bot with some of the training data there are inbuilt data provided for corpus  English you can you to train your bot with basic data like below.
bot.train("chatterbot.corpus.english")

It will use to train the data from the below path
Once the training will start it will look like below.


Once data has train use the below like of code for recursively run the bot request and response way .
while True:
    qus=input('You: ')
    if qus=='stop':
        break
    ans=bot.get_response(qus)
    print('EB: ',ans)

One you execute your above line of code it will go to the infinite loop till you type “Stop” or nany code error and your bot will look like below.


No comments:

Post a Comment