I'm getting started with pytorch and used a few transformation to build the following model using one of the tutorials as a reference:
model = torch.nn.Sequential(
torch.nn.Linear(D_in, H),
torch.nn.ReLU(),
torch.nn.Linear(H, D_out),
)
I want to use an LSTM network, so I tried to do the following:
model = torch.nn.Sequential(
torch.nn.LSTM(D_in, H),
torch.nn.Linear(H, D_out)
)
which gives me this error:
RuntimeError: input must have 3 dimensions, got 2
Why am I seeing this error? I anticipate there's something fundamentally wrong in my understanding of how transformations (networks?) can be chained in pytorch...
EDIT
After following @esBee's suggestion, I found that following runs correctly. This is because an LSTM expects the input to be of the folowing dimension:
input of shape (seq_len, batch, input_size): tensor containing the features of the input sequence. The input can also be a packed variable length sequence
local_x = local_x.unsqueeze(0)
y_pred, (hn, cn) = layerA(local_x)
y_pred = y_pred.squeeze(0)
y_pred = layerB(y_pred)
However, the fact that my original training/test dataset is only of sequence length 1 makes me feel like I'm doing something incorrectly. What is the purpose of this parameter in the context of neural networks?