Output Binary Array

I am just starting with PyTorch and I can’t seem to figure out how to output an array of 6 binary values or probabilities that do not sum to 1. All of my training data has labels such as [0, 1, 1, 0, 1, 1] for a single entry representing the presence of certain chemical compounds.

I’m just trying to get an output value that is similar to my labels or a collection of probabilities such as [0.0, 0,9, 0.7, 0.1, 0,8, 0.9]. I don’t know what that would be called and I’m sorry I can’t phrase my question well.

It looks like you are dealing with a multi-label calssification, i.e. each sample might have more than a single ground truth class.
If that’s the case, you could use nn.BCEWithLogitsLoss and use an output layer as:

nn.Linear(in_features, nb_classes)

Each unit in the output layer will be treated as giving the probability for the corresponding class independently.
The target should be a FloatTensor having the same shape as your model output in this case, e.g. [batch_size, nb_classes].

Let us know, if you need more information or get stuck somewhere.

1 Like