Hi @Dmitriy. The reason it fails is because the last batch of your epoch will be of size 1 when using  batch_size = 10 or batch_size = 20, as your dataset length is 23761. Because of this, labels.size() = torch.Size([1, 1]) will result in a size of torch.Size([]) after



 Dmitriy:

labels = labels.squeeze()


giving the error you mention. To solve this replace the line by labels = labels.squeeze(1) to avoid squeezing the batch dimension, or set drop_last=True in your Dataloader.
Note moreover that nn.CrossEntropyLoss() already performs nn.LogSoftmax() (see https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html?highlight=crossentropyloss#torch.nn.CrossEntropyLoss 2). Doublecheck if



 Dmitriy:

return F.logsigmoid(x)


is desired. Hope this helps!