For a multi-class classification use case nn.CrossEntropyLoss expects a model output containing logits in the shape [batch_size, nb_classes] and a target tensor in the shape [batch_size] containing class indices in the range [0, nb_classes-1].
Based on this error:



 A_Shamsadini:

IndexError: Target 1 is out of bounds.


I would guess that your model returns an output in the shape [batch_size, 1] and thus (in the multi-class classification setup) returns a single logit for class0.
In case you are working on a binary classification, use nn.BCEWithLogits instead or keep nn.CrossEntropyLoss and return logits for both classes via an output in the shape [batch_size, 2].