Pata_Naheen:

output shape: torch.Size([2])


Since Y is of shape (1000,1,2), then indexing this tensor by target = Y[i] will make target to have shape (1, 2). But the input to the loss function defined as torch.nn.CrossEntropyLoss needs input to have shape (N,C) and target to be of shape (N). (N is the batch-size)
So, I think you should reshape both target and the output of your model accordingly. So, the target should have shape (1), and output should have shape (1, 2). But I think you are using one-hot vectors for the target, so that needs to be changed to be a tensor of class labels from {0, 1},