© Abhishek Singh, Karthik Ramasubramanian, Shrey Shivam  2019
A. Singh et al.Building an Enterprise Chatbothttps://doi.org/10.1007/978-1-4842-5034-1_7

7. Introduction to Microsoft Bot, RASA, and Google Dialogflow

Abhishek Singh1 , Karthik Ramasubramanian1 and Shrey Shivam2
(1)
New Delhi, Delhi, India
(2)
Donegal, Donegal, Ireland
 

In the previous chapter, we discussed how to build an in-house chatbot framework with natural language and conversation capabilities. Building a solution from scratch has advantages that we discussed previously. However, there are use cases and scope where it could be easier, quicker, and cheaper to use readily available online intent classification and conversation management frameworks to build your chatbot client.

In this chapter, we will introduce some of the popular online chatbot frameworks and how to use them.

Microsoft Bot Framework

Microsoft Bot Framework is a comprehensive framework for building enterprise-grade conversational AI experiences. It offers a set of cognitive services through its cloud hosting service called Azure. Azure Cognitive Services enable us to build intelligent enterprise-grade bots. We can use its QnA Maker service to build a quick FAQ bot or use LUIS (Language Understanding Intelligent Service) to build a sophisticated virtual assistant. Figure 7-1 shows the various cognitive services of the bot framework and other components required for an end-to-end conversational AI experience.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig1_HTML.jpg
Figure 7-1

Components of a bot framework

Introduction to QnA Maker

Microsoft’s QnA Maker provides a quick way of building a bot on FAQ URLs, structured documents, manuals, and soon. Its powerful crawler and parser engine extracts all possible questions and answers from the content and makes them available via bot. It is a cognitive service tool that builds and trains a simple QnA bot.

QnA Maker is a free service that responds to a user’s utterances or asks in a natural conversational way. It is able to provide helpful answers to semi-structured data with its question/answer mechanism based on its language processing techniques.

A common challenge for most informational bot scenarios is to separate out the content management from the bot design and development, since content owners are usually domain experts who may not be technical. QnA Maker addresses this by enabling a no-code QnA management experience.

QnA Maker allows you to edit, remove, or add QnA pairs with an easy-to-use interface and then publish your knowledge base as an API endpoint for a bot service. It’s simple to train the bot using a familiar chat interface, and the active learning feature automatically learns question variations from users over time and adds them to the knowledge base. Use the QnA Maker endpoint to seamlessly integrate with other APIs like a language understanding service and speech APIs to interpret and answer user questions in different ways.

We discussed previously that having a knowledge base is essential to answer users’ queries. It is the underlying information repository that provides answers to users’ queries. A knowledge base is a logical term for various types of structured, semi-structured, and unstructured information that can be stored in an underlying database with test processing capabilities. QnA Maker exposes its knowledge base/database through API services.

Once we create an account and log in to www.qnamaker.ai , it will ask us to create a new knowledge base.

The first step is to create a new Azure QnA service for our knowledge base, which requires creation of the following in Azure:
  1. 1.
    Creation of a resource group: Some of the services of QnA Maker are not available in all regions at this point, so we used the (US) west US region for creating and deploying all the components for the demo, as seen in Figure 7-2.
    ../images/478492_1_En_7_Chapter/478492_1_En_7_Fig2_HTML.jpg
    Figure 7-2

    Resource group creation step

     
  2. 2.
    Creation of a QnA Maker resource: As see in Figure 7-3, we need to provide a name and other details for the resource creation. Please note that we used the Azure Free Tier subscription for the demo. Pricing tiers and subscriptions may vary based on your account.
    ../images/478492_1_En_7_Chapter/478492_1_En_7_Fig3_HTML.jpg
    Figure 7-3

    QnA Maker creation

     
Once the QnA Maker resource is created, different resource components will be visible in the Azure All Resources dashboard, as shown in Figure 7-4.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig4_HTML.jpg
Figure 7-4

The All Resources dashboard

