neulab/docprompting-conala huggingface dataset:
Module: tf.random.experimental Public API for tf.random.experimental namespace. Classes class Algorithm: An enumeration. class Generator: Random-number generator. Functions create_rng_state(...): Creates a RNG state from an integer or a vector. get_global_generator(...): Retrieves the global generator. set_global_generator(...): Replaces the global generator with another Generator object. stateless_fold_in(...): Folds in data to an RNG seed to form a new RNG seed. stateless_split(...): Splits an RNG seed into num new seeds by adding a leading axis.
tf.random.experimental.stateless_fold_in Folds in data to an RNG seed to form a new RNG seed.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.experimental.stateless_fold_in  
tf.random.experimental.stateless_fold_in(
    seed, data
)
 For example, in a distributed-training setting, suppose we have a master seed and a replica ID. We want to fold the replica ID into the master seed to form a "replica seed" to be used by that replica later on, so that different replicas will generate different random numbers but the reproducibility of the whole system can still be controlled by the master seed: 
master_seed = [1, 2]
replica_id = 3
replica_seed = tf.random.experimental.stateless_fold_in(
  master_seed, replica_id)
print(replica_seed)
tf.Tensor([1105988140          3], shape=(2,), dtype=int32)
tf.random.stateless_normal(shape=[3], seed=replica_seed)
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0.03197195, 0.8979765 ,
0.13253039], dtype=float32)>

 


 Args
  seed   an RNG seed (a tensor with shape [2] and dtype int32 or int64). (When using XLA, only int32 is allowed.)  
  data   an int32 or int64 scalar representing data to be folded in to the seed.   
 


 Returns   A new RNG seed that is a deterministic function of the inputs and is statistically safe for producing a stream of new pseudo-random values. It will have the same dtype as data (if data doesn't have an explict dtype, the dtype will be determined by tf.convert_to_tensor).
tf.random.experimental.stateless_split Splits an RNG seed into num new seeds by adding a leading axis.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.experimental.stateless_split  
tf.random.experimental.stateless_split(
    seed, num=2
)
 Example: 
seed = [1, 2]
new_seeds = tf.random.experimental.stateless_split(seed, num=3)
print(new_seeds)
tf.Tensor(
[[1105988140 1738052849]
 [-335576002  370444179]
 [  10670227 -246211131]], shape=(3, 2), dtype=int32)
tf.random.stateless_normal(shape=[3], seed=new_seeds[0, :])
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([-0.59835213, -0.9578608 ,
0.9002807 ], dtype=float32)>

 


 Args
  seed   an RNG seed (a tensor with shape [2] and dtype int32 or int64). (When using XLA, only int32 is allowed.)  
  num   optional, a positive integer or scalar tensor indicating the number of seeds to produce (default 2).   
 


 Returns   A tensor with shape [num, 2] representing num new seeds. It will have the same dtype as seed (if seed doesn't have an explict dtype, the dtype will be determined by tf.convert_to_tensor).
tf.random.gamma     View source on GitHub    Draws shape samples from each of the given Gamma distribution(s).  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.gamma, tf.compat.v1.random_gamma  
tf.random.gamma(
    shape, alpha, beta=None, dtype=tf.dtypes.float32, seed=None, name=None
)
 alpha is the shape parameter describing the distribution(s), and beta is the inverse scale parameter(s). 
Note: Because internal calculations are done using float64 and casting has floor semantics, we must manually map zero outcomes to the smallest possible positive floating-point value, i.e., np.finfo(dtype).tiny. This means that np.finfo(dtype).tiny occurs more frequently than it otherwise should. This bias can only happen for small values of alpha, i.e., alpha << 1 or large values of beta, i.e., beta >> 1.
 The samples are differentiable w.r.t. alpha and beta. The derivatives are computed using the approach described in (Figurnov et al., 2018). Example: samples = tf.random.gamma([10], [0.5, 1.5])
# samples has shape [10, 2], where each slice [:, 0] and [:, 1] represents
# the samples drawn from each distribution

samples = tf.random.gamma([7, 5], [0.5, 1.5])
# samples has shape [7, 5, 2], where each slice [:, :, 0] and [:, :, 1]
# represents the 7x5 samples drawn from each of the two distributions

alpha = tf.constant([[1.],[3.],[5.]])
beta = tf.constant([[3., 4.]])
samples = tf.random.gamma([30], alpha=alpha, beta=beta)
# samples has shape [30, 3, 2], with 30 samples each of 3x2 distributions.

loss = tf.reduce_mean(tf.square(samples))
dloss_dalpha, dloss_dbeta = tf.gradients(loss, [alpha, beta])
# unbiased stochastic derivatives of the loss function
alpha.shape == dloss_dalpha.shape  # True
beta.shape == dloss_dbeta.shape  # True

 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output samples to be drawn per alpha/beta-parameterized distribution.  
  alpha   A Tensor or Python value or N-D array of type dtype. alpha provides the shape parameter(s) describing the gamma distribution(s) to sample. Must be broadcastable with beta.  
  beta   A Tensor or Python value or N-D array of type dtype. Defaults to 1. beta provides the inverse scale parameter(s) of the gamma distribution(s) to sample. Must be broadcastable with alpha.  
  dtype   The type of alpha, beta, and the output: float16, float32, or float64.  
  seed   A Python integer. Used to create a random seed for the distributions. See tf.random.set_seed for behavior.  
  name   Optional name for the operation.   
 


 Returns
  samples   a Tensor of shape tf.concat([shape, tf.shape(alpha + beta)], axis=0) with values of type dtype.    References: Implicit Reparameterization Gradients: Figurnov et al., 2018 (pdf)
tf.random.get_global_generator Retrieves the global generator.  View aliases  Main aliases 
tf.random.experimental.get_global_generator Compat aliases for migration See Migration guide for more details. tf.compat.v1.random.experimental.get_global_generator, tf.compat.v1.random.get_global_generator  
tf.random.get_global_generator()
 This function will create the global generator the first time it is called, and the generator will be placed at the default device at that time, so one needs to be careful when this function is first called. Using a generator placed on a less-ideal device will incur performance regression.
 


 Returns   The global tf.random.Generator object.
tf.random.learned_unigram_candidate_sampler     View source on GitHub    Samples a set of classes from a distribution learned during training.  View aliases  Main aliases 
tf.nn.learned_unigram_candidate_sampler Compat aliases for migration See Migration guide for more details. tf.compat.v1.nn.learned_unigram_candidate_sampler, tf.compat.v1.random.learned_unigram_candidate_sampler  
tf.random.learned_unigram_candidate_sampler(
    true_classes, num_true, num_sampled, unique, range_max, seed=None, name=None
)
 This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max). The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution. The base distribution for this operation is constructed on the fly during training. It is a unigram distribution over the target classes seen so far during training. Every integer in [0, range_max) begins with a weight of 1, and is incremented by 1 each time it is seen as a target class. The base distribution is not saved to checkpoints, so it is reset when the model is reloaded. In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.
 


 Args
  true_classes   A Tensor of type int64 and shape [batch_size, num_true]. The target classes.  
  num_true   An int. The number of target classes per training example.  
  num_sampled   An int. The number of classes to randomly sample.  
  unique   A bool. Determines whether all sampled classes in a batch are unique.  
  range_max   An int. The number of possible classes.  
  seed   An int. An operation-specific seed. Default is 0.  
  name   A name for the operation (optional).   
 


 Returns
  sampled_candidates   A tensor of type int64 and shape [num_sampled]. The sampled classes.  
  true_expected_count   A tensor of type float. Same shape as true_classes. The expected counts under the sampling distribution of each of true_classes.  
  sampled_expected_count   A tensor of type float. Same shape as sampled_candidates. The expected counts under the sampling distribution of each of sampled_candidates.
tf.random.log_uniform_candidate_sampler     View source on GitHub    Samples a set of classes using a log-uniform (Zipfian) base distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.nn.log_uniform_candidate_sampler, tf.compat.v1.random.log_uniform_candidate_sampler  
tf.random.log_uniform_candidate_sampler(
    true_classes, num_true, num_sampled, unique, range_max, seed=None, name=None
)
 This operation randomly samples a tensor of sampled classes (sampled_candidates) from the range of integers [0, range_max). The elements of sampled_candidates are drawn without replacement (if unique=True) or with replacement (if unique=False) from the base distribution. The base distribution for this operation is an approximately log-uniform or Zipfian distribution: P(class) = (log(class + 2) - log(class + 1)) / log(range_max + 1) This sampler is useful when the target classes approximately follow such a distribution - for example, if the classes represent words in a lexicon sorted in decreasing order of frequency. If your classes are not ordered by decreasing frequency, do not use this op. In addition, this operation returns tensors true_expected_count and sampled_expected_count representing the number of times each of the target classes (true_classes) and the sampled classes (sampled_candidates) is expected to occur in an average tensor of sampled classes. These values correspond to Q(y|x) defined in this document. If unique=True, then these are post-rejection probabilities and we compute them approximately.
 


 Args
  true_classes   A Tensor of type int64 and shape [batch_size, num_true]. The target classes.  
  num_true   An int. The number of target classes per training example.  
  num_sampled   An int. The number of classes to randomly sample.  
  unique   A bool. Determines whether all sampled classes in a batch are unique.  
  range_max   An int. The number of possible classes.  
  seed   An int. An operation-specific seed. Default is 0.  
  name   A name for the operation (optional).   
 


 Returns
  sampled_candidates   A tensor of type int64 and shape [num_sampled]. The sampled classes.  
  true_expected_count   A tensor of type float. Same shape as true_classes. The expected counts under the sampling distribution of each of true_classes.  
  sampled_expected_count   A tensor of type float. Same shape as sampled_candidates. The expected counts under the sampling distribution of each of sampled_candidates.
tf.random.normal     View source on GitHub    Outputs random values from a normal distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.normal, tf.compat.v1.random_normal  
tf.random.normal(
    shape, mean=0.0, stddev=1.0, dtype=tf.dtypes.float32, seed=None, name=None
)
 Example that generates a new set of random values every time: 
tf.random.set_seed(5);
tf.random.normal([4], 0, 1, tf.float32)
<tf.Tensor: shape=(4,), dtype=float32, numpy=..., dtype=float32)>
 Example that outputs a reproducible result: 
