Do you think that you get bored when no one is there to interact with you or guide you. We cannot create a human sudden as it needs 9 months, but if you are a python programmer then it’s simple to create a chat bot to interact with you.
Many packages in python are awe-inspiring that just a few lines of code would make great applications. Come on lets not waste time because its time to build a chat bot. We are going to do this using chatterbot package in python using pip.
ChatterBot is a machine-learning based conversational dialog engine build in Python which makes it possible to generate responses based on collections of known conversations.
Installation of PyPi
- To install chatterbot from python package index,use pip command in the python terminal.
pip install chatterbot
- If you have already installed chatterbot,then upgrade it using the command,
pip install chatterbot –upgrade
Steps to create chat bot
- Import a sub package called chatbot from chatterbot package.
from chatterbot import chatbot
- Name your chat bot as “my guide” and create.
chatbot=ChatBot(‘my guide’, trainer=’chatterbot.trainers.ListTrainer’)
- Now train your bot with some general facts.
chatbot.train([“Hi what do you want to know?”, “The capital of India is Delhi”, “The capital of Italy is Rome”, “The capital of Phillipines is Manila”, “Come back again to know more”])
- Get a response to the user’s input text from your chat bot.
response = chatbot.get_response(‘Tell me some countries and its capital cities.‘)
- And finally if you run your code, your chat bot works very well.This is a simple program and you can make your bot even better using logical adapters in chatterbot package and do more.
READ MORE:Getting started with python installation