Weighted Multi-class loss

Please may I know how to code weighted multiclass loss ?

Assuming you are using nn.CrossEntropyLoss you could pass the weight argument as described in the docs:

weight (Tensor, optional ) – a manual rescaling weight given to each class. If given, has to be a Tensor of size C

1 Like