How to extract entity in form only when user is asked for this entity

Hi, I want to create register form with 4 required slots

- first_name
- last_name
- email
- birth_date

For first_name and last_name I’m using custom slot mappings:

 def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
        return {
            "first_name": [self.from_text()],
            "last_name": [self.from_text()]
        }

And for email and birth_date I’m using duckling extractor

My question is: how to prevent assigning birth_date slot when user is asked for any other slot?

Example:

- Hey! How can I help you?
register
- Okay, I'll need you to provide me some information about yourself
- Give me your first name
January
- Give me your last name
Jefferson
- Give me your email
jf@aa.com
- first name: January
- last name: Jefferson
- email: jf@aa.com
- birth date: 2020-01-01
- Is this data correct?

As you can see duckling extracted date from provided first_name (January) and didn’t even ask for it. Is there any way of limiting entity extraction in form so it’ll extract only entity that user is asked for?

Hi @kaladin, as far as I know that is not possible. The entity recognition/extraction is independent of the form. Rasa extracts whatever it detects and fills in the slots. However, you can maybe solve the problem using validation (Forms). In the validation method you have access to all slots and the user message. You could check what the value of the requested slot is, e.g. what question the bot just asked, and check if only that slot was newly set.

1 Like

Hi @Tanja , i am also facing same issue. if i have person_name and company_name entities ,sometime when i enter person_name it takes it as company_name as both are alphabets, how can we differentiate between these 2 . similarly i have campaign_budget and campaign_size and both are in numbers , here also when i enter 100000 it sets both the slots.

Please suggest.

Differentiating between name values is very very hard and requires lots of training data. The Spacy entity extractor got some pretrained models for names and companies. You might want to use these, if they fit to your language. For numbers, its pretty much impossible and you need to rely on the context as explained above.

Thank you all for the replies. I solved this problem in the way sugested by @Tanja

Solution:

def validate_time(self, value, dispatcher, tracker, domain):
    requested_slot = tracker.current_state()['slots']['requested_slot']
   
    if requested_slot == 'time':
        return {"time": value}
    else:
        return {"time": tracker.get_slot('time')}

hello @kaladin , will you help me out with the first_name and last_name extraction , as you have shown above , i have tried the same but got the error { Failed to extract slot First_name with action Register_form } . Thank you