Multi Label Classification in pytorch
Hi Everyone, I’m trying to use pytorch for a multilabel classification, has anyone done this yet? I have a total of 505 target labels, and samples have multiple labels (varying number per sample). I tried to solve this by banalizing my labels by making the output for each sample a 505 length vector with 1 at position i, if it maps to label i, and 0 if it doesn’t map to label i. Then, I tried to use the multilabelmarginloss(). Problem I’m facing - with more iterations, the output of the model should move towards a sparse vector with most elements 0 and a few elements 1, but it is actually moving towards a vector with often very large negative values. Can some one tell me how to go about this? Thanks!
SpandanMadan
Do you have a smaller dataset? 505 target labels with very few samples might just not train well. Maybe add weight decay?
smth
SpandanMadan
Can you tell us what kind of loss function you used?
jlee
I’d like to try doing the same. Can you suggest any small multi-label datasets, (i.e. samples with multiple labels), to start experimenting with? I’m a novice with this type of problem, so not sure where’s the simplest place to start? Best regards, Ajay
AjayTalati
i’m also learning pytorch, and take it as an exercise, the input is BCHW, using multilabelmarginloss()
dablyo
Kind regards, Ajay
AjayTalati
I’ve execute train loop in python console by this way: then
dablyo
I got simiar result, I got zero loss from the second epoch. Do you find the reason?
sshuair
Hi there, hope that helps? Aj
AjayTalati
bartolsthoorn
Kind regards, Ajay
AjayTalati
@AjayTalati Now once you have your prediction, you need to threshold. 0.5 is the default naive way but it’s probably not optimal. In any case, once you get there, great !
mratsim
Does anyone understand how MultiMarginLoss is calculated exactly? I’m not sure I understand completely.
nabergh
mratsim
Hi Everyone, However, my obtained result isn’t good at all. As a result, my precise questions are as follows:
ahkarami
Your loss function is correct btw.
mratsim
ahkarami
the MultiLabelMarginLoss doesn’t work, loss become 0 in 2nd minibatch. I’m whole confused
dablyo
Hi, I used BCELoss. It’s the standard for multi label classification in many ways. Give it a shot.
SpandanMadan