A06 Ai Prac5
A06 Ai Prac5
Theory:
Chatbots:
A chatbot can be defined as a computer program that converses with users over the internet as any human
would with natural language and sentiments. It is a program or piece of software that automatically responds to
messages sent over a website chatbox, email, social media messaging app, or text.
For a deeper understanding of Chatbot, we can define it as a computer program that impersonates human
conversations in its natural format, which may include text (since the advent of bots) or spoken language using
artificial intelligence (AI) techniques such as Natural Language Processing (NLP) and audio analysis. One of the
primary aspects of an AI-based bot is that it is dynamic.
A chatbot is a smart application that reduces human work and helps an organization to solve basic queries
of the customer. Today most of the companies, business from different sector makes use of chatbot in a different
way to reply their customer as fast as possible. chatbots also help in increasing traffic of site which is top reason of
business to use chatbots.
Chatbot asks for basic information of customers like name, email address, and the query. If a query is
simple like product fault, booking mistake, need some information then without any human connection it can solve
it automatically and If some problem is high then It passes the details to the human head and helps customer to
connect with organization manager easily. And most of the customers like to deal and talk with a chatbot.
How do the Chatbots function?
The main technology that lies behind chatbots is NLP and Machine Learning.
When a question is presented to a chatbot, a series or complex algorithms process the received input,
understand what the user is asking, and based on that, determines the answer suitable to the question.
Chatbots have to rely on the ability of the algorithms to detect the complexity of both text and spoken
words. Some chatbots perform very well to the point it becomes difficult to differentiate whether the user is a
machine or a human.
However, handling complex conversations is a huge challenge; where there is a usage of various figures of
speech, it may be difficult for machines to understand.
Why we need Chatbots?
Cost and Time Effective: Humans cannot be active on-site 24/7 but chatbots can and the replying power of
chatbots is much fast than humans.
Cheap Development cost: with the advancement in technology many tools are developed that help easy
development and integration of chatbots with little investment.
Human Resource: Today Chatbots can also talk with text o speech technology so it gives the feel as a human is
talking on another side.
Business Branding: Businesses are changing with technology and chatbot is one out of them. Chatbot also helps in
advertising, branding of organization product and services and give daily updates to users.
Types of Chatbots:
1. Rule-based chatbots: Chatbots follow a set of established rules or flows to respond to questions posted by
a user. All your simple applications contain rule-based chatbots, which respond to queries based on the
rules they are trained on. For instance, a weather application, where you ask for weather forecast and it
fetches the data from different sources and responds with the information.
Rule-based chatbots may not be able to hold complex conversations. It can only accomplish the
tasks it is programmed to perform unless more improvements are made by the developer.
2. Self-learning chatbots: Self-learning bots are highly efficient because they are capable to grab and identify
the user’s intent on their own. They are build using advanced tools and techniques of Machine Learning,
Deep Learning, and NLP. Self-learning bots are further divided into 2 subcategories.
a. Retrieval-based chatbots:- Retrieval-based it is somewhat the same as Rule- based where
predefined input patterns and responses are embedded.
b. Generative-Based chatbots:- It is based on the same phenomenon as Machine Translation
build using sequence 2 sequences neural network.
Most of the organization uses self-learning chatbot along with embedding some rules like Hybrid version of both
methods which makes chatbot powerful to handle each situation during a conversation with a customer.
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:
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:
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:
The good thing is that ChatterBot offers this functionality in many different languages. So, you
can also specify a subset of a corpus in a language you would prefer.
Conclusion: Thus we have successfully implemented elementary Chatbot for Customer interaction
application.