Rasa: How to handle short (one word) answers with entities?

Created on 28 Jun 2018  路  17Comments  路  Source: RasaHQ/rasa

Imagine a bot asking "What are your favourite animals"? In a lot of NLU examples, a typical answer ist written as "My favourite animals are Elephants and Penguins". This answer provides enough context to train an "animal entity" to pick up the relevant pieces of information.

In reality however, the user very likely gives a very short answer, like "Elephants and Penguins", "All Birds" or just "Dogs". These answers provide no context at all. What is a good strategy to get the relevant pieces of information out of these answers?

One problem that I'm facing is that entities in rasa_nlu are not bound to an intent. If I create something like an "generic string answer intent" with "string entities", then these entities will be found in other intents where they don't belong.

Right now I'm just using the rasa_nlu component and use the intents and entities for another bot framework. If this can't be solved with just rasa_nlu, can rasa_core give outside-context in some way to aid in these cases?

type

Most helpful comment

In the case you're describing you should use rasa_core - this handles the context of a conversation, you could have two custom actions at those points of the story, one action_store_hour_from setting the hour_from slot, and the other action_store_hour_to setting the hour_to slot

All 17 comments

Yes, so with rasa core you could write a custom action that checks whether an entity was extracted from the previous sentence or not and then decide what to do if it wasn't. You could for example ask the user to repeat what they said, or just store the whole sentence in a slot (if it's just a single word)

As for entities not being bound to an intent, is this a problem if it's found in other intents? With rasa core you can handle different intent/entity combinations separately

@BeWe11 were you able to get a solution working?

@wrathagom I'm now using intents to differentiate the answers. For example, I use a "NumberRangeIntent" for sentences like "between 1412 and 552" and a "NumberExactIntent" for sentences like "1412 and 552". I use Duckling to pick out the numbers as entities.

This works, but feels more like a workaround than a solution . I'm still unclear what the best practices are regarding short answers without much context. Especially in cases where you can't use pretrained entities from spacy/duckling.

This must be a common usecase (or not?), so I'm still grateful for any hint of how to set this up in a better way.

@BeWe11 I have implemented my custom Entity extractor, but i'm having the same problem. I want to be able to access to the last bot's questions, in order to give to the extractor some context (instead of "five" -> "how old are you? five"). But I can't find how to put this bot's question in my entity extractor class. Any idea?

I join the question.

Could you provide some example of how to solve this problem? For example when you'd like to reserve a room using "from", "to" hours the conversation may look like:

You: I'd like to make a room reservation
Bot: Which hour should the reservation begin?
You: 10
Bot: Which hour should the reservation end?
Your: 12

I guess that in such case there will be two slots e.g. "hour_from", "hour_to". Having answer like "10" which is an hour without any context you won't know whether it should be stored in "hour_from" or "hour_to" slot.

In the case you're describing you should use rasa_core - this handles the context of a conversation, you could have two custom actions at those points of the story, one action_store_hour_from setting the hour_from slot, and the other action_store_hour_to setting the hour_to slot

@akelad
Thanks, I've managed to do it. To make it easier for others I describe my approach:

There are 3 slots: hour, hour_from and hour_to. Rasa NLU is trained to recognize various formats of time and Rasa Core is trained whether to run action_store_hour_from or action_store_hour_to depending on the context (story). Depending on action value of slot hour is reassigned to slot hour_from or hour_to.

I'm gonna close this issue, as pwierzgala's problem has been solved and I'm working on something different right now. Thank you all for your input!

@akelad I am facing the same sort of issue. Instead of providing my client, domain specific chatbot, my team is building a framework on top of rasa stack and rasa UI to allow user to configure a chatbot. Having said this, it would be difficult to provide a custom action solution to user since it will require fiddling with backend code. User might need to write custom actions for slot filling which we simply can't allow, as they are not technical people.

currently am appending the one word responses to previous bot responses which works fine untill user gives similar kind of training data in NLU. There can be one more way, if we somehow know at the backend what slot needs to be filled for this on word response. Is thr any way we can associate an action to slot eg when action utter_ask_city is invoked backend code already knows that since utter_ask_city is associated with city slot , just fill the user response as it is. Or , is thr any way we can define this in stories.

There has to be some concrete solution to this as this is natural way of doing conversations. Any suggestions?

Please post these kind of questions in our forum

In the case you're describing you should use rasa_core - this handles the context of a conversation, you could have two custom actions at those points of the story, one action_store_hour_from setting the hour_from slot, and the other action_store_hour_to setting the hour_to slot

How do you ask the question to the user regarding the entity?

