0% found this document useful (0 votes)
96 views8 pages

Chatboat

The document discusses developing a chatbot for customer service interactions using Python. It describes chatbots and different types including rule-based and self-learning chatbots. It then discusses the ChatterBot library in Python which can be used to build chatbots using machine learning algorithms. The steps to create a basic chatbot app include importing classes, creating and training the chatbot using sample responses, and interacting with the chatbot.

Uploaded by

Hitesh Mali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views8 pages

Chatboat

The document discusses developing a chatbot for customer service interactions using Python. It describes chatbots and different types including rule-based and self-learning chatbots. It then discusses the ChatterBot library in Python which can be used to build chatbots using machine learning algorithms. The steps to create a basic chatbot app include importing classes, creating and training the chatbot using sample responses, and interacting with the chatbot.

Uploaded by

Hitesh Mali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

LP II AI and Cloud Computing

Title: Develop an elementary chatbot for any suitable customer interaction application.

Aim:
Implement chatbot which interact with the customer and responds to the query asked by the
customer.

Prerequisites:
Chatbot implementation concepts, python, chatbot libraries.

Objectives:
Student should be able to customer care chatbot.

Theory:

What is a Chatbot?
A chatbot is an AI-based software designed to interact with humans in their natural languages. These
chatbots are usually converse via auditory or textual methods, and they can effortlessly mimic human
languages to communicate with human beings in a human-like manner

Chatbots can be categorized into two primary variants – Rule-Based and Self-learning.

The Rule-based approach trains a chatbot to answer questions based on a set of pre-determined rules on
which it was initially trained. These set rules can either be very simple or very complex. While rule-based
chatbots can handle simple queries quite well, they usually fail to process more complicated
queries/requests.

As the name suggests, self-learning bots are chatbots that can learn on their own. These leverage advanced
technologies like Artificial Intelligence and Machine Learning to train themselves from instances and
behaviours. Naturally, these chatbots are much smarter than rule-based bots. Self-learning bots can be
further divided into two categories – Retrieval Based or Generative.

Chatbot in Today’s Generation

Today, we have smart AI-powered Chatbots that use natural language processing (NLP) to understand
human commands (text and voice) and learn from experience. Chatbots have become a staple customer
interaction tool for companies and brands that have an active online presence (website and social network
platforms).

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 48


LP II AI and Cloud Computing

hatterBot Library

ChatterBot is a Python library that is designed to deliver automated responses to user inputs. It makes use
of a combination of ML algorithms to generate many different types of responses. This feature allows
developers to build chatbots using python that can converse with humans and deliver appropriate and
relevant responses. Not just that, the ML algorithms help the bot to improve its performance with
experience.

Another excellent feature of ChatterBot is its language independence. The library is designed in a way that
makes it possible to train your bot in multiple programming languages.

How does ChatterBot function?

When a user enters a specific input in the chatbot (developed on ChatterBot), the bot saves the input along
with the response, for future use. This data (of collected experiences) allows the chatbot to generate
automated responses each time a new input is fed into it.

The program chooses the most-fitting response from the closest statement that matches the input, and then
delivers a response from the already known selection of statements and responses. Over time, as the
chatbot engages in more interactions, the accuracy of response improves.

How To Make A Chatbot In Python?

1. Prepare the Dependencies

The first step in creating a chatbot in Python with the ChatterBot library is to install the library in your
system. It is best if you create and use a new Python virtual environment for the installation. To do so, you
have to write and execute this command in your Python terminal:

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 49


LP II AI and Cloud Computing

You can also install ChatterBot‘s latest development version directly from GitHub. For this, you will have
to write and execute the following command:

pip install git+git://github.com/gunthercox/ChatterBot.git@master

If you wish to upgrade the command, you can do so as well:

Now that your setup is ready, we can move on to the next step to create chatbot using python.

2. Import Classes

Importing classes is the second step in the Python chatbot creation process. All you need to do is import
two classes – ChatBot from chatterbot and ListTrainer from chatterbot.trainers. To do this, you can execute
the following command:

3. Create and Train the Chatbot

This is the third step on creating chatbot in python. The chatbot you are creating will be an instance of the
class ―ChatBot.‖ After creating a new ChatterBot instance, you can train the bot to improve its
performance. Training ensures that the bot has enough knowledge to get started with specific responses to
specific inputs. You have to execute the following command now:

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 50


LP II AI and Cloud Computing

Here, the argument (that corresponds to the parameter name) represents the name of your Python chatbot.
If you wish to disable the bot‘s ability to learn after the training, you can include the ―read_only=True‖
command. The command ―logic_adapters‖ denotes the list of adapters used to train the chatbot.

While the ―chatterbot.logic.MathematicalEvaluation‖ helps the bot to solve math problems, the
―chatterbot.logic.BestMatch‖ helps it to choose the best match from the list of responses already provided.

Since you have to provide a list of responses, you can do it by specifying the lists of strings that can be
later used to train your Python chatbot, and find the best match for each query. Here‘s an example of
responses you can train your chatbot using python to learn:

You can also create and train the bot by writing an instance of ―ListTrainer‖ and supplying it with a list of
strings like so:

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 51


LP II AI and Cloud Computing

Now, your Python chatbot is ready to communicate.

4. Communicate with the Python Chatbot

To interact with your Python chatbot, you can use the .get_response() function. This is how it should look
while communicating:

However, it is essential to understand that the chatbot using python might not know how to answer all your
questions. Since its knowledge and training is still very limited, you have to give it time and provide more
training data to train it further.

5. Train your Python Chatbot with a Corpus of Data

In this last step of how to make a chatbot in Python, for training your python chatbot even further, you can
use an existing corpus of data. Here‘s an example of how to train your Python chatbot with a corpus of data
provided by the bot itself:

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 52


LP II AI and Cloud Computing

Code:

# Importing chatterbot

from chatterbot import ChatBot

# Create object of ChatBot class

bot = ChatBot('Buddy')

# Create object of ChatBot class with Storage Adapter

bot = ChatBot(

'Buddy',

storage_adapter='chatterbot.storage.SQLStorageAdapter',

database_uri='sqlite:///database.sqlite3'

# Create object of ChatBot class with Logic Adapter

bot = ChatBot(

'Buddy',

logic_adapters=[

'chatterbot.logic.BestMatch',

'chatterbot.logic.TimeLogicAdapter'],

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 53


LP II AI and Cloud Computing

# Inport ListTrainer

from chatterbot.trainers import ListTrainer

trainer = ListTrainer(bot)

trainer.train([

'Hi',

'Hello',

'I need your assistance regarding my order',

'Please, Provide me with your order id',

'I have a complaint.',

'Please elaborate, your concern',

'How long it will take to receive an order ?',

'An order takes 3-5 Business days to get delivered.',

'Okay Thanks',

'No Problem! Have a Good Day!'

])

# Get a response to the input text 'I would like to book a flight.'

response = bot.get_response('I have a complaint.')

print("Bot Response:", response)

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 54


LP II AI and Cloud Computing

name=input("Enter Your Name: ")

print("Welcome to the Bot Service! Let me know how can I help you?")

while True:

request=input(name+':')

if request=='Bye' or request =='bye':

print('Bot: Bye')

break

else:

response=bot.get_response(request)

print('Bot:',response)

By:: Dr. Sunil D. Rathod and Prof. Komal Jakotiya Page 55

You might also like