Skip to content
All library documents

Inspecting Keras LSTM and Dense Layer Weights

Article BigQuant

Summary

The document explains how to inspect trained parameters in a Keras model that combines an LSTM layer, an auxiliary input, and several dense layers. It distinguishes trainable variables from the arrays returned by the model’s weight retrieval method, then shows how the array order maps to layer kernels and biases. This lets a researcher identify a particular dense-layer bias or trace the auxiliary input’s contribution through the network.

It also describes splitting the LSTM’s packed parameters into input, forget, cell, and output gate slices. The forget gate uses separate input and recurrent kernels plus a bias, with each slice corresponding to the gate’s units. The examples illustrate model inspection, not trading performance or predictive value. Parameter ordering and gate layout depend on the Keras implementation and model configuration, so the described indices should be checked against the specific model and library version before use.

Key ideas

  • Keras exposes trainable variables by layer and can return their values as an ordered list of arrays.
  • The example model’s dense-layer bias is found by matching the array order to the layer variables.
  • An LSTM’s packed kernel, recurrent kernel, and bias can be sliced into separate gate parameters.
  • An auxiliary feature concatenated with the LSTM output enters the first dense layer through its corresponding input row.
  • Reading parameters reveals model structure but does not by itself explain predictive behavior or establish trading value.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.