LSTM-forecaster / classes /LSTMModelClass.py
nkapila6's picture
Upload 373 files
964e116 verified
import torch.nn as nn
import torch
class LSTMModel(nn.Module):
def __init__(self, input_size=1, hidden_size=50, num_layers=1, batch_first=True):
super().__init__()
self.lstm = nn.LSTM(input_size=input_size, hidden_size=hidden_size, num_layers=num_layers, batch_first=batch_first)
self.linear = nn.Linear(hidden_size, 1)
def forward(self, x):
x, _ = self.lstm(x)
x = self.linear(x[:, -1, :]) # Use the output of the last time step
return x