Spaces:
Sleeping
Sleeping
File size: 667 Bytes
c786710 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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) |