Azure Cognitive Services: Analyze User Messages

With the Microsoft Azure Extension, one can detect Named Entitiesrecognize a language, or analyze the sentiment in a user message. This tutorial explains how to use the Cognitive Services in Cognigy.AI

   Watch Cognigy Showcase "Sentiment Analysis: Three Powerful Use Cases for Customer Service Bots"


Table of Contents

  1. Install the Microsoft Azure Extension
  2. Create an Azure Connection
  3. Analyze the Sentiment of a message
  4. Recognize the language

Install the Microsoft Azure Extension

The first step is to install the required integration. In this case, a so-called Extension is Installed to Cognigy.AI. Thus, navigate to the Extensions Marketplace inside of the Virtual Agent and add the Microsoft Azure Extension by clicking on the Install button. Now follow this installation guide and upload the Extension to Cognigy, where it will be displayed as the following:

microsoft-azure-extension-uploaded.PNG

Congrats! The installation of the Extension is finished!

Create an Azure Connection

In this step, a so-called Connection will be created. If one, in Cognigy.AI, clicks on the previously uploaded Extension, the following details can be observed:

azure-extension-detail-view.png

The red-marked part in the above figure shows, that there is a Connection required. Therefore, it needs to be created and filled with the information about the Azure Text Analytics Resource. In order to do so, one initial Azure Flow Node needs to be added to a Flow:

  1. Create a new Flow in Cognigy.AI
  2. Inside of the Flow Chart, click on + and navigate to the Microsoft Azure Extension:

    azure-extension-flow-menu.PNG

  3. For example, add the Analyze Sentiment Flow Node by clicking on it:

    azure-analyze-sentiment-flow-node.PNG

  4. In order to edit the Flow Node and create the Connection, please click on it. An Edit Node menu will be opened on the right side of the screen:

    azure-analyze-sentiment-flow-node-edit-menu.PNG
  5. Right next to the Connection field (the first one at the top), one needs to click on the + button. The Connection menu will be opened at the center of the screen:

    azure-analyze-sentiment-flow-node-connection.PNG
  6. Insert the related Azure credentials/information of the organization to the fields.
    1. key
      1. The API Key of the created Azure Text Analytics Resource.
    2. region
      1. The region of the Azure installation, e.g. westus or westeurope. The region is defined in the creation process of the resource in Azure.
    3. Both values can be found in the Azure Cognitive Services Resource Group:
      azure-textanalyticsresourcegroup.png
      After clicking on the API Key link, the information is visible and can be copied to Cognigy.AI:
      azure-text-analytics-resource-apikey.PNG
  7. Click on the Create button

Analyze the Sentiment of a message

Since the Connection is provided, the exposed Flow Nodes can be used now. In this case, the already added Analyze Sentiment Flow Node can help to understand the user's mood. In the Edit menu of this Node, the current input text will be analyzed in English, while one could change the language based on the provided select menu. However, as soon as the users writes something, the message will be analyzed:
azure-sentiment-result-example-chat.PNG

Such as displayed in the figure above, the result consists of three different so-called Sentiment Scores:

  • Positive
  • Neutral
  • Negative

From default, the detailed information is stored in the input object and looks similar to this:

{
  "microsoft": {
    "azure": {
      "sentiment": {
        "documents": [
          {
            "id": "1",
            "sentiment": "positive",
            "confidenceScores": {
              "positive": 0.97,
              "neutral": 0.02,
              "negative": 0.01
            },
            "sentences": [
              {
                "sentiment": "positive",
                "confidenceScores": {
                  "positive": 0.97,
                  "neutral": 0.02,
                  "negative": 0.01
                },
                "offset": 0,
                "length": 37,
                "text": "I would like to order a pizza salami."
              },
              {
                "sentiment": "neutral",
                "confidenceScores": {
                  "positive": 0.01,
                  "neutral": 0.98,
                  "negative": 0.01
                },
                "offset": 38,
                "length": 36,
                "text": "Please bring it as soon as possible!"
              }
            ],
          }
        ],
      }
    }
  }
}

With this data stored, a dynamic message can be sent to the user by extracting the sentiment using Cognigy Script:

input.microsoft.azure.sentiment.documents[0].sentiment

Finally, this value can be inserted into a Say Node:

The sentiment of this sentence is {{input.microsoft.azure.sentiment.documents[0].sentiment}}

The message used in the example above is configured such as the following:

The sentiment of this sentence is {{input.microsoft.azure.sentiment.documents[0].sentiment}} Positive: {{input.microsoft.azure.sentiment.documents[0].confidenceScores.positive}} Neutral: {{input.microsoft.azure.sentiment.documents[0].confidenceScores.neutral}} Negative: {{input.microsoft.azure.sentiment.documents[0].confidenceScores.negative}}

Potential Use-Cases

Generally speaking, the sentiment score can be used in order to change the conversation or, better said, respond to the user appropriately. If the user is angry, one could try to improve the user experience by forwarding the conversation to a human or sending a voucher. Otherwise, a postive sentiment could lead to a very friendly and active conversation, using emojis and other media contents.

Recognize the language

Next to the users's mood, the actual language that is used could be detected automatically. One could imagine, that the user changes the language during the conversation or tries to speak German with an English configured virtual agent. The Detect Language Flow Node lets Cognigy.AI react to those events:

azure-detectlanguage-example.PNG

From default, the systems takes the current message of the user and detects the language. It is defined in the Edit menu of the Node:

azure-extension-detect-language.PNG

Similar to the previous Flow Node, this one stores the information into the input object, from default, as well while it can be extracted with Cognigy Script:

input.microsoft.azure.language.documents[0].detectedLanguage.name

With this script, the name of the recognized language is extracted -- in this case "Spanish". Because of the fact that people could use multiple languages in the same text message, the Confidence Score should be considered as well. It tells Cognigy.AI how probable the detection is:

input.microsoft.azure.language.documents[0].detectedLanguage.confidenceScore

One could now use this value and check if it is greater than 0.7 (70%), for example, and then switch the locale or do something similar.


Comments

0 comments

Article is closed for comments.

Was this article helpful?
1 out of 1 found this helpful