Aren’t u using CrossEntropyLoss? I think u should use cross entropy for multi-class classification.
For the ordinary BCELoss, according to here, the weight are just a number that is multiplied to each value in a batch, so the shape of weight must equal to the shape of a single batch.
>>> import torch as tc
>>> from torch import nn
>>> bsz = 10
>>> loss0 = nn.BCELoss(weight = tc.full([bsz], 0.5))  # "weight" can contain values of any number.
>>> loss1 = nn.BCELoss()
>>> inp, tar = tc.zeros(bsz), tc.ones(bsz)
>>> loss0(inp, tar)
tensor(13.8155)
>>> loss1(inp, tar)
tensor(27.6310)