Hi Daniel!



 Danielr13:

My output obviously is no longer on a 0:1 scale it can now become negative and above 1 but I dont think this matters much since taking the maximum of the output will still return the correct prediction on the test data.


Yes, this is correct.  Taking the argmax() of the output of your final
Linear layer gives you the integer label of the class that your model
is predicting to be the most likely.  (Just to be precise, you are taking
the argmax() rather than the max()).  The fact that you are applying
argmax() to logits instead of probabilities doesn’t change the fact
that you are determining the label of the most likely class.


Could you expand more on how to use the Cross-Entropy Loss without one-hot encoding? I thought that it was necessary for multi-class problems?


No, one-hot encoding is not necessary.  Leaving pytorch aside, you
might elect to specify your labelled classes with one-hot encoding or
with integer class labels (or some other way).  It’s the same information,
just packaged differently.
Pytorch’s CrossEntropyLoss requires that you pass in integer class
labels for its target.  (Note, in your code you are passing in integer
class labels – you convert your one-hot labels to integer labels right
in your call to criterion().)


My current targets are integers ranging from 1:3.


For CrossEntropyLoss you want your integer class labels to range
over {0, 1, 2} (so you can simply subtract 1 from your current labels).
In general, CrossEntropyLoss takes class labels that range over
[0, nClass - 1].
As an aside, I don’t know precisely what your:
y_train_encoded = to_categorical(y_train)[:,1:4]

is doing, but I assume that it is converting your initial 1-2-3 integer
labels to one-hot encoding.  Then your torch.max(y_train, 1)[1]
(in effect, argmax()) is converting your one-hot labels to 0-1-2
integer labels.  Of course, you can more simply convert 1-2-3 labels
to 0-1-2 labels by subtracting 1.
Best.
K. Frank