This is unreleased documentation for Rasa Documentation Main/Unreleased version.
For the latest released documentation, see the latest version (3.x).

Version: Main/Unreleased


TEDPolicy Objects

DefaultV1Recipe.ComponentType.POLICY_WITH_END_TO_END_SUPPORT, is_trainable=True
class TEDPolicy(Policy)

Transformer Embedding Dialogue (TED) Policy.

The model architecture is described in detail in In summary, the architecture comprises of the following steps:

- concatenate user input (user intent and entities), previous system actions,
slots and active forms for each time step into an input vector to
pre-transformer embedding layer;
- feed it to transformer;
- apply a dense layer to the output of the transformer to get embeddings of a
dialogue for each time step;
- apply a dense layer to create embeddings for system actions for each time
- calculate the similarity between the dialogue embedding and embedded system
actions. This step is based on the StarSpace
( idea.


def get_default_config() -> Dict[Text, Any]

Returns the default config (see parent class for full docstring).


def __init__(config: Dict[Text, Any],
model_storage: ModelStorage,
resource: Resource,
execution_context: ExecutionContext,
model: Optional[RasaModel] = None,
featurizer: Optional[TrackerFeaturizer] = None,
fake_features: Optional[Dict[Text, List[Features]]] = None,
entity_tag_specs: Optional[List[EntityTagSpec]] = None) -> None

Declares instance variables with default values.


def model_class() -> Type[TED]

Gets the class of the model architecture to be used by the policy.


Required class.


def run_training(model_data: RasaModelData,
label_ids: Optional[np.ndarray] = None) -> None

Feeds the featurized training data to the model.


  • model_data - Featurized training data.
  • label_ids - Label ids corresponding to the data points in model_data. These may or may not be used by the function depending on how the policy is trained.


def train(
training_trackers: List[TrackerWithCachedStates],
domain: Domain,
precomputations: Optional[MessageContainerForCoreFeaturization] = None,
**kwargs: Any) -> Resource

Trains the policy (see parent class for full docstring).


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

Predicts the next action (see parent class for full docstring).


def persist() -> None

Persists the policy to a storage.


def persist_model_utilities(model_path: Path) -> None

Persists model's utility attributes like model weights, etc.


  • model_path - Path where model is to be persisted


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

Loads a policy from the storage (see parent class for full docstring).

TED Objects

class TED(TransformerRasaModel)

TED model architecture from


def __init__(data_signature: Dict[Text, Dict[Text, List[FeatureSignature]]],
config: Dict[Text, Any], max_history_featurizer_is_used: bool,
label_data: RasaModelData,
entity_tag_specs: Optional[List[EntityTagSpec]]) -> None

Initializes the TED model.


  • data_signature - the data signature of the input data
  • config - the model configuration
  • max_history_featurizer_is_used - if 'True' only the last dialogue turn will be used
  • label_data - the label data
  • entity_tag_specs - the entity tag specifications


def batch_loss(
batch_in: Union[Tuple[tf.Tensor, ...], Tuple[np.ndarray,
...]]) -> tf.Tensor

Calculates the loss for the given batch.


  • batch_in - The batch.


The loss of the given batch.


def prepare_for_predict() -> None

Prepares the model for prediction.


def batch_predict(
batch_in: Union[Tuple[tf.Tensor, ...], Tuple[np.ndarray, ...]]
) -> Dict[Text, Union[tf.Tensor, Dict[Text, tf.Tensor]]]

Predicts the output of the given batch.


  • batch_in - The batch.


The output to predict.