I have a time series classification task in which I should output a classification of 3 classes for every time stamp t.
All data is labeled per frame.
In the data set are more than 3 classes [which are also imbalanced].
I want to use CrossEntropyLoss.
My net should see all samples sequentially, because it uses that for historical information.
Thus, I can’t just eliminate all irrelevant class samples at preprocessing time.
In case of a prediction on a frame which is labeled differently than those 3 classes, I don’t care about the result.

My model outputs a vector of 3 log probabilities, but the label batch has more than 3 labels. Using the weight= parameter with 0 weights for classes I want to ignore yields
{RuntimeError}weight tensor should be defined either for all 3 classes or no classes but got weight tensor of shape: [5] at C:/w/b/windows/pytorch/aten/src\THCUNN/generic/ClassNLLCriterion.cu:44
because the weight's shape was larger than that of the model output.

How to do this correctly in Pytorch?