ganeshkonapalli commited on
Commit
7a1a3c1
·
verified ·
1 Parent(s): 8bd141f

Create models/deberta_model.py

Browse files
Files changed (1) hide show
  1. models/deberta_model.py +20 -0
models/deberta_model.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ import torch.nn as nn
4
+ from transformers import DebertaModel
5
+ from config import DROPOUT_RATE, DEBERTA_MODEL_NAME
6
+
7
+ class DebertaMultiOutputModel(nn.Module):
8
+ def __init__(self, num_labels):
9
+ super(DebertaMultiOutputModel, self).__init__()
10
+ self.deberta = DebertaModel.from_pretrained(DEBERTA_MODEL_NAME)
11
+ self.dropout = nn.Dropout(DROPOUT_RATE)
12
+ self.classifiers = nn.ModuleList([
13
+ nn.Linear(self.deberta.config.hidden_size, n_classes) for n_classes in num_labels
14
+ ])
15
+
16
+ def forward(self, input_ids, attention_mask):
17
+ outputs = self.deberta(input_ids=input_ids, attention_mask=attention_mask)
18
+ pooled_output = outputs.last_hidden_state[:, 0, :] # Use CLS token output
19
+ pooled_output = self.dropout(pooled_output)
20
+ return [classifier(pooled_output) for classifier in self.classifiers]