How can I make a single LSTM cell model?

I wish to make a single cell LSTM model. So far, I’ve managed to make this model but I am not sure if it is implemented correctly:

class SingleLSTMCell(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.model = nn.LSTMCell(config.INPUT_SIZE,
                                 config.HIDDEN_SIZE) # (input_size, hidden_size)
        self.h_0 = torch.randn(config.BATCH_SIZE,
                               config.HIDDEN_SIZE,
                               requires_grad=True) # Initial hidden state: (batch, hidden_size)
        self.c_0 = torch.randn(config.BATCH_SIZE,
                               config.HIDDEN_SIZE,
                               requires_grad=True) # Initial cell state: (batch, hidden_size)

    def forward(self, x):        
        x = self.model(x, (self.h_0, self.c_0))
        return x

Where config is a class which holds parameters to create the model.

  • I want my model to be input a tensor of size (1, time_steps) which represents a one dimensional time series. Example: how price of a product fluctuates in 100 days.
  • The model should output N time steps in the future, tensor of size (1, N). Example: output how the price of a product will be in the next 7 days.