Build A Chatbot with Microsoft Bot Framework Composer & Composite Entities

Surface The Power of LUIS Composite Entities Via Composer

Cobus Greyling
7 min readNov 30, 2020

--

Introduction

Even though most NLU tools converge on the same basic principles for entities and intents, when it comes to developing the dialog various approaches are followed.

With creating the state machine or managing the dialog nodes, four distinct approaches are currently followed in the chatbot marketplace for dialog creation and management.

  • Design Canvas
  • Dialog Configuration
  • Native Code
  • ML Stories

Bot Framework Composer falls into the category of Dialog Configuration.

The holy grail is to have a composer or design environment where the call-flow can be designed graphically and simultaneously create executable code.

Or least a design which can be imported into a chatbot framework and executed.

This allows for rapid deployment of chatbot experiences.

General challenges often experienced with this approach include:

  • Complex flows cannot be accommodated practically
  • Massive redundancy
  • Fine programmatic tuning not always possible
  • Digression is Hard to Implement
  • Nested Menus & Conversational Nodes Are Hard to Drop Into
  • Finite Journeys Often Lead to Fallback Proliferation

What Is Bot Framework Composer

The Bot Framework Composer is an open source tool based on the Bot Framework SDK.

Key Aspects Include:

  • A visual editing canvas for conversation flows
  • In context editing for language understanding (NLU)
  • Tools to train, test and manage language understanding (NLU) and QnA components
  • Language generation and templating system
  • A ready-to-use bot runtime executable

Integration of Composer with LUIS allows for powerful natural language understanding to be surfaced in a conversational design. Within Composer an .lu file can be defined, which can be deployed locally from Composer to LUIS in the cloud.

An .lu file contains Markdown-like, simple text based definitions for LUIS concepts. Various concepts expressed via the .lu file format.

One of these concepts is composite entities.

Entity Decomposition

Machine Learned Entities were introduced to LUIS November 2019. Entity decomposition is important for both intent prediction and for data extraction with the entity.

We start by defining a single entity, called

  • Travel Detail.

Within this entity, we defined three sub-entities. You can think of this as nested entities or sub-types. The three sub-types defined are:

  • Time Frame
  • Mode
  • City

From here, we have a sub-sub-type for City:

  • From City
  • To City
User input examples, with composite entities defined contextually.

Looking at this image, it is clear how a hierarchy can be established and structure introduced to entities.

Combining Composer with Composite Entities

First we need to create two dialogs:

  • Greeting
  • Travel
Adding A New Dialog in Bot Framework Composer

Greeting will merely greet the user, and await input from the user. This is a very simple flow depicted below.

Basic Welcome Dialog flow.

From here we can create a second dialog flow called Travel.

The Travel dialog which is invoked with trigger phrases or intents.

This dialog will be used to illustrate how a dialog can be called with intent examples.

These intent examples is defined within the dialog.

The entity examples are also defined here via the .lu file.

Later we will see how, when starting the bot via composer, the NLU configurations are sent to LUIS in the cloud.

