A simple chatbot Using Chatterbot part 01

shrimali senevirathna
3 min readJun 16, 2020

--

Here are the simple steps to make a simple chatbot with using an interesting python library ChatterBot which is a Machine learning-based, language independent and provides space to generate the response based on the data collected previously.

First Step

Check Prerequisites

  • python should be installed to your pc

If you want to check whether you have installed python go to the command-line interface (*simply type cmd in the search box) and type

python

if you have already installed python it will give the version and other details or else you can check the python version by typing

python -V or python -version

Let’s start to build our chatbot …

Second step ***

Install the packages from the Github page of chatterbot

What is a Package?

A package contains all the files you need for a module. Modules are Python code libraries you can include in your project.

Go to chatterbot GitHub page and there they have given full instructions about how to download that library into your machine. Here I am explaining with an extra simplification.

simply go to the command prompt and type

install -U chatterbot

then that will install some necessary dependencies to build our chatbot. If anyone does not have any idea what is this pip and where is it coming from, PIP is a package manager for python packages. We can check the pip version from the command

pip -version

If you do not have PIP installed, you can download and install it from this page

ChatterBot comes with a data utility module that can be used to train chatbots. For this purpose, we need to install chatterbot-corpus package. Type in the command prompt

pip install -U chatterbot_corpus

So this will install the corpus package and then let's move to the next step!

Third Step

Choose your favourite editor like Visual Studio Code (can be any editor I prefer VScode) and open it to make a new file.

Fourth step

Go to the GitHub documentation and there go to the examples and select the basic example(if you are familiar with chatterbot u can try other examples too) from this link here.

copy the code and paste in your editor and save it.

from chatterbot import Chatbot — — — — — — — — this is the class of the chatbot.

from chatterbot.trainers import ListTrainer — — — — — — — this is the trainer and is a basic collection of sentences. These sentences have a connection to one another.

Change the code by adding a loop as given below.

Fifth step

Congratulations! You made your first Python chatbot! Run your code and see what is happening.

Every time running the code it automatically creates an SQLite file and gives the output. If you are analysing the chatbot you can understand that when we are asking the different question the chatbot gives you the same answer stored previously because it cannot think and say. How this process is happening?. So we will get deep into this Fifth step in the next article….

--

--