Deep Learning · TEE · section
Model answer: LSTM and GRU memory
Recurrent neural networks
Question
Question. Compare a vanilla RNN, an LSTM and a GRU. Explain the roles of the LSTM gates and state the GRU convention used in this course.
Answer — step by step
A vanilla RNN repeatedly transforms the current input and previous hidden state. LSTMs and GRUs add learned gates that control the retention and replacement of information. Gates usually use sigmoid, so their entries lie between 0 and 1; gate multiplication controls how much of a corresponding value is passed.
LSTM
An LSTM carries a cell state c and a hidden state h. Its forget gate f controls the old cell contribution. Its input gate i controls admission of a new candidate c-tilde. Its output gate o controls the exposed hidden state.
c_t=f_t\odot c_{t-1}+i_t\odot\widetilde c_th_t=o_t\odot\tanh(c_t)The candidate is commonly formed using tanh, so it can be negative. Gate multiplication is elementwise. The updated cell is not the same as the hidden output; the second equation is another required step.
GRU
A GRU carries one hidden state rather than a separate LSTM-style cell state. A reset gate r controls how previous hidden information contributes to candidate formation. An update gate z mixes the old state and candidate. This guide uses:
h_t=(1-z_t)\odot h_{t-1}+z_t\odot\widetilde h_tThus z near 1 favors the new candidate under this convention. Some sources exchange z and 1 − z; always follow the equation printed in the question.
| Model | Carried state | Main gates | Typical parameter implication for the same dimensions |
|---|---|---|---|
| Vanilla RNN | Hidden state | None of these memory gates | Fewest affine transformations |
| LSTM | Cell and hidden states | Forget, input and output gates | Four affine transformations including candidate |
| GRU | Hidden state | Reset and update gates | Three affine transformations including candidate |
Gated models improve control over information flow but do not guarantee perfect indefinite memory. Their benefit must be evaluated for the sequence task.