Size mismatch in RNN

Hey All,

I’m building a RNN to analyze audio. My current framework is input of 10000, hidden layer of 1000, output of 1.

My code looks like this - I loosely based it on this model here

class discriminator(torch.nn.Module):

    def __init__(self,input_size,hidden_size):
        self.input_size = input_size
        self.hidden_size = hidden_size
        self.i2h = torch.nn.Linear(input_size+hidden_size,hidden_size)
        self.i2o = torch.nn.Linear(input_size+hidden_size,1)
        self.softmax = torch.nn.LogSoftmax(dim=1)
        self.learning_rate = 0.005

    def forward(self, input, hidden):
        combined =,hidden),0)
        hidden = self.i2h(combined)
        output = self.softmax(self.i2o(combined))
        return output,hidden

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

    def train_rnn(self,input_tensor,result_tensor):

        hidden = self.initHidden()


        for i in range(input_tensor.size()[0]):
            output, hidden = self.forward(input_tensor[i],hidden)

        loss = torch.nn.NLLLoss(output,result_tensor)
        for p in self.parameters():

        return output, loss.item()

I am putting in a [15,10000,1] tensor in as a test input into a discriminator with an input size of 10000 and a hidden size of 10000, and am getting this error:

Traceback (most recent call last):

  File "", line 123, in <module>


  File "", line 109, in main

    output,loss = disc.train_rnn(test[0],test[1])

  File "", line 75, in train_rnn

    output, hidden = self.forward(input_tensor[i],hidden)

  File "", line 61, in forward

    hidden = self.i2h(combined)

  File "/Users/glma2016/anaconda3/lib/python3.7/site-packages/torch/nn/modules/", line 477, in __call__

    result = self.forward(*input, **kwargs)

  File "/Users/glma2016/anaconda3/lib/python3.7/site-packages/torch/nn/modules/", line 55, in forward

    return F.linear(input, self.weight, self.bias)

  File "/Users/glma2016/anaconda3/lib/python3.7/site-packages/torch/nn/", line 1024, in linear

    return torch.addmm(bias, input, weight.t())

RuntimeError: size mismatch, m1: [20000 x 1], m2: [20000 x 10000] at /Users/soumith/code/builder/wheel/pytorch-src/aten/src/TH/generic/THTensorMath.cpp:2070

I don’t know where this m2 is getting this mismatch from - the i2h linear layer should just be a normal linear layer. Where should I start troubleshooting?