Backpropagation algorithm derivation
3.1.9· AI-ML › Neural Network Fundamentals
Backprop EXISTS kyun karta hai?
YE problem kya solve karta hai? Ek neural network mein millions of weights hote hain. Gradient descent se train karne ke liye hume har weight ke liye chahiye. Har derivative ko independently chain rule se compute karna same sub-expressions ko billions baar repeat karega.
YE fast kyun hai: Ek early-layer weight ke w.r.t. loss ke gradient mein later layers ke w.r.t. gradient ek factor ke roop mein contained hota hai. Toh agar hum later gradients pehle compute karein aur unhe cache karein, toh har earlier gradient sasta ho jaata hai. Yeh shared-subproblems ki caching exactly dynamic programming hai computational graph pe.
Setup aur notation
Consider karo layer ( se tak). Layer ke liye:
- = weight matrix, = bias vector
- — pre-activation
- — activation ( = activation function)
- (input), (output)
- = loss
Chaar equations ko scratch se derive karna
Step 1 — Output layer error
KAISE: Chain rule se, loss par depend karta hai sirf ke through:
Yeh step kyun? hi se loss tak ka ek maatra path hai, isliye hum iske through chain karte hain.
Kyunki , doosra factor hai. Vector form mein:
jahaan elementwise product hai (Hadamard).
Step 2 — Recurrence: from
Recurrence kyun? loss ko affect karta hai sirf next layer ke pre-activations ke through. Toh:
pe sum kyun? layer ke har neuron mein fan out hota hai; total sensitivity = un sabhi paths pe sum (multivariable chain rule).
Ab compute karo. Kyunki aur :
Substitute karne par:
Matrix form mein:
Step 3 — Weights ke w.r.t. Gradient
, isliye :
Yeh outer product kyun? Har weight input ko neuron se connect karta hai; uska gradient = ( ka blame) × ( ki activity).
Step 4 — Biases ke w.r.t. Gradient
, isliye
Worked example 1 — ek 2-2-1 network haath se
Input , target . Sigmoid , MSE loss .
Weights: , , , .
Forward:
- , . Kyun? , .
- , .
Backward:
- . Kyun? .
- .
- (BP1).
- (BP3). Kyun? scalar ko har activation se multiply karo.
- . ; ; isliye (BP2).
Ab ek gradient-descent step in gradients ka subtract karta hai. Done — ek full pass.
Worked example 2 — sharing kaam kyun bachata hai
ke liye hume chahiye tha, jisne ko reuse kiya (jo already compute ho chuka tha). Agar hum instead se tak fully chain karte toh layer 2 se guzarne wale path ko dobara recompute karna padta. Ek 100-layer net mein woh reuse linear aur exponential cost ke beech ka farak hai.
Flashcards
kya represent karta hai?
BP1 (output error) formula?
BP2 (recurrence) formula?
Backward pass mein transpose kyun?
Gradient w.r.t. weights (BP3)?
Gradient w.r.t. bias (BP4)?
Backprop naive chain rule ke mukable efficient kyun hai?
Kya hum ko pe evaluate karte hain ya pe?
Sigmoid ke liye, ?
BP2 derivation mein pe sum kyun?
Recall Ek 12-saal ke bachche ko explain karo (Feynman)
Ek robot jawab guess karta hai aur woh galat hota hai. Khud ko fix karne ke liye, woh poochta hai "mere kaun se knobs ne galti ki, aur kitni?" Aakhri knob check karna aasaan hai. Phir woh bachi hui blame ko apne pehle wale knob ko whisper karta hai, aur woh ek pehle wale ko, shuruaat tak. Har knob sirf apne baad wale knob ki whisper sunta hai — koi poori story redo nahi karta. Phir har knob thoda si uss direction mein turn karta hai jo blame kam kare. Woh whisper-passing-backwards hi backpropagation hai.
Connections
- Chain rule (multivariable) — har step ka mathematical engine.
- Gradient descent — backprop ke produce kiye gradients consume karta hai.
- Activation functions and their derivatives — supply karta hai (sigmoid, ReLU, tanh).
- Computational graphs and autodiff — backprop reverse-mode automatic differentiation hai.
- Vanishing and exploding gradients — repeated aur products ka seedha consequence.
- Loss functions (MSE, cross-entropy) — BP1 mein determine karte hain.