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 = torch.cat((category, input, hidden), 1)
hidden = self.i2h(input_combined)
output = self.i2o(input_combined)
output_combined = torch.cat((hidden, 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_letters=48
n_hidden = 128
n_categories=2
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))
or
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 “char_rnn_classification_MODIFIED.py”, line 42, in
output, next_hidden = rnn(input, hidden)
File “/home/neuro/anaconda3/envs/tensorflow/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 325, in call
result = self.forward(*input, **kwargs)
File “char_rnn_classification_MODIFIED.py”, line 20, in forward
combined = torch.cat((input, 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?
Regards