- August, 2020
- Share It
Bots are becoming a part of our everyday life. More and more chats are popping up from different web pages, FB pages, from different messaging apps. We are communicating more and more using voice control and who is listening to our commands? Bots, of course. Is this a story of bots taking over the world? Well, for now I am not sure, and I will come back to that question later. ☺
A Chatbot is a program that can conduct an intelligent conversation. I know for sure that they are becoming a big part of IT community and, from a professional perspective, I think that at least people from the industry should have some basic understanding.
From business point of view, it sounds good to have a 24/7 employee who can answer customers’ questions and provide some services without complaining or asking for a pay raise. ☺
So, what is giving the Bot’s its brain and what are we using under the hood to design human understandable communication flow?
The answer is NLP – Natural Language Processing & NLU – Natural Language Understanding.
NLP is artificial intelligence (AI) context which is a layer between humans communicating using human language and computer systems. NLP itself consists of few elements such as natural language understanding, discourse analysis, relationship extraction and few other language analysis areas.
NLU is subset of NLP that is focused on language understanding. Reading, comprehension, and semantic analysis are the most important elements of NLP.
Most of the major NLU solutions have support for simple scenarios, like Q&A, which can be used out of the box, hence no need for custom backend solutions. So simple bot’s can be created just using NLU solutions.
All big IT companies already have a solution for NLP-NLU layer and most of them are free. So, to implement a bot for your FB page you just need to create an agent which will model dialogs for your business and use NLP that you have chosen for language processing.
Current solutions and few remarks about those solutions:
- Facebook – Wit.ai – Completely free platform even for commercial use. Largest number of supported languages, currently 50;
- Amazon – Lex – Amazon Web Service for building conversational interface using text and voice input. It’s using the same deep learning engine that powers Amazon Alexa;
- Microsoft – LUIS – stands for Language Understanding, machine learning-based service. Good Azure integration;
- IBM – Watson assistant. Name does not come from Sherlock Homes’ assistant, it is named after IMB’s founder and first CEO, Thomas J. Watson;
- Google – Dialogflow let’s get into this one:
Dialogflow
– is a natural language understanding platform developed by Google, used to integrate a conversational user interface. It can be used for text and speech. It also supports majority of platforms like FB Messenger, Alexa, Google Assistant and Slack…
DialogFlow, like other similar platforms, is enabling us to easily create bots, and the machine learning part is enabling us to create more intelligent conversations and to improve them over time. Also, DialogFlow is providing us with an easy way to hook up our bot to some conversation platform.
DilogFlow setup
To use Dialogflow you only need Google/Gmail account. With your account you can login to Dialogflow console. Also, if you want some other people to work on the same project, you can share your project by adding access rights to different Google accounts. Two or more people can work on the same project if they are using different accounts.
Building Blocks of Chatbot’s
Agent translates user requests to actionable data (intents). For easier understanding, for every Chatbot there will be a different agent. If you are creating a Chatbot for car renting, then your agent will be named something like CARBOT. For purpose of this article I am creating a Chatbot for fashion store: as the brand is called cozy2wear, my agent will be named CozyBot.
When creating an agent, you are choosing language for your Chatbot. For now Serbian is not supported so I will take English.
DialogFlow is also providing you with a large number of prebuild agents as templates. So when creating an agent you can start from scratch or choose prebuild agent from similar field and use that as a starting point. For my CozyBot I have chosen Online Shopping template as my template.
Intents are describing the tendency of the user-entered sentence. Set of intents are usually created so that user entries could be translated into actions expected by the software. Every agent has a Welcome intent which greets the user and Fallback intent which is triggered when no other intent is recognized. For all other conversation scenarios we are creating intents. For fashion store example, the intents will be product.search where we can provide products by categories, delivery.options where a user can get details about delivery based on country.
Entities are parameter values that are extracted from conversation. In intent examples bolded words are entities for that intent. So for product category is entity for search intent and for delivery intent country is entity.
I won’t go into too much details for managing dialogs. I will just add that we can create linear conversations that will go from follow logical path of conversation and nonlinear conversations which will enable users to jump from one conversation to another. For instance, if a user finds a skirt by some parameters, like price, we can provide him with a conversation for matching shirts which will trigger nonlinear intent for shirts.
Each intent has a setting to enable fulfillment. If an intent requires some action by your system or a dynamic response, you should enable fulfillment for the intent. If an intent without fulfillment enabled is matched, Dialogflow uses the static response you defined for the intent.
In more complicated cases we want to use our, or some other external API’s for fulfillment of intents and of course it is possible to add them to intent flows. Also, DialogfLow is providing easy way to web hook your Chatbot to any API protocol.
This article is just scratching surface of Chatbot’s. I didn’t cover parts about small talk, training, validation and many other topics. Idea is to understand building blocks that are used and to see how easy is to create a bot.
Just to added that Dialogflow V2 API was released in June 2020 with some additional features.
I was introduced to this topic on a project for Chabot which is one of many interesting projects that I have been working while I’m working at enjoy.ing.
So to get back to question of talking over the world. There is an interesting story about Microsoft failed Twitter bot project.1 In 2016 Microsoft released Twitter bot called Tay. Idea was to collect tweets from other users and using them to create its own tweets. 16 hours after the release they had to shut it down as it started tweeting racist and sexually charged messages. They tried one more time and after same result Microsoft had abounded that project. From this perspective maybe it was a sign of things to come (even the first letter in Chatbot name is the same as currently most famous twitter account). It was just an echo of voices from Twitter.
Can Chatbots change the world, can they take somebody’s job? Probably yes, but it will also create new kinds of jobs. As always, technology is changing the world and we must keep track, adapt and try to use it for good purpose. ☺
Author: Marko Oljača, Software Engineer @ enjoy.ing
Support by: Goran Mihajlović, Senior Software Engineer @ enjoy.ing
1 https://en.wikipedia.org/wiki/Tay_(bot)