tf.keras.random.categorical
Stay organized with collections
Save and categorize content based on your preferences.
Draws samples from a categorical distribution.
tf.keras.random.categorical(
logits, num_samples, dtype='int32', seed=None
)
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.
Args |
logits
|
2-D Tensor with shape (batch_size, num_classes). Each row
should define a categorical distibution with the unnormalized
log-probabilities for all classes.
|
num_samples
|
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.
|
dtype
|
Optional dtype of the output tensor.
|
seed
|
A Python integer or instance of
keras.random.SeedGenerator .
Used to make the behavior of the initializer
deterministic. Note that an initializer seeded with an integer
or None (unseeded) will produce the same random values
across multiple calls. To get different random values
across multiple calls, use as seed an instance
of keras.random.SeedGenerator .
|
Returns |
A 2-D tensor with (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 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.random.categorical\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/random/random.py#L32-L74) |\n\nDraws samples from a categorical distribution. \n\n tf.keras.random.categorical(\n logits, num_samples, dtype='int32', seed=None\n )\n\nThis function takes as input `logits`, a 2-D input tensor with shape\n(batch_size, num_classes). Each row of the input represents a categorical\ndistribution, with each column index containing the log-probability for a\ngiven class.\n\nThe function will output a 2-D tensor with shape (batch_size, num_samples),\nwhere each row contains samples from the corresponding row in `logits`.\nEach column index contains an independent samples drawn from the input\ndistribution.\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 row should define a categorical distibution with the unnormalized log-probabilities for all classes. |\n| `num_samples` | 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. |\n| `dtype` | Optional dtype of the output tensor. |\n| `seed` | A Python integer or instance of [`keras.random.SeedGenerator`](../../../tf/keras/random/SeedGenerator). Used to make the behavior of the initializer deterministic. Note that an initializer seeded with an integer or None (unseeded) will produce the same random values across multiple calls. To get different random values across multiple calls, use as seed an instance of [`keras.random.SeedGenerator`](../../../tf/keras/random/SeedGenerator). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A 2-D tensor with (batch_size, num_samples). ||\n\n\u003cbr /\u003e"]]