5.6.12 · HinglishMachine Learning (Aerospace Applications)

Recurrent neural networks — hidden state, BPTT

1,745 words8 min readRead in English

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.

Figure — Recurrent neural networks — hidden state, BPTT

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?
Time tak dekhe gaye saare inputs ka ek running summary/memory, jo har step par aur se update hota hai.
RNN hidden-state update likho.
.
RNN weights time ke across share kyun hoti hain?
Variable-length sequences handle karne ke liye aur time-invariance encode karne ke liye (har step same rule); ek param, kai uses.
Ek sentence mein BPTT kya hai?
Ordinary backprop jo RNN par time ke over unrolled apply hota hai, jahan shared weights ke gradients saare steps par summed hote hain.
ko do sources se gradient kyun milta hai?
Yeh loss ko seedha output ke via aur indirectly next state ke via affect karta hai; multivariate chain rule paths ko sum karta hai.
Recurrent Jacobian kya hai?
.
RNNs mein gradients kyun vanish/explode hote hain?
Backprop kai similar Jacobians multiply karta hai; jaisa behave karta hai, toh vanish hota hai aur explode hota hai.
Exploding/vanishing gradients ke do standard fixes?
Gradient clipping (explode) aur gated cells LSTM/GRU near-identity memory path ke saath (vanish).
Plain linear recurrence ki jagah tanh kyun use karo?
Linear net ko ek linear map mein collapse karta hai aur memory gate nahi kar sakta; tanh state ko bound karta hai aur nonlinearity add karta hai.
Truncated BPTT kya sacrifice karta hai?
Truncation window se lambe gradients (aur is tarah learnable dependencies) zero set ho jaate hain.

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

Concept Map

feeds

feeds

tanh keeps bounded

produces

reused every step

enables

models

used for

loop unrolled into

trained by

computes

via multivariate chain rule

Input xt

Hidden state ht

Previous state h t-1

Output yt

Shared weights Whh Wxh Why

Time invariance + variable length

Sequences: flight data over time

Aerospace: predict next state, anomaly

Unrolled deep net

Backprop Through Time

delta_t = output path + future path

Gradient dL/dWhh