The implementation looks alright for a 2-class classification.
As said before, you could also use a single output unit and then nn.BCEWithLogitsLoss for a binary classification, but your approach should also work.