But I still see the same error using your code. It is because
a = torch.LongTensor(3).random_(5)
for a_ in a:
    print(a_.size())

returns
torch.Size([])
torch.Size([])
torch.Size([])

But nn.CrossEntropyLoss()  needs target to have shape  torch.Size([1]).