notice
This is documentation for Rasa Open Source Documentation v2.0.x, which is no longer actively maintained.
For up-to-date documentation, see the latest version (2.2.x).
rasa.utils.tensorflow.model_data
FeatureSignature Objects
Stores the shape and the type (sparse vs dense) of features.
RasaModelData Objects
Data object used for all RasaModels.
It contains all features needed to train the models.
__init__
Initializes the RasaModelData object.
Arguments:
label_key
- the key of a label used for balancing, etc.label_sub_key
- the sub key of a label used for balancing, etc.data
- the data holding the features
get
Get the data under the given keys.
Arguments:
key
- The key.sub_key
- The optional sub key.
Returns:
The requested data.
items
Return the items of the data attribute.
Returns:
The items of data.
values
Return the values of the data attribute.
Returns:
The values of data.
keys
Return the keys of the data attribute.
Arguments:
key
- The optional key.
Returns:
The keys of the data.
first_data_example
Return the data with just one feature example per key, sub-key.
Returns:
The simplified data.
does_feature_not_exist
Check if feature key (and sub-key) is present and features are available.
Arguments:
key
- The key.sub_key
- The optional sub-key.
Returns:
True, if no features for the given keys exists, False otherwise.
is_empty
Checks if data is set.
number_of_examples
Obtain number of examples in data.
Arguments:
data
- The data.Raises
- A ValueError if number of examples differ for different features.
Returns:
The number of examples in data.
feature_dimension
Get the feature dimension of the given key.
Arguments:
key
- The key.sub_key
- The optional sub-key.
Returns:
The feature dimension.
add_data
Add incoming data to data.
Arguments:
data
- The data to add.key_prefix
- Optional key prefix to use in front of the key value.
add_features
Add list of features to data under specified key.
Should update number of examples.
Arguments:
key
- The keysub_key
- The sub-keyfeatures
- The features to add.
add_lengths
Adds np.array of lengths of sequences to data under given key.
Arguments:
key
- The key to add the lengths tosub_key
- The sub-key to add the lengths tofrom_key
- The key to take the lengths fromfrom_sub_key
- The sub-key to take the lengths from
split
Create random hold out test set using stratified split.
Arguments:
number_of_test_examples
- Number of test examples.random_seed
- Random seed.
Returns:
A tuple of train and test RasaModelData.
get_signature
Get signature of RasaModelData.
Signature stores the shape and whether features are sparse or not for every key.
Returns:
A dictionary of key and sub-key to a list of feature signatures (same structure as the data attribute).
as_tf_dataset
Create tf dataset.
Arguments:
batch_size
- The batch size to use.batch_strategy
- The batch strategy to use.shuffle
- Boolean indicating whether the data should be shuffled or not.
Returns:
The tf.data.Dataset.
prepare_batch
Slices model data into batch using given start and end value.
Arguments:
data
- The data to prepare.start
- The start index of the batchend
- The end index of the batchtuple_sizes
- In case the feature is not present we propagate the batch with None. Tuple sizes contains the number of how many None values to add for what kind of feature.
Returns:
The features of the batch.