Featured

Let's Learn about RASA Policies

What are policies? How they affect your model? What is its importance? What are different policies present in RASA? These are some of the questions which comes in mind of any new RASA developer. We will be discussing answers of all these questions in detail.

Before moving ahead to learn about policies, it will be helpful to have a look on rasa pipelines.


What are policies in Rasa?

Once we have correctly predicted our intents and entities, the model now has to identify the actions which are required to be performed in order to give a final output. Policies are used to decide which action needs to be performed at each step in a conversation. There are machine Learning and Rule Based policies which your assistant can use.

While predicting the next action, RASA uses intents, entities and the conversation done so far.


How Policies predict next action in RASA.
RASA Prediction


You can add policies in config.yml file under the keyword policies. These policies along with the Intents, Entities and conversation done so far will assign a confidence score to the predicted actions. Now among these actions the one having the highest confidence score will get executed.

In situations where two policies predict with equal confidence, the next action will be decided based on the priorities of the policies. Following are some policies with their priorities

  • RulePolicy —> 6
  • MemoizationPolicy or AugmentedMemoizationPolicy —> 3
  • UnexpecTEDIntentPolicy —> 2
  • TEDPolicy —> 1
Note: Here, the higher number represents the higher priority. 

This means that if TEDPolicy predicts an action with a confidence score of 0.87 and RulePolicy also predicts an action with same confidence, then the preference will be given to the action predicted by RulePolicy because it has higher priority. 

Let’s discuss what policies we have and how they work…

  1. TEDPolicy

The Transformer Embedding Dialogue(TED) Policy is a multi-task architecture for predicting next action. It uses features from current conversation turn as well as the previous conversational turn to predict the next action. It decides which turn to remember for encoding its current dialogue state. It is a machine learning Policy. At every turn, transformer accepts three types of data as inputs, user's message, past activity and any value in assistant's memory i.e. slots. Each of these is featurised and connected before taken care by the transformer.


Following is an example of how to declare TEDPolicy:

policies:

- name: TEDPolicy

  epochs: 200

  max_history: 5


Here, max_history parameter will tell the context which is required to keep while doing predictions for next action. Increasing the value of epochs and max_history may increase the training time.


    2. MemoizationPolicy


This policy remembers stories from stories file which is the Training data fed by the designer itself. That is why it has higher priority while predicting the next actions. If it found a story matching with the stories of your training data, it will predict the next action with a confidence of 1.0.


While looking for a match in your training data, the policy will take the last max_history number of turns into account. One turn is said to be one message sent by the user and any action the assistant performed before waiting for the next message.


policies:

  - name: "MemoizationPolicy"

    max_history: 3


    3. RulePolicy


It is a rule based policy. It helps you to impose strict rule-based behaviour on your assistant. It checks the rules from rules.yml file which has the training data provided by the designer.

Example of rules.py,


rules:

 - rule: Chitchat

 steps:

  - intent: chitchat

  - action: utter_chitchat


Example of config.yml,

policies:

  - name: "RulePolicy"

    core_fallback_threshold: 0.3


RASA Custom Policies 

You can also create custom policies to customise your bot. To create a custom policy you have to create a python file performing your custom task. Once you have a mature python code in that file you can define the path of the class you have created in config.yml file. Following is an example of how you can define a custom policy.

policies:

  - name: "path.to.your.policy.class"

    arg1: “value.of.argument1”



Conclusion

RASA provides a wide list of options to customise your Assistant. We have touched very few of them. Policies are used to predict the next action which is required to be performed. We can use different policies in different ways to make our assistant more efficient to perform a task. We can also create custom Policies and their priorities. There are few more policies which helps us to handle out of scope queries and those are Fallback Policy and Multi-fallback Policy. We will discuss about them later.

Happy Learning :) 

Comments

Popular Posts