The Non-Coder’s Guide to Chatbots
Every chatbot developer, as part of his or her learning process, will eventually write some tutorials and I am certainly no exception to that. I’m aware that already dozens of tutorials are out there and yet I’m here to write another one because I believe I can explain some aspects better than most of the articles I’ve seen.
Chatbots have come a long way in the past few years and you probably know that since you are reading this. Brands have been using chatbots to engage their customers because competing for space on your phone is really hard as most of the apps that get downloaded are hardly used once. These bots help us to hide the service layers behind the plain English conversational layers so that we no longer have to fiddle our way with clunky apps to book a cab or order a pizza. Everyone has understood the convenience afforded by bots that can schedule a meeting or book a restaurant.
Most of the value of deep learning today is in narrow domains where you can get a lot of data. Here's one example of something it cannot do: have a meaningful conversation. There are demos, and if you cherry-pick the conversation, it looks like it's having a meaningful conversation, but if you actually try it yourself, it quickly goes off the rails.-Andrew NG, American Businessman
Deep Dive into Bots:
Since these chatbots live inside your chat application, there is no need to download anything which is win-win for everyone.
Retrieval Based Chatbots:
Earlier chatbots relied on rule-based approach and had the hard-coded response. Smart programmers like you would try to predict everything a user could say and build a huge list of responses to every question you can think of.This has not changed much even after the advancements in deep learning, we still have to predict the entire conversational flow in advance and build a repository of pre-defined responses, but this effort can hugely be reduced with the help of machine learning. We can identify the intent behind the query using a simple classifier so that it puts together two questions with the same intent even if worded differently and can have a similar response to it.
Deep learning is making new discoveries every day and is changing the tech rapidly. These models don’t rely on hard-coded responses, instead generate them from the scratch. Since it requires a huge amount of data, it comes with its own inefficiencies like making grammatical errors, irrelevant or inconsistent responses. I don’t see them being deployed in any of the production systems yet. They don’t seem to work in practice and business will not risk their customers with chatbots that have so much freedom to respond back. Most of the value of deep learning today is in narrow domains where you can get a lot of data. Here’s one example of something it cannot do: have a meaningful conversation.
Understanding language is the holy grail of machine learning.-John Giannandrea, Software Engineer
Understanding language is the holy grail of machine learning. — John Giannandrea. There are two big components of an intelligent chatbot.
This piece works on understanding the true meaning of the sentence which can be inferred using various techniques like classifying the intent (using Sklearn, TensorFlow etc), identifying the important entities (using NER libs like Spacy, CoreNLP etc), finding the sentiment and storing the context in a variable and looping that in the conversation.
NLU still struggles with identifying the true meaning of the sentence but these statistical components when put together helps us in closing the gap and is the best we have today.
This framework allows us to classify the intent and identify the entities by also giving the flexibility to use different libraries for classification and named entity recognition tasks.
After understanding what the user had to say, this module’s main function is to find a response. These bots mimic the human-human interactions and this is where it starts getting complicated.
The Dialogue manager is responsible for preserving the state of the chat history and in turn maintaining the flow of the conversation.
Guides conversations, taking the history and external context of a conversation into account. Instead of thousands of rules, Rasa picks up patterns from real conversations.
This lets you define your own stories using different rules. No Machine learning is used in defining the flow of conversation.
There are two types of dialogue when building the conversational scenarios.
This is similar to a question/answer model. The aim of this dialogue is to collect the necessary information to complete the task. This is also termed as slot filling as we need mandatory entities to be filled before proceeding to the next step.
For example, while creating a bot to book a movie ticket. We need to know few necessary information before booking the ticket like Name of the Movie and Show Timings. The bot will keep asking the required questions to fill this information and it has to be smart enough to pick the correct entity for the respective slot.
Non Linear Dialogue
A non-linear dialogue depends entirely on the user’s response and can have several branches which allow the conversation to take different paths during its flow. This type of dialogue seems more humanly and hence can get more messy and complicated if not handled properly.
Chatbots, also called Conversational Agents or Dialogue System are best described as NLU modules combined with a dialogue manager.
Intent / Interactions:
Intent represents a mapping between what a user says and what action should be taken by your software. These are pre-defined components of the bot that defines the user’s request and categorize them to take appropriate action.
Any important data or parameter required from the user’s request to proceed further is termed as an entity. State of the art NER systems can be used to extract these entities from a sentence.
Some entities which are mandatory, are termed as slot and the process of slot filling is to constantly prompt user until these slots are filled.
Contexts represent the current context of a user’s request. This is helpful for differentiating phrases which may be vague or have different meanings depending on the user’s preferences, geographic location, the current page in an app, or the topic of conversation. For example, if a user is listening to music and finds a band that catches their interest, they might say something like: “I want to hear more of them”. As a developer, you can include the name of the band in the context with the request, so that the agent can use it in other intents.
When the user request does not belong to any of the mentioned intents, we can have a set of responses like I didnt understand, I dont quite know what that means etc.
After finding the intent of the request and filling all the necessary slots, the bot might need to perform a particular action supposedly a cloud/lambda function connecting to a third party plugin.
Once your chatbot is up and ready to face the humans, its time to integrate it with some of the leading chatbot platforms. Most of the bot frameworks come with their own plugin to make the integration seamless. Platforms like Telegram, Messenger, Google Assistant opens up new opportunities by showcasing your products and services to the vast audience it holds and in turn grow your business.
One of the most challenging parts about designing a chatbot is to make the conversation flow as natural and efficient as possible and not how to classify intents, identify entities, generate rich responses, or to do some jazzy technical integrations. It is not technically difficult to build a bot but it is a matter of rich user experience and wanting your user to come back to you. A great design should focus less on what the chatbot has to say and more about what the user has to say.
Don’t try too hard to quickly fill your slots by asking direct questions, as that may sound too commanding and boring and might shove away the user. If handled properly, most of the questions do not need an answer in the first place if you have sufficient information about the user. Another way is to store the user’s context and carry it along the conversation which is handy in case of any doubts.
If it’s necessary to ask a question, try asking it in different ways and take due care that you don’t ask a question which the user has already answered which usually happens if the entity recognition fails. (More Training!!) Repetition of a bot’s response should be avoided at any cost even when responding in different sessions altogether. The best approach is to have a bunch of pre-configured responses for the same utterance and then randomly picking responses while replying back.
User loves when their bots have a sense of humor and capable of cracking a joke based on the context. This can get tricky as not everyone enjoys witty replies, so use this with precaution and is advisable only if you have a sentiment analyzer to predict your user’s mood. Giving a name and a personality to your bot is important to personify the bot. Chatbot users usually have few personal questions they would like to ask, and your bot should better be ready for them.