Spaces:
Sleeping
Sleeping
File size: 718 Bytes
e7e1e5b 0a30d68 e7e1e5b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | import torch.nn as nn
from transformers import AutoModel
class MedBERTClassifier(nn.Module):
def __init__(self, model_name, num_classes):
super().__init__()
self.bert = AutoModel.from_pretrained(model_name)
self.dropout = nn.Dropout(0.3)
self.norm = nn.LayerNorm(self.bert.config.hidden_size)
self.classifier = nn.Linear(self.bert.config.hidden_size, num_classes)
def forward(self, input_ids, attention_mask):
outputs = self.bert(
input_ids=input_ids,
attention_mask=attention_mask
)
cls_output = outputs.pooler_output
x = self.dropout(cls_output)
logits = self.classifier(x)
return logits |