Trigger phrases (intent: #Travel) can be entered for the Travel dialog.

Here is an example utterances added to the Travel intent:

- I want to travel
- We are thinking of traveling
- We are planning a trip
- Our family is looking at traveling
- Shortly we will plan a vacation
- We are planning our annual trip

In LUIS it looks as follows after deployment from Composer.

On starting the bot in Composer, the configuration is pushed to the cloud.

The next step is to ask the user for the travel plans, this utterance will contain several entities, hence the utterance will be defined by entities which are:

  • Compound
  • Contextual
  • Composite

Below is the .lu file used to define the entities within Composer.

- # TravelInfo- {TravelDetail={TimeFrame=2 august}} we need to travel from {TravelDetail={City={FromCity=berlin}}} to {TravelDetail={City={ToCity=paris}}} by {TravelDetail={Mode=train}}- i would like to take a {TravelDetail={Mode=bus}} from {TravelDetail={City={FromCity=madrid}}} to {TravelDetail={City={ToCity=lisbon}}} {TravelDetail={timeframe=tomorrow}}- in {TravelDetail={timeframe=two weeks}} time i must travel by {TravelDetail={Mode=train}} from {TravelDetail={City={FromCity=athens}}} to {TravelDetail={City={ToCity=berlin}}}- {TravelDetail={timeframe=monday}} we need to take the {TravelDetail={Mode=train}} from {TravelDetail={City={FromCity=paris}}} to {TravelDetail={City={ToCity=rome}}}- on {TravelDetail={timeframe=3 august}} i am leaving {TravelDetail={City={FromCity=paris}}} for {TravelDetail={City={ToCity=lisbon}}} by {TravelDetail={Mode=train}}- {TravelDetail={timeframe=thursday}} i want to take a {TravelDetail={Mode=plane}} from {TravelDetail={City={FromCity=paris}}} to {TravelDetail={City={ToCity=amsterdam}}}- composite TravelDetail = [timeframe, ToCity, FromCity, Mode]

Looking at the user input node, the prompt from the chatbot is defined in Bot Asks, and under the User Input Tab, the expected responses are defined by using the .lu file.

Values can be extracted at this point too.

The User Input Dialog Node, with the Bot soliciting the user input and under the User Input tab the text is processed.

And finally the various parameters extracted from the user input can be used in the conversation.

- So you want to go to ${dialog.ToCity} from ${dialog.FromCity} by ${dialog.Mode} on ${dialog.timeframe}?

Testing Your Bot

The chatbot is initialized by clicking on the blue Start Bot button in the top right-hand corner. Once the bot has initialized, click on Test in Emulator.

The Bot Framework Emulator is a desktop application that allows bot developers to test and debug their bots, either locally or remotely. Using the Emulator, you can chat with your bot and inspect the messages that your bot sends and receives. The Emulator displays messages as they would appear in a web chat UI and logs JSON requests and responses as you exchange messages with your bot. Before you deploy your bot to the cloud, run it locally and test it using the Emulator. You can test your bot using the Emulator even if you have not yet created it with Azure Bot Service or configured it to run on any channels.

The Emulator can be downloaded here.

A conversation via the Emulator

From the conversation above it is evident how the entities can be extracted contextually and presented back as confirmation. This makes for a very natural and human like conversation.

Due to the composite nature of the entities, we could also extract the cities etc.

The result from the LUIS interaction is available in Bot Emulator for inspection. This helps with troubleshooting to determine if the problem lies in the LUIS results or Composer.

{
"recognizerResult": {
"alteredText": null,
"entities": {
"City": [
"Bonn",
"Berlin"
],
"FromCity": [
"Bonn"
],
"Mode": [
"train"
],
"ToCity": [
"Berlin"
],
"TravelDetail": [
"Thursday",
"train",
"Bonn",
"Berlin"
],
"timeframe": [
"thursday"
]
},
"intents": {
"TextInput_Response_USYSvV": {
"score": 0.9555109
}
},
"text": "On thursday we are taking the train from Bonn to Berlin"
}
}

From this JSON file it is clear that the entity called TravelDetail has four values:

  • Thursday
  • train
  • Bonn
  • Berlin

Cities can be further decomposed into:

  • Bonn
  • Berlin

Etc.

Conclusion

Microsoft has a comprehensive approach to chatbots in specific and AI Assistants in general. When it comes to NLU environments LUIS is the world leader in entity types and data structures with supporting tools.

Add the power of Azure to combine LUIS with Bot Framework and

  • native code,
  • Composer or
  • Power Virtual Agents,

and you have a powerful conversational AI environment.

This environment can further be augmented with Azure’s cognitive functionality.

--

--

Cobus Greyling

I explore and write about all things at the intersection of AI & language; LLMs/NLP/NLU, Chat/Voicebots, CCAI. www.cobusgreyling.com