How to include context in intent detection?

Hi, I’m new to Rasa and trying to figure out the concepts and best practices. From my understanding the intent detection process is completely separate from the dialog/context management process - am I correct?

If so, that means that the intent detection does not include any context and every user input must map to just one intent. This is a very limiting constraint, and I’m not sure how to model many conversation flows - especially question-oriented conversations where the answers can be short/generic.

How would you model the following conversation?

User: Hi, I want to take your quiz
Bot: OK. First question: Do you like cats?
User: yes
Bot: Do you have a cat?
User: I have two cats

The problem is that for the second question, the user may respond with “yes” instead. So it looks like there should be a shared intent between these answers. However, the utterance “I have two cats” is not a logical answer for “Do you like cats?”, so I can’t just create an intent with both of these examples.

It doesn’t seem possible to elegantly solve this problem without using context information in the intent detection phase. Is there a solution I’m missing? What is the accepted way of handling short/generic responses, where the meaning is derived from the context?

2 Likes

It doesn’t seem like an unusual scenario. How are people not struggling with this with virtually any Rasa Form? When you ask a question, you can’t expect the user to answer with enough information all the time. They answer with context, so we’ll have to analyze their input using the “context” of the conversation (can be as simple as “these intents are only relevant after this response/when trying to fill a certain slot from intent”) in order to process even the simplest of examples…

Hi @Gur, welcome to the forum :slight_smile: . Yes you’re right, intent detection only works on the basis of the single user utterance and is run before the dialogue manager. The DM then takes the past state of the conversation and current NLU output in order to predict the next action the bot should take. (The exception to that is the currently experimental End-to-end TEDPolicy, which predicts both intents and actions, see. e.g. this forum thread).

This is a limitation in the sense that you describe, that the same answer can mean different things based on the context. In your example, the user might already respond to the first question with I have two cats, with the intent to confirm that they indeed like cats.

However, for the example conversation you posted,you could keep those as different intents:

- intent: affirm
  examples: |
    - yes
    - of course
    - sure

- intent: has_a_cat
  examples: |
    - I have a cat
    - I have two cats
    - My cat's name is Felix

and then write stories containing the different possible turns of the conversation, from which the dialogue manager can learn how different intents can appear at which point in the conversation:

- story: likes and has a cat
  steps:
  - intent: take_quiz
  - action: ask_likes_cat
  - intent: affirm
  - action: ask_has_cat
  - intent: has_cat
  - action: next_action

- story: likes and has a cat 2
  steps:
  - intent: take_quiz
  - action: ask_likes_cat
  - intent: affirm
  - action: ask_has_cat
  - intent: affirm
  - action: next_action
...

This is just one option that came to my mind from the example conversation you posted. But in general, which concrete task are you trying to solve with your bot? That might inform other potential solutions, since you already mentioned forms in your second post.

2 Likes

Thank you for your reply.

I’m just trying to learn how to use Rasa, and it seems to me like this problem occurs in most conversations. Users don’t provide enough context in their input to match with a specific intent. When you ask a question, you can’t expect the user to give a complete answer. Humans answer questions (especially ones with a closed number of options) with context. They don’t repeat the keywords from the question in their answer, so intent classification without context is quite tricky.

The problem with the solution you suggested is that you divided the answers to the second question to “generic affirmations” and “detailed answers that are specific enough to associate with this context”

Where would you put “I do”? is it an affirmation? If so, how would you handle a third yes/no question like “Are you a dog person?” The answer “I do” doesn’t fit here, and the answer “I am” doesn’t fit the previous questions.

Handling all non-specific positive answers as generic affirmations isn’t possible without creating multiple “generic intents”, and re-arranging them every time a question doesn’t fit 100% with all the examples for an intent.

Examle:

- intent: affirm
  examples: |
    - yes

- intent: affirm_quality
  examples: |
    - I am

- intent: affirm_action
  examples: |
    - I do

- intent: has_a_cat
  examples: |
    - I have a cat
    - I have two cats
    - My cat's name is Felix

This isn’t maintainable because if these intents will have many examples, every time we try to use it we’ll have to make sure all the examples fit. If not, or there is another non-specifc answer that fits the new question (but not all the existing ones), we’ll have to re-arrange the intents (like I just did to your solution, when a new question arrived)

On the other hand, handling these non-specific answers in a dedicated intent for the new question is problematic too:

- intent: is_dog_person
  examples: |
    - I am

What if we want to add the question “Are you a tall?”? The answer “I am” is applicable here as well.

How do people handle contextual user answers like these? (Other than the e2e training feature that looks cool btw:)