Accessing the LSTM properties


I have a seq2seq encoder model (Custom class), of which I want to access the RNN properties such as:

  1. hidden state size
  2. number of layers
  3. number of directions.

I am able to get the LSTM object (‘torch.nn.modules.rnn.LSTM’) by invoking the ._modules property on the encoder model. On printing the LSTM object, I see this output:

LSTM(500, 250, num_layers=2, dropout=0.3, bidirectional=True)

How do I access these items from the LSTM object?

You can directly access these properties and print them:

model = nn.LSTM(10, 10, 2, 0.3, bidirectional=True)

1 Like