Logic Apps - Integrating LUIS Application With Logic Apps To Predict Intent In User Utterances

Introduction

Any business which performs online transactions needs to providesome kind of chat support for the issues related to their business. This can be done by developing chat applications where the consumers directly chat with the agent of the business who then solve their problems. A new alternative to answering frequently asked questions is the use of the ChatBot which is intelligent enough to understand the questions raised by the user and determine the solutions to them on the real-time basis. Or in the case of an administrator, if they are managing a lot of operative tasks or a lot of source code bases, then an intelligent bot is of great help.

For the bot to become intelligent, the important step is that the bot should understand the language in which humans communicate with the bot (e.g English, French, Hindi etc.). To facilitate this understanding Microsoft has provided developers with a powerful feature called Language Understanding (LUIS). This feature can be used to understand the language by comparing the uttered sentence against the intents and the entities defined while creating the LUIS application.

When the bot is being developed, the LUIS app can be consumed from the azure functions using the LUIS API or it can be consumed to get the predictions by calling the LUIS app from a logic app. This article will discuss the consumption of the LUIS app from the Logic App.

What are Logic Apps?

Logic Apps are a piece of integration workflow hosted on Azure which is used to create scale-able integrations between various systems.These are very easy to design and provide connectivity between various disparate systems using many out of the box connectors as well as with the facility to design custom connectors for specific purposes. This makes integration easier than ever as the design aspect of the earlier complex integrations is made easy with minimum steps required to get a workflow in place and get it running.

What is LUIS?

As per Microsoft:

"Language Understanding (LUIS) allows your application to understand what a person wants in their own words. LUIS uses machine learning to allow developers to build applications that can receive user input in natural language and extract meaning from it. A client application that converses with the user can pass user input to a LUIS app and receive relevant, detailed information back."

Key Concepts In LUIS

  1. Utterance: This is the actual command spoken/written by the User /APP
  2. Intents: Intents describe the actual intention behind the command given by the user.
    e.g. when the user says "Find me all the Pushes made on the PublicWorks Repository", what user wants is the list of the Pushes made on the PublicWorks repository, hence Push made is the intent here.
  3. Entity: This is extra information that is present in the utterance which helps LUIS to understand the utterance more. In the above PublicWorks is the name of the repository and hence is the entity which gives the name of the repository on which the Push is to be queried.

Scope

This article focuses on creating a LUIS app which understands the various functions that can be performed on the repository. Once the intent to identify the action on the repository is created and the LUIS app is trained and published, the LUIS app will be consumed from the Logic APP which will pass the utterance to the LUIS app and get the prediction form the LUIS app.

Design - LUIS App

