3.1.11 · HinglishNeural Network Fundamentals

Vanishing and exploding gradients

1,788 words8 min readRead in English

3.1.11 · AI-ML › Neural Network Fundamentals


Kya ho raha hai actually

KYA multiply hota hai? Ek plain feed-forward net mein, har layer compute karta hai: Backprop error ko chain rule use karke backward push karta hai.


Derivation from first principles

Maano "layer pe error" hai.

Step 1 — consecutive layers ko link karo. Kyunki hai, chain rule deta hai: Yeh step kyun? Layer ka error loss tak sirf layer ke through pahunchta hai, toh hum ka error lete hain, use weights ke through pull back karte hain, aur scale karte hain is baat se ki is neuron ka output apni input ke saath kitna change hota hai, yaani .

Step 2 — layers ke across unroll karo. Step 1 ko last layer se layer 1 tak baar baar apply karne par: Yeh step kyun? Har layer ek aur multiplicative factor insert karti hai. Layer se layer tak jaane mein links cross hote hain, toh product mein factors hote hain.

Step 3 — magnitude ko bound karo (key insight). Norms lo. Agar har factor satisfy karta hai , toh: Yeh step kyun? Ek product ka norm norms ka product hota hai, aur factors hain. Ab behaviour clearly samajh aata hai:

  • vanish.
  • explode.
  • signal preserved. Yahi poora design goal hai.

Activation choice kyun matter karti hai

Sigmoid kyun vanish karta hai: iska derivative kabhi se zyada nahi hota. Toh perfectly scaled weights ke saath bhi, ; kaafi layers mein ke factors compound hokar near zero ho jaate hain. ReLU ka derivative positive inputs ke liye hota hai, toh yeh signal ko shrink nahi karta (iska factor exactly hai), yahi reason hai ki deep nets mein yeh dominate karta hai.

Figure — Vanishing and exploding gradients

Fixes (80/20 jo zyaadatar cases solve karta hai)

  1. Weight initialization ko scale karo taaki variance preserve ho.
    • Xavier/Glorot (tanh/sigmoid ke liye): .
    • He (ReLU ke liye): (extra kyunki ReLU aadhe inputs ko zero kar deta hai). Kyun: shuruaat mein rakhta hai.
  2. Non-saturating activations — ReLU / LeakyReLU (slope ).
  3. Batch/Layer Normalization — har layer mein ko re-center/scale karta hai taaki healthy range mein rahe.
  4. Residual (skip) connections Jacobian ko ek term deta hai, toh gradient ke paas hamesha ek "" path hota hai (factor ).
  5. Gradient clipping (exploding ke liye) — rescale karo agar threshold ho.
  6. LSTM/GRU gates (RNNs ke liye) — additive cell state near- recurrence deta hai.

Worked examples


Common mistakes


Active recall

Backprop mein kaunsa operation gradients ko vanish ya explode karta hai?
Jacobians ki repeated multiplication (weights × activation derivatives) layers ke across — bahut saare factors ka ek product.
Ek -layer net ke gradient mein kitne multiplicative factors hote hain?
, ek per layer-to-layer link, toh bound jaisa scale karta hai.
Stability kaunsi ek quantity se determine hoti hai?
Per-layer gain ; chahiye.
Sigmoid vanishing gradients kyun promote karta hai?
Iska derivative hai, toh factors hamesha signal ko shrink karte hain.
Sigmoid derivative ki maximum value kya hai aur kahan?
, par (jahan hoti hai).
He vs Xavier init — kab aur kyun factor of 2?
He ReLU ke liye (); ReLU ke ~aadhe activations zero karne ko compensate karta hai. Xavier tanh/sigmoid ke liye ().
Kaunsi fix specifically exploding gradients ko target karti hai?
Gradient clipping (gradient ko rescale karo agar uska norm ek threshold se zyada ho).
Residual connections kyun help karte hain?
Layer Jacobian ban jaata hai, gradient ke liye ek guaranteed gain- identity path deta hai.
, ke liye shrink factor estimate karo.
( factors use karke); order either way.
Kya loss high ho sakta hai jabki gradients vanish ho rahe hon?
Haan — early layers frozen rehti hain jabki later layers still seekhti hain.
Recall Feynman: 12-saal ke bacche ko samjhao

Socho tum ek message 20 doston ki line mein whisper kar rahe ho. Agar har dost thoda dheere whisper kare, toh end mein koi awaaz nahi — yahi vanishing gradient hai (pehle doston ko correction sunti hi nahi). Agar har dost thoda zyada unchhi awaaz mein bole, toh end mein sab chilla rahe hain — yahi exploding hai. Hum ise theek karte hain sabko message same volume par repeat karna sikhaakar (gain ), achhe starting rules se (He/Xavier) aur shortcuts se (skip connections) taaki message poori line mein survive kare.

Connections

  • Backpropagation — woh chain-rule product jo problem create karta hai.
  • Activation Functions — sigmoid/tanh/ReLU aur unke derivatives.
  • Weight Initialization — Xavier & He as -control.
  • Batch Normalization — pre-activations ko well-scaled rakhta hai.
  • Residual Networks (ResNet) — gradient flow ke liye identity paths.
  • LSTM and GRU — additive cell state recurrent version fix karta hai.
  • Gradient Descent — yeh gradients weights update karne ke liye kaise use hote hain.

Concept Map

enables

uses

multiplies

each factor

bounded by

raised to power

gamma < 1

gamma > 1

gamma approx 1

effect

effect

goal

Deep network depth

Backprop passes error backward

Chain rule per layer

Product of many Jacobians

W transpose times diag sigma prime

Norm factor gamma

gamma^L-1 scaling

Vanishing gradient

Exploding gradient

Signal preserved

Early layers stop learning

Weights blow up, loss NaN

Stable deep training