File size: 799 Bytes
7cfcb41
 
 
 
 
 
 
6a5f60d
 
 
 
 
 
 
7cfcb41
 
6a5f60d
7cfcb41
 
 
6a5f60d
 
 
7cfcb41
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
import torch
import torch.nn as nn
from transformers import AutoModel

class EmotionClassifier(nn.Module):
    def __init__(self, model_name="microsoft/deberta-v3-base"):
        super().__init__()
        # IMPORTANT: use the SAME NAME you used during training
        self.transformer = AutoModel.from_pretrained(model_name)
        
        hidden = self.transformer.config.hidden_size
        
        # IMPORTANT: your saved checkpoint uses out.weight & out.bias
        self.out = nn.Linear(hidden, 5)

    def forward(self, input_ids, attention_mask):
        outputs = self.transformer(
            input_ids=input_ids,
            attention_mask=attention_mask
        )
        
        cls_rep = outputs.last_hidden_state[:, 0, :]
        logits = self.out(cls_rep)
        return logits