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
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.
- 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.
- 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.
- 1.
Create a QnA service in Microsoft Azure (which we just did).
- 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. - 3.
Name your knowledge base.
- 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 . - 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.
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.
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.
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.
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/ .
Core: A chatbot framework similar to Mutters, with machine learning-based dialog management
NLU: An intent classification module providing intent classification and entity extraction.
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 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
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.
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.
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 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.
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.
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.