Search⌘ K
AI Features

Understanding LSTM Activations and Stabilized Gradients

Understand how LSTM activations work, including cell state and gate functions, and learn how stabilized gradients in LSTM networks prevent vanishing or exploding gradients, enabling modeling of long-term dependencies in sequential data. This lesson covers parameters, activation functions, and why sigmoid recurrent_activation is critical for effective deep learning in rare event prediction.

Activations in LSTM

The activations below:

c~=tanh(wc(x)xt+wc(h)ht1+bc)\tilde{c} = \text{tanh}(w_c^{(x)}x_t + w_c^{(h)}h_{t-1} + b_c)

for c~t\tilde{c}_t and

ht=ottanh(ct)h_t = o_t\text{tanh}(c_t)

for emitting hth_t correspond to the activation argument in an LSTM layer in TensorFlow. By default, it is tanh. These expressions act as learned features and, therefore, can take any value. With tanh activation, they are in (1,1)(−1, 1). Other suitable activations can also be used for them. On the other hand, the activations for input, output, and forget gates are referred to as the argument recurrent_activation in TensorFlow. These gates act as scales. Therefore, they are intended to stay in (0,1)(0,1). Their default is, hence, sigmoid. For most purposes, it’s essential to keep recurrent_activation as sigmoid.

Note: The recurrent_activation should be sigmoid. The default activation is tanh but can be set to other activations such as relu.

Parameters

Suppose an LSTM layer has mm cells, that is, the layer size equal to mm. The cell mechanism is for one cell in an LSTM layer. The parameters involved in the cell are, w(h),w(x),bw_·^{(h)}, w_·^{(x)}, b_·, where · is c,i,f,c,i,f, and oo.

A cell intakes the prior output of all the other sibling cells in the layer. Given the layer size is mm, the prior output from the layer cells will be an mm-vector ht1h_{t−1} and, therefore, the w(h)w_·^{(h)} are also of the same length mm.

The weight for the input time-step xtx_t is a pp-vector given there are pp features, that is, xtRpx_t ∈ \mathbb{R}^p. Lastly, the bias on a cell is a scalar.

Combining them for each of c,i,f,o,c, i, f, o, the total number of parameters in a cell is 4(m+p+1)4(m+p+1).

In the LSTM layer, there are mm cells. Therefore, the total number of parameters in a layer are:

n_parameters=4m(m+p+1)n\_parameters = 4m(m + p + 1) ...