Because your output has shape [136, 1], I conclude that your
network has a single output, and you are performing a single-label
(in contrast to multi-label) binary classification problem.
Even though you technically have two classes (the “0” or “no”
class and the “1” or “yes” class), the pos_weight constructor
argument of BCEWithLogitsLoss only takes a single weight,
namely that for the “1” (“positive”) class.
Thanks for your reply. I have much more of my 0 class and not much of my 1 class. So you are saying I should pass in just the weight of my 1 class. Would that be 28.36 / 0.5090?
0.5090 is the “weight” of my 0 class and 28.36 is the weight of my 1 class.
But, to be concrete, let’s take an extreme example:
Let’s say that your entire training set consists of 1,000 samples,
990 class-“0” samples, and 10 class-“1” samples. If you want
to reweight the classes in your loss function to fully account for
this imbalance, you would use: