multilayer RNN with chainer (LSTM)

284 Views Asked by At

I'm able now to create and teach single layer rnn-s with Chainer, but I run into errors when I try to expand my network. Here is my code, I commented out the 2. hidden layer part, so this should run as a single layer net

#Regression
class Regression(Chain):
    def __init__(self, predictor):
        super(Regression, self).__init__(predictor=predictor)
    def __call__(self, x, t):
        y = self.predictor(x)
        loss = F.mean_squared_error(y, t)
        report({'loss': loss}, self)
        return loss
        #return loss
#%%
#RNN
class RNN(Chain):
    def __init__(self):
        super(RNN, self).__init__(
            lstm=L.LSTM(12, 50),  #
          #  lstm2=L.LSTM(100, 100),
            out=L.Linear(50, 1),  #
        )

    def reset_state(self):
        self.lstm.reset_state()
        #self.lstm2.reset_state()

    def __call__(self, x):
        h = self.lstm(x)
      #  h2 = self.lstm(h)
        y = self.out(h2)
        return y

Error: unindent does not match any outer indentation level on row : h2 = self.lstm(h)

what Mi doing wrong?

1

There are 1 best solutions below

0
On

Check if you have mixed your tabs with spaces. Even better, go to your IDE and make your tab to insert spaces automatically. Otherwise, this code runs fine (after I import everything)