I have a huggingface model:
model_name = 'bert-base-uncased'
model = BertForSequenceClassification.from_pretrained(model_name, num_labels=1).to(device)
How can I change the default classifier head? Since it's only a single LinearClassifier. I found this issue in the huggingface github which said:
You can also replace self.classifier with your own model.
model = BertForSequenceClassification.from_pretrained("bert-base-multilingual-cased") model.classifier = new_classifier
where new_classifier is any pytorch model that you want.
However, I can't figure out how the structure of the new_classifier
should look like (in particular the inputs and outputs so it can handle batches).