Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Hello, Habr! Today we will discuss how to solve tasks that typically require human intervention using Azure. Operators spend a lot of time answering the same questions and handling phone calls and text messages. Chatbots automate communication and recognition, reducing the burden on people. They are also used in Azure DevOps, allowing, for example, the approval of releases and management of builds—viewing, starting, and stopping—directly from Slack or Microsoft Teams. Essentially, a chatbot resembles a CLI, but is interactive and allows developers to stay within the context of the chat discussion.

In this article, we will talk about tools for creating chatbots, demonstrate how they can be enhanced with cognitive services, and describe how to accelerate development through ready-made services in Azure.

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Chatbots and Cognitive Services: Similarities and Differences

To create bots in Microsoft Azure, the Azure Bot Service and the Bot Framework platform are used. Together, they provide a software suite for building, testing, deploying, and managing bots, enabling the creation of both simple and advanced communication systems with support for speech, natural language recognition, and other capabilities.

Suppose you need to implement a simple bot based on a corporate Q&A service or, conversely, create a functional bot with a complex branching communication system. For this, you can utilize a range of tools, broadly divided into three groups: 

  1. Rapid development services for dialogue interfaces (bots).
  2. Ready-made AI cognitive services for various use cases (image recognition, speech, knowledge base, and search).
  3. Services for creating and training AI models.

People often intuitively mix up 'bots' and 'cognitive services' because both concepts share a communication principle, and in the use case scenarios of bots and services, there are dialogues. However, chatbots operate with keywords and triggers, while cognitive services handle arbitrary requests, which are typically processed by humans: 

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Cognitive services are another means of communication with the user, helping to convert arbitrary requests into clear commands and pass them on to the bot. 

Thus, chatbots are applications for handling queries, while cognitive services are tools for intelligent query analysis that run separately, but can be accessed by the chatbot, making it 'intelligent'. 

Creating Chatbots

The recommended bot design scheme in Azure looks as follows: 

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

For the design and development of bots in Azure, the Bot Frameworkis used. There are bot examples, and the framework's capabilities change, so it is necessary to consider the version of the SDK being used in the bots.

The framework implies several options for creating bots: using classic code, command-line tools, or flowcharts. The last option visualizes dialogues; for this, the Bot Framework Composercan be used. It was created based on the Bot Framework SDK as a visual development tool that interdisciplinary teams could use to create bots.

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Bot Framework Composer allows creating a dialogue structure that the bot will work with using blocks. Additionally, triggers can be created, i.e., keywords that the bot will respond to during the dialogue, such as 'operator', 'theft', or 'stop' and 'that's enough'.

In Bot Framework Composer, a complex branching dialogue system can be created using Adaptive Dialogs.Dialogues can use both cognitive services and event cards (Adaptive Cards):

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

After creation, the chatbot can be deployed in the subscription, with an automatically prepared script generating all required resources: cognitive services, Application Plan, Application Insights, database, and so on.

QnA Maker

To create simple bots based on corporate FAQs, the cognitive service QnA Maker can be used. Implemented as a simple web wizard, it allows providing a link to a corporate knowledge base (FAQ URLs) or using a document database in *.doc or *.pdf format as a basis. After creating the index, the bot will automatically select the most appropriate answers to user queries.

With QnAMaker, you can also create chains of follow-up questions with automatic button creation, supplement the knowledge base with metadata, and refine the service during use.

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

Working with other cognitive services

Azure has many different cognitive services. Technically, these are standalone web services that can be invoked from code. In response, the service sends a JSON of a specific format that can be utilized in a chatbot.

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform
The following are commonly used in chatbots:

  1. Text recognition.
  2. Recognition of developer-defined image categories using Custom Vision Service (a production case: recognizing whether an employee is wearing a helmet, safety glasses, or a mask).
  3. Facial recognition (a great use case is verifying if the surveyed person has posted their own picture or, say, a photo of a puppy or a person of the opposite gender).
  4. Speech recognition.
  5. Image analysis.
  6. Translation (we all remember how much noise synchronous translation caused in Skype).
  7. Spell checking and suggestions for correcting errors.