Now, we log into www.qnamaker.ai/Create and follow the five steps required to create a knowledge base:
  1. 1.

    Create a QnA service in Microsoft Azure (which we just did).

     
  2. 2.

    Connect the QnA service to the knowledge base.

    As shown in Figure 7-5, you can select the previously created Azure QnA service upon refreshing this page.
    ../images/478492_1_En_7_Chapter/478492_1_En_7_Fig5_HTML.jpg
    Figure 7-5

    Connecting the QnA service to the knowledge base

     
  3. 3.

    Name your knowledge base.

     
  4. 4.

    Populate the knowledge repository.

    We found a FAQ page on the website of Prudential Financial, a fortune 500 insurance company. The FAQ page had 73 questions and answers that we could use for the demo. This information will be added to the knowledge repository, as shown in Figure 7-6. The reference page URL used for the demo is www.prudential.com/faq .
    ../images/478492_1_En_7_Chapter/478492_1_En_7_Fig6_HTML.jpg
    Figure 7-6

    Populating the knowledge base with data from a URL source

     
  5. 5.

    Create the knowledge base.

    The QnA maker service crawls the provided URL and extracts information in the form of questions and answers for us to review, add more data, and save and train, as shown in Figure 7-7. There are more options, such as testing the service before publishing.

     
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig7_HTML.jpg
Figure 7-7

Extraction of question/answer pairs by the QnA service

The next step is to publish this knowledge base for use by the bot by clicking the Publish button, as shown in Figure 7-8.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig8_HTML.jpg
Figure 7-8

Publishing the knowledge repository

Upon publishing the knowledge base, the previously created qna-maker-demo QnA service is ready to be used. We can then make a POST request to the service to query the knowledge base with a question and it will respond with an answer. Figures 7-9 and 7-10 show an example request via POSTMAN for the question asked (“change beneficiary”), which the QnA service matched with a similar question in the knowledge base (“How do I change my beneficiary?”).
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig9_HTML.jpg
Figure 7-9

HTTP POST request to demo-faq-kb knowledge base with authorization

../images/478492_1_En_7_Chapter/478492_1_En_7_Fig10_HTML.jpg
Figure 7-10

The question asked for the response shown in Figure 7-9

You can see how to use Microsoft QnA Maker using Azure to quickly build a fully functional Q&A service. This service can be integrated with a WebApp bot client or Facebook Messenger or any other third-party messaging service.

The functionality of the QnA Maker service is essentially a relevant search engine in the back end that indexes content data and uses a text-based scoring logic to rank best matching content. However, this service is not conversational and does not perform language understanding to identify user intents before taking an action. Microsoft provides another cognitive service called LUIS that is created for this purpose.

Introduction to LUIS

Language Understanding Intelligent Service (LUIS) is a cloud-based API service and a component of cognitive services, as shown in Figure 7-1. It takes user input and applies machine learning techniques to predict user intent. It also uses its Named Entity Recognition (NER) matching techniques to identify named entities in the user utterance to provide a meaningful response. This is illustrated in Figure 7-11. In a nutshell, LUIS is an intent classification engine that provides the best matching (top scoring) intent based on the user utterance.

The first step in the process is to create a LUIS app consisting of a domain-specific language model. At the time of creation of the app, we can select a prebuilt domain model, build our own natural language model, or leverage the prebuilt domain with our own customization.
  • Prebuilt model: LUIS provides many prebuilt domain models including predefined intents of common usage with various utterances and prebuilt entities of various domains. These prebuilt entities can also be leveraged without having to use intents and utterances of the prebuilt model. Depending on whether the prebuilt model is suitable for your use case, prebuilt models can be a good, quick starter.

  • Custom entities: LUIS provides several ways in which we can define our custom intents along with sample utterances. We can also define our domain-centric custom entities leveraging NER matching capabilities.

../images/478492_1_En_7_Chapter/478492_1_En_7_Fig11_HTML.jpg
Figure 7-11

LUIS intent classification illustration

The creation of a LUIS app is simple and similar to what we will discuss when we create an Alexa app (for integration with IRIS) in Chapter 9, so we will skip the explanation of the same in this chapter.

Once the intents, utterances, and domain-related entities are defined using the custom or prebuilt model, the LUIS app is then published. Publishing an app means making it available for use. Once published, a client application can send utterances to a LUIS service endpoint, as illustrated in Figure 7-12. LUIS responds with a JSON response.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig12_HTML.jpg
Figure 7-12

Example LUIS bot flow

Introduction to RASA

