(logits, dtype=tf.int32,
                       sample_shape=(), seed=None)
return _call_sampler(_sample_n, sample_shape)
Samples from categorical distribution.
Samples from categorical distribution.
Samples from categorical distribution .
def categorical_sample(logits, dtype=tf.int32,
                       sample_shape=(), seed=None):
  """Samples from categorical distribution."""
  logits = tf.convert_to_tensor(logits, name="logits")
  event_size = tf.shape(logits)[-1]
  batch_shape_tensor = tf.shape(logits)[:-1]
  def _sample_n(n):
    """Sample vector of categoricals."""
    if logits.shape.ndims == 2:
      logits_2d = logits
    else:
      logits_2d = tf.reshape(logits, [-1, event_size])
    sample_dtype = tf.int64 if logits.dtype.size > 4 else tf.int32
    draws = tf.multinomial(
        logits_2d, n, seed=seed, output_dtype=sample_dtype)
    draws = tf.reshape(
        tf.transpose(draws),
        tf.concat([[n], batch_shape_tensor], 0))
    return tf.cast(draws, dtype)
  return _call_sampler(_sample_n, sample_shape)
def categorical_sample ( logits , dtype = tf . int32 , sample_shape = ( ) , seed = None ) : logits = tf . convert_to_tensor ( logits , name = "logits" ) event_size = tf . shape ( logits ) [ - 1 ] batch_shape_tensor = tf . shape ( logits ) [ : - 1 ] def _sample_n ( n ) : """Sample vector of categoricals.""" if logits . shape . ndims == 2 : logits_2d = logits else : logits_2d = tf . reshape ( logits , [ - 1 , event_size ] ) sample_dtype = tf . int64 if logits . dtype . size > 4 else tf . int32 draws = tf . multinomial ( logits_2d , n , seed = seed , output_dtype = sample_dtype ) draws = tf . reshape ( tf . transpose ( draws ) , tf . concat ( [ [ n ] , batch_shape_tensor ] , 0 ) ) return tf . cast ( draws , dtype ) return _call_sampler ( _sample_n , sample_shape )