Following are the steps that need to be performed to create a LUIS app.

  1. Log on to the LUIS portal (https://www.LUIS.ai) using the Azure credentials.
  2. Create a LUIS application. Refer to the sample screenshot below.

    Azure

  3. Create new simple entities, RepoName and ActionAskedAbout, as per the sample below.

    Azure

    Azure

  4. Create a composite Entity RepoAction which will encapsulate the entities created above. Refer to the following screen shot.

    Azure

  5. Create an intent ActionsOnRepo to understand that the intent behind the utterance is to do/query certain action on the certain repository.

    Azure

  6. The list of utterances used to train the app are as follows.

    Azure

  7. Map the Composite entity created above to the Utterances entered above.
  8. Train the LUIS app using the Train button in the portal. Once the App is trained, it can be tested using sample inputs.

LUIS Cognitive Service Account

In order to consume the LUIS app from the logic apps, the LUIS app must be published to the Resource group so that logic app connectors can use it, in order to do so, a LUIS cognitive services account needs to be set up in the Azure. Refer to following steps to set up the account.

  1. Select the Cognitive Services blade.

    Azure
  2. Create the Account.

    Azure

Publish LUIS App

Once an account for LUIS is created, the publication of the app becomes very easy. Navigate to the Publish Tab in the LUIS portal and select the environment (Production/Staging) and the time zone.

Azure

 

Select the region where the LUIS app needs to be Hosted and click on Add Keys, this will allow the LUIS portal to link the LUIS app to the LUIS account created above.

Azure

 

Once done, click on the publish button, this will publish the LUIS app into the LUIS account created earlier.

The LUIS app is now available to be consumed by the Logic App

Logic App

The logic app design is simple. Create a request-response Logic App and add the connection to the LUIS account by providing a name and the key for the user from the LUIS portal, the key for the user (Author ID) can be found under the User Setting as shown below.

Azure
Create the connection using this authoring key. Refer sample screenshot

Azure

 Following is the complete design of the Logic App.

Azure

Testing

The following message was fed to the Logic App from the PostMan.

  1. {  
  2.    "Utterance" : "Please bring me all the pulls done on the PublicWorks repository"  
  3. }  

The response generated by the Logic App was:

  1. {  
  2.     "query""Please bring me all the pulls done on the PublicWorks repository",  
  3.     "topScoringIntent": {  
  4.         "intent""ActionsOnRepo",  
  5.         "score": 0.9880099  
  6.     },  
  7.     "intents": [{  
  8.         "intent""ActionsOnRepo",  
  9.         "score": 0.9880099  
  10.     }, {  
  11.         "intent""Available Functions",  
  12.         "score": 0.009692609  
  13.     }, {  
  14.         "intent""None",  
  15.         "score": 0.00528933574  
  16.     }],  
  17.     "entities": [{  
  18.         "entity""pulls",  
  19.         "type""ActionAskedAbout",  
  20.         "startIndex": 24,  
  21.         "endIndex": 28,  
  22.         "score": 0.9956364  
  23.     }, {  
  24.         "entity""pulls",  
  25.         "type""RepoAction",  
  26.         "startIndex": 24,  
  27.         "endIndex": 28,  
  28.         "score": 0.9969615  
  29.     }, {  
  30.         "entity""publicworks",  
  31.         "type""RepoAction",  
  32.         "startIndex": 42,  
  33.         "endIndex": 52,  
  34.         "score": 0.84949106  
  35.     }, {  
  36.         "entity""publicworks",  
  37.         "type""RepoName",  
  38.         "startIndex": 42,  
  39.         "endIndex": 52,  
  40.         "score": 0.73795265  
  41.     }],  
  42.     "compositeEntities": [{  
  43.         "parentType""RepoAction",  
  44.         "value""pulls",  
  45.         "children": [{  
  46.             "type""ActionAskedAbout",  
  47.             "value""pulls"  
  48.         }]  
  49.     }, {  
  50.         "parentType""RepoAction",  
  51.         "value""publicworks",  
  52.         "children": [{  
  53.             "type""RepoName",  
  54.             "value""publicworks"  
  55.         }]  
  56.     }],  
  57.     "luisPrediciton""{\"query\":\"Please bring me all the pulls done on the PublicWorks repository\",\"topScoringIntent\":{\"intent\":\"ActionsOnRepo\",\"score\":0.9880099},\"intents\":[{\"intent\":\"ActionsOnRepo\",\"score\":0.9880099},{\"intent\":\"Available Functions\",\"score\":0.009692609},{\"intent\":\"None\",\"score\":0.00528933574}],\"entities\":[{\"entity\":\"pulls\",\"type\":\"ActionAskedAbout\",\"startIndex\":24,\"endIndex\":28,\"score\":0.9956364},{\"entity\":\"pulls\",\"type\":\"RepoAction\",\"startIndex\":24,\"endIndex\":28,\"score\":0.9969615},{\"entity\":\"publicworks\",\"type\":\"RepoAction\",\"startIndex\":42,\"endIndex\":52,\"score\":0.84949106},{\"entity\":\"publicworks\",\"type\":\"RepoName\",\"startIndex\":42,\"endIndex\":52,\"score\":0.73795265}],\"compositeEntities\":[{\"parentType\":\"RepoAction\",\"value\":\"pulls\",\"children\":[{\"type\":\"ActionAskedAbout\",\"value\":\"pulls\"}]},{\"parentType\":\"RepoAction\",\"value\":\"publicworks\",\"children\":[{\"type\":\"RepoName\",\"value\":\"publicworks\"}]}]}",  
  58.     "desiredIntent""ActionsOnRepo",  
  59.     "isDesiredIntent"true  
  60. }  

The response clearly indicates that the the input utterance follows the intent "ActionsOnRepo" and the intent that the logic app was expecting from the utterance is as expected. The LUIS correctly predicted the name of the repository as the "publicworks" and the ActionAsked about as "Pulls". Following part of the response is indicative of that .

  1. "compositeEntities": [{  
  2.         "parentType""RepoAction",  
  3.         "value""pulls",  
  4.         "children": [{  
  5.             "type""ActionAskedAbout",  
  6.             "value""pulls"  
  7.         }]  
  8.     }, {  
  9.         "parentType""RepoAction",  
  10.         "value""publicworks",  
  11.         "children": [{  
  12.             "type""RepoName",  
  13.             "value""publicworks"  
  14.         }]  

Conslusion

As is clear from the testing results, the LUIS app can be consumed to get the predictions about the Utterances provided to the Logic App.

See Also

Refer to the following articles on TechNet Wiki for more reading around LUIS.

References

The following article was referred to quote information about LUIS.