I have (for illustration) an LSTM(insize, hiddensize, num_layers=3, bidirectional=True, batch_first=True) and I want to use the last hidden state of each instance in a batch as an input to a Linear layer.
The Linear layer requires a tensor that has the batch instances in the first dimension, but the LSTM returns the last hidden state as shape (num_layers*isbidirectional), batchsize, hiddensize, (where isbidirectional is 2 if bidirectional, otherwise 1) even if batch_first=True
Maybe I am missing something here, but would it not be much more convenient if the hidden state would be of shape batchsize, (num_layers*isbidirectional), hiddensize?
What is the best way to create the necessary tensor that can be used as an input to the linear layer so that the batches are in the first dimension?
One thing I want to achieve is to just create a 2-dimensional tensor of shape batchsize, (num_layersisbidirectionalhiddensize) so that the 2nd dimensions has all the hidden vectors that belong to each element in the batch dimension concatenated. How would one do this ideally?