rasa.core.policies.policy

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.

Supported Data Objects

class SupportedData(Enum)

Enumeration of a policy's supported training data type.

trackers_for_supported_data

@staticmethod
def trackers_for_supported_data( supported_data: SupportedData, trackers: TrackerListTypeVar ) -> TrackerListTypeVar

Return trackers for a given policy.

Arguments:

Returns:

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

Policy Objects

class Policy(GraphComponent)

Common parent class for all dialogue policies.

supported_data

@staticmethod
def 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

def init(config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, execution_context: ExecutionContext, featurizer: Optional[TrackerFeaturizer] = None) -> None

Constructs a new Policy object.

create

@classmethod
def create(cls, config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, execution_context: ExecutionContext, **kwargs: Any) -> Policy

Creates a new untrained policy (see parent class for full docstring).

featurizer

@property
def featurizer() -> TrackerFeaturizer

Returns the policy's featurizer.

train

@abc.abstractmethod
def train(training_trackers: List[TrackerWithCachedStates], domain: Domain, **kwargs: Any) -> Resource

Trains a policy.

Arguments:

Returns:

A policy must return its resource locator so that potential children nodes can load the policy from the resource.

predict_action_probabilities

@abc.abstractmethod
def predict_action_probabilities(tracker: DialogueStateTracker, domain: Domain, rule_only_data: Optional[Dict[Text, Any]] = None, **kwargs: Any) -> PolicyPrediction

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

Arguments:

Returns:

The prediction.

load

@classmethod
def load(cls, config: Dict[Text, Any], model_storage: ModelStorage, resource: Resource, execution_context: ExecutionContext, **kwargs: Any) -> Policy

Loads a trained policy (see parent class for full docstring).

format_tracker_states

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

Format tracker states to human readable format on debug log.

Arguments:

Returns:

the string of the states with user intents and actions.

repr

def repr() -> Text

Returns text representation of object.

PolicyPrediction Objects

class PolicyPrediction()

Stores information about the prediction of a Policy.

init

def 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:

for_action_name

@staticmethod
def 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:

Returns:

The prediction.

eq

def eq(other: Any) -> bool

Checks if the two objects are equal.

Arguments:

Returns:

True if other has the same type and the values are the same.

max_confidence_index

@property
def 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
def max_confidence() -> float

Gets the highest predicted confidence.

Returns:

The highest predicted confidence.

confidence_scores_for

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

Returns confidence scores if a single action is predicted.

Arguments:

Returns:

the list of the length of the number of actions.

InvalidPolicyConfig Objects

class InvalidPolicyConfig(RasaException)

Exception that can be raised when policy config is not valid.