Text Slot¶
text
¶Use For: | User preferences where you only care whether or not they’vebeen specified. |
---|---|
Example: | |
Description: | rasa_core.slots.Slot Results in the feature of the slot being set to 1 if any value is set.Otherwise the feature will be set to 0 (no value is set). |
Slots which influence the conversation need to be added to your stories or rules. This also applies for the case if the slot was set by a custom action. For example, you can use a boolean slot set by a custom action to control the dialogue flow based on its value using the following stories. Rasa has two main components: Rasa NLU (Natural Language Understanding): Rasa NLU is an open-source natural language processing tool for intent classification (decides what the user is asking), extraction of the entity from the bot in the form of structured data and helps the chatbot understand what user is saying. If you do not define slot mappings in the actions file, slots will be only filled by the entities with the same name as the slot that is picked up from the user input. Slots can be picked with the single entity but FormAction supports inputs like yes/no questions and free-text input.
Boolean Slot¶
bool
¶![Slot Slot](/uploads/1/3/7/6/137678399/481039144.png)
Use For: | True or False |
---|---|
Example: | |
Description: | Checks if slot is set and if True |
Categorical Slot¶
categorical
¶Use For: | Slots which can take one of N values |
---|---|
Example: | |
Description: | Creates a one-hot encoding describing which of the values matched. |
Float Slot¶
float
¶Use For: | Continuous values |
---|---|
Example: | |
Defaults: | max_value=1.0 , min_value=0.0 |
Description: | All values below min_value will be treated as min_value , the samehappens for values above max_value . Hence, if max_value is set to1 , there is no difference between the slot values 2 and 3.5 interms of featurization (e.g. both values will influence the dialogue inthe same way and the model can not learn to differentiate between them). |
List Slot¶
list
¶Use For: | Lists of values |
---|---|
Example: | |
Description: | The feature of this slot is set to 1 if a value with a list is set,where the list is not empty. If no value is set, or the empty list is theset value, the feature will be 0 . The length of the list stored inthe slot does not influence the dialogue. |
Unfeaturized Slot¶
unfeaturized
¶Use For: | Data you want to store which shouldn’t influence the dialogue flow |
---|---|
Example: | |
Description: | There will not be any featurization of this slot, hence its value doesnot influence the dialogue flow and is ignored when predicting the nextaction the bot should run. |
The Slot base class¶
rasa_core.slots.
Slot
(name, initial_value=None, value_reset_delay=None, auto_fill=True)[source]¶feature_dimensionality
()[source]¶How many features this single slot creates.
The dimensionality of the array returned by as_feature needsto correspond to this value.
as_feature
()[source]¶
Have questions or feedback?¶
We have a very active support community on Rasa Community Forumthat is happy to help you with your questions. If you have any feedback for us or a specificsuggestion for improving the docs, feel free to share it by creating an issue on Rasa CoreGitHub repository.
Slots are your bot’s memory. They act as a key-value storewhich can be used to store information the user provided (e.g their home city)as well as information gathered about the outside world (e.g. the result of adatabase query).
Most of the time, you want slots to influence how the dialogue progresses.There are different slot types for different behaviors.
For example, if your user has provided their home city, you might have a
text
slotcalled home_city
. If the user asks for the weather, and you don’t know their homecity, you will have to ask them for it. A text
slot only tells Rasa Core whetherthe slot has a value. The specific value of a text
slot(e.g. Bangalore or New York or Hong Kong) doesn’t make any difference.If the value itself is important, use a
categorical
slot. There arealso boolean
, float
, and list
slots.If you just want to store some data, but don’t want it to affect the flowof the conversation, use an unfeaturized
slot.How Rasa Uses Slots¶
The
rasa_core.policies.Policy
doesn’t have access to the value of your slots.It receives a featurized
representation.As mentioned above, for a text
slot the value is irrelevant.The policy just sees a 1
or 0
depending on whether it is set.You should choose your slot types carefully!
How Slots Get Set¶
You can provide an initial value for a slot in your domain file:
There are multiple ways that slots are set during a conversation:
Slots Set from NLU¶
If your NLU model picks up an entity, and your domain contains a slot with the same name,the slot will be set automatically. For example:
In this case, you don’t have to include the
-slot{}
part in the story, becauseit is automatically picked up.Slots Set By Clicking Buttons¶
You can use buttons as a shortcut.Rasa Core will send messages starting with a
/
to the RegexInterpreter
,which expects NLU input in the same format as in story files, e.g. /intent{entities}
.For example, if you let users choose a color by clicking a button, the button payloadsmight be /choose{'color':'blue'}
and /choose{'color':'red'}
You can specify this in your domain file like this: (see details in Domain Format)
Slots Set by Actions¶
The second option is to set slots by returning events in custom_actions.In this case, your stories need to include the slots.For example, you have a custom action to fetch a user’s profile, andyou have a
categorical
slot called account_type
.When the fetch_profile
action is run, it returns a rasa_core.events.SlotSet
event.In this case you do have to include the
-slot{}
part in your stories.Rasa Core will learn to use this information to decide on the correct action totake (in this case, utter_welcome_premuim
or utter_welcome_basic
).Note
It is very easy to forget about slots if you are writingstories by hand. We strongly recommend that you build up thesestories using Interactive Learning rather than writing them.
Custom Slot Types¶
Maybe your restaurant booking system can only handle bookings for up to 6 people.In this case you want the value of the slot to influence thenext selected action (and not just whether it’s been specified).You can do this by defining a custom slot class.
Salle de spectacle casino lac leamy. In the code below, we define a slot class called
NumberOfPeopleSlot
.The featurization defines how the value of this slot gets converted to a vectorto our machine learning model can deal with.Our slot has three possible “values”, which we can represent with a vector of length 2
.(0,0) | not yet set | |
(1,0) | between 1 and 6 | |
(0,1) | more than 6 |
Now we also need some training stories, so that Rasa Corecan learn from these how to handle the different situations.
Pre-defined Slot Types¶
Here are all of the predefined slot classes and what they’re useful for:
text
¶Use For: | User preferences where you only care whether or not they’vebeen specified. |
---|---|
Example: | |
Description: | rasa_core.slots.Slot Results in the feature of the slot being set to 1 if any value is set.Otherwise the feature will be set to 0 (no value is set). |
bool
¶Use For: | True or False |
---|---|
Example: | |
Description: | Checks if slot is set and if True |
categorical
¶Slot List Rasa Example
Use For: | Slots which can take one of N values |
---|---|
Example: | |
Description: | Creates a one-hot encoding describing which of the values matched. |
float
¶Use For: | Continuous values |
---|---|
Example: | |
Defaults: | max_value=1.0 , min_value=0.0 |
Description: | All values below min_value will be treated as min_value , the samehappens for values above max_value . Hence, if max_value is set to1 , there is no difference between the slot values 2 and 3.5 interms of featurization (e.g. both values will influence the dialogue inthe same way and the model can not learn to differentiate between them). |
list
¶Use For: | Lists of values |
---|---|
Example: | |
Description: | The feature of this slot is set to 1 if a value with a list is set,where the list is not empty. If no value is set, or the empty list is theset value, the feature will be 0 . The length of the list stored inthe slot does not influence the dialogue. |
unfeaturized
¶Slot Example Rasa Al
Use For: | Data you want to store which shouldn’t influence the dialogue flow |
---|---|
Example: | |
Description: | There will not be any featurization of this slot, hence its value doesnot influence the dialogue flow and is ignored when predicting the nextaction the bot should run. |