How To Use Microsoft LUIS With Bot Framework Composer

How To Use Microsoft LUIS With Bot Framework Composer

Here Is A Simple Tutorial To Get You Started With NLU

Introduction

How can we integrate Composer with LUIS…

Firstly, we are going to run Composer locally on my machine and connect to LUIS in the cloud. The NLU configurations we create on Composer will be deployed to a LUIS account. What is LUIS?

Language Understanding (LUIS) is a cloud-based API service that applies custom machine-learning intelligence to a user’s conversational, natural language text to predict overall meaning, and pull out relevant, detailed information.

A client application for LUIS is any conversational application that communicates with a user in natural language to complete a task. Examples of client applications include social media apps, chat bots, and speech-enabled desktop applications.

And, Composer is a tool from Microsoft which allows for graphic development of a conversational application; with language generations, state management and integration points.

Setup Composer Recognizer

Within Composer you can setup three recognizer types:

  • None (Of course)
  • Regular Expressions
  • LUIS
Image for post
Composer Has Three Recognizer Types

It has to be stated that the regular expressions are very powerful and handy.

Without using any NLU, you can build a decent conversational interface merely based on regular expressions.

You will see the moment we select LUIS a text editor appears.

This text editor is where the intents and entities are defined which will be uploaded to LUIS in the cloud.

The file format is very simplistic and the editor alerts you to syntax errors.

Whenever a change is required, you can update the LUIS configuration file and the changes will be deployed to LUIS. Successful deployment can be verified by logging into LUIS.

LUIS File Format

This simple demo cover all the aspects you will require. This demo can easily be built out into a larger application.

The language understanding file we will use:

# BookFlight
- I want to book a flight
- I need to book a flight
- book a flight for me please#FlightDetail
- My family and I want to go on holiday to {toCity=Seattle}
- We are thinking of traveling to {toCity=Denver}
- Our destination will be {toCity=Milan} for our holiday
- We want to visit {toCity=Lisbon}
- On our trip our first stop will be at {toCity=Lisbon}
- We want to travel to {toCity=Lisbon}

There are two intents in the file, BookFlight and FlightDetail.

Bookflight does not have any entities, and we merely want to capture the intent for directing the dialog. This intent can be used to determine which dialog to invoke.

The FlightDetail intent has entities defined. There is only one entity of toCity type. The aim is to capture the city name which will be the travel destination.

Three things need to be noted on these entities:

  • There is no lookup list or reference table, these are truly contextual entities.
  • The value and position of the entity is detected by the context in which the entity appears, within the sentence.
  • Machine Learning is employed by LUIS to define the entities and the process of determining them.
Image for post
Microsoft Bot Framework Composer LUIS File

Greeting Dialog

When you create a bot, you can choose an existing template, or creating from scratch. For this project I chose Create from scratch.

Image for post
Creating a Bot from Scratch

In doing this, a Greeting dialog is always created automatically. All we have to do, is add a Send a response conversational node. This node will present the user with a message saying: Welcome to the travel bot!

This is the Greeting conversational flow after we have added the greeting. The text is entered in the properties tab on the right.

Image for post
Two Dialogs Are Visible: Greeting & BookFlight

Travel Dialog With NLU Integration

The principle if Composer is to have different dialogs for different sections of your application. We will only have one dialog called book flight. This dialog will be invoked when the #BookFlight intent is satisfied.

The intents which are defined in the text editor shows up on the top-right; which is a convenient automatic propagation of the defined NLU elements. The moment our user enters the following text, or a variation of it…

I want to book a flight
- I need to book a flight
- book a flight for me please

…this dialog will be invoked.

The dialog asks the user to state their destination city. The city name is captured in the variable dialog.city and we are extracting the entity toCity.

Application Deployment

On deployment of your Composer application, you will be prompted for your LUIS credentials. The deployment process is seamless and relatively fast. When in LUIS.ai, click on your email address at the very top right-hand corner, and the User Settings page will be visible, containing your LUIS primary key.

