It depends on your loss function.
If you use nn.CrossEntropyLoss or nn.NLLLoss for a classification use case, then you are right.
The output of your model should give logits (or log probabilities) for each sample in the batch and each class, i.e. its output will be [batch_size, nb_classes].
The targets however are just holding the class index for each sample in the batch, i.e. its shape will be [batch_size].
However, if you use another loss function, e.g. nn.MSELoss, the shapes of the model’s output and target should be the same.
The docs 78 give an overview of the different loss functions and the expected shapes.