I have a LSTM network which returns me an output for each input. So when I have an input tensor of shape [seq_length, batch_size, features], it will return me [seq_length, batch_size, hidden_size].
Now I want to apply a fully connected network to each output. However as far as I understand nn.Sequential(nn.Linaer(...)) does only allow to process shapes like [batch_size, features].
However, my input would have the shape [seq_length, batch_size, hidden_size]. And the output shape should than look like [seq_length, batch_size, fc_last_layer_dim]. Is there any way it can process three dimensions in that fashion?
Thank you, but I could not really see how this applies to my situation.
Are you suggesting that I would require a custom nn.Module subclass which basically does the same as Sequential except has an additional for-loop in the forward to go through the third dimension?
input (seq_len, batch, input_size)
output (seq_len, batch, hidden_size * num_directions): tensor containing the output features (h_t) from the last layer of the RNN, for each t.
I don’t know of anyway to do this using the sequential module
And yes I’m suggesting loop on:
Output, (hx, cx) = model(input, (hx,cx))
I’m walking my dog right now and using phone for this but can provide actual code example later if you need when with computer
Well, the problem is not with the LSTM, that works just fine. But the fully connected layer applied to the LSTM output can not process the additional dimension. So maybe I’m not understanding correctly what you are suggesting.