import torch import torch.nn as nn from transformers import DebertaModel from config import DROPOUT_RATE, DEBERTA_MODEL_NAME class DebertaMultiOutputModel(nn.Module): def __init__(self, num_labels): super(DebertaMultiOutputModel, self).__init__() self.deberta = DebertaModel.from_pretrained(DEBERTA_MODEL_NAME) self.dropout = nn.Dropout(DROPOUT_RATE) self.classifiers = nn.ModuleList([ nn.Linear(self.deberta.config.hidden_size, n_classes) for n_classes in num_labels ]) def forward(self, input_ids, attention_mask): outputs = self.deberta(input_ids=input_ids, attention_mask=attention_mask) pooled_output = outputs.last_hidden_state[:, 0, :] # Use CLS token output pooled_output = self.dropout(pooled_output) return [classifier(pooled_output) for classifier in self.classifiers]