Thank you for your replies!
I guess Chris’ answer is the more general solution.
However, in my case, I think masking should work better. Just for being sure: using the regular output, I should adjust my targets so that they are of size (n_batches, padded_len) by filling them with sequence_len times the class_index and pad them together. So assuming I use pad value 0 for my targets, I should then use ignore_index=0 in my Loss?
I’m just asking this as I’m a bit curious about the targets. 
Regards,
Unity05