import torch import torch.nn as nn from transformers import BertModel, BertTokenizer class BERTRegression(nn.Module): def __init__(self): super(BERTRegression, self).__init__() self.bert = BertModel.from_pretrained("bert-base-uncased") self.dropout = nn.Dropout(0.1) self.linear = nn.Linear(self.bert.config.hidden_size, 1) def forward(self, input_ids, attention_mask): outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask) pooled_output = outputs.pooler_output pooled_output = self.dropout(pooled_output) logits = self.linear(pooled_output) return logits.squeeze(-1)