LSTM: the neural network that chooses what to forget

You know how a normal neural network reads a sentence? It looks at the whole thing at once and decides what it means. That sounds fine — until the sentence gets long enough that the answer depends on a word near the start. By the time the network has looked at everything, the word at the beginning has been washed out. The network knows every word in the sentence and still cannot connect the dots.

LSTMs solve this by being the kind of neural network that actively chooses what to remember and what to forget. Not "fails to remember" — actually chooses. This tutorial walks through how that works, why it is necessary, what each little piece is doing, and where you have probably already used an LSTM today without realising it.

If you have ever wondered why a chatbot from 2016 sometimes lost the thread of what you said, or how your phone guesses the next word as you type, the answer involves a small piece of machinery called an LSTM cell — and it is the subject of everything that follows.

Why does the network forget the start of a sentence?

Let us start with two sentences and ask a normal neural network to fill in the blank:

The clouds are in the ___.

If the network has seen enough English, it will say "sky". That one is easy — the answer sits right next to the blank.

Now a longer one:

I grew up in France ... I speak fluent ___.

The answer is "French", but the word that decides it — "France" — sits many words before the blank. To get this right, the network has to remember "France" from way back at the start, hold onto it across all the words in the middle, and then use it at the end. A normal feed-forward neural network reads the sentence as one bag of words; by the time it reaches the blank, "France" has been mixed in with everything else and its signal has washed out.

This is not a mistake on the network's part. It is built into how a normal recurrent network works. Every time a new word comes in, the network multiplies its current "memory" by the same set of weights and adds a tiny bit of new information. Multiply any number smaller than 1 by itself enough times and it shrinks toward zero. After twenty or thirty words, the influence of the first word is essentially zero. Bengio, Simard and Frasconi proved in 1994 that this is not just intuition — the gradient that would tell the network "you should have paid more attention to that early word" decays exponentially with distance, so the network literally cannot learn to reach across long gaps Bengio1994.

The picture below shows what a vanilla recurrent network actually looks like, compared with the LSTM we are about to build:

Caption: Side by side, two repeating modules. The left one is the vanilla RNN cell — a single tanh box with a self-loop. The right one is the LSTM cell — four interacting layers and a long horizontal line running across the top. That horizontal line is the new piece. It is what makes long sentences survivable. Olah2015

A nice way to picture the wash-out is the latch neuron diagram below. Imagine a single neuron with a self-loop labelled w. Each step, the neuron reads its current value, multiplies it by w, and adds a tiny piece of new input. When w is smaller than 1 — which is exactly what training will push it toward so the network stays stable — the value coming back around shrinks every step. Bold dots at the start of panel (b) are the meaningful input the neuron was supposed to hold onto; hollow squares further along are just noise. By the time the network has been hit with twenty noise squares, the bold dots have all but vanished Bengio1994.

Caption: A single self-recurrent neuron with its self-loop weight w. Panel (a) shows the neuron and its equation. Panel (b) shows what the input actually looks like: bold filled dots at the start (the meaningful signal) followed by a long stretch of hollow squares (noise the network must ignore). With w less than 1, the bold dots get smaller and smaller every step.

So the failing pattern is: same network, same weights, every word. Multiplying by the same small number every time dilutes whatever came before. We will see in the next chapter what to do about it.

A running notepad that survives the sentence

Suppose you are reading a mystery novel. You are halfway through chapter six, the detective has just found a torn letter, and a new character walks in. What do you do? You do not stop and reread chapters one through five. You have been keeping a running summary in your head this whole time — "the butler had no alibi, the letter implicates the niece, the new character is the victim's sister" — and when the new clue arrives, you update that summary. You cross out the bits that no longer fit and add the new ones in. The summary itself persists across every page.

That running summary is what an LSTM gives the network.

The technical name is the cell state, and you can see it in the diagram below: the horizontal line that runs straight across the top of the cell, untouched by most of what is going on inside. Olah calls it "kind of like a conveyor belt" — it carries information forward through the whole sentence, with only small, controlled changes made along the way Olah2015.

Caption: The same LSTM cell with the horizontal line on top highlighted. That line is the cell state — the running notepad. It survives every time step nearly intact. The gates are the small operations that touch it along the way.

If the cell state stays untouched and just one weight w is used to pass it forward (set to 1.0, not a number smaller than 1), then the signal from the start of the sentence does not shrink. It just sits there, waiting. This is the "constant error carousel" trick that Hochreiter and Schmidhuber introduced in 1997: a memory line whose contents can be updated by gates but whose backward-flowing error signal does not get multiplied by small weights on every step Hochreiter1997. The 1997 paper proved this can carry meaningful information across more than a thousand time steps — a far cry from the much shorter context that an ordinary recurrent network can hold onto across a single sentence.

