notice

This is documentation for Rasa Documentation v2.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (3.x).

Version: 2.x

rasa.core.policies.policy

SupportedData Objects

class SupportedData(Enum)

Enumeration of a policy's supported training data type.

trackers_for_policy

| @staticmethod
| trackers_for_policy(policy: Union["Policy", Type["Policy"]], trackers: Union[List[DialogueStateTracker], List[TrackerWithCachedStates]]) -> Union[List[DialogueStateTracker], List[TrackerWithCachedStates]]

Return trackers for a given policy.

Arguments:

  • policy - Policy or policy type to return trackers for.
  • trackers - Trackers to split.

Returns:

Trackers from ML-based training data and/or rule-based data.

Policy Objects

class Policy()

supported_data

| @staticmethod
| supported_data() -> SupportedData

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__

| __init__(featurizer: Optional[TrackerFeaturizer] = None, priority: int = DEFAULT_POLICY_PRIORITY, should_finetune: bool = False, **kwargs: Any, ,) -> None

Constructs a new Policy object.

featurizer

| @property
| featurizer() -> TrackerFeaturizer

Returns the policy's featurizer.

set_shared_policy_states

| set_shared_policy_states(**kwargs: Any) -> None

Sets policy's shared states for correct featurization.

train

| train(training_trackers: List[TrackerWithCachedStates], domain: Domain, interpreter: NaturalLanguageInterpreter, **kwargs: Any, ,) -> None

Trains the policy on given training trackers.

Arguments:

training_trackers: the list of the :class:rasa.core.trackers.DialogueStateTracker

  • domain - the :class:rasa.shared.core.domain.Domain
  • interpreter - Interpreter which can be used by the polices for featurization.

predict_action_probabilities

| predict_action_probabilities(tracker: DialogueStateTracker, domain: Domain, interpreter: NaturalLanguageInterpreter, **kwargs: Any, ,) -> "PolicyPrediction"

Predicts the next action the bot should take after seeing the tracker.

Arguments:

  • tracker - the :class:rasa.core.trackers.DialogueStateTracker
  • domain - the :class:rasa.shared.core.domain.Domain
  • interpreter - Interpreter which may be used by the policies to create additional features.

Returns:

The policy's prediction (e.g. the probabilities for the actions).

persist

| persist(path: Union[Text, Path]) -> None

Persists the policy to storage.

Arguments:

  • path - Path to persist policy to.

load

| @classmethod
| load(cls, path: Union[Text, Path], **kwargs: Any) -> "Policy"

Loads a policy from path.

Arguments:

  • path - Path to load policy from.

Returns:

An instance of Policy.

format_tracker_states

| @staticmethod
| format_tracker_states(states: List[Dict]) -> Text

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

PolicyPrediction Objects

class PolicyPrediction()

Stores information about the prediction of a Policy.

__init__

| __init__(probabilities: List[float], policy_name: Optional[Text], policy_priority: int = 1, events: Optional[List[Event]] = None, optional_events: Optional[List[Event]] = None, is_end_to_end_prediction: bool = False, is_no_user_prediction: bool = False, diagnostic_data: Optional[Dict[Text, Any]] = None, hide_rule_turn: bool = False, action_metadata: Optional[Dict[Text, Any]] = None) -> None

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 the Policy 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 the Policy 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.
  • is_no_user_prediction - 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.
  • diagnostic_data - Intermediate results or other information that is not necessary for Rasa to function, but intended for debugging and fine-tuning purposes.
  • hide_rule_turn - True if the prediction was made by the rules which do not appear in the stories
  • action_metadata - Specifies additional metadata that can be passed by policies.

for_action_name

| @staticmethod
| for_action_name(domain: Domain, action_name: Text, policy_name: Optional[Text] = None, confidence: float = 1.0, action_metadata: Optional[Dict[Text, Any]] = None) -> "PolicyPrediction"

Create a prediction for a given action.

Arguments:

  • domain - The current model domain
  • action_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__

| __eq__(other: Any) -> bool

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

| @property
| max_confidence_index() -> int

Gets the index of the action prediction with the highest confidence.

Returns:

The index of the action with the highest confidence.

max_confidence

| @property
| max_confidence() -> float

Gets the highest predicted probability.

Returns:

The highest predicted probability.

confidence_scores_for

confidence_scores_for(action_name: Text, value: float, domain: Domain) -> List[float]

Returns confidence scores if a single action is predicted.

Arguments:

  • action_name - the name of the action for which the score should be set
  • value - the confidence for action_name
  • domain - the :class:rasa.shared.core.domain.Domain

Returns:

the list of the length of the number of actions