# tf.random.stateless_categorical

View source

Draws deterministic pseudorandom samples from a categorical distribution.

### Aliases:

• `tf.compat.v1.random.stateless_categorical`
• `tf.compat.v2.random.stateless_categorical`
``````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, 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  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.

#### Returns:

The drawn samples of shape `[batch_size, num_samples]`.
{"ft_lang_label":"__label__en","ft_lang_prob":0.6056156,"math_prob":0.9436853,"size":1232,"snap":"2019-51-2020-05","text_gpt3_token_len":302,"char_repetition_ratio":0.1514658,"word_repetition_ratio":0.0,"special_character_ratio":0.2353896,"punctuation_ratio":0.24193548,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9875371,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-12-08T04:49:11Z\",\"WARC-Record-ID\":\"<urn:uuid:e3365ff0-72f8-4aa6-87a9-f61eb6be5f61>\",\"Content-Length\":\"591508\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:1bc5982b-72b8-4718-89e9-2d61f902d997>\",\"WARC-Concurrent-To\":\"<urn:uuid:241634c4-3a59-4c49-a036-9587c919501c>\",\"WARC-IP-Address\":\"49.4.29.130\",\"WARC-Target-URI\":\"http://tensorfly.cn/tfdoc/api_docs/tf/random/stateless_categorical.html\",\"WARC-Payload-Digest\":\"sha1:OIRHLCA3YO3QMYVPVHNVWX734M2SW3MD\",\"WARC-Block-Digest\":\"sha1:U7KSXH6YLP43E3XCXPYPHG3BG6AAF6SX\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-51/CC-MAIN-2019-51_segments_1575540506459.47_warc_CC-MAIN-20191208044407-20191208072407-00484.warc.gz\"}"}