Monday, 15 July 2019

How do chatbots work?

  • Hey, what’s up?
  • How’re you doing?
  • How do you do?
  • Hello!
Anything familiar in these sentences?
They all are some or the other variations of a greeting message.
How do you respond when someone asks you one of the above questions?
You respond, typically like - I am good, how about you?
Some other day you might respond as - I am fine, thanks for asking.
This is exactly how ChatBots work. A typical ChatBot maps a sentence into a so-called intent which in this case is the greeting intent. With every intent are associated a set of responses. The bot picks up one of these responses and sends it back to the user. This is done so as to give a more natural feel to the bot by avoiding sending the exact same response again and again.
What is the AI here?
The element of Artificial Intelligence comes in during the intent recognition. The bot is supposed to take a look at the words and possibly their arrangement in order to figure out what the intent is. This can be done in multiple ways like:
  • Simple word mapping: words like hi, hello, what’s, etc can be mapped to the greeting intent. However, this is quite inaccurate because ‘hello, who the hell are you?’ doesn’t quite sound like a greeting :P
  • Machine Learning: if you are familiar with Machine Learning, you would be able to easily identify that the above problem is a supervised learning based classification problem. In simpler words, the problem at our hand is as follows - you are given a bunch of sentences and the corresponding intent against them. Now, you are given a new sentence and you need to classify it as belonging to one of the intents. This problem can be solved using a number of ways. The simplest way would be to use a Naive Bayes based implementation. In this implementation, we convert the sentence into a vector of numbers. The corresponding intents are also given ‘codes’ to identify them numerically. This input is fed to a training algorithm which learns how to classify these sentences. Later on, the trained model can be used to classify new sentences (if it has been trained well). Over time, it can be retrained with fresh data so as to make it learn better.
A more complex Machine Learning approach will involve training a multi-layer artificial neural network which is almost sure to give far better accuracy.
Once the intent has been identified, the bot can pick up one of the answers corresponding to the intent.
It is easy to code your own bot using Python. Some libraries worth trying are:
  • Sklearn - it provides Naive Bayes classifier out-of-the-box.
  • Tensorflow - you can write your own neural network
Hope that explains the working of a ChatBot :)

1 comment:

How much time will it take to create Quora?

If you really want to build a product that scales to 100 million users, it will be a real big gun and I am sure you will face many challen...