# classification problem in pytorch with loss function CrossEntropyLoss returns negative output in prediction

I am trying to train and predict SVHN dataset (VGG architecture). I get very high validate/test accuracy by just getting the largest output class. However, the output weights are of large positive and negative numbers. Are they supposed to parsed as exp(output)/sum(exp(output)) to be converted to probability? Thank you!

The numbers to which you are referring are probably the logits of the NN. The logits have to be transformed using a activation function which could be :

• Softmax ( which you shown ) for classification tasks.

• Linear activation function for regression tasks.

Softmax activation function :

The mathematical notion is as follows :

$$\Large S( y_i ) = \frac{ e^{y_i}}{ \sum e^{y_i} }$$

It converts the logits to class probabilities which sum upto 1. It is widely used in multiclass classification problems.

CNNs for classification need to produce class probabilities which are produced by a softmax activation function at the output layer.