tf.random.stateless_categorical
Stay organized with collections
Save and categorize content based on your preferences.
Draws deterministic pseudorandom samples from a categorical distribution.
tf.random.stateless_categorical(
logits,
num_samples,
seed,
dtype=tf.dtypes.int64
,
name=None
)
This is a stateless version of tf.categorical
: if run twice with the
same seeds and shapes, 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.
Example:
# 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])
Args |
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] Tensor, the seed to the random number generator. Must have
dtype int32 or int64 . (When using XLA, only int32 is allowed.)
|
dtype
|
The integer type of the output: int32 or int64 . Defaults to
int64 .
|
name
|
Optional name for the operation.
|
Returns |
The drawn samples of shape [batch_size, num_samples] .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.random.stateless_categorical\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.13.1/tensorflow/python/ops/stateless_random_ops.py#L905-L945) |\n\nDraws deterministic pseudorandom samples from a categorical distribution.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.random.stateless_categorical`](https://www.tensorflow.org/api_docs/python/tf/random/stateless_categorical)\n\n\u003cbr /\u003e\n\n tf.random.stateless_categorical(\n logits,\n num_samples,\n seed,\n dtype=../../tf/dtypes#int64,\n name=None\n )\n\nThis is a stateless version of `tf.categorical`: if run twice with the\nsame seeds and shapes, it will produce the same pseudorandom numbers. The\noutput is consistent across multiple runs on the same hardware (and between\nCPU and GPU), but may change between versions of TensorFlow or on non-CPU/GPU\nhardware.\n\n#### Example:\n\n # samples has shape [1, 5], where each value is either 0 or 1 with equal\n # probability.\n samples = tf.random.stateless_categorical(\n tf.math.log([[0.5, 0.5]]), 5, seed=[7, 17])\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `logits` | 2-D Tensor with shape `[batch_size, num_classes]`. Each slice `[i, :]` represents the unnormalized log-probabilities for all classes. |\n| `num_samples` | 0-D. Number of independent samples to draw for each row slice. |\n| `seed` | A shape \\[2\\] Tensor, the seed to the random number generator. Must have dtype `int32` or `int64`. (When using XLA, only `int32` is allowed.) |\n| `dtype` | The integer type of the output: `int32` or `int64`. Defaults to `int64`. |\n| `name` | Optional name for the operation. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The drawn samples of shape `[batch_size, num_samples]`. ||\n\n\u003cbr /\u003e"]]