RASA is an open source stack of machine learning libraries for developers to create contextual chatbots. RASA also provides a paid enterprise-grade platform. Client services can connect with various APIs in the RASA platform. More details on the RASA platform can be found at https://rasa.com/products/rasa-platform/ .

The RASA stack has two main components:
  • Core: A chatbot framework similar to Mutters, with machine learning-based dialog management

  • NLU: An intent classification module providing intent classification and entity extraction.

As shown in Figure 7-13, both Core and NLU modules provide various functionalities that can be customized, trained, and integrated on a custom dataset for contextual AI-based virtual assistants.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig13_HTML.jpg
Figure 7-13

Functionalities of Core and NLU modules

  • Turn natural language into structured data: This functionality is similar to what we discussed in the QnA Maker example, in which structured, semi-structured, and unstructured data was parsed in some meaningful form in the knowledge base for querying.

  • ML-based dialogue: RASA provides its own dialogue management module that can be customized and modelled via a series of simple steps. We discussed an implementation of conversation management in IRIS in Chapter 6 with finite state machines.

  • Custom word vectors: RASA provides customization to train word vectors for our domain. Several word embeddings are generated in the process, which helps the engine in better intent classification. Word2vec is a popular neural network model that generates word embeddings from user text.

  • Entity extraction: By using the built-in or custom-built entity recognition models, RASA can identify entities in user utterances.

  • Match messages to multiple intents: A user utterance can be matched to multiple intents, and different match scores along with the best matching intent are returned in response.

  • Interactive learning: We discussed in the last chapter how to enhance IRIS by extending the design to support a continuous improvement framework through interactive learning. RASA also provides simple ways to enable interactive learning that teaches the bot new skills.

The RASA framework for chatbots makes use of the two models to effectively flow the conversation, as shown in Figure 7-14.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig14_HTML.jpg
Figure 7-14

Flow of conversation using the Core and NLU modules of RASA

The message is basically handled at two stages: one at the Core module, which manages the conversation, and one at the NLU module, which provides the essential language services. The external API calls or CRM connections are dealt with by the RASA platform with the help of RASA core trackers. The next section discusses some more details on how the two modules work.

RASA Core

RASA Core refers to the main component, which receives and responds to the requests. The module is robust and has a flow-based approach to handle all requests, as shown in Figure 7-15.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig15_HTML.jpg
Figure 7-15

Working on the RASA framework

The RASA framework has a six-step flow to handle all incoming messaging requests and respond to them. The steps are described below; however, more details can be found at http://rasa.com/docs/#rasa_core.agent.Agent .

The interpreter receives the message and converts it into a dictionary including the original text, the intent, and any entities that were found. The tracker keeps track of the conversations and passes on the state with new message to policy. The policy module prepares the response for the request. Once the response is ready in the policy module, it is passed to the tracker and action. The tracker updates the state of conversation and the action sends the response back to the user.

The above implementation helps all the conversations to flow through RASA and at the same time keeps track of conversations to maintain states of conversations.

RASA NLU

RASA Natural Language Understanding (NLU) module is a tool that does the intent classification and entity extraction for all the messages incoming from the user. It is a fully open source tool developed for the core purpose of being used in chatbot development.

The RASA NLU can be hosted as a service for your chatbot to use. The RASA NLU also allows you to train different types of models using your own data. From the perspective of chatbot developers, the RASA NLU module has two parts:
  • Training: This module allows you to train models on your own data. Having your own data to train allows you to develop a NLU that is business specific.

  • Server: This module serves as the training model to the chatbot. It can be hosted as an API service and runs at the back end.

The key benefit of using the open source NLU module is that you don’t need to send your data outside to Google or Amazon to train on intents and entities. And, being open source, you can tweak the models or develop your own models as per your needs. The architecture for the RASA NLU also allows it to run from everywhere as a service. You may not need to make network calls if your architecture demands that.

Refer to the extensive documentation of RASA at https://rasa.com/docs/ .

Introduction to Dialogflow

Dialogflow is an offering of Google for developing human-computer interactions. It was formerly known as API.ai as a platform for managing APIs for chatbots. Google bought the company in September 2016 and renamed it Dialogflow in 2017. It is now a core offering on Google for voice-based application development for all of its platforms including Google Home, Google Assistant, and other voice-enabled services. The capability of Dialogflow to integrate with virtually all platforms including wearables, home applications, speakers, smart devices, etc. makes it one of the most popular platforms for developing chatbots.

