Extracting multiple slots from a single utterance - Rasa Open Source - Rasa Community Forum

👋 Introducing the Rasa Playground

Extracting multiple slots from a single utterance

1.6k views

post by chrisbangun on Feb 17, 2020

hey team,

I am currently exploring the slot filling capabilities to create a shopping bot assistance. Currently I have a very simple bot where I can get all the required slots filled by asking questions upon questions. However, my bot still cannot extract multiples entities from a single user utterance.

For example:

is there a nice [dress](item) below [$50](price) for [female](gender)?

ideally, three entities are extracted from the msg above - dress, $50 and female. Yet, I haven’t figure it out how. I’ve seen the examples provided in Github, but it is still unclear to me.

The following is my stories.md

## happy path
* greet
    - utter_greet
* request_item
    - shopping_form
    - form{"name": "shopping_form"}
    - form{"name": null}
    - utter_slots_values
* thankyou
    - utter_noworries

actions.py

class ShoppingForm(FormAction):

def name(self) -> Text:
        return "shopping_form"

@staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        return ["item", "size", "price", "brand", "color", "gender"]

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        """A dictionary to map required slots to
            - an extracted entity
            - intent: value pairs
            - a whole message
            or a list of them, where a first match will be picked"""
        return{
            "item": self.from_entity(entity='item', not_intent="chitchat"),
            "price": [
                self.from_entity(entity="price", intent=["inform"]),
                self.from_intent(intent="deny", value=False),
                ],

"size": [
                self.from_entity(entity="size", intent=["inform", "request_item"]),
                self.from_entity(entity="number"),
                ],

"gender": [
                self.from_entity(entity="gender", intent=["inform", "request_item"]),
                self.from_text(),
                ],

"brand": [
                self.from_entity(entity="brand", intent=["inform", "request_item"]),
                self.from_intent(intent="deny", value=False),
            ],

"color": [
                self.from_entity(entity="color", intent=["inform", "request_item"]),
                self.from_intent(intent="deny", value=False),
                ],
            }

not sure if this question has been asked before, there are something similar but somehow I still couldn’t figure how to fix this. Could anyone give me some pointers?

Thanks

post by Tanja on Feb 18, 2020

Extracting multiple entities from a user message is definitely possible. I guess, you are using the CRFEntityExtractor in your pipeline. This component will extract any number of entities. If you run your bot in debug mode, for example, rasa shell --debug, you should see all entities that were extracted by this component. If you see multiple entities over there, you should take a closer look at your slot mapping inside your form action.

Do you see multiple entities picked up in your logs when enabling debug mode?

post by chrisbangun on Feb 19, 2020

Hi @Tanja

Thank you for your reply. I found the bug where I had some typos in my domain.md.

Thank you again

post by Shaan27 on Nov 27, 2020

My example is like :— Show me some properties with 2 to 3 bedrooms between 2500 sqft and 3500 sqft and price between $2750000 to $3000000 in Washington, DC 20008

When trying to extract the slot values, slots are getting overwritten. then I used “auto_fill: False” but now Bot asking each slots to enter, in my below case, as the number of slots are more, so its too time taking to enter 1 by1. so please suggest a better way to solve this.

Training dataShow me some properties with [2](unitsizemin) to [3](unitsizemax) bedrooms between [2500](minarea) sqft and [3500](maxarea) sqft and price between $[2750000](minprice) to $[3000000](maxprice) in [Washington](city), [DC 20008](locality)

Please suggest how to solve such long questions.