zooraff:

On the other hand, I have read somewhere, that NLL recognizes 1D vector of labels and matches it with output layer (after applying logSoftmax, 5 classes as ouput), is it true? It does not work for me either…


Yes, that should work as explained:



 ptrblck:

nn.NLLLoss expects your model to output a tensor of the shape [batch_size, nb_classes] and a target of [batch_size] containing the class indices for a usual multi-class classification use case.


You should also apply F.log_softmax on your output, but this already seems to be the case.
Why does it not work for you? Do you get any error?
After squeezing the target, the shape looks alright.