Label Layout in Multi-Class Classification

I am a bit new to ML and PyTorch and I’ve been trying to get to grips with this all. I’m trying to train an LSTM that gives me probabilites for my multi-class data. For example, I have a sentence and each sentence can be given a label from 0 to 4 (and only one label, so it’s not multi-label classification).

Right now, I was working from an example (using my own data), but it seems that was for binary classification. When passing y to my model during training, it appears that it is only a tensor of labels corresponding to each sentence like [1,4,2,0,2,2,3,1] (so that would be a batch of 8 sentences, each sentence given one label). If I want to do multi-class, must I pass y so that it looks like [0,0,1,0,0], which correspomds to label 2? I’m just not sure at all what way my labels must be passed for this.

Thanks in advance.

The first approach of passing the class indices to the criterion, which should be nn.CrossEntropyLoss or nn.NLLLoss, is correct. Both loss functions expect a target containing the class indices and are not expecting a one-hot encoded target (which would be the second approach).