Entity named recognition with spacy

Hello, I have a problem with entity recognition, i used the spacyentityrecognition, but when I try to extract the entity “PERSON” i have this error message “Failed to extract slot PERSON with action contact_form” I try to find a guide or an exemple for using spacy but i did not find. Could you please tell me if you have an answer for my problem ? thanks

Hi @sarah !

Are you using the method slot_mappings() to set slots inside the form? Check the docs, have an explanation of how to use that in section Custom slot mappings

Tell me if it was helpful. If not, maybe you can provide me more info about what are you using!

1 Like

Thank you for replying ! Yes I use this method but i don’t understand what i am doing wrong.

This is my pipeline :

language: “fr” # your two-letter language code

pipeline:

  • name: SpacyNLP
  • name: SpacyTokenizer
  • name: SpacyFeaturizer
  • name: RegexFeaturizer
  • name: LexicalSyntacticFeaturizer
  • name: CountVectorsFeaturizer
  • name: CountVectorsFeaturizer analyzer: “char_wb” min_ngram: 1 max_ngram: 4
  • name: DIETClassifier epochs: 100
  • name: EntitySynonymMapper
  • name: ResponseSelector epochs: 100
  • name: SpacyEntityExtractor dimensions: [“PERSON”]

and this is how I use the method slot_mappings() :

class ContactForm(FormAction):

def name(self) -> Text:
    return "contact_form"

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:

    print("required_slots(tracker: Tracker)")
    return ["PERSON", "prenom", "numero", "email"]
	
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
    return{
        "nom": [
            self.from_entity(entity="PERSON")
            ],
        "prenom": self.from_entity(entity = "prenom",intent="entreePrenom"),
        "email": self.from_entity(entity = "email", intent = "entreeEmail"),
        "numero": self.from_entity(entity = "numero", intent = "entreeNumero")
        }


    

def submit(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict]:
            
    dispatcher.utter_message(template="utter_submit",
                             nom = tracker.get_slot('PERSON'),
                             prenom = tracker.get_slot('prenom'),
                             email = tracker.get_slot('email'),
                             numero = tracker.get_slot('numero'))

    return []

Can you please tell me if you are seing something I did wrong, thks

@sarah1

mmm I can see that you don’t specify the model that you are using. For example: I use this:

pipeline:
  - name: SpacyNLP
    model: "es_core_news_md"
  - name: SpacyTokenizer
  - name: SpacyFeaturizer
    pooling: mean
  - name: SpacyEntityExtractor
    dimensions: ["PER"]

Is a spanish model and the name of the label “PER” depends on the model that you are using.

Also, make sure you include the entity in the domain.yml file. In my case:

entities:
- email
- PER
- telefono

The slot_mappings seems fine

1 Like

I did like you said, but it is not recognizing the names i didn’t write in my nlu file. I still have this error Failed to extract slot PERS with action contact_form

@sarah1! I realized that:

In required_slots you define: [“PERSON”, “prenom”, “numero”, “email”]

It should be: [“nom”, “prenom”, “numero”, “email”]

PERSON is the entity, not the slot

Try:

@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:

    print("required_slots(tracker: Tracker)")
    return ["nom", "prenom", "numero", "email"]
	
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
    return{
        "nom": [
            self.from_entity(entity="PERSON")
            ],
        "prenom": self.from_entity(entity = "prenom",intent="entreePrenom"),
        "email": self.from_entity(entity = "email", intent = "entreeEmail"),
        "numero": self.from_entity(entity = "numero", intent = "entreeNumero")
        }

def submit(self, dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any]) -> List[Dict]:
            
    dispatcher.utter_message(template="utter_submit",
                             nom = tracker.get_slot('nom'),
                             prenom = tracker.get_slot('prenom'),
                             email = tracker.get_slot('email'),
                             numero = tracker.get_slot('numero'))

    return []
1 Like

Thank you very much ! it’s working now

1 Like

Hola Flore,

How did you write your intent for recognising the entities?. I think your issue is related to a problem I am having described here)

I am unsuccessfully trying with things like:

- You can call me [PERSON](PERSON)

Muchas gracias