Volko76 commited on
Commit
68a15c2
·
verified ·
1 Parent(s): 701ae5b

Upload model_architecture.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. model_architecture.py +32 -0
model_architecture.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ class StockPredictor(nn.Module):
5
+ def __init__(self, input_size, hidden_size=128, num_layers=2, dropout=0.3):
6
+ super(StockPredictor, self).__init__()
7
+
8
+ self.lstm = nn.LSTM(
9
+ input_size=input_size,
10
+ hidden_size=hidden_size,
11
+ num_layers=num_layers,
12
+ batch_first=True,
13
+ dropout=dropout
14
+ )
15
+
16
+ self.fc1 = nn.Linear(hidden_size, 64)
17
+ self.fc2 = nn.Linear(64, 32)
18
+ self.fc3 = nn.Linear(32, 1)
19
+ self.relu = nn.ReLU()
20
+ self.dropout = nn.Dropout(dropout)
21
+
22
+ def forward(self, x):
23
+ lstm_out, _ = self.lstm(x)
24
+ last_output = lstm_out[:, -1, :]
25
+
26
+ x = self.relu(self.fc1(last_output))
27
+ x = self.dropout(x)
28
+ x = self.relu(self.fc2(x))
29
+ x = self.dropout(x)
30
+ x = self.fc3(x)
31
+
32
+ return x