import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
torch.manual_seed(1)
lstm = nn.LSTM(3, 3)  # Input dim is 3, output dim is 3
inputs = [autograd.Variable(torch.randn((1, 3)))
for _ in range(5)]  # make a sequence of length 5
initialize the hidden state.
hidden = (autograd.Variable(torch.randn(3, 1, 3)),
autograd.Variable(torch.randn((3, 1, 3))))
for i in inputs:
# Step through the sequence one element at a time.
# after each step, hidden contains the hidden state.
out, hidden = lstm(i.view(1, 1, -1), hidden)
error
File “t7.py”, line 19, in 
out, hidden = lstm(i.view(1, 1, -1), hidden)
File “/Users/yangjian/miniconda3/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 357, in call
result = self.forward(*input, **kwargs)
File “/Users/yangjian/miniconda3/lib/python3.6/site-packages/torch/nn/modules/rnn.py”, line 190, in forward
self.check_forward_args(input, hx, batch_sizes)
File “/Users/yangjian/miniconda3/lib/python3.6/site-packages/torch/nn/modules/rnn.py”, line 158, in check_forward_args
’Expected hidden[0] size {}, got {}’)
File “/Users/yangjian/miniconda3/lib/python3.6/site-packages/torch/nn/modules/rnn.py”, line 154, in check_hidden_size
raise RuntimeError(msg.format(expected_hidden_size, tuple(hx.size())))
RuntimeError: Expected hidden[0] size (1, 1, 3), got (3, 1, 3)