Upload model.py
Browse files
model.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from torch import nn
|
2 |
+
|
3 |
+
class ClassificationModel(nn.Module):
|
4 |
+
def __init__(self, base_model):
|
5 |
+
super(ClassificationModel, self).__init__()
|
6 |
+
self.base_model = base_model
|
7 |
+
self.classifier = nn.Sequential(
|
8 |
+
nn.Linear(768, 256),
|
9 |
+
nn.ReLU(),
|
10 |
+
nn.Dropout(0.3),
|
11 |
+
nn.Linear(256, 8),
|
12 |
+
nn.LogSoftmax(dim=1)
|
13 |
+
)
|
14 |
+
|
15 |
+
def forward(self, input_ids, attention_mask):
|
16 |
+
hidden_states = self.base_model(input_ids=input_ids, attention_mask=attention_mask).last_hidden_state
|
17 |
+
cls_output = hidden_states[:, 0, :]
|
18 |
+
probs = self.classifier(cls_output)
|
19 |
+
return probs
|