Is SoftmaxLayer broken in version I know, it's probably me. Here's a MWE of the issue.

enter image description here

Note that this works fine if e.g. Exp is substituted for SoftmaxLayer[].

enter image description here


1 Answer 1


It works if you explicitly specify the loss function:

NetTrain[testnet, {{1, 2} -> {0.2, 0.8}}, 
 LossFunction -> CrossEntropyLossLayer["Binary"]]

The default is Automatic, which chooses CrossEntropyLossLayer["Index"] and expects indices as training targets.

From the documentation of LossFunction:

When a loss layer is chosen automatically for a port, the loss layer to use is based on the layer within the net whose output is connected to the port, as follows:

SoftmaxLayer[] -> use CrossEntropyLossLayer["Index"]

ElementwiseLayer[LogisticSigmoid] -> use CrossEntropyLossLayer["Binary"]

NetPairEmbeddingOperator[] -> use ContrastiveLossLayer[]

other non-loss layers -> use MeanSquaredLossLayer[]

loss layers -> use unchanged


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.