Here is an example using nn.CrossEntropyLoss
showing how the loss weighting is applied on an unreduced loss and normalized afterwards.
The DataLoader
returns a batch containing samples in dim0
(the batch dimension) so you can directly access them.