Module 7 · Recurrent Neural Networks for Time Series Forecasting

The LSTM Conveyor Belt

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

Who sets the gates

One step of the cell step 1

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.

Set all four slots at once

The two gates are independent, so the cell can write without erasing. A GRU, the lighter cousin of the LSTM, ties them together.

Four things to try

  1. ✓Ride the belt. Carry the 0.80 in slot 1, untouched, for 8 steps.
  2. ✓Erase and write. In one step, replace what slot 2 holds with the new candidate.
  3. ✓Remember, but stay quiet. Keep a value in slot 3 for 3 steps while its hidden state shows 0.
  4. ✓Forget slowly. Leave slot 4's forget gate at 50%, write nothing, and run 5 steps.

The belt through time each column is one step, the newest on the right

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.

1 · A belt next to the state

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.

2 · The one line that makes an LSTM

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.

3 · When, not what

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.

4 · Seeing is not remembering

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.