LSTM — gates, cell state
WHAT is an LSTM?
WHY do we need it? In aerospace we predict things over long horizons — e.g. estimating fatigue accumulation in a wing spar from a long vibration history, or predicting remaining useful life (RUL) of a turbine blade. The relevant event (a micro-crack initiation) may have happened thousands of timesteps ago. A plain RNN forgets it; an LSTM can hold it in .
HOW it works — the four computations
At each timestep we concatenate the previous output and current input: . All gates are affine maps of this vector passed through a squashing function.
Why sigmoid for gates? acts like a valve opening fraction: = fully closed (block), = fully open (pass). Why tanh for candidate? lets the written value be positive or negative, centered at zero — good for signed features.
DERIVATION — why the cell update kills vanishing gradients
Let's derive from scratch why helps gradients survive.
Step 1 — the RNN problem. In a plain RNN, . Backprop through steps multiplies Jacobians: Why this step? Chain rule across timesteps. Each factor has and often , so the product exponentially — gradients vanish.
Step 2 — the LSTM cell path. Take the derivative of the cell recurrence along the line only: Why this step? In , treating other terms as inputs, the direct partial is just — no weight matrix, no tanh', just an elementwise gate.
Step 3 — chain along the cell path. Why this matters: if the forget gate stays near (network chooses to remember), the product stays near — the gradient flows back undiminished. The LSTM can learn to keep the highway open. That's the constant error carousel.

Worked Example 1 — one scalar timestep
Take scalar states. Given , and pre-activations chosen so that .
- Cell: . Why? Keep 90% of old memory, add 80% of the new candidate.
- Output: . Why? Read out 60% of the (squashed) cell content.
Worked Example 2 — "remember forever"
Suppose the task needs to store a value seen at for 1000 steps. If the network sets for all , then Why this step? With forget gate wide open and input gate shut, the memory is copied perfectly — a plain RNN literally cannot do this without exploding/vanishing.
Worked Example 3 — aerospace framing
Vibration sensor stream feeds an LSTM predicting bearing RUL. A rare high-amplitude spike at should influence the prediction at . Training pushes (write the spike into ), then afterwards (hold it), and (read it out when forecasting). Why? The gates are learned data-dependent switches — gradient descent discovers this routing automatically.
Common Mistakes
Flashcards
What two states does an LSTM carry between timesteps?
Write the cell-state update equation.
What is and why does it matter?
Why sigmoid for gates but tanh for the candidate?
What does the output gate do?
Why initialize the forget-gate bias positive?
In a plain RNN, why do gradients vanish?
Setting gives what behaviour?
Recall Feynman: explain to a 12-year-old
Imagine a toy train on a track carrying a note. At each station there are three gatekeepers with dials. Gatekeeper 1 (forget) decides how much of the old note to erase. Gatekeeper 2 (input) decides how much of a new note to add. Gatekeeper 3 (output) decides how much of the note to read aloud right now. Because the train just carries the note along the track (adding, not rewriting from scratch), it can keep an important message for a very long time — that's why the LSTM remembers things a normal robot brain forgets.
Connections
- Recurrent Neural Networks (RNN) — the base LSTM improves on.
- Vanishing & Exploding Gradients — the problem the cell state solves.
- GRU — Gated Recurrent Unit — cheaper cousin (merges gates).
- Backpropagation Through Time (BPTT) — how these gradients are computed.
- Sigmoid and Tanh Activations — the squashing functions used.
- Remaining Useful Life (RUL) Prediction — aerospace application.
- Time Series Forecasting — general use case.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, normal RNN ek hi memory rakhta hai jise har step pe overwrite kar deta hai — isliye purani important baat bahut jaldi "smear" ho jaati hai, aur gradients vanish ho jaate hain. LSTM ka jugaad simple hai: usne ek alag cell state banaya, ek tarah ki conveyor belt / highway, jispe information seedhi flow karti hai bina baar-baar multiply hue. Isko control karte hain teen chhote gates — forget (), input (), aur output () — jo sigmoid se aate hain, matlab se tak ki "valve opening" hoti hai.
Core formula yaad rakho: , aur output . Yaani forget gate decide karta hai purani memory ka kitna hissa rakhna hai, input gate naye candidate (jo tanh se signed value deta hai) ka kitna add karna hai, aur output gate batata hai ki abhi kitna "padh ke bahar" nikaalna hai. FICO — Forget, Input, Candidate, Output — yaad rakhna easy hai.
Gradient wali beauty yeh hai: , koi weight matrix ya tanh' nahi. Agar network rakhe to gradient bina ghata hue back propagate hota hai — isko constant error carousel kehte hain. Isliye LSTM 1000 steps purani baat bhi yaad rakh sakta hai.
Aerospace mein yeh gold hai: turbine blade ya bearing ka Remaining Useful Life predict karna ho, ya wing vibration se fatigue estimate karna ho — koi critical spike 200th step pe aaya jo 5000th step ki prediction ko affect karta hai, LSTM khud seekh leta hai ki us spike ko mein store kar ke hold karo. Ek chhoti si galti se bachna: forget gate ka bias positive initialize karo () taaki shuru mein network default se yaad rakhe, warna sab bhoolta rahega.