@akelad
Thanks, I've managed to do it. To make it easier for others I describe my approach:

There are 3 slots: hour, hour_from and hour_to. Rasa NLU is trained to recognize various formats of time and Rasa Core is trained whether to run action_store_hour_from or action_store_hour_to depending on the context (story). Depending on action value of slot hour is reassigned to slot hour_from or hour_to.

How do you ask the question to the user regarding the entity?
what intent do you assign to this text? In my case single word is getting None intent which throws the error in rasa core.

@Raghvendr Here you have a sample story which I use to make a room reservation:

* provide_reservation_data{"room_name": "_"}
    - collect_reservation_data
    - slot{"room_name": "_"}
    - slot{"requested_slot": "time_from"}
* define_time{"time": "_"}
    - set_time_from
    - slot{"time_from": "_"}
    - collect_reservation_data
    - slot{"requested_slot": "time_to"}
* define_time{"time": "_"}
    - set_time_to
    - slot{"time_to": "_"}
    - collect_reservation_data
* confirm
    - make_reservation

and the conversation that fits this story may look like the following:

User: Make a reservation for room XXX
Bot: What time should the reservation begin?
User: 10:00
Bot: What time should the reservation end?
User: 12:00
Bot: You want to make a reservation for room XXX from 10:00 to 12:00. Should I proceed?
User: yes
Bot: The reservation was made successfully.

Please not that:

  • "collect_reservation_data" is my custom action build with FormAction class.
  • Rasa NLU is trained to recognize intention "define_time" which basicly looks at various time format like: 10, 10:32, 8:09, 15:6 etc. The time entity is stored in "time" slot.
  • "set_time_from" and "set_time_to" are actions that rewrite whatever is in stored in "time" slot to one of slots: "time_from" and "time_to".

Below I enclose direct answers to your questions.

How do you ask the question to the user regarding the entity?
The FormAction class asks one of questions:

  • What time should the reservation begin?
  • What time should the reservation end?

What intent do you assign to this text?
The intent is not connected with questuion asked by the bot but with the answer given by the user and this intent is "define_time". If the user's answer contains information about time e.g. "12:23" then it is assigned to slot "time" and then reassigned to one of slots: "time_from", "time_to" depending on a context.

In my case single word is getting None intent which throws the error
All my single-word time definition are correctly recognized with probability higher than 90%. I have 18 examples of such strings in Rasa NLU training data.

..., or just store the whole sentence in a slot (if it's just a single word)

Can you provide an example?

@Raghvendr Here you have a sample story which I use to make a room reservation:

* provide_reservation_data{"room_name": "_"}
    - collect_reservation_data
    - slot{"room_name": "_"}
    - slot{"requested_slot": "time_from"}
* define_time{"time": "_"}
    - set_time_from
    - slot{"time_from": "_"}
    - collect_reservation_data
    - slot{"requested_slot": "time_to"}
* define_time{"time": "_"}
    - set_time_to
    - slot{"time_to": "_"}
    - collect_reservation_data
* confirm
    - make_reservation

and the conversation that fits this story may look like the following:

User: Make a reservation for room XXX
Bot: What time should the reservation begin?
User: 10:00
Bot: What time should the reservation end?
User: 12:00
Bot: You want to make a reservation for room XXX from 10:00 to 12:00. Should I proceed?
User: yes
Bot: The reservation was made successfully.

Please not that:

  • "collect_reservation_data" is my custom action build with FormAction class.
  • Rasa NLU is trained to recognize intention "define_time" which basicly looks at various time format like: 10, 10:32, 8:09, 15:6 etc. The time entity is stored in "time" slot.
  • "set_time_from" and "set_time_to" are actions that rewrite whatever is in stored in "time" slot to one of slots: "time_from" and "time_to".

Below I enclose direct answers to your questions.

How do you ask the question to the user regarding the entity?
The FormAction class asks one of questions:

  • What time should the reservation begin?
  • What time should the reservation end?

What intent do you assign to this text?
The intent is not connected with questuion asked by the bot but with the answer given by the user and this intent is "define_time". If the user's answer contains information about time e.g. "12:23" then it is assigned to slot "time" and then reassigned to one of slots: "time_from", "time_to" depending on a context.

In my case single word is getting None intent which throws the error
All my single-word time definition are correctly recognized with probability higher than 90%. I have 18 examples of such strings in Rasa NLU training data.

Can you share a code snippet for the collect_reserveration_data action ?

Thanks.

@pwierzgala , could you post your custom action function to set from_tim and to_time?

Was this page helpful?
0 / 5 - 0 ratings