Enrich Chatbot Entities With Patterns, Roles & Groups Using Rasa

Enrich Chatbot Entities With Patterns, Roles & Groups Using Rasa

…And Capture Concepts In User Input

Introduction

A conversational interface is an invitation you extend to the user to input their data in an unstructured and conversational manner.

Image for post
Typical example of user unstructured input not being recognized and the chatbot enforcing predetermined structure.

It is imperative that the digital assistant is able to take the unstructured input from the user and ideally structure the input correctly on the first pass.

The less ideal situation is where the chatbot prompts for information already volunteered by the user.

Hence, forcing the user to input data in a structure acceptable by the chatbot. Keeping in mind, a structure not visible to the user.

The conversation to the left is a classic example of how, only the basic intent of the user is detected by the chatbot on the first pass.

The entities are disregarded and asked for, again; one at a time.

The way to approach this, is to handle it, as we do in human-to-human conversation.

City is an entity, but there are actually two types of cities, the from/departure city and the to/destination city. Hence the entity of city has two roles. And these two roles are arranged in a certain pattern including the date and possibly the mode of travel.

This is very close to how we as humans extract entities; detecting the patterns and identifying the roles.

Image for post
Within Intents entities need to be defined. Entities can further be defined with roles and patterns.

The basic premise is to create roles for an entity, and then establish patterns in which those roles might be used.

These patterns then serves as a guide for the Conversational AI platform to detect patterns in user utterances. And subsequently useful conversational data.

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

So, different roles can be seen as subsets or types of the entity Cities.

Multiple roles can be added to an entity.

Contextual information is maintained for an entity in this way. We are also going to combine the roles defined for the entity with a pattern.

How To Implement Roles & Patterns With Rasa?

The best way to illustrate the use of entity roles and patterns in Rasa is by means of an example. Let’s look at a basic banking example.

Image for post
An Entity type of Currency can have different roles assigned to it. In this case, there is a From Currency role and a To Currency role. The pattern is constituted by the sequence: From Currency, To Currency, Time Fame.

In the nlu.md file, I have defined an intent to exchange money from one currency to another. This is an example of a user utterance with compound entities.

Within the user utterance, three entities are defined:

  • Transaction
  • Currency
  • Date/Time

Here is an example of how to define entities with roles in the nlu.md file.

- intent: exchange
  examples: |
  - I want to [change](transaction) [US dollars]{"entity": "currency", "role": "change_from"} to [Euros]{"entity": "currency", "role": "change_to"} on [Friday](date_time)
  - Can I [exchange](transaction) [euros]{"entity": "currency", "role": "change_from"} for [Rand]{"entity": "currency", "role": "change_to"} on [Saturday](date_time)
  - give me a rate to [change](transaction) [pounds sterling]{"entity": "currency", "role": "change_from"} for [Japanese Yen]{"entity": "currency", "role": "change_to"} on [Monday](date_time)
  - what are rates to [convert](transaction) [Australian Dollar]{"entity": "currency", "role": "change_from"} for [Russian Ruble]{"entity": "currency", "role": "change_to"} on [next week Thursday](date_time)
  - I want to [change](transaction) [US dollars]{"entity": "currency", "role": "change_from"} to [Canadian dollar]{"entity": "currency", "role": "change_to"} on [Friday](date_time)
Image for post
nlu.yml format

The entity of currency is broken up into two roles:

  • Change From and
  • Change To.

Here is a practical example of user input requesting to exchange money. This is performed using Postman and the Rasa NLU API.

Image for post
User utterance example with multiple compound entities.

The JSON output clearly define the recognized intent of exchange. With this, three entities are identified. The entity of currency has an additional value of role. In this case, the segmenting the currency changed from and to.

Image for post
The intent is identified as exchange with the entities and respective roles.

Group Entities

Entity groups allow for entities to be grouped together in different groupings. Using the banking example, I have created the entity tiers. There are 5 tiers; Silver, Gold and Bronze; grouped together. Constituting group one.

Platinum Black are grouped together. Constituting group two.

Image for post
Account Tiers are entities, which can be grouped together. An implementation example is priority routing for premium clients.

This is an example of how to define entities with groups in the nlu.md file.

- intent: tiers
  examples: |
  - [Silver]{"entity": "tiers", "group": "1"} accounts have lower interest for saving than [Platinum]{"entity": "tiers", "group": "2"}
  - [Gold]{"entity": "tiers", "group": "1"} accounts have lower interest for saving than [black]{"entity": "tiers", "group": "2"}- [Bronze]{"entity": "tiers", "group": "1"} accounts have lower interest for saving than [Platinum]{"entity": "tiers", "group": "2"}
Image for post
nlu.yml format

And the example of a user utterance, mentioning two of the tiers.

The result is a JSON output with the entity tiers defined, and the grouping of the entity.

Image for post
The intent tiers is correctly identified, with the group value for each entity.

Conclusion

Instead of the chatbot forcing the user to structure input according an unseen pattern, the chatbot must create the structure from user input. And, have the capability to take the user input, identify intent, patterns, roles and intents.


The caution in using this feature from Rasa:

his feature is experimental. We introduce experimental features to get feedback from our community, so we encourage you to try it out! However, the functionality might be changed or removed in the future.


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

Cobus Greyling – MediumEven though most NLU tools converge on the same basic principles for entities and intents, when it comes to developing…cobusgreyling.medium.com

How To Create An Opensource NLU API With RasaYou Have Access To An Exceptional Natural Language Understanding Toolcobusgreyling.medium.com

NLU Training DataThe goal of NLU (Natural Language Understanding) is to extract structured information from user messages. This usually…rasa.com

Open source conversational AIBuild contextual AI assistants and chatbots in text and voice with our open source machine learning framework. Scale it…www.rasa.com