How to use Weighted BceLosswithLogit in multi-lable classfication?

Hi Everyone,I’m trying to use pytorch for a multilabel classification.

I used nn.BCEWithLogitsLoss() at first,but it did not work.

There are 28 classes and half of the data in class 0 and class 25 (quite imbalanced).

So I try to add weight in BCEWithLogitsLoss() to solve the problem but do not know how.

Can some one tell me how to go about this?

Thanks!!!

You might find this explanation useful, it’s just on this topic.