tf.random.set_seed(5);
tf.random.normal([2,2], 0, 1, tf.float32, seed=1)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[-1.3768897 , -0.01258316],
      [-0.169515   ,  1.0824056 ]], dtype=float32)>
 In this case, we are setting both the global and operation-level seed to ensure this result is reproducible. See tf.random.set_seed for more information.
 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output tensor.  
  mean   A Tensor or Python value of type dtype, broadcastable with stddev. The mean of the normal distribution.  
  stddev   A Tensor or Python value of type dtype, broadcastable with mean. The standard deviation of the normal distribution.  
  dtype   The type of the output.  
  seed   A Python integer. Used to create a random seed for the distribution. See tf.random.set_seed for behavior.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the specified shape filled with random normal values.
tf.random.poisson     View source on GitHub    Draws shape samples from each of the given Poisson distribution(s). 
tf.random.poisson(
    shape, lam, dtype=tf.dtypes.float32, seed=None, name=None
)
 lam is the rate parameter describing the distribution(s). Example: samples = tf.random.poisson([10], [0.5, 1.5])
# samples has shape [10, 2], where each slice [:, 0] and [:, 1] represents
# the samples drawn from each distribution

samples = tf.random.poisson([7, 5], [12.2, 3.3])
# samples has shape [7, 5, 2], where each slice [:, :, 0] and [:, :, 1]
# represents the 7x5 samples drawn from each of the two distributions

 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output samples to be drawn per "rate"-parameterized distribution.  
  lam   A Tensor or Python value or N-D array of type dtype. lam provides the rate parameter(s) describing the poisson distribution(s) to sample.  
  dtype   The type of the output: float16, float32, float64, int32 or int64.  
  seed   A Python integer. Used to create a random seed for the distributions. See tf.random.set_seed for behavior.  
  name   Optional name for the operation.   
 


 Returns
  samples   a Tensor of shape tf.concat([shape, tf.shape(lam)], axis=0) with values of type dtype.
