Home Audience Developers The Connect Between Artificial Intelligence and Chatbots

The Connect Between Artificial Intelligence and Chatbots


Automation is taking over many human functions at many levels. One example is of the function of answering queries in various fields like banking, software and e-commerce. Utilising a bot saves the company the cost of employing a person, since the bot will not join another firm, requires no salary and no perquisites, while it works diligently! What more could an entrepreneur want?

Have you ever got confused after hearing terms like artificial intelligence, machine learning, deep learning and data science? Is there any difference between them or do they all mean the same thing? If there are differences, then why do people use them interchangeably?

So, before getting into artificial intelligence and its applications, let’s understand a bit about all these terms and see how they are related.

Note: These technologies and methods are evolving dynamically and are very vast in scope. There are different ways to define them and I have tried to explain them in a layman’s terms.

Artificial intelligence (AI)

Artificial intelligence is the technique that enables machines (mostly computers) to replicate human behaviour. This is a big umbrella term covering Big Data, machine learning, data engineering, data science and a lot more. There could be a combination of multiple small sub-components to design one solution. Refer Figure 1 for pictorial representation.

Machine learning (ML)

Machine (computer) learning (studying) involves training a machine to learn by its previous experiences. In simple words, ML is a set of tools that helps in learning from data. ML widely uses statistical tools to make sense of given data sets. ML is divided into three categories.

  1. Supervised learning: This deals with already known data, which means labelled data sets with a finite number of characteristics—like the data of your employees with their names, ages, salaries and designations.
  2. Unsupervised learning: This deals with unknown data or unlabelled data sets with unknown characteristics, like a bucket full of fruits, but you don’t know how many varieties there are in it.
  3. Reinforcement learning: This allows the machines to automatically determine the ideal behaviour within a specific context. Reinforcement signals (reward and feedback) help a machine to learn how it should behave.

Deep learning (DL)

Deep learning is a branch of machine learning that is based on unsupervised feature learning. DL is also known as a multi-layered neural network. Just like the human brain works on neural networks, DL uses the multi-layered networks to process data and make decisions. As the name indicates, it helps in reading the hidden meaning deep inside the data.

Data science (DS)

Data science is about understanding and visualising the data to derive meaning out of it. Since there is a very thin line between the skills set and responsibilities of data scientists and data engineers, people get confused about their roles. Data engineers are focused on building infrastructure and architecture for data generation while data scientists focus on the advanced mathematics and statistical analysis of that generated data. It overlaps with what AI does and subsequently with ML (refer to Figure 1 to understand this better).

These four branches all need various mathematical tools and methods like probability, statistics, linear algebra, numerical optimisation and computer programming.

Now that we know what artificial intelligence is and how it is related with machine learning, let’s try to understand a well-known application of AI, called a chatbot.

Have you ever wondered how you get an instant reply from Priya, Pankaj, Alex or John while seeking help on any banking, shopping or hotel service portal?

Initially, when I was unaware of machine learning, I used to wonder how these banks managed to hire people that resolved customer queries instantly over a chat. But ML amazed me with its magic and chatbots are one among its many applications.


This is defined as “A computer program (based on artificial intelligence) designed to simulate conversation with human users, especially over the Internet.”

A chatbot is an automated assistant that communicates with us through text messages or voice commands. It is a virtual companion that integrates into websites, applications or instant messengers and helps entrepreneurs to get closer to customers.

Types of chatbots

Depending upon the business case, we can classify chatbots into two large categories.

A simple chatbot works based on pre-defined keywords and a set of rules. These rules will select an appropriate answer for a given asked question. For example, we can design a chatbot to:

  • Respond to FAQs
  • Check hotel room availability and bookings
  • Handle flight enquiries

Smart chatbots rely on machine learning methods, wherein all the previous chats are recorded for later processing so that they get a more accurate response for every new query. In this case, results are generated dynamically based on algorithms that can be applied on the data set that is specific to the problem being dealt with. Such bots can:

  • Suggest a food menu based on one’s previous orders.
  • Act as a daily fitness tracker and provide suggestions based on current health. Extending this to the next level, a smart bot can search for nearby hospitals and also book an appointment for you.

Google Home and Amazon Alexa are the best examples of smart chatbots; they are multi-lingual and work with voice commands rather than text messages.

Figure 1: Venn diagram for AI and its components

Structure of a chatbot

A chatbot is often described as one of the most advanced and promising interactions between humans and machines. Chatbots simulate the conversation (mostly text messages) with the user in natural language. The best thing about chatbots is that they can be integrated with any interface like in social networks, smartphone applications, messengers, etc.

Natural language processing is used to convert text input to process the query and pass it on to the logic parser, where it extracts the data/knowledge based on the ML algorithm. Once the result is generated, it is passed to the natural language generator (NLG) engine to convert the machine’s output into human readable format (text), after which it is fetched by the frontend interface and presented to the user. Refer Figure 2 for pictorial representation.

Designing one’s own chatbot

There are several ways to design and implement a chatbot. Based on your comfort level, you can select any one of the following tools.

  1. ChatterBot: This has a Python library that makes it easy to generate automated responses for a user’s input.
  2. NLTK: This has a Python based open source natural language processing platform embedded with a huge set of methods and corpus packages.
  3. Scikit Learn: This provides a range of supervised and unsupervised machine learning algorithms through a consistent interface in Python.
Figure 2: Structure of a chatbot

One can use a combination of different tools and libraries to design an efficient chatbot, as shown below in the code snippet of a simple response to a greeting:

greeting_input = (“hello”, “hi”, “greetings”, “sup”, “what’s up”,”hey”,)

greeting_responses = [“hi”, “hey”, “*nods*”, “hi there”, “hello”, “I am glad! You are talking to me”]

def greeting(sentence):

“””If user’s input is a greeting, return a greeting response”””

for word in sentence.split():

if word.lower() in greeting_input:

print random.choice(greeting_resonses)

The following code snippet is for a dynamic response to a greeting, using Scikit-learn and NLTK:

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics.pairwise import cosine_similarity

import nltk

import numpy as np

nltk.download(‘punkt’) # one-time use only

nltk.download(‘wordnet’) # one-time use only

sent_tokens = nltk.sent_tokenize(raw)# converts to list of sentences

word_tokens = nltk.word_tokenize(raw)# converts to list of words



user_response = input()



if(user_response==’thanks’ or user_response==’thank you’):


print “BOT: You are welcome!!”



print “BOT: “+greeting(user_response)





print “BOT: “

print response(user_response)




print “BOT: Bye! See you soon..”

Note: This snippet is just for purposes of understanding and more code may be needed to make it work.



Please enter your comment!
Please enter your name here