How it works
This LSTM cell diagram shows one long short-term memory cell at one time step. Name the forget gate, the input gate and the output gate, then the cell state and the hidden state that enter and leave.
Read the full guide
Read the two lines
The top line carries the cell state, the memory of the cell, from left to right. The bottom line brings in the previous hidden state, and the input joins it from below.
Find the three gates
Each box with the sigmoid sign is a gate: it gives every value a number between 0 and 1. From the left they are the forget gate, the input gate and the output gate. Each acts through a multiply point.
What the signs mean
The sigmoid sign and tanh are activation functions. The multiply sign is element-wise multiplication and the plus sign is addition.
- The tanh box between the gates makes the new values. Texts name it differently, so it is not asked.
Questions and answers
What are the three gates of an LSTM cell?
The forget gate, the input gate and the output gate. Each is a layer with a sigmoid activation, so its values lie between 0 and 1, and each scales another signal by element-wise multiplication.
What is the difference between the cell state and the hidden state?
The cell state is the internal memory of the cell: it runs along the top line and is changed by one multiplication and one addition. The hidden state is the output of the cell at each time step.
What does the forget gate do in an LSTM?
It decides how much of the previous cell state is kept. A value near 1 keeps a piece of the old memory and a value near 0 discards it.
What does LSTM stand for?
Long short-term memory. It is a kind of recurrent neural network, introduced in 1997, built to keep information over many time steps.