nn.CrossEntropyLoss is used for multi-class classification use cases, i.e. each sample belongs to only one class (out of multiple classes). nn.BCEWithLogitsLoss is used for a binary classification use case, i.e. each sample belongs to the positive or negative class (or something in between would even be possible), or for multi-label classification use cases, i.e. each samples belongs to zero, one, or multiple classes.