Skip to content
class

LstmOpts

LstmOpts

Parameter bag for LSTM operations.

Used by lstm_forward, lstm_forward_train, and lstm_backward. weights is supplied separately as std::vector<Storage> in the order [W_ih, W_hh, b_ih, b_hh] per layer; bidirectional layers double the count (forward block followed by reverse block).

When proj_size > 0 (the projected-LSTM / LSTMP variant) an additional weight tensor W_hr of shape (proj_size, hidden_size) is appended per layer so the order becomes [W_ih, W_hh, b_ih, b_hh, W_hr]. The recurrent weight W_hh then has its second axis sized proj_size instead of hidden_size because the projected hidden state feeds the next time step. The cell state c_n keeps shape hidden_size regardless.

Attributes

input_size, hidden_sizeint
Input feature size and recurrent hidden size.
num_layersint
Number of stacked LSTM layers.
seq_len, batch_sizeint
Time and batch dimensions of the input sequence.
batch_firstbool
If true the input is laid out as (batch, seq, input); otherwise (seq, batch, input).
bidirectionalbool
Whether to run a reverse-direction stack alongside the forward.
has_biasbool
Whether the per-gate bias terms are present.
proj_sizeint
0 ⇒ standard LSTM; > 0 ⇒ projected (LSTMP) variant.