-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprobing_model.py
50 lines (42 loc) · 1.62 KB
/
probing_model.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from torch import nn
class MultiLayerProbingModel(nn.Module):
def __init__(self, embedding_dim, num_classes, activation=None):
super(MultiLayerProbingModel, self).__init__()
# Inputs to hidden layer linear transformation
self.input = nn.Linear(embedding_dim, 256)
self.dropout = nn.Dropout(p=0.2)
self.sigmoid = nn.Sigmoid()
# Output layer, 10 units - one for each digit
self.fc = nn.Linear(256, num_classes)
# Define sigmoid activation and softmax output
#self.relu = nn.ReLU()
if activation == 'softmax':
self.activation = nn.Softmax(dim=1)
elif activation == 'sigmoid':
self.activation = nn.Sigmoid()
else:
self.activation = None
def forward(self, x):
# Pass the input tensor through each of our operations
x = self.input(x)
x = self.dropout(x)
x = self.sigmoid(x)
#x = self.hidden(x)
#x = self.relu(x)
x = self.fc(x)
if self.activation != None:
x = self.activation(x)
return x
class LinearProbingModel(nn.Module):
def __init__(self, embedding_dim, num_classes, activation=None):
super(LinearProbingModel, self).__init__()
self.input = nn.Linear(embedding_dim, num_classes)
self.dropout = nn.Dropout(p=0.2)
# Define sigmoid activation and softmax output
self.activation = nn.Softmax(dim=1)
def forward(self, x):
# Pass the input tensor through each of our operations
x = self.dropout(x)
x = self.input(x)
x = self.activation(x)
return x