Extract first and last names using actions

I have a form which asks the user for its first and last name as separate slots. The slots are filled with type: from_text.

Now I was to extract the named entities from the text shared by the user, fill the respective slots or take corrective actions if the name is not recognized correctly.

Is there a way to use entity extractors like Duckling/spaCY in action Validate Forms for the same?

Please share the action.py code if someone has implemented it.

What do you mean by the name not being recognised? Does it mean the name is not registered in your database, or that it’s a fake/pseudonym?

Hi Snek,

Please consider the dialogue flow below:

Scenario 1: Extract name provided correctly but in a sentence [BOT]: Please specify the first name? e.g. John [User]: My first name is Manish Expected Behavior: The validate form action should sets the slot first_name with value Manish after extraction using spaCy/Duckling

Scenario 2: Extract name provided as per asked design [BOT]: Please specify the first name? e.g. John [User]: Manish Expected Behavior: The validate form action should sets the slot first_name with value Manish

Scenario 2: Name not provided/recognized correctly [BOT]: Please specify the first name? e.g. John [User]: how does this works? Expected Behavior: The validate form action is unable to extract the name detail and hence utter something like: I cannot recognize what you said can you please rephrase for the first name, e.g. if your name is John Smith please write John.

spacy is a python package, so you can always import the spacy package in your actions code,

import spacy
## Load the nlp module in cache upon startup of your action server
nlp = spacy.load("en_core_web_sm")

class YourAction:

doc = nlp(input_sentence)

for ent in doc.ents:
    print(ent.text, ent.start_char, ent.end_char, ent.label_)

Duckling runs as an external service to your rasa action server, so if you have used the requests package you can simply make a POST request to the duckling server to extract named entities from your action server.

As far as names goes, i don’t like both spaCy or Duckling would work for you, but for the other types of entities it will.

what you could also do is add spacy Entity extractor in your config.yml so when the sentences is passed, it will extract entities and you can set the slot in the actions.py

1 Like