Accelerating development with Azure services: building chatbots and cognitive services using the platform

Hey Habr! Today we'll show you how to use Azure to solve tasks that usually require human participation. Operators spend a lot of time answering the same questions, processing phone calls and text messages. Chatbots automate communication and recognition and reduce the burden on people. Bots are also used in Azure DevOps, where they allow, for example, to approve releases, manage builds - view, start and stop - directly from Slack or Microsoft Teams. In fact, a chatbot is somewhat reminiscent of CLI, only interactive, and allows the developer not to leave the context of the discussion in the chat.

In this article, we'll talk about chatbot tools, show how they can be enhanced with cognitive services, and describe how to speed up development with out-of-the-box services in Azure.

Accelerating development with Azure services: building chatbots and cognitive services using the platform

Chatbots and cognitive services: how are they similar and what is the difference

Microsoft Azure uses the Azure Bot Service and the Bot Framework to create bots. Together they are a set of software for building, testing, deploying and administering bots, which allows you to create from ready-made modules both simple and advanced communication systems with support for speech, natural language recognition and other features.

Suppose you need to implement a simple bot based on a corporate question and answer service or, conversely, create a functional bot with a complex branched communication system. To do this, you can use a number of tools, conditionally divided into three groups: 

  1. Services for rapid development of dialog interfaces (bots).
  2. Ready-made cognitive AI services for different use cases (pattern recognition, speech, knowledge base and search).
  3. Services for creating and training AI models.

Usually people intuitively confuse “bots” and “cognitive services” because both concepts are based on the principle of communication, and there are dialogues in the scenario of using bots and services. But chatbots work with keywords and triggers, while cognitive services work with arbitrary requests that are usually processed by people: 

Accelerating development with Azure services: building chatbots and cognitive services using the platform

Cognitive services are another way to communicate with the user, helping to convert an arbitrary request into a clear command and pass it on to the bot. 

Thus, chatbots are query applications, and cognitive services are smart query analysis tools that run separately, but which can be accessed by the chatbot, becoming “intelligent”. 

Creation of chat bots

The recommended design pattern for a bot in Azure is as follows: 

Accelerating development with Azure services: building chatbots and cognitive services using the platform

To design and develop bots in Azure, use BotFramework. There is on GitHub bot examples, the capabilities of the framework change, so you need to take into account the version of the SDK that is used in the bots.

The framework includes several options for creating bots: using classic code, command line tools, or flowcharts. The last option renders dialogs, for this you can use the manager Bot Framework Composer. It was built on top of the Bot Framework SDK as a descriptive development tool that interdisciplinary teams could use to build bots.

Accelerating development with Azure services: building chatbots and cognitive services using the platform

The Bot Framework Composer allows you to use blocks to create a dialog structure that the bot will work with. Additionally, you can create triggers, that is, keywords that the bot will respond to during the dialogue. For example, the words “operator”, “theft” or “stop” and “enough”.

In Bot Framework Composer, you can create a complex system of dialogs using Adaptive Dialogs. Dialogs can use both cognitive services and event cards (Adaptive Cards):

Accelerating development with Azure services: building chatbots and cognitive services using the platform

After creation, you can deploy a chatbot in a subscription, and an automatically prepared script will create all the necessary resources: cognitive services, Application plan, Application Insights, database, and so on.

QnA Maker

To create simple bots based on corporate databases of questions and answers, you can use the QnA Maker cognitive service. Implemented as a simple web wizard, it allows you to submit a link to the corporate knowledge base (FAQ Urls) as an input or use a database of documents in *.doc or *.pdf format as a basis. After creating the index, the bot will select the most appropriate answers to the user's questions.

Using QnAMaker, you can also create chains of clarifying questions with automatic creation of buttons, supplement the knowledge base with metadata, and further train the service during use.

The service can be used as a chatbot that implements only this one function, or as part of a complex chatbot that uses, depending on the request, other AI services or elements of the Bot Framework.

Working with other cognitive services

There are many different cognitive services on the Azure platform. Technically, these are self-contained web services that can be called from code. In response, the service sends json of a certain format that can be used in the chat bot.

Accelerating development with Azure services: building chatbots and cognitive services using the platform
The most commonly used chatbots are:

  1. Text recognising.
  2. Recognition of developer-defined categories of Custom Vision Service images (production case: recognition whether an employee is wearing a hard hat, goggles or mask).
  3. Face recognition (an excellent use case is to check whether the person posted his face, or, say, a photo of a dog or a photo of a person of the opposite sex).
  4. Speech recognition.
  5. Image analysis.
  6. Translation (we all remember how much noise simultaneous translation made in Skype).
  7. Spell check and suggestions for correcting errors.