tf.random.set_global_generator Replaces the global generator with another Generator object.  View aliases  Main aliases 
tf.random.experimental.set_global_generator Compat aliases for migration See Migration guide for more details. tf.compat.v1.random.experimental.set_global_generator, tf.compat.v1.random.set_global_generator  
tf.random.set_global_generator(
    generator
)
 This function creates a new Generator object (and the Variable object within), which does not work well with tf.function because (1) tf.function puts restrictions on Variable creation thus reset_global_generator can't be freely used inside tf.function; (2) redirecting a global variable to a new object is problematic with tf.function because the old object may be captured by a 'tf.function'ed function and still be used by it. A 'tf.function'ed function only keeps weak references to variables, so deleting a variable and then calling that function again may raise an error, as demonstrated by random_test.py/RandomTest.testResetGlobalGeneratorBadWithDefun .
 


 Args
  generator   the new Generator object.
tf.random.shuffle     View source on GitHub    Randomly shuffles a tensor along its first dimension.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.shuffle, tf.compat.v1.random_shuffle  
tf.random.shuffle(
    value, seed=None, name=None
)
 The tensor is shuffled along dimension 0, such that each value[j] is mapped to one and only one output[i]. For example, a mapping that might occur for a 3x2 tensor is: [[1, 2],       [[5, 6],
 [3, 4],  ==>   [1, 2],
 [5, 6]]        [3, 4]]

 


 Args
  value   A Tensor to be shuffled.  
  seed   A Python integer. Used to create a random seed for the distribution. See tf.random.set_seed for behavior.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of same shape and type as value, shuffled along its first dimension.
