How to set slots in custom components?

Hi Rasa Community,

I am currently developing a custom component for sentimental analysis. What I want is after the user input is classified by the pretrained model, the slot of the predicted label could be set to true. Like this:

User input: “I am feeling excited today!” → Slot: {“excitement”: True}

According to this post, it seems like I have to store the label in an entity first, so I did the following.

Then in the domain file, I set auto_fill of these slots to be True. So far the code is working properly and when I am in debug mode, the slot is actually set. But the problem is that the rasa test couldn’t run:

I got the test running by assigning zeros the starting position and ending position when I convert to rasa compatible format:

But the story test failed, and the error log is:

Here is the test_stories.yml:

I think it is failing because of the random number I assigned to “start” and “end”. But as you can see in the above example, “excitement” is not a part of the sentence, so I couldn’t specify the values for “start” and “end”.

In summary, my main questions are:

  1. Is there any way to get around with it (e.g. setting specific numbers to “start” and “end”), so that I can pass rasa test?
  2. Is there any way to set slots in rasa NLU pipeline (before the core)?

Thanks for your help! Yinzhou

You can set entity in message attribute, like below:

        extracted = [
                "start": 0,
                "end": len(text),
                "text": text,
                "value": "San",
                "confidence": 1.0,
                "additional_info": None,
                "entity": 'city',

        message.set(ENTITIES, message.get(ENTITIES, []) + extracted, add_to_output=True)

It’s work fine for me. You can clone my project, and add above code in tokenizer file.

1 Like