Repository navigation
Expand file tree
/
Copy pathmapping_function.py
More file actions
133 lines (105 loc) · 4.25 KB
/
Copy pathmapping_function.py
File metadata and controls
133 lines (105 loc) · 4.25 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import torch.nn as nn
class MLP_old(nn.Module):
def __init__(self, input_size=768, hidden_size=1024, output_size=768):
super(MLP, self).__init__()
self.model = nn.Sequential(
nn.Linear(input_size, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, hidden_size*2),
nn.ReLU(),
nn.Linear(hidden_size*2, hidden_size),
nn.ReLU(),
nn.Linear(hidden_size, output_size)
)
def forward(self, x):
return self.model(x)
class Linear_MLP(nn.Module):
def __init__(self, input_size=768, hidden_size=1024, output_size=768):
super(Linear_MLP, self).__init__()
self.model = nn.Sequential(
nn.Linear(input_size, hidden_size),
nn.Linear(hidden_size, hidden_size*2),
nn.Linear(hidden_size*2, hidden_size),
nn.Linear(hidden_size, output_size)
)
def forward(self, x):
return self.model(x)
class MLP(nn.Module):
def __init__(self, input_dim, output_dim):
super(MLP, self).__init__()
hidden_dim = 5 * output_dim # Hidden layer dimension as 5x output dimension
# Define the layers of the MLP
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, hidden_dim)
self.fc3 = nn.Linear(hidden_dim, hidden_dim)
self.fc4 = nn.Linear(hidden_dim, output_dim)
# SELU activation
self.activation = nn.SELU()
# L2 normalization for the output
self.l2_norm = nn.functional.normalize
def forward(self, x):
x = self.activation(self.fc1(x))
x = self.activation(self.fc2(x))
x = self.activation(self.fc3(x))
x = self.fc4(x)
x = self.l2_norm(x, p=2, dim=1) # Apply L2 normalization along the feature dimension
return x
class Fix_MLP(nn.Module):
def __init__(self, input_dim, output_dim):
super(Fix_MLP, self).__init__()
hidden_dim = 3840
# Define the layers of the MLP
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, hidden_dim)
self.fc3 = nn.Linear(hidden_dim, hidden_dim)
self.fc4 = nn.Linear(hidden_dim, output_dim)
# SELU activation
self.activation = nn.SELU()
# L2 normalization for the output
self.l2_norm = nn.functional.normalize
def forward(self, x):
x = self.activation(self.fc1(x))
x = self.activation(self.fc2(x))
x = self.activation(self.fc3(x))
x = self.fc4(x)
x = self.l2_norm(x, p=2, dim=1) # Apply L2 normalization along the feature dimension
return x
class Big_MLP(nn.Module):
def __init__(self, input_dim, output_dim):
super(Big_MLP, self).__init__()
hidden_dim = 5120
# Define the layers of the MLP
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, hidden_dim)
self.fc3 = nn.Linear(hidden_dim, hidden_dim)
self.fc4 = nn.Linear(hidden_dim, output_dim)
# SELU activation
self.activation = nn.SELU()
# L2 normalization for the output
self.l2_norm = nn.functional.normalize
def forward(self, x):
x = self.activation(self.fc1(x))
x = self.activation(self.fc2(x))
x = self.activation(self.fc3(x))
x = self.fc4(x)
x = self.l2_norm(x, p=2, dim=1) # Apply L2 normalization along the feature dimension
return x
class Costom_MLP(nn.Module):
def __init__(self, input_dim, hidden_dim, output_dim):
super(Costom_MLP, self).__init__()
# Define the layers of the MLP
self.fc1 = nn.Linear(input_dim, hidden_dim)
self.fc2 = nn.Linear(hidden_dim, hidden_dim)
self.fc3 = nn.Linear(hidden_dim, hidden_dim)
self.fc4 = nn.Linear(hidden_dim, output_dim)
# SELU activation
self.activation = nn.SELU()
# L2 normalization for the output
self.l2_norm = nn.functional.normalize
def forward(self, x):
x = self.activation(self.fc1(x))
x = self.activation(self.fc2(x))
x = self.activation(self.fc3(x))
x = self.fc4(x)
x = self.l2_norm(x, p=2, dim=1) # Apply L2 normalization along the feature dimension
return x