# How to set slots in custom components?

**URL:** <https://forum.rasa.com/t/how-to-set-slots-in-custom-components/43560>\
**Category:** Rasa Open Source\
**Created:** [May 13, 2021, 6:32pm UTC](https://forum.rasa.com/t/how-to-set-slots-in-custom-components/43560 "2021-05-13T18:32:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jozhou22](https://avatars.discourse-cdn.com/v4/letter/j/d6d6ee/32.png) [@Jozhou22](https://forum.rasa.com/u/Jozhou22)\
**Post date:** [May 13, 2021, 6:32pm UTC](https://forum.rasa.com/t/how-to-set-slots-in-custom-components/43560/1 "2021-05-13T18:32:57Z")

</div>

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](http://forum.rasa.com/t/custom-slot-set-in-nlu-custom-nlu-component/33280), it seems like I have to store the label in an entity first, so I did the following.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/9/9eb46b351e67c9e52d007ff6cbd32d2fe308f8ee.png)

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:

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/c/ced1600d582df8e8a8e16b98d9d738710b977aba.png)

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

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/f/fa23940e37b47182362c572ff3b3689b4dac5cdc.png)

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

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/e/e52e76cffba5d1f7a20c2cb5029240d95b66383b.png)Here is the test\_stories.yml: ![image](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/e/e3f8e97a4ebbaab50efffb9adf80a5a2f7861b2f.png)

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

---

<div class="post-metadata">

**Author:** ![Dustyposa](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/dustyposa/32/13745_2.png) [@Dustyposa](https://forum.rasa.com/u/Dustyposa)\
**Post date:** [May 14, 2021, 6:20am UTC](https://forum.rasa.com/t/how-to-set-slots-in-custom-components/43560/2 "2021-05-14T06:20:03Z")

</div>

You can set entity in `message` attribute, like below:

```python
        extracted = [
            {
                "start": 0,
                "end": len(text),
                "text": text,
                "value": "San",
                "confidence": 1.0,
                "additional_info": None,
                "entity": 'city',
                EXTRACTOR: self.name
            }
        ]

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

```

It’s work fine for me. You can clone my [project](https://github.com/Dustyposa/rasa_ch_faq), and add above code in [tokenizer](https://github.com/Dustyposa/rasa_ch_faq/blob/main/compoments/nlu/tokenizers/bert_tokenizer.py) file.
