# How to get the loss function used in NetTrain?

When the third argument to NetTrain is set to Automatic, how can you tell what loss function it actually used and extract it?

Looking at the docs, I don't see it as a property that can be asked for in the fourth argument.

I agree it would be nice if you could query this information interactively from the progress window after starting a training session. But using a property (4th argument of NetTrain) you can explicitly ask for the 'loss network', which is the network in which loss layers have been attached and which is used to actually do the training.

net = LinearLayer[];
data = {1 -> 1.9, 2 -> 4.1, 3 -> 6.0, 4 -> 8.1};
NetTrain[net, data, Automatic, "LossNet", MaxTrainingRounds -> 1]


In this case you'll see it is a NetGraph that uses a MeanSquaredLossLayer. If the net already has loss layers the loss network is typically the same as the training network.

The actaul internal function is NeuralNetworksAttachLoss[net, spec] if you want access to it directly. You can leave spec off if you just want the automatic choice.

• The "LossNet" argument does not appear to work in version 11.3. Is there a new way to get the information? – Seth Chandler Aug 10 '18 at 18:13

In the doc of NetTrain`,it says

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

• But what is it exactly, are there explicit rules for each type of layer? – M.R. Sep 2 '17 at 1:44