Thank you so much for your reply  it helped me a lot. But now I have questions about  nn.BCEWithLogitsLoss and using it with weights.
For example I have 2 classes samples: y = [0,1,1,1,1,0,0,1,0]
and I’d like to get the highest recall, how should I set up weights properly?