Imbalance of pos/neg examples within each class with MultiLabelSoftMarginLoss

Hello. I read a lot of posts about class imbalance, but I am not sure that they are applicable in my case because the majority is talking about the imbalance between classes in a multi-class classification problem, while in my case I am rather concerned about the imbalance of positive and negative examples within each class. The following is a tally of the number of pos/neg examples with each class:

Total number of examples = 4000
class1: n_positive = 948, n_negative = 4000 - 948 = 3052
class2: n_positive = 575, n_negative = 4000 - 575 = 3425
class3: n_positive = 917, n_negative = 4000 - 917 = 3083
class4: n_positive = 672, n_negative = 4000 - 672 = 3328

So we have a lot of rows in the dataset where there is [0,0,0,0]

As you can see there is an imbalance between classes as well. I am using MultiLabelSoftMarginLoss loss function which has a weight parameter to tackle that problem. I can pass to it a tensor of size C with the following values [1/948, 1/575, 1/917, 1/672] (if I thinking correctly?) to get rid of classes imbalance.

But most importantly how to deal with the issue of imbalance within each class. For example, there are 948 only positive examples for class 1 and 3052 negative examples. I guess that I should weight them as well. How to tell the loss function to not only penalize the most frequently occuring class but also most frequently occuring value (0/1) within each class, otherwise model will always predict [0,0,0,0].

Maybe in that case BCEWithLogitsLoss with pos_weight = [3052/948, 3425/575, 3083/917, 3328/671] and weight = [1/948, 1/575, 1/917, 1/672] (as in MultiLabelSoftMarginLoss)? What do you think about it?

Any advice would be very appreciated.

I was also thinking about this approach while reading your post, so I would at least try it and see, if your training benefits from it.