Policies
Policies
Overview
These docs are for version 1.x of Rasa Open Source.
Introduction
The rasa.core.policies.Policy class decides which action to take at every step in the conversation.
Configuring Policies
Your project’s config.yml file takes a policies key which you can use to customize the policies your assistant uses.
policies:
- name: "KerasPolicy"
featurizer:
- name: MaxHistoryTrackerFeaturizer
max_history: 5
state_featurizer:
- name: BinarySingleStateFeaturizer
- name: "MemoizationPolicy"
max_history: 5
- name: "FallbackPolicy"
nlu_threshold: 0.4
core_threshold: 0.3
fallback_action_name: "my_fallback_action"
- name: "path.to.your.policy.class"
arg1: "..."
Max History
One important hyperparameter for Rasa Core policies is the max_history. This controls how much dialogue history the model looks at to decide which action to take next.
max_history: 5
Data Augmentation
When you train a model, by default Rasa Core will create longer stories by randomly gluing together the ones in your stories files. You can alter this behavior with the --augmentation flag.
Action Selection
At every turn, each policy defined in your configuration will predict a next action with a certain confidence level.
Keras Policy
The KerasPolicy uses a neural network implemented in Keras to select the next action. The following is a basic structure of the model.
def model_architecture(self, input_shape, output_shape):
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Masking, LSTM, Dense, TimeDistributed, Activation
# Build Model
model = Sequential()
model.add(Masking(mask_value=-1, input_shape=input_shape))
model.add(LSTM(self.rnn_size, dropout=0.2))
model.add(Dense(input_dim=self.rnn_size, units=output_shape[-1]))
model.compile(loss="categorical_crossentropy", optimizer="rmsprop", metrics=["accuracy"])
return model
Policies Definitions
Memoization Policy
The MemoizationPolicy just memorizes the conversations in your training data.
Augmented Memoization Policy
Remembers examples from training stories for up to max_history turns.
Fallback Policy
Invokes a fallback action if intent recognition confidence is below a specified threshold.
policies:
- name: "FallbackPolicy"
nlu_threshold: 0.3
core_threshold: 0.3
fallback_action_name: 'action_default_fallback'
Form Policy
The FormPolicy is an extension of the MemoizationPolicy which handles the filling of forms. Once a FormAction is called, the FormPolicy will continually predict the FormAction until all required slots in the form are filled.