One small historical note before we go further. The original 1997 paper had only two gates, not three. Hochreiter and Schmidhuber's original cell used an input gate and an output gate; the forget gate — the one that lets the cell throw things away — was added later by Gers, Schmidhuber and Cummins in 2000. The version we use today is the post-2000 three-gate form, but the cell state running across the top has been there since the very beginning.

Three little decision-makers on the notepad

The cell state carries information forward. But carrying forward is not enough — sometimes the network needs to forget the gender of an old subject to make room for a new one. Sometimes it needs to write a new fact into the notepad. Sometimes it needs to actually use what's in the notepad to answer the question at hand.

These three jobs are done by three small decision-makers, each of which sits on the cell state and asks one yes-or-no question:

  • Forget gate: "Should I cross this out?" It looks at the current word and the recent context, and for every piece of information in the cell state, it outputs a number between 0 and 1 — 0 means "completely throw this away", 1 means "completely keep this". Numbers in between mean "keep some of it". This is the gate that lets the network revise its summary.
  • Input gate: "Should I add this?" It decides what new information gets written into the cell state. There are actually two pieces working together: a filter that picks which slots to update, and a proposal of the new values to write into those slots. In the language-model example, this is where the network writes down "the new subject is female" or "the location is France".
  • Output gate: "Should I show this?" It decides what to read out from the cell state and pass to the next step. The cell state may contain lots of facts, but only some of them are relevant right now. The output gate filters them down to the ones that matter for the current decision.

Caption: The full LSTM cell. The horizontal line on top is the cell state from the last chapter. The forget gate sits at the top left, the input gate and a tanh candidate layer in the middle, and the output gate at the bottom — three small filters that decide what gets crossed out, what gets added, and what gets read out. The same diagram style shows up across Goodfellow's textbook, Chollet's textbook, Karpathy's lecture notes, and most modern tutorials Olah2015.

Here is the intuition in one sentence. The cell state is your running summary of the novel. The forget gate is the red pen that crosses out bits that no longer fit. The input gate is the pencil that writes in new clues. The output gate is the bit you tell your friend when they ask "so what's going on?" — you do not recite your entire summary, you pick the parts that matter right now.

The same three gates appear in every modern textbook chapter on LSTMs. Goodfellow's Deep Learning textbook, in its section on LSTMs, draws the cell the same way: a central state unit, a forget gate that controls how much of the previous state survives, an input gate that controls how much new information gets added, and an output gate that controls how much of the cell's content influences the prediction Goodfellow2016.

A quick aside on how the network learns to use these gates, because you might be wondering. The mechanism is conceptually simple. After the network makes a prediction, you look at how wrong it was and trace that error backward through every step of the sentence. Each gate's weights get nudged to make the error smaller next time. Over thousands of sentences, the forget gate learns to cross out subject genders when a new subject appears; the input gate learns to write down locations when the word "in" is followed by a country name; the output gate learns to release the location only when the verb "speak" is nearby. This is called backpropagation through time — the network is literally learning, by example, which decisions to make at each gate. We will not dig into the math; the take-away is that the gates are not hard-coded. The network figures them out from data.

So an LSTM is one notepad plus three small filters. That is the whole mechanism.

Why a bigger normal network still loses

A natural next question is: why not just make a normal network bigger? Add more layers, more neurons, more of everything. Does that not fix the wash-out problem?

It does not. Stacking more layers on top of a vanilla recurrent network still leaves the underlying problem untouched. Every time step, the network multiplies its current memory by some weight and adds new input. That multiplication happens whether the network has two layers or two hundred. The deeper you stack, the more multiplications you do — which is the opposite of what you want. The diagram from chapter one still tells the whole story: a single self-recurrent neuron with weight w less than 1, and the bold dots at the start of the input getting smaller and smaller with every step Bengio1994.

Caption: The same latch neuron from chapter one, looked at from a different angle. The wash-out happens at every single time step — it is structural, not a depth problem. Making the network deeper adds more steps in series; it does not change the fact that w is still less than 1.

The deeper issue is not depth. The deeper issue is that a normal network treats every input bit equally. Look at the long sentence again:

I grew up in France ... I speak fluent ___.

A plain network sees "I", "grew", "up", "in", "France", "and", "many", "years", "later", "I", "speak", "fluent". The word "France" is no more important to the network than the word "and" or "years". Every one of those words gets the same weight; every one of them has an equal vote in what the network ends up remembering. By the time we reach the blank, the signal from "France" has been averaged out by all the other, less informative words.

