Solved by ptrblck in post #4 
              
              
                That sounds right! 
I’m not sure, what S samples are in your example, but here is a small dummy code snippet showing, what I mean: 
batch_size = 10
nb_classes = 2

model = nn.Linear(10, nb_classes)
weight = torch.empty(nb_classes).uniform_(0, 1)
criterion = nn.CrossEntropyLoss(weight=weight, reducti…