Multi binary-class classification

Hello peeps,

I have some audio data for which i computed the audio features. The labels for each input feature is 20 binary classes. i.e. for each input element there are 20 classes (1 or 0).
My initial understanding is that this is a multi-label classification that can be addressed using nn.BCELoss.

Can you guys let me know if I got this right and to explain how nn.BCELoss works?

Thank you

Hi @lima, nn.BCELoss is designed for binary classification task. The prediction and label are both of shape (batch, ...).
In your case, you have 20 classes, which is a multi-class classification task. You can use nn.CrossEntropyLoss where the prediction is a float tensor of shape (batch, class, ...) and the label is a long tensor of shape (batch, ...).

Hi @nateanl thank you for your answer. but what about the fact that each class should either be 1 or 0?

I see, if the input has more than one classes that are labeled as 1, then you should use nn.BCELoss and make your prediction and label both of shape (batch, class).

1 Like

Hi @nateanl The idea is the following. I have computed the mfcc features for some audio data, and I have trained my model to do phoneme classification.
Now instead of the phoneme classification, I would like to do a phonetic feature classification (i.e. classify the individual phonetic features (total 20) for each audio frame). I believe nn.BCELoss can do the job, but what about the prediction and labels shape?

If you are dealing with multi-label classification sigmoid + nn.BCELoss should be what you are looking for; and if you are looking for multi-class classification (each of your sample will belong to only one of the 20 classes) then softmax + nn.CrossEntropyLoss are the things.

1 Like

Thank you @xdwang0726