Assuming I’m remembering correctly, BCEWithLogitsLoss is expecting an all-ones encoding rather than a sparse representation, i.e. the target labels should be length 18 with each value representing one of the classes.