There is a built-in function for BCELoss exactly as I written. Do not need to implement it yourself as if you look at the issue it is for 2017 and it is closed. See this thread about it BCELoss vs BCEWithLogitsLoss 26.
About the error, your model’s output has shape [batch_size, 2] and I don’t know about the labels but based on error, your labels have shape []batch_size, 25]. Can you explain the labels?