Hi,
I was trying the weight parameter of the cross-entropy loss, and I observed that I’m achieving the same results when I’m using the default reduction parameter:
>>> import torch

>>> input = torch.randn(1, 5, requires_grad=True)
tensor([[ 1.2900,  0.4519, -0.2622, -0.5862, -0.5304]], requires_grad=True)

>>> target = torch.empty(1, dtype=torch.long).random_(5)
tensor([0])

>>> weights = torch.randn(5).abs()
tensor([1.4737, 0.8730, 0.7921, 0.2246, 1.5051])

>>> cross_entropy = torch.nn.CrossEntropyLoss()
>>> cross_entropy_weighted = torch.nn.CrossEntropyLoss(weight=weights)

>>> cross_entropy(input,target)
tensor(0.6727, grad_fn=<NllLossBackward>)

>>> cross_entropy_weighted(input,target)
tensor(0.6727, grad_fn=<NllLossBackward>)

Am I doing the weighting correctly? How is it supposed to be used the weight parameter of cross-entropy loss?
Thanks