Recurrent neural networks — hidden state, BPTT
5.6.12· Coding › Machine Learning (Aerospace Applications)
1. Hidden state kya hai? (WHAT)
tanh kyun? Yeh mein squash karta hai, state ko bounded rakhta hai taaki recirculate hote waqt blow up na ho, aur 0 par centered hai (sigmoid ke unlike), jo gradients ko healthier rakhta hai.
Weights share kyun? Sequence kisi bhi length ki ho sakti hai. Agar har step ke apne weights hote toh (a) variable length handle nahi ho sakti, aur (b) "same physical rule har instant apply hoti hai" yeh generalize nahi ho sakta. Sharing mein time-invariance bake hoti hai.
2. Network ko unroll karna (HOW sochna hai)
Ek RNN ek loop hai, lekin gradients compute karne ke liye hum ise ek deep feed-forward net mein unroll karte hain — ek layer har time step ke liye, saari layers ek saath tied hoti hain.

3. BPTT ko first principles se derive karna
Hum chahte hain ek total loss ke liye, jahan , ko target se compare karta hai.
Step 0 — pre-activation. Define karo , toh . Kyun? Pre-activation ko naam dene se hum chain rule cleanly apply kar sakte hain.
Step 1 — gradient hidden state mein wapas flow karna. loss ko do tareekon se affect karta hai: seedha ke through, aur indirectly next step ke through. Toh define karo : Sum kyun? Multivariate chain rule: ek variable jo kai paths feed karta hai woh sum of path gradients contribute karta hai. Yahi BPTT ka dil hai — gradient time mein peeche pass hota hai.
Step 2 — recurrent Jacobian. Kyunki , use karke. Kyun? ke through phir linear map ke through chain rule.
Step 3 — shared weights par accumulate karna. Kyunki har step par reuse hoti hai, iska gradient saare steps ke contributions ka sum hai: Phir sum kyun? Same weight-sharing logic: ek parameter, kai uses ⇒ saare "jobs" add up karo.
4. RNNs train karna kyun mushkil hai: vanishing/exploding gradients
ko tak expand karo: door-future losses ke gradients Jacobians ke product se multiply hote hain:
5. Worked example — haath se tiny scalar RNN
Sab kuch scalar ho: , inputs , .
Forward.
- . Kyun? Update rule mein plug karo.
- .
Loss. Maano (final step par target 1). .
Backward (BPTT).
- .
- . Kyun? times .
- . Pehla term 0 kyun? Step 1 par koi output loss nahi.
ke w.r.t. gradient (steps par sum, "input" ke taur par): Do terms kyun? Weight step 1 par use hua ( multiply karke) aur step 2 par ( multiply karke). Dono sum karo.
6. Worked example — sharing generalisation mein kyun help karta hai
Task: detect karo "airspeed 3 consecutive samples ke liye badh rahi hai." 3 ki fixed window par ek feed-forward net ko slot-1, slot-2, slot-3 ke liye alag weights seekhne padte hain. Ek RNN ek comparison rule seekhta hai aur use stream mein chalte waqt apply karta hai — toh yeh bina retraining ke 5-sample window ke liye bhi kaam karta hai. Yeh step kyun important hai: yeh dikhata hai ki weight sharing = ek prior ki "physics har instant same hai."
Recall Feynman: 12-saal ke bachche ko explain karo
Socho tum ek story ek word at a time padh rahe ho aur apne dimaag mein ek chhota sticky note rakh rahe ho jisme likha hai "abhi tak kya hua." Har naya word, sticky note update karo. Woh sticky note hidden state hai. Jab ending galat ho, tum poori story mein peeche jaate ho yeh pata lagane ke liye ki kaun se pehle words ne tumhe gadbad kiya — aur tum same reading rules poore time use karte ho, toh saari corrections add up karo. Woh story-mein-peeche-blame karna BPTT hai. Mushkil: bahut lambi story ke baad tumhara "blame signal" kuch nahi ho jaata (vanishing gradient), toh net shuruaat bhool jaata hai.
Flashcards
Hidden state kya represent karta hai?
RNN hidden-state update likho.
RNN weights time ke across share kyun hoti hain?
Ek sentence mein BPTT kya hai?
ko do sources se gradient kyun milta hai?
Recurrent Jacobian kya hai?
RNNs mein gradients kyun vanish/explode hote hain?
Exploding/vanishing gradients ke do standard fixes?
Plain linear recurrence ki jagah tanh kyun use karo?
Truncated BPTT kya sacrifice karta hai?
Connections
- Feed-forward Neural Networks — RNN unrolled = deep tied-weight feed-forward net.
- Backpropagation — BPTT unrolled graph par backprop hai.
- LSTM and GRU — vanishing gradients ke liye gated fixes.
- Vanishing and Exploding Gradients
- Time Series Forecasting — flight-data / sensor prediction.
- Kalman Filter — classical recursive state estimator; learned hidden state ka conceptual cousin.
- Sequence Modeling in Flight Data