notice
This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).
rasa.core.policies.policy
SupportedData Objects
Enumeration of a policy's supported training data type.
trackers_for_supported_data
Return trackers for a given policy.
Arguments:
supported_data
- Supported data filter for thetrackers
.trackers
- Trackers to split.
Returns:
Trackers from ML-based training data and/or rule-based data.
Policy Objects
Common parent class for all dialogue policies.
supported_data
The type of data supported by this policy.
By default, this is only ML-based training data. If policies support rule data, or both ML-based data and rule data, they need to override this method.
Returns:
The data type supported by this policy (ML-based training data).
__init__
Constructs a new Policy object.
create
Creates a new untrained policy (see parent class for full docstring).
featurizer
Returns the policy's featurizer.
train
Trains a policy.
Arguments:
training_trackers
- The story and rules trackers from the training data.domain
- The model's domain.**kwargs
- Depending on the specifiedneeds
section and the resulting graph structure the policy can use different input to train itself.
Returns:
A policy must return its resource locator so that potential children nodes can load the policy from the resource.
predict_action_probabilities
Predicts the next action the bot should take after seeing the tracker.
Arguments:
tracker
- The tracker containing the conversation history up to now.domain
- The model's domain.rule_only_data
- Slots and loops which are specific to rules and hence should be ignored by this policy.**kwargs
- Depending on the specifiedneeds
section and the resulting graph structure the policy can use different input to make predictions.
Returns:
The prediction.
load
Loads a trained policy (see parent class for full docstring).
format_tracker_states
Format tracker states to human readable format on debug log.
Arguments:
states
- list of tracker states dicts
Returns:
the string of the states with user intents and actions
__repr__
Returns text representation of object.
PolicyPrediction Objects
Stores information about the prediction of a Policy
.
__init__
Creates a PolicyPrediction
.
Arguments:
probabilities
- The probabilities for each action.policy_name
- Name of the policy which made the prediction.policy_priority
- The priority of the policy which made the prediction.events
- Events which thePolicy
needs to have applied to the tracker after the prediction. These events are applied independent of whether the policy wins against other policies or not. Be careful which events you return as they can potentially influence the conversation flow.optional_events
- Events which thePolicy
needs to have applied to the tracker after the prediction in case it wins. These events are only applied in case the policy's prediction wins. Be careful which events you return as they can potentially influence the conversation flow.is_end_to_end_prediction
-True
if the prediction used the text of the user message instead of the intent.probabilities
0 -True
if the prediction uses neither the text of the user message nor the intent. This is for the example the case for happy loop paths.probabilities
2 - Intermediate results or other information that is not necessary for Rasa to function, but intended for debugging and fine-tuning purposes.probabilities
3 -True
if the prediction was made by the rules which do not appear in the storiesprobabilities
5 - Specifies additional metadata that can be passed by policies.
for_action_name
Create a prediction for a given action.
Arguments:
domain
- The current model domainaction_name
- The action which should be predicted.policy_name
- The policy which did the prediction.confidence
- The prediction confidence.action_metadata
- Additional metadata to be attached with the prediction.
Returns:
The prediction.
__eq__
Checks if the two objects are equal.
Arguments:
other
- Any other object.
Returns:
True
if other has the same type and the values are the same.
max_confidence_index
Gets the index of the action prediction with the highest confidence.
Returns:
The index of the action with the highest confidence.
max_confidence
Gets the highest predicted confidence.
Returns:
The highest predicted confidence.
confidence_scores_for
Returns confidence scores if a single action is predicted.
Arguments:
action_name
- the name of the action for which the score should be setvalue
- the confidence foraction_name
domain
- the :class:rasa.shared.core.domain.Domain
Returns:
the list of the length of the number of actions
InvalidPolicyConfig Objects
Exception that can be raised when policy config is not valid.