Google Dialogflow functioning is similar to the previous discussed chatbots, with some variations in naming technology and technical architecture on how it implements the flow. A typical conversation with a chatbot in Dialogflow looks like Figure 7-16.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig16_HTML.jpg
Figure 7-16

Dialogflow-based chatbot

The user responses are allowed in both written format and in voice/speech. The responses are captured by the Google Assistance module and then converted into text to allow the chatbot to be voice enabled. Google Assistance can be replaced by other integration options as well.

The key steps to building a chatbot with Dialogflow are discussed below. You are encouraged to go through the official documentation for Dialogflow at https://dialogflow.com/ .
  • The first step is to create a Dialogflow account and then create a Dialogflow agent, which lets you define a natural language understanding model.

  • The second step is to define how information is extracted from user utterances. This is done by defining extract parameters for entities. This is helpful to understand important attributes in user utterances, providing better matches based on extracted entities.

  • In order for a chatbot to be conversational, we need to define and manage states with contexts in the next step.

  • Finally, the Dialogflow agent can be integrated with Google Assistant, which lets us deploy the agent. This allows users to invoke actions through the assistant to interact.

The above tutorial details can be found at https://dialogflow.com/docs . Below we present selected steps in the process to build a chatbot using Dialogflow.

Creating an agent means creating an NLU model that will understand the chats happening with that agent. So, if you want to create a chatbot for two different domains, you may need to create two different agents and train them accordingly. See Figure 7-17.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig17_HTML.jpg
Figure 7-17

Creation of an agent in Dialogflow

The next step is to create intents using the Dialogflow console. The intent can be defined along with the utterances using the rich UI of Dialogflow. The console window looks similar to Figure 7-18.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig18_HTML.jpg
Figure 7-18

Intent creation in Dialogflow

The Dialogflow console also provides a simulator at the right side of the window to test the trained intents in a simulated environment. This helps you to test your model before deploying it to production. The simulation window looks similar to Figure 7-19.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig19_HTML.jpg
Figure 7-19

Dialogflow simulation window

Actions and parameters are extracted from the entity extraction module of Dialogflow. The parameters extracted then can be used for fulfilment and generating the responses. The Entity extraction mechanism is driven by powerful Google ML models. A basic training phase and entity extraction in Dialogflow is shown in Figure 7-20.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig20_HTML.jpg
Figure 7-20

Entity extraction in Dialogflow

The contexts can be managed by the console as well, and your bot can be trained on missed intents that the chatbot was not able to understand. Every time you simulate the model, it gets trained on the latest data provide to its intent engine.

Dialogflow connects with outside services and CRMs using its fulfilment service. The fulfillment service allows you to create custom API endpoints and expose them to your chatbot. The fulfillment service in Dialogflow is called Web Hooks.

One of the great features is the capability to integrate the chatbot with multiple platforms with just few clicks. Figure 7-21 shows the integration options available with Dialogflow. The ecosystem of Dialogflow is very strong, and it offers good integration models in Nodejs for developers to build chatbots and features as per their requirements.
../images/478492_1_En_7_Chapter/478492_1_En_7_Fig21_HTML.jpg
Figure 7-21

Integration options in Dialogflow

Summary

We discussed different chatbot frameworks and how they are useful to build a simple chatbot client. However, these frameworks have advantages and disadvantages.

Microsoft Bot Framework is open source and available on GitHub but some of its services such as Lex or Azure come at an additional cost. It’s designed to be easy to use as a set of services.

RASA is also open source and provides enterprise platform support. It requires development and programming knowledge since it is designed for developers. It does not provide out-of-the-box integration to other messaging clients. It can be hosted on-premise, but it does not provide direct user info management support.

Dialogflow provides out-of-the-box integration with some popular messaging platforms such as Facebook Messenger, Skype, and Google Assistant and provides the complete toolkit required for building bots. However, it cannot be operated on-premise.

The chapter also discussed the key features of various platforms and presented essential information required for developers to start working on these platforms. The chapter concluded with an introduction to an enterprise-level paid platform.

In the next chapter, we will discuss how the custom chatbot designed in previous chapters can be extended to integrate with various third-party services and enterprise databases to provide responses to the client.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset