Infer intent from extracted entity + context

Hi :slightly_smiling_face:

I am facing what, I think, is a common issue when starting with Rasa.

Let’s say I have a bot that can handle two use cases:

  • It can display the current weather in a particular city
  • It can display the population of a particular city.

Stories could look like this, respectively:

# Ask weather
* ask_weather{"GPE": "Paris"}
    - utter_on_it
    - do_weather_api

# Ask population
* ask_population{"GPE": "Paris"}
    - utter_on_it
    - do_cityinfo_api

For cases where the user doesn’t specify the city:

# Ask weather but no location
* ask_weather
    - utter_ask_location
* inform_about_location{"GPE": "Paris"}
    - utter_on_it
    - do_weather_api

# Ask population but no location
* ask_population
    - utter_ask_location
* inform_about_location{"GPE": "Paris"}
    - utter_on_it
    - do_cityinfo_api

On the NLU side, the inform_about_location could be triggered by somewhat specific utterances such as “oh sorry, Paris” or even “in Paris”.

Very often however, the user is going to reply with a single-word “sentence” such as “Paris”. Here, on the NLU side, the answer “Paris” is going to be detected by ner_spacy but the intent is going to be null - I don’t think training the NLU model to link a big list of cities to the inform_about_location intent is such a good idea (I might be wrong here).

However, the intent is clear when you look both at the context (position in the story) and the extracted entity: if the GPE entity is extracted by ner_spacy after utter_ask_location, the intent is probably to inform about the location.

My question is: how can I “materialize” this in Rasa? What I want is something like this…

# Ask weather but no location
* ask_weather
    - utter_ask_location
* null{"GPE": "Paris"}
    - utter_on_it
    - do_weather_api

# Ask population but no location
* ask_population
    - utter_ask_location
* null{"GPE": "Paris"}
    - utter_on_it
    - do_cityinfo_api

…where actions are triggered only depending on context and entities detected by pre-trained models.

This problem has already been mentioned: here and here for example, but this doesn’t help me.

Thank you very much! Rasa is awesome :+1:

Anthony

2 Likes

Hey, yeah this very typically for Rasa and I want something very similiar like here: Force user message to a specific intent for slot filling

For now I think you can use a custom action which checks for the context like last intents or actions and then force/trigger the specific intent. I have not tried yet but this could be done.

Thank you - I had not seen your previous post.

For now I think you can use a custom action which checks for the context like last intents or actions and then force/trigger the specific intent. I have not tried yet but this could be done.

I have seen such a suggestion but I don’t really visualize it. Would you mind providing an example? How do you trigger the custom action itself? Thanks :slight_smile:

Have you found a good solution for this? Having a similar issue

Facing the same problem!

I used FormAction plus setting fallback_threshold to negative number to solve this problem. In FormAction validation, say the intent was incorrectly detected (other than ‘inform’ intent) you can re-ask the same question again by returning empty list. if it is okay to use user’s last intent, you can just set that value to the slot to fill etc. You don’t have to set fallback_threashold to negative as long as the intent confidence is greater than threashold (regardless of intent detected) but problem occurs when detected intent confidence is zero. That’s when you want to set fallback_threashold to negative on dialog training. So… how user can get out of potential trap? I do 2 things. (a) train hand off human intent and if detected, go ahead get out of form and set follow up action of you need (b) bot will utter special exit method that user can type (e.g. /exit) then it ends converstaion etc.

@naoko using Forms I don’t think you’d even need to the negative fallback_threshold. What exactly is it for?

If you use self.from_text(intent=None) to extract values from Form answers, you shouldn’t really have a problem. And you can always train an inform intent with almost any kind of answer so it will always be recognized.

1 Like