Lai Learns Neural Networks

Lesson 25·The library·4 min read

Of What the Keeper Shelveth, and What She Casteth Out

LSTMs and gates: choosing what to remember and what to forget

“Do not try to keep everything. A mind that holds every trifle has no room left for what matters. Ask of each thing: is this needed? If not, set it down without regret, and keep your hands free for the next.”

Invented, in the spirit of Marcus Aurelius

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:

  1. What to let go. That outdated almanac? Out it goes, making room.
  2. What to take in. This new history of the village? Yes, that earns a place on the shelf.
  3. 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:

And it controls them with three gates, one for each of the keeper’s decisions:

  1. The forget gate decides what to remove from the memory cell.
  2. The input gate decides what new information is worth writing in.
  3. 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

In one line

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.

Next time

We’ll be guests at a lively dinner party. Many conversations are happening at once, and a good host must choose whom to listen to. She’ll introduce us to attention: focusing on what matters most in the moment.