My loss function is:
def loss_fn(inp, target):
    zeros_sum = (target == 0).sum(dim = 0).float()
    one_sum = (target == 1).sum(dim = 0).float()

    pos_weight = zeros_sum / one_sum 
    loss_fn = torch.nn.BCEWithLogitsLoss(reduction='mean', pos_weight=pos_weight)
    
    loss = loss_fn(inp, target)

    return loss

However, in certain batches, there are no one_sum examples for a particular class. How do I deal with pos_weight in those cases?