tf.random.stateless_binomial Outputs deterministic pseudorandom values from a binomial distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.stateless_binomial  
tf.random.stateless_binomial(
    shape, seed, counts, probs, output_dtype=tf.dtypes.int32, name=None
)
 The generated values follow a binomial distribution with specified count and probability of success parameters. This is a stateless version of tf.random.Generator.binomial: 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: counts = [10., 20.]
# Probability of success.
probs = [0.8]

binomial_samples = tf.random.stateless_binomial(
    shape=[2], seed=[123, 456], counts=counts, probs=probs)

counts = ... # Shape [3, 1, 2]
probs = ...  # Shape [1, 4, 2]
shape = [3, 4, 3, 4, 2]
# Sample shape will be [3, 4, 3, 4, 2]
binomial_samples = tf.random.stateless_binomial(
    shape=shape, seed=[123, 456], counts=counts, probs=probs)

 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output tensor.  
  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.)  
  counts   Tensor. The counts of the binomial distribution. Must be broadcastable with probs, and broadcastable with the rightmost dimensions of shape.  
  probs   Tensor. The probability of success for the binomial distribution. Must be broadcastable with counts and broadcastable with the rightmost dimensions of shape.  
  output_dtype   The type of the output. Default: tf.int32  
  name   A name for the operation (optional).   
 


 Returns
  samples   A Tensor of the specified shape filled with random binomial values. For each i, each samples[..., i] is an independent draw from the binomial distribution on counts[i] trials with probability of success probs[i].
tf.random.stateless_categorical     View source on GitHub    Draws deterministic pseudorandom samples from a categorical distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.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 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   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].
tf.random.stateless_normal     View source on GitHub    Outputs deterministic pseudorandom values from a normal distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.stateless_normal  
tf.random.stateless_normal(
    shape, seed, mean=0.0, stddev=1.0, dtype=tf.dtypes.float32, name=None
)
 This is a stateless version of tf.random.normal: 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.
 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output tensor.  
  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.)  
  mean   A 0-D Tensor or Python value of type dtype. The mean of the normal distribution.  
  stddev   A 0-D Tensor or Python value of type dtype. The standard deviation of the normal distribution.  
  dtype   The type of the output.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the specified shape filled with random normal values.
tf.random.stateless_parameterized_truncated_normal Outputs random values from a truncated normal distribution.  View aliases  Compat aliases for migration 
See Migration guide for more details. tf.compat.v1.random.stateless_parameterized_truncated_normal  
tf.random.stateless_parameterized_truncated_normal(
    shape, seed, means=0.0, stddevs=1.0, minvals=-2.0, maxvals=2.0, name=None
)
 The generated values follow a normal distribution with specified mean and standard deviation, except that values whose magnitude is more than 2 standard deviations from the mean are dropped and re-picked. Examples: Sample from a Truncated normal, with deferring shape parameters that broadcast. 
means = 0.
stddevs = tf.math.exp(tf.random.uniform(shape=[2, 3]))
minvals = [-1., -2., -1000.]
maxvals = [[10000.], [1.]]
y = tf.random.stateless_parameterized_truncated_normal(
  shape=[10, 2, 3], seed=[7, 17],
  means=means, stddevs=stddevs, minvals=minvals, maxvals=maxvals)
y.shape
TensorShape([10, 2, 3])

 


 Args
  shape   A 1-D integer Tensor or Python array. The shape of the output tensor.  
  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.)  
  means   A Tensor or Python value of type dtype. The mean of the truncated normal distribution. This must broadcast with stddevs, minvals and maxvals, and the broadcasted shape must be dominated by shape.  
  stddevs   A Tensor or Python value of type dtype. The standard deviation of the truncated normal distribution. This must broadcast with means, minvals and maxvals, and the broadcasted shape must be dominated by shape.  
  minvals   A Tensor or Python value of type dtype. The minimum value of the truncated normal distribution. This must broadcast with means, stddevs and maxvals, and the broadcasted shape must be dominated by shape.  
  maxvals   A Tensor or Python value of type dtype. The maximum value of the truncated normal distribution. This must broadcast with means, stddevs and minvals, and the broadcasted shape must be dominated by shape.  
  name   A name for the operation (optional).   
 


 Returns   A tensor of the specified shape filled with random truncated normal values.