Thanks a lot for the reply!
I didn’t quite understand that the ground truth couldn’t be one-hot encoded, while the output of my network should have switched shape [batch, N_classes, length] instead of [batch, length, N_classes].
But now, say my vector also has a positional encoding, so it is no longer of dimension [batch, length, N_classes] but now [batch, length, N_classes + 4], and can take two positive values (one for N_class, and one for the positional encoding), ex :
label = [0,1,0,0,0,...] #shape [1, 1, 21] for a single item and single row
pos = [0, 0, 1, 0] #shape [1, 1, 4] for a single item and single row
final_encoding = torch.cat([label,pos], dim = 2) #shape [1,1,25] for a single item/row

So now, my network predict both the class AND the positional encoding. If I slice my tensor and then run two different CrossEntropyLoss for each of the subtensor, will Autograd still work ?
Best,
Richie