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](/content/docs/index.html).

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:

```yaml
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](https://legacy-docs-oss.rasa.com/docs/rasa/model-configuration#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. They look like this, where higher numbers have higher priority:

- 6 - `RulePolicy`
- 3 - `MemoizationPolicy` or `AugmentedMemoizationPolicy`
- 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. For the next action prediction, the dialogue transformer encoder output and the system action labels are embedded into a single semantic vector space. We use the dot-product loss to maximize the similarity with the target label and minimize similarities with negative samples.

If you want to learn more about the model, check out [our paper](https://arxiv.org/abs/1910.00486) and on our [youtube channel](https://www.youtube.com/watch?v=j90NvurJI4I&list=PL75e0qA87dlG-za8eLI6t0_Pbxafk-cxb&index=14&ab_channel=Rasa) where we explain the model architecture in detail.

#### TED Policy architecture comprises the following steps:

1. 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.

2. Feed the embedding of the input vector into the dialogue transformer encoder.
3. Apply a dense layer to the output of the dialogue transformer to get embeddings of the dialogue for each time step.
4. Apply a dense layer to create embeddings for system actions for each time step.
5. Calculate the similarity between the dialogue embedding and embedded system actions. This step is based on the [StarSpace](https://arxiv.org/abs/1709.03856) idea.
6. Concatenate the token-level output of the user sequence transformer encoder with the output of the dialogue transformer encoder for each time step.
7. Apply 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`:
This parameter sets the number of times the algorithm will see the training data (default: `1`).

Here is how the config would look like:

```yaml
policies:
  - name: TEDPolicy
    epochs: 200
```

- `max_history`:
This parameter controls how much dialogue history the model looks at to decide which action to take next.

Here is how the config would look like:

```yaml
policies:
  - name: TEDPolicy
    max_history: 8
```

- `number_of_transformer_layers`: This parameter sets the number of sequence transformer encoder layers to use for sequential transformer encoders for user, action and action label texts and for dialogue transformer encoder.
- `transformer_size`: This parameter sets the number of units in the sequence transformer encoder layers to use for sequential transformer encoders for user, action and action label texts and for dialogue transformer encoder.
- `connection_density`: This parameter defines the fraction of kernel weights that are set to non zero values for all feed forward layers in the model.
- `split_entities_by_comma`: This parameter defines whether adjacent entities separated by a comma should be treated as one, or split.

### Configuration Parameters

The above configuration parameters are the ones you should configure to fit your model to your data.

| Parameter                          | Default Value           | Description                                                                                                    |
|------------------------------------|-------------------------|----------------------------------------------------------------------------------------------------------------|
| hidden_layers_sizes                 | text: []                | Hidden layer sizes for layers before the embedding layers for user messages and bot messages in previous actions.| 
| dense_dimension                     | text: 128               | Dense dimension for sparse features to use after they are converted into dense features.                        |
| concat_dimension                    | text: 128               | Common dimension to which sequence and sentence features of different dimensions get converted before concatenation.| 
| encoding_dimension                  | 50                      | Dimension size of embedding vectors before the dialogue transformer encoder.                                     |
| transformer_size                    | text: 128               | Number of units in user text sequence transformer encoder.                                                    |
| use_gpu                             | True                    | This parameter defines whether a GPU (if available) will be used training.                                    |

### UnexpecTED Intent Policy

The `UnexpecTEDIntentPolicy` helps you review conversations and also allows your bot to react to unlikely user turns. It should only be used in conjunction with at least one other policy, as the only action that it can trigger is the special `action_unlikely_intent` action.

The `UnexpecTEDIntentPolicy` learns the set of intents that are most likely to be expressed by the user given the conversation context from training stories. It uses this learned information at inference time by checking if the predicted intent by NLU is the most likely intent.

**Configuration:**

You can pass configuration parameters to the `UnexpecTEDIntentPolicy` using the `config.yml` file. Here is how the config would look like:

```yaml
policies:
  - name: UnexpecTEDIntentPolicy
    epochs: 200
    max_history: 8
```  
#### More Configurable Parameters

| Parameter                          | Default Value           | Description                                                                                                    |
|------------------------------------|-------------------------|----------------------------------------------------------------------------------------------------------------|
| ignore_intents_list                | []                      | This parameter lets you configure `UnexpecTEDIntentPolicy` to ignore the prediction of `action_unlikely_intent`.|
| tolerance                           | 0.0                     | The `tolerance` parameter helps adjust the threshold score used during prediction of `action_unlikely_intent`.  |

### 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 will predict the next action from the matching stories of your training data with a confidence of `1.0`. If no matching conversation is found, the policy predicts `None` with confidence `0.0`.

**Configuration:**

```yaml
policies:
  - name: MemoizationPolicy
    max_history: 3
```

## Configuring Policies

### Max History

One important hyperparameter for Rasa policies is the `max_history`. This controls how much dialogue history the model looks at to decide which action to take next.

**Configuration Example:**

```yaml
policies:
  - name: TEDPolicy
    max_history: 5
    epochs: 200
    batch_size: 50
    max_training_samples: 300
```

### Data Augmentation

When you train a model, Rasa will create longer stories by randomly combining the ones in your stories files. This can be helpful in teaching your policy to ignore the dialogue history when it isn't relevant.

You can alter this behavior with the `--augmentation` flag, which allows you to set the `augmentation_factor` that determines how many augmented stories are subsampled during training.

## Custom Policies

Rasa 3.0 unified the implementation of NLU components and policies. This allows you to write custom policies and reference them in your configuration.
