Skip to contents

This function takes as input logits, a 2-D input tensor with shape (batch_size, num_classes). Each row of the input represents a categorical distribution, with each column index containing the log-probability for a given class.

The function will output a 2-D tensor with shape (batch_size, num_samples), where each row contains samples from the corresponding row in logits. Each column index contains an independent samples drawn from the input distribution.


random_categorical(logits, num_samples, dtype = "int32", seed = NULL)



2-D Tensor with shape (batch_size, num_classes). Each row should define a categorical distibution with the unnormalized log-probabilities for all classes.


Int, the number of independent samples to draw for each row of the input. This will be the second dimension of the output tensor's shape.


Optional dtype of the output tensor.


An R integer or instance of random_seed_generator(). Used to make the behavior of the initializer deterministic. Note that an initializer seeded with an integer or NULL (unseeded) will produce the same random values across multiple calls. To get different random values across multiple calls, use as seed an instance of random_seed_generator().


A 2-D tensor with (batch_size, num_samples).