The input and target shapes look as if you were dealing with a multi-label classification use case, i.e. each sample might belong to zero, one, or more classes.
If that’s the case, then your approach should be correct.
However, the example targets seem to be one-hot encoded, which looks like a multi-class classification, where each sample belongs to one class only.
In that case you should use nn.CrossEntropyLoss and use class indices as your target tensor via: target = torch.argmax(target,1).