Spaces:
Runtime error
Runtime error
File size: 684 Bytes
28bc44f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
from transformers import BertModel
import torch.nn as nn
import torch.nn.functional as F
class SentimentModel(nn.Module):
def __init__(self, config):
super(SentimentModel, self).__init__()
self.bert = BertModel.from_pretrained(modelName, return_dict=False)
self.dropout = nn.Dropout(0.3)
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
def forward(self, input_ids, attention_mask):
_, pooled_output = self.bert(
input_ids=input_ids,
attention_mask=attention_mask)
pooled_output = self.dropout(pooled_output)
logits = self.classifier(pooled_output)
return logits |