Class Softmax

All Implemented Interfaces:
Activation

public class Softmax extends AbstractActivation
Softmax converts a real vector to a vector of categorical probabilities.

The elements of the output vector are in range (0, 1) and sum to 1.

Each vector is handled independently. The axis argument sets which axis of the input the function is applied along.

Softmax is often used as the activation for the last layer of a classification network because the result could be interpreted as a probability distribution.

The softmax of each vector x is computed as: exp(x) / tf.sum(exp(x)).

The input values in are the log-odds of the resulting probability.

  • Field Details

  • Constructor Details

    • Softmax

      public Softmax()
      Creates a softmax activation where the default axis is AXIS_DEFAULT which indicates the last dimension.
    • Softmax

      public Softmax(int axis)
      Creates a Softmax activation
      Parameters:
      axis - The dimension softmax would be performed on.
    • Softmax

      public Softmax(Map<String,Object> config)
      Creates a Softmax activation from a config map.
      Parameters:
      config - the configuration map, if the map contains an entry for axis that value is used, otherwise AXIS_DEFAULT is used.
      Throws:
      IllegalArgumentException - if the configuration contains unsupported keys for this class or if the value for the name key does not match the name for the Activation
  • Method Details

    • softmax

      public static <T extends TNumber> Operand<T> softmax(Ops tf, Operand<T> input)
      Converts a vector of values to a probability distribution along the last axis.

      The elements of the output vector are in range (0, 1) and sum to 1.

      Each vector is handled independently. The axis argument sets which axis of the input the function is applied along.

      Softmax is often used as the activation for the last layer of a classification network because the result could be interpreted as a probability distribution.

      The softmax of each vector x is computed as exp(x) / tf.reduce_sum(exp(x)). The input values in are the log-odds of the resulting probability.

      Type Parameters:
      T - teh data type of the input
      Parameters:
      tf - the TensorFlow Ops
      input - the input
      Returns:
      the output of softmax transformation (all values are non-negative and sum to 1).
    • softmax

      public static <T extends TNumber> Operand<T> softmax(Ops tf, Operand<T> input, Operand<TInt32> axis)
      Converts a vector of values to a probability distribution.

      The elements of the output vector are in range (0, 1) and sum to 1.

      Each vector is handled independently. The axis argument sets which axis of the input the function is applied along.

      Softmax is often used as the activation for the last layer of a classification network because the result could be interpreted as a probability distribution.

      The softmax of each vector x is computed as exp(x) / tf.reduce_sum(exp(x)). The input values in are the log-odds of the resulting probability.

      Type Parameters:
      T - teh data type of the input
      Parameters:
      tf - the TensorFlow Ops
      input - the input
      axis - Integer, axis along which the softmax normalization is applied.
      Returns:
      the output of softmax transformation (all values are non-negative and sum to 1).
    • getConfig

      public Map<String,Object> getConfig()
      Gets a configuration map with entries
      • axis and value set with axis.
      Specified by:
      getConfig in class AbstractActivation
      Returns:
      config the configuration map
    • call

      public <T extends TNumber> Operand<T> call(Ops tf, Operand<T> input)
      Gets the calculation operation for the activation.
      Type Parameters:
      T - the data type of the input and the result
      Parameters:
      tf - the TensorFlow Ops
      input - the input tensor
      Returns:
      The operand for the activation
    • getName

      public String getName()
      Get the name of the activation as known by the TensorFlow Engine
      Specified by:
      getName in class AbstractActivation
      Returns:
      the name of the activation as known by the TensorFlow Engine
    • getAxis

      public int getAxis()
      Gets the axis along which the softmax normalization is applied.
      Returns:
      the axis along which the softmax normalization is applied.