A single LSTM unit is reading a sentence. At every step its three gates have already produced their values — in a real LSTM each gate is a small network that computes its own value from the current token and the previous hidden state, but here the numbers are handed to you so you can watch what they do to the memory.
Two things travel along the chain: the cell state , the long-term memory that runs straight through with only small controlled edits, and the hidden state , this step's visible answer.
Each step supplies four numbers:
| symbol | name | job |
|---|---|---|
| forget gate | how much of the old cell state survives | |
| input gate | how much of the candidate gets written in | |
| candidate | what this step could add to the memory | |
| output gate | how much of the memory is revealed now |
The memory is edited, then read out:
Task: write lstm_run(gates, c0). gates is a list of [f, i, g, o], one entry per time step in order, and c0 is the cell state before the first token arrives. Return a list of [c_t, h_t] pairs, one pair per step, with every value rounded to 4 decimal places.
Watch the third step of the first case: forget gate at , input gate at , and the cell state crosses that step completely untouched. That is the conveyor belt — and it is the reason an LSTM can hold something for hundreds of steps while a plain RNN's single memory is rewritten from scratch every time.