Download src/models/model_gru.py from GoldenGrapeGentleman1/FinMM-Project-FinMM: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/GoldenGrapeGentleman1/FinMM-Project-FinMM/resolve/main/src/models/model_gru.py
- Command line
-
hf download hf://GoldenGrapeGentleman1/FinMM-Project-FinMM/src/models/model_gru.py
-
curl -L -o model_gru.py https://huggingface.co/GoldenGrapeGentleman1/FinMM-Project-FinMM/resolve/main/src/models/model_gru.py
1.6 kB
| """ | |
| GRU Baseline Model for Time Series Prediction. | |
| A standard GRU baseline without advanced techniques. | |
| """ | |
| import torch | |
| import torch.nn as nn | |
| class GRUBaseline(nn.Module): | |
| """ | |
| Simple GRU Baseline for time series forecasting. | |
| Uses standard configuration without advanced optimizations | |
| to serve as a fair baseline comparison. | |
| """ | |
| def __init__(self, configs): | |
| super().__init__() | |
| self.pred_len = configs.pred_len | |
| self.c_in = configs.c_in | |
| # Standard GRU configuration (single layer, moderate hidden size) | |
| hidden_size = 64 # Conservative hidden size for baseline | |
| self.gru = nn.GRU( | |
| input_size=configs.c_in, | |
| hidden_size=hidden_size, | |
| num_layers=1, # Single layer baseline | |
| batch_first=True, | |
| dropout=0.0 # No dropout for simple baseline | |
| ) | |
| # Simple linear projection | |
| self.fc = nn.Linear(hidden_size, configs.pred_len * configs.c_in) | |
| def forward(self, x): | |
| """ | |
| Args: | |
| x: [B, SeqLen, C] - Input time series (OHLCV) | |
| Returns: | |
| [B, PredLen, C] - Predicted time series | |
| """ | |
| # GRU encoding | |
| _, h_n = self.gru(x) # h_n: [1, B, hidden] | |
| h_n = h_n.squeeze(0) # [B, hidden] | |
| # Project to prediction | |
| out = self.fc(h_n) # [B, pred_len * c_in] | |
| out = out.view(-1, self.pred_len, self.c_in) # [B, pred_len, c_in] | |
| return out | |