Construct a net that explicitly computes a loss :
In[]:=
net=NetGraph[{LinearLayer[2],SoftmaxLayer[],MeanSquaredLossLayer[]},{1->2->3},"Input"->"Scalar"]
Out[]=
NetGraph

uniniti
aliz
ed
Number of inputs:
2
Loss
port:
real

Initialize the net and evaluate it on an input :
In[]:=
net=NetInitialize[net];
In[]:=
net[<|"Input"->1,"Target"->{2,3}|>]
Out[]=
4.15388