Image for post
LUIS Credential Window

To deploy the application from Composer, click on Start Bot, allow the process to run from Publishing to Reload to the Test In Emulator state.

Image for post
Deploy the Composer Application

After deployment in composer, check back in luis.ai if the new conversational app is visible. You can click on the App name to view the intents and entities transposed into the LUIS environment.

Image for post
LUIS.ai view with the app loaded

More Articles on Microsoft Bot Framework Composer & Emulator

Bot Framework Emulator

To test your bot, you will need to have the Bot Framework Emulator installed. It is a lightweight test interface or chat client, if you like.

microsoft/BotFramework-EmulatorThe Bot Framework Emulator is a desktop application that allows bot developers to test and debug bots built using the…github.com

In composer, click on Test in Emulator and from here click yes to launch the emulator.

And here is our conversation, with the toCity entity extracted and presented in isolation as we planned.

Image for post
Emulator View of Our Conversation

Within the emulator, full conversation traces are available. The LUIS return values are also visible in the Emulator.

Image for post
LUIS return JSON

This helps when Composer is not perhaps presenting the correct information, and you want to determine if the problem sits with LUIS or Composer.

Reservations & Observations

Intents Only

For a larger conversational agent, you will always have multiple dialogs. Defining intents for each of the dialogs is a good way of sending your user on a specific journey within the chatbot.

Especially if the chatbot is task orientated and the user needs to move from state to state.

Using intents per dialog makes for a more conversational and unstructured experience.

Compound Entities

It is highly likely to have two or more entities per intent. LUIS has the capability to detect and identify these compound or multiple entities per user utterance fully contextual.

I would like to take a bus from
{From_City=Madrid}
to
To_City=Lisbon}
tomorrow.

I found this hard to do in Composer, and all things considered, I feel tempted to access LUIS from Composer with an API call just for more flexibility and control.

Nested Entities

Taking the idea of compound entities even further, in LUIS you can define nested entities within a single sentence.

I would like to take a 
{Travel Detail={Mode=bus}}
from
{Travel Detail={City={From City=Madrid}}}
to
{Travel Detail={City={To City=Lisbon}}}
{Travel Detail={Time Frame=tomorrow}}

By using machine learned methods, LUIS can extract the contextual entities and decompose them. So you have this idea of complex entities with sub-entities, and sub-sub-entities etc.

I have yet to see how Composer will accommodate these.

Fragmented NLU Model

Having the Composer client push NLU configurations to LUIS.ai can lead to a fragmented structure on LUIS. You will have multiple smaller applications which will be continually updated as Composer applications are deployed. Changes in LUIS will not be propagated.

Training the NLU Model

Managing and training a single NLU model within LUIS has advantages and propagating the NLU functionally from LUIS down to the applications and clients and not visa versa makes more sense.

LUIS Tools

LUIS has an array of remarkable training and bench marking tools which really comes to the fore with a single NLU model.

Complexities can easily be catered for and presented via an API in a simple way.

Composer might detract from this as the LUIS visibility and functionality in Composer seems rudimentary compared to what is available.

Conclusion

One thing is for sure, Microsoft is following a multi-pronged approach to solving for Conversational AI. With LUIS, Bot Framework, Power Virtual Agents and Composer, it is evident that their arsenal is growing.

Microsoft allows for high level configuration, GUI’s and also native code when it comes to developing a chatbot.



Cobus GreylingHi, I’m Cobus… Currently I conceptualize, mock-up, wire-frame, prototype and develop final products. Primarily…cobusgreyling.me

Cobus Greyling – MediumRead writing from Cobus Greyling on Medium. NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer…medium.com

LUIS (Language Understanding) – Cognitive Services – MicrosoftEdit descriptionluis.ai

Bot Framework Composer Documentation – Quickstarts, Tutorials, SamplesBot Framework Composer is a visual designer that lets you quickly and easily build sophisticated conversational bots…docs.microsoft.com

Leave a Reply

Your email address will not be published. Required fields are marked *