LUIS

Also, to create bots, you may need LUIS (Language Understanding Intelligent Service). Service tasks:

  • Determine whether the user's statement makes sense and whether the bot's reaction is necessary.
  • Reduce efforts to transcribe the user's speech (text) into commands understandable to the bot.
  • Predict true user goals/intentions and extract key information from phrases in dialogue.
  • To enable the developer to launch the bot using just a few examples of meaning recognition and subsequent further training of the bot in the process.
  • Enable the developer to use visualization to evaluate the quality of command transcription.
  • Help with incremental improvements in the recognition of true targets.

In fact, the main goal of LUIS is to understand with a certain probability what the user meant and convert a natural request into a coherent command. To recognize query values, LUIS uses a set of intents (meanings, intentions) and entities (either pre-configured by developers, or taken and pre-formed "domains" - some ready-made libraries of type phrases prepared by Microsoft). 

A simple example: you have a weather forecast bot. For him, the intent will be the translation of a natural request into an “action” - a request for a weather forecast, and the entities will be the time and place. Here is a diagram of how the CheckWeather intent works for such a bot.

Intent
Essence
Natural Query Example

CheckWeather
{"type": "location", "entity": "moscow"}
{"type":"builtin.datetimeV2.date","entity":"future","resolution":"2020-05-30"}
What will the weather be like in Moscow tomorrow?

CheckWeather
{ "type": "date_range", "entity": "this weekend" }
Show me the forecast for this weekend

To combine QnA Maker and LUIS, you can use Dispatch

Accelerating development with Azure services: building chatbots and cognitive services using the platform

When you work with QnA Maker and receive a request from a user, the system determines with what percentage of probability the answer from QnA is suitable for the request. If the probability is high, the user is simply given a response from the corporate knowledge base; if it is low, the request can be sent to LUIS for clarification. Using Dispatcher allows you not to program this logic, but to automatically determine this edge of request separation and quickly distribute them.

Bot testing and publishing

Another local application is used for testing, Bot framework emulator. Using the emulator, you can communicate with the bot and check the messages that it sends and receives. The emulator renders messages as they would appear in a web chat interface and logs JSON requests and responses when communicating with the bot.

An example of using the emulator is presented in this demo, which shows the creation of a virtual assistant for BMW. The video also talks about new accelerators for creating chatbots - templates:

Accelerating development with Azure services: building chatbots and cognitive services using the platform
https://youtu.be/u7Gql-ClcVA?t=564

You can also use templates when creating your chatbots. 
Templates allow you not to write typical bot functions again, but to add ready-made code as a “skill”. An example would be working with a calendar, scheduling appointments, etc. Ready-made skills code published on github.

Testing was successful, the bot is ready, and now we need to publish it and connect channels. The publication is carried out using Azure tools, and messengers or social networks can be used as channels. If there is no data entry channel you need, you can search for it in the corresponding community on GitHab. 

Also, to create a full-fledged chat bot as a communication interface with the user and cognitive services, you will, of course, need additional Azure services, such as databases, serverless (Azure Functions), as well as LogicApp services and, possibly, Event Grid.

Accelerating development with Azure services: building chatbots and cognitive services using the platform

Valuation and analytics

You can use both the built-in analytics of the Azure Bot Service and the dedicated Application Insights service to evaluate user interaction.

As a result, information can be collected according to the following criteria:

  • How many users accessed the bot from different channels during the selected time period.
  • How many users who sent one message came back later and sent another one.
  • How many actions were sent and received using each channel during the specified time interval.

With Application Insights, you can monitor any application in Azure, and chatbots in particular, to gain additional insight into user behavior, workload, and chatbot response. It should be noted that the Application Insights service has its own interface in the Azure portal.

Also, the data collected through this service can be used to create additional visualizations and analytical reports in PowerBI. An example of such a report and a template for PowerBI can be taken here.

Accelerating development with Azure services: building chatbots and cognitive services using the platform

Thank you all for your attention! In this article, we have used material from a webinar by Microsoft Azure architect Anna Fenyushina “When people don’t have time. How to 100% use chatbots and cognitive services to automate routine processes ”, where we clearly showed what chatbots are in Azure and what are the scenarios for their use, and also demonstrated how to create a bot in QnA Maker in 15 minutes and how the query structure in LUIS stands for. 

We did this webinar as part of the Dev Bootcamp Online Developer Marathon. It was about products that speed up development and relieve some of the routine workload from company employees using automation tools and ready-made pre-configured Azure modules. Recordings of other webinars that were included in the marathon are available at the links:

Source: habr.com

Add a comment