Intent Matching to be affected by Entity Extracted


I understand that entity extraction and intent matching are independent of each other as of now. However, if I require a model where I want the intent to be matched based on the extracted entity, how do I go about it?

You see I have intents that are trained with very similar (and even same) training phrases and the only way to tell them apart would be using entities. DialogFlow seemed to be handling this right but I need to switch my project to RASA because of some limitations with DialogFlow.

I am using CRFEntityExtractor (with BILOU_flag set) and SklearnIntentClassifier in the pipeline along with the SpacyNLP, SpacyTokenizer, SpacyFeaturizer, RegexFeaturizer, EntitySynonymMapper. I still need to get myself familiarized with the components so I am not sure if this pipeline is what I would end up using but this is the current situation.


Hi @iszainab. Rasa Open Source uses DIET by default for intent classification and entity extraction. I recommend watching videos 1-4 and reading this blog post to understand how it works.

You could customize the NLU pipeline or create custom NLU components to achieve what you are describing, but I am not sure I understand the advantage of it. Why do you require a model where the intent needs to be classified based on the extracted entity?

Yes I have gone through the documentation referred.

All right let me explain with an example. Say I have two intents, one shows me information on an author (info_author) and another shows me information on a book (info_book). Both of them contain the training phrase (or you know can be triggered by the phrase) "Show information about ".

I want to be able to match the right intent for the following messages:

  1. Show me information about Jane Austen
  2. Show me information about Pride and Prejudice

I hope this clears it up.

@iszainab Why not use a single intent info and then extract the entity? You will know what to do because the intent is info and you have either a book or author entity

Yes but its not that I only want to see if its a book or an author, those are the entity types and not entity values. What I would require is the name of the book or author and knowledge of the fact that its a book or author, respectively.

Is there a way to know what entity type was extracted? And can I create stories based on which entity type was extracted? So say I create a single intent info and two actions info_book and info_author and wish to structure such that if the entity type was book, the action info_book is called (the story with that action is run) and vice versa.


Is there a way to know what entity type was extracted?

Yes, you will want to store the entities NLU extracts as slots

And can I create stories based on which entity type was extracted?

Yes, you can then use slots in your stories to influence how the dialogue progresses

Thank you @tyd! :slight_smile:

I will look into it and if I need more help, I’ll reach out.


Could you help me determine the flow of my story please? Continuing the example from above: I have an intent info that extracts either a book or an author from the message, now how do I check which one and then call the relevant action?

## test book story
*info {<book was extracted>}
 - info_book
## test author story
*info{<author was extracted}
  - info_author

I’ve written a function to extend the tracker class that tells me which entity type ( book or author ) was last inserted in the slot. I want that to be put in the slot entity_type which then I can use here in the stories above but I can’t figure out where in code do I handle the insertion in slot part?

The flow that I have in my mind is something like this:

  1. User says “Show me information about Jane Austen”
  2. Info intent is matched
  3. Entity is extracted, it was an author
  4. I put “author” in the entity_type slot explicitly
  5. The relevant action is triggered

How do I do this? Thank you.

@iszainab I recommend checking out this video to understand how you can use slots to influence how the conversation goes

Hi @tyd,

Thank you I was able to get my use case to work.

I have another query I’m not sure if I should be opening a separate thread but here goes: say I want to select (randomly) from multiple responses (strings) in a custom action and also want to be able to send it as a custom (json) response after doing some string substitutions in it. What would be the best way to do that using options that RASA provides?

If there is none, I do have a solution of my own that does not involve using any of RASA’s response mechanisms but I want to be absolutely sure that it is so.


@iszainab If you use template responses, you can add multiple and it will randomly select one each time. However, if you want to do a template response, then you will likely want to use another Python library like random

@tyd no, randomization thing does not work with response templates. Only the first one is picked, you can check this.

So basically this cannot be done with any of the options that RASA provides. I have set up an architecture of my own, I’ll be using that then.

Thanks a bunch! :slight_smile:

@iszainab I just tested it, and it works. You can see this in the docs # multiple responses - bot will randomly pick one of them here. You can define the response template and then call dispatcher.utter_template from the custom action

Does it work for chitchat?

So I need to have custom actions for anywhere that I want to do this? Utterance or retrieval actions wont work?

Can you check @erohmensing’s response on this thread Small talk using Response selector - random responses?

And also, can you provide the source code that you used for testing it?

@tyd One more thing, I want to be able to add string substitutions as well in my responses. I found a way to do it with slots but:

  1. Not all substitutions come from the input, some come from the database.
  2. I don’t want to retrain everytime I make changes.
  3. The slot loses values on reset.
  4. It adds essentially unneeded information to the slots in the tracker