[SOLVED] Multi-target not supported error in Cross entropy loss

Hi,

I got stuck at an error:

exception has occurred: RuntimeError

multi-target not supported at /pytorch/aten/src/THNN/generic/ClassNLLCriterion.c:21

loss = criterion(model(x_train), y_train)

here both, model(x_train) and y_train are tensors of the shape (4, 2), where 4 is my batch size and 2 is my class size, i.e. i can have only 2 labels.

Cross entropy should give the error between my softmax output over classes and the one hot encoded class labels, I am doing exactly that, still getting an error.

Does cross entropy not support minibatches?

okay, solution is just to use the target labels --> no need for one hot encoding of the class labels

2 Likes