Stay organized with collections Save and categorize content based on your preferences.

TensorFlow 1 version View source on GitHub

Draws deterministic pseudorandom samples from a categorical distribution.

This is a stateless version of tf.categorical: if run twice with the same seeds, it will produce the same pseudorandom numbers. The output is consistent across multiple runs on the same hardware (and between CPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU hardware.


# samples has shape [1, 5], where each value is either 0 or 1 with equal
# probability.
samples = tf.random.stateless_categorical(
    tf.math.log([[0.5, 0.5]]), 5, seed=[7, 17])

logits 2-D Tensor with shape [batch_size, num_classes]. Each slice [i, :] represents the unnormalized log-probabilities for all classes.
num_samples 0-D. Number of independent samples to draw for each row slice.
seed A shape [2] integer Tensor of seeds to the random number generator.
dtype integer type to use for the output. Defaults to int64.
name Optional name for the operation.

The drawn samples of shape [batch_size, num_samples].