How determine class weights for 1 output

I am creating a NN for classification with 1 binary output. I’m using BCELoss for my loss function. My dataset is unbalanced: 97% for 0/false & 3% for 1/true. So I’d like to adjust the class weights during the loss function (nn.BCELoss(weights= ???)). I don’t know what the function is asking for???

If I send/use (weights=(.97, .03)) I get an error message telling me (I think) that I’m sending two values when pytorch is expecting 1 (one output class).

Please help me understand. What is pytorch expecting? Is it expecting 1 number? is so, how do I calculate it?

Thank you for taking the time to read and consider my problem!!!

Use nn.BCEWithLogitsLoss and provide the pos_weight argument as described in the docs:

For example, if a dataset contains 100 positive and 300 negative examples of a single class, then pos_weight for the class should be equal to 300/100=3. The loss would act as if the dataset contains 3×100=300 positive examples.