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).
rasa.utils.tensorflow.layers_utils
random_indices
Creates batch_size * n
random indices that run from 0
to n_max
.
Arguments:
batch_size
- Number of items in each batchn
- Number of random indices in each examplen_max
- Maximum index (excluded)
Returns:
A uniformly distributed integer tensor of indices
batch_flatten
Flattens all but last dimension of x
so it becomes 2D.
Arguments:
x
- Any tensor with at least 2 dimensions
Returns:
The reshaped tensor, where all but the last dimension are flattened into the first dimension
get_candidate_values
Gathers candidate values according to IDs.
Arguments:
x
- Any tensor with at least one dimensioncandidate_ids
- Indicator for which candidates to gather
Returns:
A tensor of shape (batch_size, 1, num_candidates, tf.shape(x)[-1])
, where
for each batch example, we generate a list of num_candidates
vectors, and
each candidate is chosen from x
according to the candidate id. For example:
reduce_mean_equal
Computes the mean number of matches between x and y.
If x
and y
have n
dimensions, then the mean equal
number of indices is calculated for the last dimension by
only taking the valid indices into consideration
(from the mask) and then it is averaged over all
other n-1
dimensions.
For e.g., if:
x = [[1,2,3,4][5,6,7,8]] y = [[1,2,3,4][5,6,0,0]] mask = [[1,1,1,1], [1,1,1,0]]
then the output will be calculated as ((4/4) + 2/3) / 2
Arguments:
x
- Any numeric tensor.y
- Another tensor with same shape and type as x.mask
- Tensor with a mask to distinguish actual indices from padding indices. Shape should be the same asx
andy
.
Returns:
The mean of "x == y"