Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,11 @@ class AdvancedModel(nn.Module):
|
|
50 |
self.lstm = nn.LSTM(input_dim, hidden_dim, num_layers=num_layers, batch_first=True, dropout=dropout)
|
51 |
self.gru = nn.GRU(input_dim, hidden_dim, num_layers=num_layers, batch_first=True, dropout=dropout)
|
52 |
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
self.transformer = TransformerEncoder(encoder_layers, num_layers=num_layers)
|
55 |
|
56 |
self.attention = nn.MultiheadAttention(hidden_dim, num_heads=nhead, dropout=dropout)
|
@@ -65,7 +69,10 @@ class AdvancedModel(nn.Module):
|
|
65 |
def forward(self, x):
|
66 |
lstm_out, _ = self.lstm(x)
|
67 |
gru_out, _ = self.gru(x)
|
68 |
-
|
|
|
|
|
|
|
69 |
|
70 |
combined = torch.cat((lstm_out[:, -1, :], gru_out[:, -1, :], transformer_out[:, -1, :]), dim=1)
|
71 |
|
@@ -77,7 +84,12 @@ def objective(trial):
|
|
77 |
hidden_dim = trial.suggest_int("hidden_dim", 64, 256)
|
78 |
output_dim = len(target_cols)
|
79 |
num_layers = trial.suggest_int("num_layers", 1, 4)
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
81 |
dropout = trial.suggest_float("dropout", 0.1, 0.5)
|
82 |
lr = trial.suggest_loguniform("lr", 1e-5, 1e-2)
|
83 |
|
|
|
50 |
self.lstm = nn.LSTM(input_dim, hidden_dim, num_layers=num_layers, batch_first=True, dropout=dropout)
|
51 |
self.gru = nn.GRU(input_dim, hidden_dim, num_layers=num_layers, batch_first=True, dropout=dropout)
|
52 |
|
53 |
+
# Adjust input_dim for transformer if it's not divisible by nhead
|
54 |
+
transformer_dim = (input_dim // nhead) * nhead
|
55 |
+
self.input_proj = nn.Linear(input_dim, transformer_dim) if input_dim != transformer_dim else nn.Identity()
|
56 |
+
|
57 |
+
encoder_layers = TransformerEncoderLayer(d_model=transformer_dim, nhead=nhead, dim_feedforward=hidden_dim, dropout=dropout)
|
58 |
self.transformer = TransformerEncoder(encoder_layers, num_layers=num_layers)
|
59 |
|
60 |
self.attention = nn.MultiheadAttention(hidden_dim, num_heads=nhead, dropout=dropout)
|
|
|
69 |
def forward(self, x):
|
70 |
lstm_out, _ = self.lstm(x)
|
71 |
gru_out, _ = self.gru(x)
|
72 |
+
|
73 |
+
# Project input for transformer if necessary
|
74 |
+
transformer_input = self.input_proj(x)
|
75 |
+
transformer_out = self.transformer(transformer_input.transpose(0, 1)).transpose(0, 1)
|
76 |
|
77 |
combined = torch.cat((lstm_out[:, -1, :], gru_out[:, -1, :], transformer_out[:, -1, :]), dim=1)
|
78 |
|
|
|
84 |
hidden_dim = trial.suggest_int("hidden_dim", 64, 256)
|
85 |
output_dim = len(target_cols)
|
86 |
num_layers = trial.suggest_int("num_layers", 1, 4)
|
87 |
+
|
88 |
+
# Ensure that hidden_dim is divisible by nhead
|
89 |
+
max_nhead = min(8, hidden_dim // 8) # Ensure at least 8 dimensions per head
|
90 |
+
nhead = trial.suggest_int("nhead", 2, max_nhead)
|
91 |
+
hidden_dim = (hidden_dim // nhead) * nhead # Adjust hidden_dim to be divisible by nhead
|
92 |
+
|
93 |
dropout = trial.suggest_float("dropout", 0.1, 0.5)
|
94 |
lr = trial.suggest_loguniform("lr", 1e-5, 1e-2)
|
95 |
|