Spaces:
Sleeping
Sleeping
| 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 |