Photo by Jef Pawlikowski on Unsplash

Improve Chatbot Accuracy By Detecting Patterns In User Input

Here Is How To Use Patterns & Roles In Microsoft LUIS


There are currently various avenues to introduce structure to entities in order to detected patterns. Microsoft LUIS, Alexa Conversations and Rasa is the leaders in this regard.

Although the examples given in this article will be based on LUIS, the underlying principles employed can be gleaned and implemented in other platforms.

The basic premise is to create roles for an entity, and then establish a pattern in which those roles might be used. This pattern then serves as a guide for the Conversational AI platform to detect patterns in user utterances. And subsequently useful conversational data.

Machine Learned Entities were introduced to Microsoft LUIS November 2019. Entity decomposition is important for both intent prediction and for data extraction in terms of entities. This superseded some of the existing functionality within LUIS.

Hence, to some extent the Roles and Patterns functionality were superseded within LUIS by ML Entities which can be decomposed. Think of ML Entities, as entities which can be nested several times over.

However, roles and patterns are still useful in certain instances; when fixed patterns need to be detected within user utterances. And perhaps users have have legacy implementations which need to be carried forward.

Let’s have a look at how Roles and Patterns can be implemented by using a simple example project.

Adding Roles to an Entity

We will start of by creating an entity called Cities. Within the entity called Cities, we want to create two roles:

  • Destination
  • Origin
Within LUIS we have the entity of Cities and under Roles we have two entries; Destination and Origin.

It is evident that Roles can be seen as subsets or types of the entity Cities. Multiple roles can be added.

Hence contextual information is maintained for an entity in this way. It needs to be noted that roles can only be used for patterns.

Combining Roles and Patterns

Now we are going to combine the roles defined for the entity with a pattern.

LUIS Intent called Distance referencing the Entity and Role.

The basic intent is created, then the entity with roles. And now we are going to add the patterns.

Sequence of Elements to Create Patterns

When creating a pattern, it needs to be linked to an intent. And it makes sense to use the same wording or utterances you used in the intent.

Adding Patterns with Entities and Roles Defined To An Intent.

Once you have clicked on Patterns, it is important to select the correct intent at the top drop-down. The patterns are defined as shown here below. In the format of Entity, colon and the Role.

How far is {Cities:Origin} from {Cities:Destination}?
We are traveling from {Cities:Origin} to {Cities:Destination}.

It is clear from these two lines that entity roles are truly contextual and not finite in their value. When testing in the LUIS console the pattern matched can be seen.

LUIS Testing Console showing the top matched patterns.

This feature is supposed to decrease the number of examples required; hence speeding up the configuration process. It is also important to note that we have not provided our model specific data regarding what our entity should map to, but an arbitrary city name can be retrieved based on a recognized pattern.


I still lean toward using ML entities which can be decomposed; entities which can be nested, as shown here:

ML Entities which are composed of smaller sub-entities.

It is a clean and simple solution for defining and recognizing patterns and extracting related entities and group then. Roles and Patterns hail from mid 2018 and presents a more complex approach.

ML Entities which are composed of smaller sub-entities.

Yet there might be instances where you want to re-use patterns and have them grouped together. There might also be legacy implementations of this approach which needs to be supported and augmented.




NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Refactoring Code Smells in Kotlin

Why Python is used for Machine Learning

Power-Ups for Jupyter Notebooks | LaptrinhX

Leaky bucket algorithm for flow control

Benefits of Custom Software development

Learning to Code 1: Introductory Yak Shaving

picture of yak you must shave before you learn to code


Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cobus Greyling

Cobus Greyling

NLP/NLU, Chatbots, Voice, Conversational UI/UX, CX Designer, Developer, Ubiquitous User Interfaces.

More from Medium

The Conversational AI Landscape & HumanFirst

Detecting Creators With NLP

75 Speech Recognition Features

Best 5 Conversation Intelligence Platforms for 2022