(p, axis=None, temperature=1)
return p
Apply the softmax transform to an array of categorical distributions.

  Args:
    p: an array of categorical probability vectors, possibly unnormalized.
    axis: the axis that spans the categories (default: -1).
    temperature: if not 1, transform the distribution by dividing the log
        probabilities and renormalizing. Values greater than 1 increase entropy,
        values less than 1 decrease entropy. A value of 0 yields a deterministic
        distribution that chooses the mode.

  Returns:
    An array of categorical probability vectors, like `p` but tempered and
    normalized.
Apply the softmax transform to an array of categorical distributions.
Apply the softmax transform to an array of categorical distributions .
def softmax(p, axis=None, temperature=1):
  """Apply the softmax transform to an array of categorical distributions.

  Args:
    p: an array of categorical probability vectors, possibly unnormalized.
    axis: the axis that spans the categories (default: -1).
    temperature: if not 1, transform the distribution by dividing the log
        probabilities and renormalizing. Values greater than 1 increase entropy,
        values less than 1 decrease entropy. A value of 0 yields a deterministic
        distribution that chooses the mode.

  Returns:
    An array of categorical probability vectors, like `p` but tempered and
    normalized.
  """
  if axis is None:
    axis = p.ndim - 1
  if temperature == 0.:
    # NOTE: in case of multiple equal maxima, returns uniform distribution.
    p = p == np.max(p, axis=axis, keepdims=True)
  else:
    # oldp = p
    logp = np.log(p)
    logp /= temperature
    logp -= logp.max(axis=axis, keepdims=True)
    p = np.exp(logp)
  p /= p.sum(axis=axis, keepdims=True)
  if np.isnan(p).any():
    pdb.set_trace()
  return p
def softmax ( p , axis = None , temperature = 1 ) : if axis is None : axis = p . ndim - 1 if temperature == 0. : # NOTE: in case of multiple equal maxima, returns uniform distribution. p = p == np . max ( p , axis = axis , keepdims = True ) else : # oldp = p logp = np . log ( p ) logp /= temperature logp -= logp . max ( axis = axis , keepdims = True ) p = np . exp ( logp ) p /= p . sum ( axis = axis , keepdims = True ) if np . isnan ( p ) . any ( ) : pdb . set_trace ( ) return p