so yo need to remove
    for i in range(len(y_pred)):

        if y_pred[i] >= 0.5:

            y_pred[i] = 1

        else: 

            y_pred[i] = 0

because by doing this you are converting probablities to labels but bceLoss expects probablities in “y_pred”
also for this you need to apply sigmoid function to last layer output!!
and last layer should be a linear layer that transforms data to n*1 dimensions