Target size that is different to the input size

Thanks a lot.
I’m not familiar with pytorch. Thanks for your help.
I changed what you have mentioned:

        
self.bert = BertForSequenceClassification.from_pretrained(BERT_MODEL_NAME, num_labels=5,return_dict=True )

and I changed the forward function to be:


    def forward(self, input_ids, attention_mask, labels=None):
        output = self.bert(input_ids, attention_mask=attention_mask)
        #output = self.classifier(output.pooler_output)
        output = torch.sigmoid(output)
        loss = 0
        if labels is not None:
            loss = self.criterion(output, labels)
        return loss, output 

then when I fit the model, this error happened:
TypeError: sigmoid(): argument ‘input’ (position 1) must be Tensor, not SequenceClassifierOutput

do you know why?