Slot Example Rasa
- 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.
- Here is the full list of slot types defined by Rasa Core, along with syntax for including them in your domain file. Actions are the things your bot can actually do. For example, an action can: respond to a user.
- This is also called slot filling. If you need to collect multiple pieces of information in a row, we recommended that you create a FormAction. This is a single action which contains the logic to loop over the required slots and ask the user for this information. There is a full example using forms in the examples/formbot directory of Rasa Core.
- Rasa version: 0.14.5. Python version: 3.6.4. Operating system (windows, osx.): Ubuntu 18.04. Issue: i am training my pizzabot model, when i fill in the pizza size slot, it is populated with no problem, however when i fill in the next slot, pizzatype, its not updating this slot and returns a null value so it keeps looping on that same slot.
In this post, you will learn how to fill the slots and to use them further using the Forms. Now you must be the thing that if we are going to fill the slots only then why are we using the Forms for that. So the reason is we want to build an effective and reliable chatbot with lesser efforts than before. So, what is forms and form action and how it builds an effective and reliable chatbot with fewer efforts?
Whatare Forms?
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.
Oneof the most common conversation patterns is to collect few pieces ofinformation from a user in order to do something (likebookinga restaurant, callingan API, searchingthedatabase, etc.). This is also called slot filling.If you want to collect multiple pieces of information in arow, we recommended that you to create a FormAction.This FormAction is the single action which have the logic to loopover the required slots and ask the user for the information untilall the slots are filled. So, this is the most important and therequired logic in the chatbot to save many lines of code and also tosave efforts for the same process.
So,how do we do it to with rasa chatbot to make it effective, reliablewith less efforts. Forthe form action we need to make the updation in the project files,which are, config.yml, actions.py, stories.md and domain.yml.
Let’sstart one by one and understand the basic functionality of each ofthem:
SetupConfiguration
Firstly, we need to include theFormPolicy in to the configuration file to make the whole processfunction properly. In this way,
The FormPolicy
is extremely simple and just always predicts the form action. This comes into action when the form action is called for the first time.
You can also check this video for more clarification,
Addingthe stories
To add the stories as per theforms in the most important step to call the FormAction and torepeatedly ask the user for the information until all the slots arefilled. Now lets understand it more briefly with the example problemthat we are going to cover in this post. Like we will add the belowstory or let’s say the happy path,
So,above is the happy path for calling the FormAction. In this story“network_issue” is the userintent to which the bot will redirect to the FormAction which is“form_info”. Here,“form{“name”:“form_info”}” isused to activate the form and “form{“name”:null}” is used to deactivate theform again. Once the FormAction is activated, the boty can executeany kind of action outside the form. The above “happy path” meansthat once the FormAction is active it can fo outside of the form andperform any action until all requested slots are filled withoutinterruption. For example, if the user starts the conversation andsays “My name is Ashish and I am using One Plus mobile.” Then theslots “NAME” and “BRAND” are automatically filled so, the botwill not ask you the question related to these slots.
To make your story work in such a way your first step is to set your slots as unfeaturized. But if the slots are not of the type unfeaturized or let’s say it’s featurized, then in that case you have to include slot{} events to show these slots being set. Not it seems to be confusing like when to use the form and when to use slot, So, to make it easier it’s not compulsory that you have to add the stories manually, you can also add them using the Interactive learning.
So this was all about adding the stories as per the FormAction. Similarly, you can add more stories according to the chatbot architecture.
Updating the actions file
In the above story, you have seen we have added the happy path as per the form action. Now we will learn what actually is happening when the form action is called. To do this you first need to define three methods:
name
:the name of this action (form_info in our case)required_slots
:a list of slots that need to be filled for thesubmit
method to work.submit
:what to do at the end of the form, when all the slots have beenfilled.
Here,what happens is firstly when the FormAction is called for the firsttime, then form gets activated and FormPolicy jumps in. TheFormPolicy
is extremely simple and just always predicts the form action. Toidentify which form has been called the first method is to be addedto the to the actions.py file, i.e.,
When the bot identifies which FormAction is to be called then it moves to the next static method which is requested_slots where all the slots are set in the order to be called when requested and here with respect to these requested slot names an utter_ask_{slot_name} is called from the domain.yml file where all the bot response are set. The static method that is to be added to the action file is :
Here you can see we are returning the list for the static method and this list specifies the order of the slots to be requested to fill values for each of them. So, it simply means firstly utter_ask_NAME will be called and vice versa.
Once all the slots are filled, submit() method is called where we can use the collected information in whatever way we want use it. For example, asking for booking confirmation with your details. This method will be added in actions.py file,
Slot Mapping
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. The slot_mappings
method defines how to extract slot values from user responses. Add the below method to your action file to extract the required information from the user response.
Thepredefined functions work as follows:
self.from_entity(entity=entity_name,intent=intent_name)
will look for an entity calledentity_name
to fill a slotslot_name
regardless of user intent ifintent_name
isNone
else only if the users intent isintent_name
.self.from_intent(intent=intent_name,value=value)
will fill slotslot_name
withvalue
if user intent isintent_name
.Note: Slot will not be filled with user intent of message triggeringthe form action. Useself.from_trigger_intent
below.self.from_trigger_intent(intent=intent_name,value=value)
will fill slotslot_name
withvalue
if form was triggered with user intentintent_name
.self.from_text(intent=intent_name)
will use the next user utterance to fill the text slotslot_name
regardless of user intent ifintent_name
isNone
else only if user intent isintent_name
.- If you want to allow acombination of these, provide them as a list as in the example above
Once you understand this just add the above methods inside a class as shown below:
Updating Domain file
Now to link the core and nlu to the action file add the following line of code to your existing chatbot in domain.yml file
Execution
When you are done with the above steps and have understood all the things clearly then train your model and test it
You will see the output something like this in the debug mode.
After this execution, you will really feel that you have reduced the number of lines of code and have built an effective and reliable chatbot with different features added to it.
This is it for this post, I hope you have understood all the things very clearly but still if you have any queries related to the topic then feel free to leave a comment below in the comment section.
Stay tuned and Enjoy learning. 🙂
In this post, you will learn how to fill the slots and to use them further using the Forms. Now you must be the thing that if we are going to fill the slots only then why are we using the Forms for that. So the reason is we want to build an effective and reliable chatbot with lesser efforts than before. So, what is forms and form action and how it builds an effective and reliable chatbot with fewer efforts?
Whatare Forms?
Oneof the most common conversation patterns is to collect few pieces ofinformation from a user in order to do something (likebookinga restaurant, callingan API, searchingthedatabase, etc.). This is also called slot filling.If you want to collect multiple pieces of information in arow, we recommended that you to create a FormAction.This FormAction is the single action which have the logic to loopover the required slots and ask the user for the information untilall the slots are filled. So, this is the most important and therequired logic in the chatbot to save many lines of code and also tosave efforts for the same process.
So,how do we do it to with rasa chatbot to make it effective, reliablewith less efforts. Forthe form action we need to make the updation in the project files,which are, config.yml, actions.py, stories.md and domain.yml.
Let’sstart one by one and understand the basic functionality of each ofthem:
SetupConfiguration
Firstly, we need to include theFormPolicy in to the configuration file to make the whole processfunction properly. In this way,
Slot Example Rasa Al
The FormPolicy
is extremely simple and just always predicts the form action. This comes into action when the form action is called for the first time.
You can also check this video for more clarification,
Addingthe stories
To add the stories as per theforms in the most important step to call the FormAction and torepeatedly ask the user for the information until all the slots arefilled. Now lets understand it more briefly with the example problemthat we are going to cover in this post. Like we will add the belowstory or let’s say the happy path,
So,above is the happy path for calling the FormAction. In this story“network_issue” is the userintent to which the bot will redirect to the FormAction which is“form_info”. Here,“form{“name”:“form_info”}” isused to activate the form and “form{“name”:null}” is used to deactivate theform again. Once the FormAction is activated, the boty can executeany kind of action outside the form. The above “happy path” meansthat once the FormAction is active it can fo outside of the form andperform any action until all requested slots are filled withoutinterruption. For example, if the user starts the conversation andsays “My name is Ashish and I am using One Plus mobile.” Then theslots “NAME” and “BRAND” are automatically filled so, the botwill not ask you the question related to these slots.
To make your story work in such a way your first step is to set your slots as unfeaturized. But if the slots are not of the type unfeaturized or let’s say it’s featurized, then in that case you have to include slot{} events to show these slots being set. Not it seems to be confusing like when to use the form and when to use slot, So, to make it easier it’s not compulsory that you have to add the stories manually, you can also add them using the Interactive learning.
So this was all about adding the stories as per the FormAction. Similarly, you can add more stories according to the chatbot architecture.
Updating the actions file
In the above story, you have seen we have added the happy path as per the form action. Now we will learn what actually is happening when the form action is called. To do this you first need to define three methods:
Slot Example Rasa Mp3
name
:the name of this action (form_info in our case)required_slots
:a list of slots that need to be filled for thesubmit
method to work.submit
:what to do at the end of the form, when all the slots have beenfilled.
Here,what happens is firstly when the FormAction is called for the firsttime, then form gets activated and FormPolicy jumps in. TheFormPolicy
is extremely simple and just always predicts the form action. Toidentify which form has been called the first method is to be addedto the to the actions.py file, i.e.,
When the bot identifies which FormAction is to be called then it moves to the next static method which is requested_slots where all the slots are set in the order to be called when requested and here with respect to these requested slot names an utter_ask_{slot_name} is called from the domain.yml file where all the bot response are set. The static method that is to be added to the action file is :
Here you can see we are returning the list for the static method and this list specifies the order of the slots to be requested to fill values for each of them. So, it simply means firstly utter_ask_NAME will be called and vice versa.
Once all the slots are filled, submit() method is called where we can use the collected information in whatever way we want use it. For example, asking for booking confirmation with your details. This method will be added in actions.py file,
Slot Mapping
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. The slot_mappings
method defines how to extract slot values from user responses. Add the below method to your action file to extract the required information from the user response.
Thepredefined functions work as follows:
Slot List Rasa Example
self.from_entity(entity=entity_name,intent=intent_name)
will look for an entity calledentity_name
to fill a slotslot_name
regardless of user intent ifintent_name
isNone
else only if the users intent isintent_name
.self.from_intent(intent=intent_name,value=value)
will fill slotslot_name
withvalue
if user intent isintent_name
.Note: Slot will not be filled with user intent of message triggeringthe form action. Useself.from_trigger_intent
below.self.from_trigger_intent(intent=intent_name,value=value)
will fill slotslot_name
withvalue
if form was triggered with user intentintent_name
.self.from_text(intent=intent_name)
will use the next user utterance to fill the text slotslot_name
regardless of user intent ifintent_name
isNone
else only if user intent isintent_name
.- If you want to allow acombination of these, provide them as a list as in the example above
Once you understand this just add the above methods inside a class as shown below:
Updating Domain file
Now to link the core and nlu to the action file add the following line of code to your existing chatbot in domain.yml file
Slot Example Rasa Song
Execution
When you are done with the above steps and have understood all the things clearly then train your model and test it
Slot Example Rasa Video
You will see the output something like this in the debug mode.
After this execution, you will really feel that you have reduced the number of lines of code and have built an effective and reliable chatbot with different features added to it.
This is it for this post, I hope you have understood all the things very clearly but still if you have any queries related to the topic then feel free to leave a comment below in the comment section.
Stay tuned and Enjoy learning. 🙂