notice

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

Version: 2.2.x

rasa.utils.tensorflow.models

RasaModel Objects

class RasaModel(tf.keras.models.Model)

Completely override all public methods of keras Model.

Cannot be used as tf.keras.Model

__init__

| __init__(random_seed: Optional[int] = None, tensorboard_log_dir: Optional[Text] = None, tensorboard_log_level: Optional[Text] = "epoch", checkpoint_model: Optional[bool] = False, **kwargs, ,) -> None

Initialize the RasaModel.

Arguments:

  • random_seed - set the random seed to get reproducible results

batch_loss

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

Calculates the loss for the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The loss of the given batch.

prepare_for_predict

| prepare_for_predict() -> None

Prepares tf graph fpr prediction.

This method should contain necessary tf calculations and set self variables that are used in batch_predict. For example, pre calculation of self.all_labels_embed.

batch_predict

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

Predicts the output of the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The output to predict.

fit

| fit(model_data: RasaModelData, epochs: int, batch_size: Union[List[int], int], evaluate_on_num_examples: int, evaluate_every_num_epochs: int, batch_strategy: Text, silent: bool = False, loading: bool = False, eager: bool = False) -> None

Fit model data.

train_on_batch

| train_on_batch(batch_in: Union[Tuple[tf.Tensor], Tuple[np.ndarray]]) -> None

Train on batch.

load

| @classmethod
| load(cls, model_file_name: Text, model_data_example: RasaModelData, finetune_mode: bool = False, *args, **kwargs, *, ,) -> "RasaModel"

Loads a model from the given weights.

Arguments:

  • model_file_name - Path to file containing model weights.
  • model_data_example - Example data point to construct the model architecture.
  • finetune_mode - Indicates whether to load the model for further finetuning.
  • *args - Any other non key-worded arguments.
  • **kwargs - Any other key-worded arguments.

Returns:

Loaded model with weights appropriately set.

batch_to_model_data_format

| @staticmethod
| batch_to_model_data_format(batch: Union[Tuple[tf.Tensor], Tuple[np.ndarray]], data_signature: Dict[Text, Dict[Text, List[FeatureSignature]]]) -> Dict[Text, Dict[Text, List[tf.Tensor]]]

Convert input batch tensors into batch data format.

Batch contains any number of batch data. The order is equal to the key-value pairs in session data. As sparse data were converted into indices, data, shape before, this methods converts them into sparse tensors. Dense data is kept.

linearly_increasing_batch_size

| @staticmethod
| linearly_increasing_batch_size(epoch: int, batch_size: Union[List[int], int], epochs: int) -> int

Linearly increase batch size with every epoch.

The idea comes from https://arxiv.org/abs/1711.00489.

TransformerRasaModel Objects

class TransformerRasaModel(RasaModel)

batch_loss

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

Calculates the loss for the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The loss of the given batch.

batch_predict

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

Predicts the output of the given batch.

Arguments:

  • batch_in - The batch.

Returns:

The output to predict.