From_text vs from_entities

Hi there,

I’m a bit confused as to when “from_text” and “from_entities” must be used.

To give you an idea, I’m creating a custom action for a form that will collect information (e.g. name, date, contact number) from users. In my NLU, I have an intent: inform where I provided examples of user’s answers. The expectation is that users will be providing answers directly (i.e. What’s your name? A: Clare) and not in sentences (My name’s Clare).

In this case, is it better to use “self.from_text” vs self.from_entity"?

def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:

    return {

        "surname": [

            self.from_text(intent="inform"),

        ],

         "name": [

            self.from_text(intent="inform"),

        ],

         "department": [

            self.from_text(intent="inform"),

        ],

        "birthdate" [

            self.from_text(intent="inform"),

        ],

        "city_residence" [

            self.from_text(intent="inform"),

        ],

        "contact_number" [

            self.from_text(intent="inform"),

        ],

        "symptoms" [

            self.from_text(intent="inform"),

        ],

        "initial_date" [

            self.from_text(intent="inform"),

        ]

    }

Hi @chiqui_hm

If you can guarantee that whatever the user enters is going to be what should end up in the slot, then you should use from_text. Make sure, however, that your assumption is correct - real users rarely behave the way you’d expect.

You can also use both, i.e. from_entity and from_text in that order. In this case, Rasa will try to find the name entity, and if it cannot find it, it’ll take the entire text. It may also be useful to set a not_intent list, in case users don’t reply to your message.

Hi @j.mosig this answers my question. i don’t think i can guarantee how the user will behave as they answer the form. thanks a lot!

1 Like

hello again, @j.mosig

i followed your suggestion, and I have two additional questions.

(1) Turns out that SpaCy is doing better at extracting names of PERSONs in sentences (e.g. last name’s {name_of_PERSON} vs just the name or surname itself (e.g. “Medallo”) even if this is in my NLU training example under intent: inform. Does this mean the from_text in my custom action is not working?

image

This is how my domain looks like. Should I perhaps add from_text here as well?

image

(2) are there any projects on github utilizing not_intent ? can’t seem to understand “excluded_intent”.

thanks!!

Hello @chiqui_hm

Yes, I think Rasa predicts action_listen after the user says “Medallo” because it doesn’t recognize the name and the from_text is missing in the domain. It should be something like this:

forms:
  PUI_form:
    surname:
    - type: from_entity
      entity: PERSON
    - type: from_text
...

I don’t know about example projects, but you can add a not_intent item to ensure that the form doesn’t fill a slot from, e.g., the full user text if the user is saying something that doesn’t fit there. For example:

forms:
 PUI_form:
   surname:
   - type: from_entity
     entity: PERSON
   - type: from_text
     not_intent: ["ask_about_weather", "bot_challenge", "swear_or_insult", "praise_bot", "thank_you"]
...

because if the user does any of the not_intents, this is certainly not an answer to the “What’s your surname?” question :smiley:

@j.mosig it worked :sob: thanks so much!!!