Entity Extraction in Stories

I am new to Rasa NLU and I wanted to know how do we extract entities in stories regardless of their value. For example, I want to ask the user his location and then extract the entity “location” from their reply and pass it to a custom action/template.

my stories.md file :

emergency path

  • greet
    • utter_greet
  • inform
    • utter_ask_location
  • tell_location
    • utter_affirm_location
  • accept
    • utter_goodbye

I want to extract the entity in the tell_location intent. looking forward for insight. :slight_smile:

you must use slot that looks like the memory of your bot here you can name it as location . I think that help you a lot Domain

@hajoura thank you for your response. I tried slots but i don’t want to hardcode key-value pairs. I want the slot in tell_location regardless of the value. The below example works fine but I do not want to define the value and fire utter_affirm_location.

  • tell_location {“location”: “pakistan”}
  • utter_affirm_location

you can use rasa interaction to create story in your bot and save it helps you

Hi @taimoor-ahmed,

If I understood you correctly you want to fill the tell_location slot regardless of the value. The best way t do it is to have a well trained NER for locations (spacy got one for english). Another way to do it (but I think it’s not the best choice) is to custom fill the slot through forms. You can do a custom slot mapping, and fill a slot with the users input (check here).

It would look something like this:

 def slot_mappings(self):
        # type: () -> 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 { "tell_location": [self.from_text()] }

This way your slot will be filled with any string given by the user.

Hope it helps.

1 Like

@BrunoRoth95 thank you for your response. I’ll try to implement your solution and let you know if I got it right.

Just curious, if I get these values from user

tell_location {“location”: “chicago”}

tell_location {“location”: “new york”}

tell_location {“location”: “seattle”}

tell_location {“location”: “trenton”}

but some of these values are not even defined in my stories.md file

  • tell_location {“location”: “new york”}
    • utter_ask_confirm
  • tell_location {“location”: “seattle”}
    • utter_ask_confirm

How would this work for missing values? Do we end up adding all the possible locations is a good idea or AI would understand and interpret accordingly?