Fine-Tuning-BERT icon indicating copy to clipboard operation
Fine-Tuning-BERT copied to clipboard

Multi-label classification issue

Open rajae-Bens opened this issue 3 years ago • 2 comments

Hi,

thank s for this great tutorial I want to apply this for a multi label text classification problem. My labels are of this format tensor([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]]) I changed the softmax function in the bert model by the sigmoid function but when I tried to train the model I got this error multi-target not supported at /pytorch/aten/src/THCUNN/generic/ClassNLLCriterion.cu:18

Could u help plz thank u

rajae-Bens avatar Sep 28 '20 10:09 rajae-Bens

Hi, you don't have to change the softmax function. Just replace the output units from 2 to the number of classes in your dataset in the layer below:

self.fc2 = nn.Linear(512,2)

prateekjoshi565 avatar Sep 28 '20 11:09 prateekjoshi565

First, thank u for responding. Well, I am confused now because in all tutorials Ive read about multi label classification, they all recommend using sigmoid for this kind of problems. Can u explain more plz Thank u

rajae-Bens avatar Sep 28 '20 12:09 rajae-Bens