-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlp.py
26 lines (24 loc) · 846 Bytes
/
mlp.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
import torch
import torch.nn as nn
class mlp(nn.Module):
def __init__(self, input_size, hidden_size, output_size):
super(mlp, self).__init__()
self.layernorm = nn.LayerNorm(input_size, input_size)
self.linear1 = nn.Linear(input_size, hidden_size)
self.dropout1 = nn.Dropout(p=0.2)
self.linear2 = nn.Linear(hidden_size, hidden_size)
self.dropout2 = nn.Dropout(p=0.2)
self.linear3 = nn.Linear(hidden_size, output_size)
def forward(self, x):
x = self.layernorm(x)
x = self.linear1(x)
x = self.dropout1(x)
x = self.linear2(x)
x = self.dropout2(x)
x = self.linear3(x)
return x
# input_size = 100
# hidden_size = 400
# output_size = 10000
# model = mlp(input_size, hidden_size, output_size)
# print(model)