Printing weights in LSTM Networks

I have problem with printing weights between inputs and first layer.

class LSTMClassifier(nn.Module):
    """Very simple implementation of LSTM-based time-series classifier."""

    def __init__(self, input_size, hidden_size, n_layers, output_size):
        self.hidden_size = hidden_size
        self.n_layers = n_layers
        self.rnn = nn.LSTM(input_size, hidden_size, n_layers, batch_first=True)
        self.fc = nn.Linear(hidden_size, output_size)
        self.batch_size = None
        self.hidden = None

    def forward(self, x):
        h0, c0 = self.init_hidden(x)
        out, (hn, cn) = self.rnn(x, (h0, c0))
        out = self.fc(out[:, -1, :])
        return out

    def init_hidden(self, x):
        h0 = torch.zeros(self.n_layers, x.size(0), self.hidden_size)
        c0 = torch.zeros(self.n_layers, x.size(0), self.hidden_size)
        return [t for t in (h0, c0)]

        return y

I know how to do this with feedforward Neural Network but with LSTM it’s not working.
Thanks for help.


Why can’t you add a print statement in your forward() function?
Can you give an example of what you want to achieve?

How this print statement should looks like?
I just wanna know what neural network see as important inputs referring to weights.

You can add print(self.rnn.weight_ih) for example. You can find here the definition of each weight and their names.

Not aure what that means :confused:

I’m just checking my theory :laughing:.
Thanks for help.