Spaces:
Sleeping
Sleeping
fix model
Browse files
model.py
CHANGED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
from transformers import AutoModel
|
| 4 |
-
|
| 5 |
-
class EmotionClassifier(nn.Module):
|
| 6 |
-
def __init__(self, model_name
|
| 7 |
-
super().__init__()
|
| 8 |
-
self.
|
| 9 |
-
hidden_size = self.
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
from transformers import AutoModel
|
| 4 |
+
|
| 5 |
+
class EmotionClassifier(nn.Module):
|
| 6 |
+
def __init__(self, model_name="microsoft/deberta-v3-base"):
|
| 7 |
+
super().__init__()
|
| 8 |
+
self.backbone = AutoModel.from_pretrained(model_name)
|
| 9 |
+
hidden_size = self.backbone.config.hidden_size
|
| 10 |
+
# Must be named `out` because your trained weights use out.weight & out.bias
|
| 11 |
+
self.out = nn.Linear(hidden_size, 5)
|
| 12 |
+
|
| 13 |
+
def forward(self, input_ids, attention_mask):
|
| 14 |
+
outputs = self.backbone(
|
| 15 |
+
input_ids=input_ids,
|
| 16 |
+
attention_mask=attention_mask
|
| 17 |
+
)
|
| 18 |
+
last_hidden_state = outputs.last_hidden_state
|
| 19 |
+
cls_token = last_hidden_state[:, 0, :]
|
| 20 |
+
logits = self.out(cls_token)
|
| 21 |
+
return logits
|