Assuming each sample can have zero, one, or multiple active classes, you could let the model return logits in the shape [batch_size, nb_classes] where each value in nb_classes would correspond to the logit for the corresponding class index.
The target could then be multi-hot encoded, where a zero would indicate an inactive and a one an active class. For the posted examples the target would thus be:
[0,1,5,3]
target = torch.tensor([[1, 1, 0, 1, 0, 1, 0]]).float()

[0, 2]
target = torch.tensor([[1, 0, 1, 0, 0, 0, 0]]).float()