LSTMCell

class LSTMCell(hidden_size, i2h_weight_initializer=None, h2h_weight_initializer=None, i2h_bias_initializer='zeros', h2h_bias_initializer='zeros', input_size=0, prefix=None, params=None, activation='tanh', recurrent_activation='sigmoid')

Long-Short Term Memory (LSTM) network cell.

Each call computes the following function:

(20)\[\begin{split}\begin{array}{ll} i_t = sigmoid(W_{ii} x_t + b_{ii} + W_{hi} h_{(t-1)} + b_{hi}) \\ f_t = sigmoid(W_{if} x_t + b_{if} + W_{hf} h_{(t-1)} + b_{hf}) \\ g_t = \tanh(W_{ig} x_t + b_{ig} + W_{hc} h_{(t-1)} + b_{hg}) \\ o_t = sigmoid(W_{io} x_t + b_{io} + W_{ho} h_{(t-1)} + b_{ho}) \\ c_t = f_t * c_{(t-1)} + i_t * g_t \\ h_t = o_t * \tanh(c_t) \end{array}\end{split}\]

where \(h_t\) is the hidden state at time t, \(c_t\) is the cell state at time t, \(x_t\) is the hidden state of the previous layer at time t or \(input_t\) for the first layer, and \(i_t\), \(f_t\), \(g_t\), \(o_t\) are the input, forget, cell, and out gates, respectively.

Parameters:
hidden_size : int

Number of units in output symbol.

i2h_weight_initializer : str or Initializer

Initializer for the input weights matrix, used for the linear transformation of the inputs.

h2h_weight_initializer : str or Initializer

Initializer for the recurrent weights matrix, used for the linear transformation of the recurrent state.

i2h_bias_initializer : str or Initializer, default ‘zeros’

Initializer for the bias vector.

h2h_bias_initializer : str or Initializer, default ‘zeros’

Initializer for the bias vector.

prefix : str, default 'lstm_'

Prefix for name of Block`s (and name of weight if params is `None).

params : Parameter or None, default None

Container for weight sharing between cells. Created if None.

activation : str, default ‘tanh’

Activation type to use. See nd/symbol Activation for supported types.

recurrent_activation : str, default ‘sigmoid’

Activation type to use for the recurrent step. See nd/symbol Activation for supported types.

Inputs:
  • data: input tensor with shape (batch_size, input_size).
  • states: a list of two initial recurrent state tensors. Each has shape (batch_size, num_hidden).
Outputs:
  • out: output tensor with shape (batch_size, num_hidden).
  • next_states: a list of two output recurrent state tensors. Each has the same shape as states.