represents a softmax net layer.


represents a softmax net layer that uses level n as the normalization dimension.

Details and Options

  • SoftmaxLayer[][input] explicitly computes the output for input.
  • SoftmaxLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • When given a NumericArray as input, the output will be a NumericArray.
  • SoftmaxLayer is typically used inside NetChain, NetGraph, etc. to normalize the output of other layers in order to use them as class probabilities for classification tasks.
  • SoftmaxLayer can operate on arrays that contain "Varying" dimensions.
  • SoftmaxLayer exposes the following ports for use in NetGraph etc.:
  • "Input"a numerical array of dimensions d1×d2××dn
    "Output"a numerical array of dimensions d1×d2××dn
  • When it cannot be inferred from other layers in a larger net, the option "Input"->n can be used to fix the input dimensions of SoftmaxLayer.
  • SoftmaxLayer[] is equivalent to SoftmaxLayer[-1].
  • SoftmaxLayer effectively normalizes the exponential of the input array, producing vectors that sum to 1. For the default level of -1, the innermost dimension is used as the normalization dimension.
  • When SoftmaxLayer[-1] is applied to a vector v, it produces the vector Normalize[Exp[v],Total]. When applied to an array of higher dimension, it is mapped onto level -1.
  • When SoftmaxLayer[n] is applied to a k-dimensional input array x_(d_(1) ... d_(k)), it produces the array , where n is the summed-over index of x.
  • SoftmaxLayer[,"Input"shape] allows the shape of the input to be specified. Possible forms for shape are:
  • na vector of size n
    {d1,d2,}an array of dimensions d1×d2×
    {"Varying",d2,d3,}an array whose first dimension is variable and remaining dimensions are d2×d3×


open all close all

Basic Examples  (2)

Create a SoftmaxLayer:

Click for copyable input

Create a SoftmaxLayer that takes a vector of length 5 as input:

Click for copyable input

Apply the layer to an input vector:

Click for copyable input

The elements of the result sum to 1:

Click for copyable input

Scope  (5)

Properties & Relations  (3)

Neat Examples  (1)

Introduced in 2016
Updated in 2018