This is what people sometimes call the boring-middle problem. The interesting information is at the start ("France") and at the end ("fluent"); the middle is just connective tissue. A plain network weights all three equally. An LSTM, with its three gates, does something different. The forget gate can learn to give the boring middle a weight close to zero — let it pass through the cell state without disturbing what's already there. The input gate can give "France" a weight close to one — write it firmly into the cell state when it arrives. The output gate can hold onto the cell state until the moment the verb "speak" appears, and then release the location. The signal from "France" survives intact not because the network is bigger, but because the gates have learned to protect it.

So the fix is not "more layers". The fix is selective memory. A mechanism that picks which pieces of information survive, rather than treating every piece the same way.

Where LSTMs actually live in the real world

So far we have been talking about LSTMs as a piece of theory. They are also a piece of engineering that has been running inside products you have probably used. Four concrete examples.

Machine translation. In 2014, Sutskever, Vinyals and Le at Google showed that two deep LSTMs glued together — one to encode the source sentence, one to decode the target sentence — could translate English to French at a quality competitive with the phrase-based statistical systems that had dominated the field for years. On the standard WMT'14 English-to-French benchmark, their single LSTM model scored BLEU 34.8, beating the strong phrase-based SMT baseline at 33.3; reranking the SMT system's outputs with the LSTM pushed the number to 36.5 Sutskever2014. A memorable detail: the source sentence was fed to the encoder backwards, which the authors said introduced many short-term dependencies and made the optimisation problem much easier.

Caption: Two chains of LSTM cells. The top chain (A, B, C, end) reads the source sentence. The bottom chain (W, X, Y, Z, end) writes the translation. The LSTM reads the input in reverse — the arrow direction makes that visible.

Inbox autocomplete on mobile. In 2016, Google deployed Smart Reply inside Inbox by Gmail. When you opened an email on your phone, the system suggested three short replies you could send with one tap. The scoring engine that picked the candidates was an LSTM — the same encoder-decoder architecture used for translation, trained on 238 million messages Kannan2016. According to the paper, Smart Reply assisted with about ten percent of all mobile replies on Inbox at the time of writing — a snapshot from 2016, not a current number. The pipeline is more than just the LSTM (there is a triggering model that decides whether to show suggestions at all, and a diversity step that keeps the three options from being near-duplicates), but the LSTM is at the centre, scoring candidate replies.

Caption: The Smart Reply production pipeline. An incoming email goes through preprocessing, a triggering decision, and then an LSTM that scores candidate replies from a whitelist of permitted responses. A diversity step selects the final three suggestions shown to the user.

Character-level text generation. In 2015, Andrej Karpathy trained LSTMs on a string of characters from Shakespeare, the Linux kernel source code, LaTeX math papers, and Wikipedia, and asked them to predict the next character. He published the results in a post titled The Unreasonable Effectiveness of Recurrent Neural Networks. Karpathy's note that "all experiments in this post use an LSTM" is verbatim — when he says RNN, he means the LSTM cell Karpathy2015. The Shakespeare model produced plausible dialogue with speaker labels. The Linux model produced plausible-looking C functions with #include blocks and mutex_unlock/spin_unlock pairs. None of this is magic — the network learns nothing about what words mean; it just learns which characters tend to follow which.

Caption: A character-level RNN reading the input "hell" one character at a time. Each column is one time step: input at the bottom (one-hot character), hidden state in the middle, output scores at the top. The green numbers are the network's confidence that the next character is the labelled target.

Time-series forecasting. LSTMs are still an active research topic, not a museum exhibit. A 2025 paper from AAAI showed that an LSTM-family model with two modern tricks — patching (chopping each series into small chunks before feeding it in) and channel independence (treating each variable as its own univariate series) — reached accuracy comparable to state-of-the-art models on five standard long-term-forecasting benchmarks: Weather, Electricity, Solar, ETTm1, and PEMS03 Kong2025. If you have ever wondered whether anyone still publishes LSTM papers, this is one published at AAAI 2025 (proceedings 2025-04-11).

Caption: The P-sLSTM pipeline. A multivariate time-series is split by channel, chopped into patches, fed through stacked sLSTM blocks (a modern LSTM variant), flattened, and projected to a forecast. The two small sub-panels on the left are expert reference for readers who already know LSTM internals.

One beat that is worth flagging explicitly so the picture is not misleading: speech recognition was an early and important LSTM success story. Earlier speech-to-text systems used LSTM acoustic models in production for years. They are mentioned here as historical context; the four concrete examples above are the ones with the clearest verifiable evidence.

