Policies
Overview
You are viewing documentation for our open source project which is maintained by the community. If you want to get started building assistants with Rasa please check out our latest documentation here.
Customizing Policies
You can customize the policies your assistant uses by specifying the policies key in your project's config.yml. There are different policies to choose from, and you can include multiple policies in a single configuration. Here’s an example of what a list of policies might look like:
policies:
- name: MemoizationPolicy
- name: TEDPolicy
max_history: 5
epochs: 200
- name: RulePolicy
Starting from Scratch?
If you don't know which policies to choose, leave out the policies key from your config.yml completely. If you do, the Suggested Config feature will provide default policies for you.
Action Selection
At every turn, each policy defined in your configuration will predict a next action with a certain confidence level. For more information about how each policy makes its decision, read into the policy's description below. The policy that predicts with the highest confidence decides the assistant's next action.
Maximum Number of Predictions
By default, your assistant can predict a maximum of 10 next actions after each user message. To update this value, you can set the environment variable MAX_NUMBER_OF_PREDICTIONS to the desired number of maximum predictions.
Policy Priority
In the case that two policies predict with equal confidence (for example, the Memoization and Rule Policies might both predict with confidence 1), the priority of the policies is considered. Rasa policies have default priorities that are set to ensure the expected outcome in the case of a tie:
- 6 -
RulePolicy - 3 -
MemoizationPolicyorAugmentedMemoizationPolicy - 2 -
UnexpecTEDIntentPolicy - 1 -
TEDPolicy
In general, it is not recommended to have more than one policy per priority level in your configuration. If you have 2 policies with the same priority and they predict with the same confidence, the resulting action will be chosen randomly.
If you create your own policy, use these priorities as a guide for figuring out the priority of your policy. If your policy is a machine learning policy, it should most likely have priority 1, the same as the TEDPolicy.
Overriding Policy Priorities
All policy priorities are configurable via the priority parameter in the policy's configuration, but we do not recommend changing them outside of specific cases such as custom policies. Doing so can lead to unexpected and undesired bot behavior.
Machine Learning Policies
TED Policy
The Transformer Embedding Dialogue (TED) Policy is a multi-task architecture for next action prediction and entity recognition. The architecture consists of several transformer encoders which are shared for both tasks. A sequence of entity labels is predicted through a Conditional Random Field (CRF) tagging layer on top of the user sequence transformer encoder output corresponding to the input sequence of tokens.
If you want to learn more about the model, check out our paper and on our YouTube channel.
TED Policy Architecture
TED Policy architecture comprises the following steps:
- Concatenate features for:
- user input (user intent and entities) or user text processed through a user sequence transformer encoder,
- previous system actions or bot utterances processed through a bot sequence transformer encoder,
- slots and active forms for each time step into an input vector to the embedding layer that precedes the dialogue transformer.
- Feed the embedding of the input vector into the dialogue transformer encoder.
- Apply a dense layer to the output of the dialogue transformer to get embeddings of the dialogue for each time step.
- Apply a dense layer to create embeddings for system actions for each time step.
- Calculate the similarity between the dialogue embedding and embedded system actions.
- Concatenate the token-level output of the user sequence transformer encoder with the output of the dialogue transformer encoder for each time step.
- Apply the CRF algorithm to predict contextual entities for each user text input.
Configuration
You can pass configuration parameters to the TEDPolicy using the config.yml file. If you want to fine-tune your model, start by modifying the following parameters:
- epochs: Sets the number of times the algorithm will see the training data (default: 1).
- max_history: Controls how much dialogue history the model looks at to decide which action to take next.
Here is how the config would look like:
policies:
- name: TEDPolicy
epochs: 200
For additional parameters, please refer to the documentation.
UnexpecTED Intent Policy
This feature is experimental. UnexpecTEDIntentPolicy helps you review conversations and also allows your bot to react to unlikely user turns. It is an auxiliary policy that should only be used in conjunction with at least one other policy.
It uses the learned information at inference time by checking if the predicted intent by NLU is the most likely intent. If it’s indeed likely to occur given the conversation context, UnexpecTEDIntentPolicy does not trigger any action. Otherwise, it triggers an action_unlikely_intent with confidence of 1.00.
Configuration
You can pass configuration parameters to the UnexpecTEDIntentPolicy using the config.yml file. For example:
policies:
- name: UnexpecTEDIntentPolicy
epochs: 200
For more information on other configurable parameters, please check the official documentation.
Memoization Policy
The MemoizationPolicy remembers the stories from your training data. It checks if the current conversation matches the stories in your stories.yml file. If so, it predicts the next action from the matching stories with high confidence. You can configure the number of conversation turns that it considers:
policies:
- name: MemoizationPolicy
max_history: 3
Rule-based Policies
Rule Policy
The RulePolicy handles conversation parts that follow a fixed behavior based on any rules defined in your training data.
To configure this policy:
policies:
- name: RulePolicy
core_fallback_threshold: 0.3
core_fallback_action_name: action_default_fallback
Configuring Policies
To set the max_history in your policy configuration:
policies:
- name: TEDPolicy
max_history: 5
epochs: 200