Search for any name in entity extraction

Hello

with following intent in my nlu.md file.

intent:name

I can only retrieve these 5 names only when asked,

how can I extract the entity for any name, as I can not add all the existing names in my nlu file

@MuraliChandran14, @Michael, @mashagua if you could answer?

@omkarcpatil

name = tracker.latest_message['text']. This will help you get the latest text from the user in your actions.py.

You have to create a story like

## name test
*greet
-utter_enter_yourname
-actions.py
-utter_hello_name

This will not use entity extraction

Hello @MuraliChandran14

i can get that, but if i am putting any name other those 5 that is not getting extracted how can i do it?

What is your stories.md look like?, Did you trigger action by name intent.

form_action.py (2.1 KB)

Stories.md

mongo exist

  • find_in_mongo
    • actions_find_in_mongo
    • action_form_ask_name ## here asking for the name
    • form{“name”: “name”}
    • form{“name”: null}
  • thanks
  • utter_goodbye

I have put it inside a form, (actions form file is uploaded) here I can only mention those 5 names, any other name is not accepted

Got it, If you are using form action. Then you have to use self.from_text() this will get user input.

In your slot mappings, Instead of self.from_entity() you have to change it to self.from_text() on name slot

will that accept any other name than 5 mentioned in nlu file? consider if i give murali as my name?

yep.

@MuraliChandran14,

thank you for suggestion, but that solution didn’t work

i tried with following variations:

1.“name”: self.from_text(entity=“name”, intent=[“name”]),

  1. “name”: self.from_text(entity=“name”),

  2. “name”: self.from_text(),

nothing is working

you can just use self.from_text(),.

Kindly check your form action is running or not.

No success

mongo exist

  • find_in_mongo
    • actions_find_in_mongo ## FYI, from this action I am internally calling next FollowupAction
    • action_form_ask_name
    • form{“name”: “action_form_ask_name”}
    • form{“name”: null}
  • thanks
  • utter_goodbye
  • utter_goodbye

I tried with the above stories and your mentioned slot mapping for name

def slot_mappings(self) -> Dict[Text, Any]:
    # return {"name": self.from_entity(entity="name",
    #                                  intent=["name"]),
    return {"name": [self.from_text()],
            "email": self.from_entity(entity="email",
                                         # intent="inform")}
                                         intent=["email"])}

as I only need name ,for email I already have a regex

can you share your output, what is storing in name slot, when you give random name.

Hello @MuraliChandran14,

thanks for the solution, i didnt notice that in my policies “formpolicy” was not mentioned which didnt validate my entity in forms, it was only taking input from rasa NLU

Hope it helped :slightly_smiling_face:

Hello, I’ve had the same problem, I can’t extract the name. How do you do if that name is in a sentence, for exemple " My name is John" ? I try to extract it with the entity “PERSON” but it did not work. Could you please tell me how do I have to do please ?

Hi @omkarcpatil !

You can use self.from_text() in slot_mapping() method of the form, but this will catch whatever phrase user write, even if it is not his name.

You can also try with SpacyEntityExtractor which comes with various pre-trained models. In my case I used the spanish model and it works very well with names!

@sarah1,

keep few examples in your nlu.md file for intent PERSON eg. (“John Cena” , “my name is John Cena”)

as per form policies after slot_mapping function it goes in validate function, you can override that function, only use following code for validate function:

it is defined as def validate_<slot_name>, so in your case def validate_PERSON:

def validate_name(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
) -> Dict[Text, Any]:
      

    print(tracker.slots)  # just to show you what is actually happening, else not needed
    If (tracker.slots['name']):
         value = tracker.slots['name']
   
    return {"name": value}

hello @flore,

great solution, but that would be difficult for extracting indian names, do spacy have model for Indian names too?

@omkarcpatil sorry I see now that spacy have not indian model. Here are the availables models -> https://spacy.io/models