And one sentence on the broader landscape. LSTMs became the dominant sequence-learning model from 2011 onwards. Around 2017, transformer-based architectures took over for most language tasks. But LSTMs did not vanish — they still hold their ground in time-series forecasting and in some on-device settings where a smaller, simpler model matters Zhang2024.

One sentence, walked through the gates

Let us put it all together by following one small sentence through the LSTM cell and watching the cell state change. The sentence we will trace is a shorter version of the long example from chapter one:

The clouds are in the France.

(Admittedly an odd sentence, but it makes the mechanism obvious.) Imagine an LSTM cell has been reading one word at a time, and we are about to feed it each word in turn.

Step 1: "The". The network sees the word "the". The forget gate looks at the cell state and the new word. There is nothing to forget yet (the cell state was initialised empty), so the forget gate mostly says "keep everything as it is". The input gate looks at "the" — it is just an article, not very informative — so it proposes a small update: maybe write down "subject = something". The output gate releases whatever is in the cell state (not much yet) to be used by the next layer. Cell state after step 1: "subject will appear soon".

Step 2: "clouds". Forget gate: "still nothing to forget." Input gate: "okay, the subject is 'clouds'". The cell state now holds "subject = clouds". The notepad has been updated.

Step 3: "are". Forget gate: "keep the subject". Input gate: "are is just a verb, no new entity to record." Output gate: "release the subject so the next layer knows what we're talking about". Cell state: still "subject = clouds".

Step 4: "in". Forget gate: "keep the subject". Input gate: "in often introduces a location — prepare to record one." The cell state now flags "a location will be named soon".

Step 5: "France". Forget gate: "keep the subject". Input gate: "France is a location — write it down." The cell state now holds "subject = clouds, location = France".

Step 6: "?" (the closing question mark). This is the moment the gates earn their keep. The forget gate looks at the new word — a question mark — and considers what to revise. In a more realistic walk-through of "I grew up in France ... I speak fluent ___?", this is the gate that decides "okay, hold onto the location, we are going to need it". The input gate considers whether to write anything new; the question mark itself is not a fact, so the input gate says "no new information to add". The output gate releases the location from the cell state so the next layer can use it to predict "French". Cell state after step 6: still "subject = clouds, location = France" — preserved, not washed out.

If the sentence were "The clouds are in the France" (no question mark, just the setup), the same mechanism would still apply: by the time the network has finished reading, the cell state holds "subject = clouds, location = France". The next step (predicting what comes after "France" in a natural sentence) can read the location out of the cell state whenever it is needed.

This is the whole picture. The cell state is the notepad. The three gates decide when to cross things out, when to write new things in, and when to read things out. The network learned how to make those decisions from data — from thousands of examples of English sentences where the answer to "what comes next?" often depended on a word much earlier in the sentence.

So an LSTM is not a network that passively remembers everything. It is a network that actively chooses what to remember, what to ignore, and what to pay attention to. That is the trick. And it is why, even in 2026, LSTM-family architectures are still being actively researched for time-series forecasting, and have historically been deployed inside mobile and email systems — and they still hold a place in the history of neural machine translation.

References

  1. Long Short-Term Memory — Hochreiter, S. & Schmidhuber, J. (1997). Neural Computation 9(8): 1735–1780. DOI 10.1162/neco.1997.9.8.1735
  2. Learning Long-Term Dependencies with Gradient Descent is Difficult — Bengio, Y., Simard, P. & Frasconi, P. (1994). IEEE Transactions on Neural Networks 5(2): 157–166. DLSI mirror PDF
  3. Understanding LSTM Networks — Olah, C. (2015-08-27). colah.github.io
  4. Deep Learning — Chapter 10: Sequence Modeling — Goodfellow, I., Bengio, Y. & Courville, A. (2016). MIT Press. deeplearningbook.org
  5. Dive into Deep Learning — Chapter 10: Modern Recurrent Neural Networks — Zhang, A., Lipton, Z. C., Li, M. & Smola, A. J. (2024, v1.0.3). d2l.ai
  6. Sequence to Sequence Learning with Neural Networks — Sutskever, I., Vinyals, O. & Le, Q. V. (2014). NIPS 2014. arXiv:1409.3215
  7. Smart Reply: Automated Response Suggestion for Email — Kannan, A. et al. (2016). KDD 2016. arXiv:1606.04870
  8. The Unreasonable Effectiveness of Recurrent Neural Networks — Karpathy, A. (2015-05-21). karpathy.github.io
  9. Unlocking the Power of LSTM for Long Term Time Series Forecasting — Kong, Y. et al. (2025). AAAI-25. arXiv:2408.10006
LSTM: the neural network that chooses what to forget