Based on the error message it seems that a weighted loss is used. While logits (or log probabilities) for 2 classes are apparently given as the output of the model (could you confirm this?), the weight tensor contains 5 values (i.e. for 5 classes).
It’s unclear how the criterion is created as it seems to be hidden in the train() method so you should make sure to define weights for the valid two classes only.