When we deal with imbalanced training data (there are more negative samples and less positive samples), usually pos_weight parameter will be used.
The expectation of pos_weight is that the model will get higher loss when the positive sample gets the wrong label than the negative sample.
When I use the binary_cross_entropy_with_logits function, I found:
import torch
import torch.nn.functional as F

pos_weight = torch.FloatTensor([5])

preds_pos_wrong =  torch.FloatTensor([0.5, 1.5])
label_pos = torch.FloatTensor([1, 0])
loss_pos_wrong = F.binary_cross_entropy_with_logits(preds_pos_wrong, label_pos, pos_weight=pos_weight)

'''
loss_pos_wrong = tensor(2.0359)
'''

preds_neg_wrong =  torch.FloatTensor([1.5, 0.5])
label_neg = torch.FloatTensor([0, 1])
loss_neg_wrong = F.binary_cross_entropy_with_logits(preds_neg_wrong, label_neg, pos_weight=pos_weight)

'''
loss_neg_wrong = tensor(2.0359)
'''


The losses derived from wrong positive samples and negative samples are the same, so how does pos_weight work in the imbalanced data loss calculation?