CoolFace
Apppublic

ilhamst/rgai10_icd10

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
model.py27 linesDownload Raw Back to src
1import torch.nn as nn2from transformers import AutoModel3class MedBERTClassifier(nn.Module):4 5    def __init__(self, model_name, num_classes):6        super().__init__()7 8        self.bert = AutoModel.from_pretrained(model_name)9 10        self.dropout = nn.Dropout(0.3)11        self.norm = nn.LayerNorm(self.bert.config.hidden_size)12        self.classifier = nn.Linear(self.bert.config.hidden_size, num_classes)13 14    def forward(self, input_ids, attention_mask):15 16        outputs = self.bert(17            input_ids=input_ids,18            attention_mask=attention_mask19        )20 21        cls_output = outputs.pooler_output22 23        x = self.dropout(cls_output)24 25        logits = self.classifier(x)26 27        return logits