Problem after including time sequence in RNN

Hello guys
I am new in pytorch and checking this beatiful tool.

I am trying to develop some RNN example

For that I work on the character class module
class RNN(nn.Module):
def init(self, input_size, hidden_size, output_size):
super(RNN, self).init()
self.hidden_size = hidden_size

    self.i2h = nn.Linear(n_categories + input_size + hidden_size, hidden_size)
    self.i2o = nn.Linear(n_categories + input_size + hidden_size, output_size)
    self.o2o = nn.Linear(hidden_size + output_size, output_size)
    self.dropout = nn.Dropout(0.1)
    self.softmax = nn.LogSoftmax(dim=1)

def forward(self, category, input, hidden):
    input_combined =, input, hidden), 1)
    hidden = self.i2h(input_combined)
    output = self.i2o(input_combined)
    output_combined =, output), 1)
    output = self.o2o(output_combined)
    output = self.dropout(output)
    output = self.softmax(output)
    return output, hidden

def initHidden(self):
    return Variable(torch.zeros(1, self.hidden_size))

I can use that class by appending
n_hidden = 128

rnn = RNN(n_letters, n_hidden, n_categories)

criterion = nn.NLLLoss()

learning_rate = 0.005

input = Variable(torch.zeros(5, n_letters))
hidden = Variable(torch.zeros(5, n_hidden))
output, next_hidden = rnn(input, hidden)

And it works fine

However when I change the input to include also time sequence like

input = Variable(torch.randn(10,5, n_letters))
hidden = Variable(torch.zeros(10,5, n_hidden))

input = Variable(torch.randn(10,5, n_letters))
hidden = Variable(torch.zeros(5, n_hidden))

It gives error like

Traceback (most recent call last):
File “”, line 42, in
output, next_hidden = rnn(input, hidden)
File “/home/neuro/anaconda3/envs/tensorflow/lib/python3.6/site-packages/torch/nn/modules/”, line 325, in call
result = self.forward(*input, **kwargs)
File “”, line 20, in forward
combined =, hidden), 1)
RuntimeError: inconsistent tensor sizes at /opt/conda/conda-bld/pytorch_1512386481460/work/torch/lib/TH/generic/THTensorMath.c:2864

Is there a way to deal with time dimension to for RNN class?

I can use instead a for loop by recursively calling the module but is there another way?