An LSTM adds a second line that runs straight through time: the cell state. Think of it as a conveyor belt. Three gates decide what stays on the belt, what gets written onto it, and what is shown. First set the gates yourself. Then watch a trained LSTM set them on a memory test.
Explained in Part 3: the LSTM
A gate is not a switch. It is a dimmer: 0% blocks everything, 100% lets everything through. Every slot of the memory has its own three dimmers. Here you set them. In a real LSTM the network computes them fresh at every step, from the new input and the previous state.
The two gates are independent, so the cell can write without erasing. A GRU, the lighter cousin of the LSTM, ties them together.
Top: the cell state, the long-term memory that rides the belt. Bottom: the hidden state, the working memory that the rest of the network sees. A value that keeps its colour along a row is riding the belt.
Move over the chart to read one step.
All four rows share the same time axis. Look for three things. The input gate opens when a marked number arrives. The forget gate stays near 1, so what is in the slot stays in the slot. And the cell state jumps at each marker: those jumps are writes.
The cell state is long-term memory. A value can step onto the belt at one time step, ride along untouched, and step off many steps later. The hidden state is working memory: what the cell is saying right now.
New cell state = forget gate × old cell state + input gate × candidate. Keep what is still useful, add what is new. Notice the plus sign: the old memory is scaled and added to, not pushed through weights and a tanh at every step.
The gate positions are not fixed. They are computed at every step from the data. So the network does not learn to forget slot 3. It learns when to forget slot 3. In the memory test, the input gate opens at the marked numbers and nowhere else.
A simple RNN reads all 100 numbers too, but its state is rewritten at every step, so the first marked number fades before the second arrives. That fading is the vanishing gradient, measured in the gradient lab.