Hey there,
When using nn.LSTM
, I can’t figure out how to manage the output of the layer. This layer outputs a tensor of size [length_seq, batch, nb_hidden]
. Hence, for a sequence of length superior to one, do you have to unroll the tensor, like you’d do it when reshaping the output of a convolution layer ?
Here’s what I wrote:
class Net(nn.Module):
def __init__(self):
nn.Module.__init__(self)
self.l1 = nn.Linear(1,32)
self.rnn = nn.LSTM(32,64,1)
self.l2 = nn.Linear(64,1)
self.adam = optim.Adam(self.parameters(), 3e-4)
def forward(self, x, hidden = None):
length_seq = 5
batch = 1
input_size = 1
x = torch.rand((length_seq,batch,input_size))
x = self.l1(x)
out, h = self.rnn(x, hidden)
out = self.l2(out)
# out.shape is actually [5,1,1]
return out, h
Also, is it just me or is running a network with LSTM much slower than when there’s no recurrence ?
Thanks a lot !