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).