Why would you like to pass the target in a one-hot format?
This would not change the fact that there are many class ids without training examples or do I misunderstand it?
I would recommend to remap the class indices to a valid range, i.e. [0, maxClassID].
Otherwise your model will output a large output tensor where a lot of logits are meaningless.
E.g. let’s assume your original target had 1000 classes. Your model would therefore output a tensor of shape [batch_size, 1000]. If your subset has only two classes, e.g. class0 and class999, your model might predict unknown classes (class1-class998).
How would you deal with it, if the maximal prediction is class789?