LUIS

Also, creating bots may require LUIS (Language Understanding Intelligent Service). The service tasks include:

  • Determining whether a user's statement makes sense and whether a bot's response is necessary.
  • Reducing the effort to transcribe user speech (text) into understandable commands for the bot.
  • Predicting true user goals/intents and extracting key information from phrases in dialogue.
  • Allowing the developer to launch the bot using just a few examples of meaning recognition and subsequently refine the bot during operation.
  • Enabling the developer to use visualization for assessing the quality of command transcription.
  • Helping with incremental improvements in recognizing true intents.

Essentially, the main goal of LUIS is to probabilistically understand what the user meant and convert a natural request into a structured command. To recognize the meanings of requests, LUIS uses a set of intents (meanings, purposes) and entities (either pre-set by developers or taken from pre-formed 'domains' – some ready-made libraries of typical phrases prepared by Microsoft). 

A simple example: you have a bot that provides weather forecasts. For it, the intent will be to translate a natural request into an 'action' – a request for the weather forecast, and the entities will be the time and place. Let’s present a schema of how the CheckWeather intent works for such a bot.

Intent
Entity
Example of a natural request

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

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

To combine QnA Maker and LUIS, you can use Dispatcher. 

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

When you work with QnA Maker and receive a request from a user, the system determines the probability that a response from QnA is suitable for the request. If the probability is high, the user simply receives an answer from the corporate knowledge base; if it’s low, the request may be sent to LUIS for clarification. Using Dispatcher allows you to automate this logic without programming it, and to quickly determine this boundary for distributing requests.

Testing and publishing the bot

For testing, another local application is used, Bot framework emulator. The emulator allows you to interact with the bot and check messages that it sends and receives. The emulator displays messages as they would appear in a web chat interface and logs the JSON requests and responses during message exchanges with the bot.

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

Accelerating Development with Azure Services: Creating 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 to avoid rewriting standard bot functions by adding ready-made code as a 'skill'. An example could be working with a calendar, scheduling meetings, etc. The code for the ready skills is available. has been published on GitHub.

The testing has been successful, the bot is ready, and now it needs to be published and connected to channels. Publication is done through Azure, and messengers or social networks can be used as channels. If there is no required input channel, you can search for it in the relevant community on GitHub. 

To create a complete chatbot for user interaction and cognitive services, you will certainly need additional Azure services such as databases, serverless (Azure Functions), as well as LogicApp services and possibly Event Grid.

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Assessment and Analytics

For evaluating user interactions, you can utilize both the built-in analytics of Azure Bot Service and the specialized Application Insights service.

As a result, you can collect information based on the following criteria:

  • How many users accessed the bot from various channels during the selected time period.
  • How many users, after sending one message, returned later and sent another one.
  • How many actions were sent and received through each channel during the specified time interval.

With Application Insights, you can monitor any applications in Azure, including chatbots, gaining additional data on user behavior, loads, and chatbot responses. It should be noted that the Application Insights service has its own interface on the Azure portal.

The data collected through this service can also 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 from here.

Accelerating Development with Azure Services: Creating Chatbots and Cognitive Services Using the Platform

Thank you all for your attention! In this article, we used material from the Microsoft Azure architect webinar, Anna Fenushina, 'When People Fall Behind. How to Utilize Chatbots and Cognitive Services 100% for Automating Routine Processes,' where we visually demonstrated what chatbots in Azure are and what scenarios they can be used for, as well as showed how to create a bot in QnA Maker within 15 minutes and how the query structure is deciphered in LUIS. 

We conducted this webinar as part of the online marathon for developers at Dev Bootcamp. It focused on products that speed up development and relieve some of the routine burdens from company employees through automation tools and ready-made Azure modules. Recordings of other webinars included in the marathon are available via the links:

Source: habr.com

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster