Welcome back
Last time, around the campfire, we met the recurrent network. It reads a story one word at a time and carries a small note of what came before. We also found its weakness: over a long tale, early details fade, just as a message fades in the whisper game.
Today we visit someone who has solved that problem gracefully, in her own small way.
The keeper of the library
Picture a small village library, and the woman who keeps it. Every day new books arrive in a crate at the door. Her shelves are not endless, so she can’t simply keep them all.
So each day she makes three quiet decisions:
- What to let go. That outdated almanac? Out it goes, making room.
- What to take in. This new history of the village? Yes, that earns a place on the shelf.
- What to bring to the front desk. Of everything on her shelves, which few books does a visitor need today? She sets those out where they can be seen.
Notice that the shelves themselves change slowly. Most books stay put for years. Only what she deliberately removes or adds ever changes. That steadiness is what lets the library remember things for a very long time.
The LSTM: a network with a librarian inside
An LSTM, which stands for Long Short-Term Memory, is a recurrent network with a librarian built into it. Like the RNN, it reads a sequence one step at a time. But instead of one note that gets rewritten at every step, it keeps two things:
- A memory cell: the shelves. Long-term memory that changes only slowly and carefully.
- A hidden state: the front desk. What the network is showing, right now, to the next step.
And it controls them with three gates, one for each of the keeper’s decisions:
- The forget gate decides what to remove from the memory cell.
- The input gate decides what new information is worth writing in.
- The output gate decides which parts of memory to bring forward right now.
How a gate works
Each gate is simply a small set of neurons, just like the ones you met with the termites. They end in an activation that squeezes their answer to somewhere between 0 and 1.
Think of it as a dial. A value near 0 means “close the gate, let nothing through.” A value near 1 means “open wide.” A value of 0.3 means “let a little through.”
And here is the lovely part: these dials are learned. Nobody tells the network what to remember. Through the same training loop you know well, the losses, the downhill steps and the blame traced backward, the gates slowly learn when to hold on and when to let go.
Why this helps with fading
Because the memory cell changes only when a gate allows it, important information can travel a long way through a sequence almost untouched. The message isn’t whispered from person to person anymore. It sits safely on a shelf until it’s needed. That’s what finally let networks remember the locked door from the start of the story.
What to carry with you
An LSTM keeps a slowly changing long-term memory, guarded by learned gates that decide what to forget, what to take in, and what to bring forward right now.
