LSTM — gates, cell state
5.6.13· Coding › Machine Learning (Aerospace Applications)
WHAT is an LSTM?
WHY do we need it? Aerospace mein hum cheezein lambe horizons par predict karte hain — jaise ek wing spar mein lambi vibration history se fatigue accumulation estimate karna, ya ek turbine blade ki remaining useful life (RUL) predict karna. Relevant event (ek micro-crack initiation) hazaaron timesteps pehle hua hoga. Ek plain RNN use bhool jaata hai; ek LSTM use mein hold kar sakta hai.
HOW it works — the four computations
Har timestep par hum previous output aur current input ko concatenate karte hain: . Sare gates is vector ke affine maps hain jo ek squashing function se guzarti hain.
Gates ke liye sigmoid kyun? ek valve opening fraction ki tarah kaam karta hai: = puri tarah band (block), = puri tarah khula (pass). Candidate ke liye tanh kyun? likhne wali value ko positive ya negative hone deta hai, zero par centered — signed features ke liye acha hai.
DERIVATION — why the cell update kills vanishing gradients
Chalo scratch se derive karte hain ki gradients ko survive karne mein kyun help karta hai.
Step 1 — the RNN problem. Ek plain RNN mein, . steps mein backprop Jacobians ko multiply karta hai: Yeh step kyun? Timesteps mein chain rule. Har factor mein hai aur aksar hoti hai, toh product exponentially — gradients vanish ho jaate hain.
Step 2 — the LSTM cell path. Sirf line ke saath cell recurrence ka derivative lo: Yeh step kyun? mein, baaki terms ko inputs maan kar, direct partial sirf hai — koi weight matrix nahi, koi tanh' nahi, sirf ek elementwise gate.
Step 3 — chain along the cell path. Yeh kyun matter karta hai: agar forget gate ke paas rehta hai (network choose karta hai yaad rakhna), toh product ke paas rehta hai — gradient bina kisi kami ke peeche flow karta hai. LSTM seekh sakta hai highway ko khula rakhna. Yahi constant error carousel hai.

Worked Example 1 — one scalar timestep
Scalar states lo. Diya gaya , aur pre-activations is tarah chosen ki .
- Cell: . Kyun? Purani memory ka 90% rakho, naye candidate ka 80% add karo.
- Output: . Kyun? (Squashed) cell content ka 60% read out karo.
Worked Example 2 — "remember forever"
Maano task ko par dekhi gayi ek value 1000 steps tak store karni hai. Agar network set kare saare ke liye, toh Yeh step kyun? Forget gate poori tarah khula aur input gate band ke saath, memory perfectly copy hoti hai — ek plain RNN literally yeh bina exploding/vanishing ke nahi kar sakta.
Worked Example 3 — aerospace framing
Vibration sensor stream ek LSTM ko feed karta hai jo bearing RUL predict karta hai. par ek rare high-amplitude spike ko par prediction par influence karna chahiye. Training push karta hai (spike ko mein write karo), phir baad mein (use hold karo), aur (forecasting karte waqt read out karo). Kyun? Gates learned data-dependent switches hain — gradient descent is routing ko automatically discover karta hai.
Common Mistakes
Flashcards
Ek LSTM timesteps ke beech kon se do states carry karta hai?
Cell-state update equation likho.
kya hai aur yeh kyun matter karta hai?
Gates ke liye sigmoid lekin candidate ke liye tanh kyun?
Output gate kya karta hai?
Forget-gate bias ko positive kyun initialize karte hain?
Ek plain RNN mein gradients kyun vanish hote hain?
set karne se kya behaviour milta hai?
Recall Feynman: 12-saal ke bacche ko samjhao
Ek khilone ki train sochao jo ek note lekar track par chal rahi hai. Har station par teen gatekeepers hain jinke paas dials hain. Gatekeeper 1 (forget) decide karta hai purane note ka kitna hissa erase karna hai. Gatekeeper 2 (input) decide karta hai naye note ka kitna hissa add karna hai. Gatekeeper 3 (output) decide karta hai abhi note ka kitna hissa zor se padhna hai. Kyunki train bas note ko track par carry karti hai (scratch se rewrite nahi karti), woh ek important message bahut lambe time tak rakh sakti hai — isliye LSTM un cheezein yaad rakhta hai jo ek normal robot brain bhool jaata hai.
Connections
- Recurrent Neural Networks (RNN) — woh base jise LSTM improve karta hai.
- Vanishing & Exploding Gradients — woh problem jo cell state solve karta hai.
- GRU — Gated Recurrent Unit — sasta cousin (gates merge karta hai).
- Backpropagation Through Time (BPTT) — yeh gradients kaise compute hote hain.
- Sigmoid and Tanh Activations — use hone wale squashing functions.
- Remaining Useful Life (RUL) Prediction — aerospace application.
- Time Series Forecasting — general use case.