I am studying NLP and trying to make a model for classifying sentences. I am creating my class with a model but I get an error saying that the input should be of type Tensor, not tuple. I use 4.21.2 transformers version.
class BertClassificationModel(nn.Module):
def __init__(self, bert_model_name, num_labels, dropout=0.1):
super(BertClassificationModel, self).__init__()
self.bert = BertForSequenceClassification.from_pretrained(bert_model_name, return_dict=False)
self.dropout = nn.Dropout(dropout)
self.classifier = nn.Linear(768, num_labels)
self.num_labels = num_labels
def forward(self, input_ids, attention_mask=None, token_type_ids=None):
pooled_output = self.bert(input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids)
pooled_output = self.dropout(pooled_output)
logits = self.classifier(pooled_output)
return logits
TypeError: dropout(): argument 'input' (position 1) must be Tensor, not tuple