Recurrent Neural Networks (RNNs) wo neural network architectures hain jo sequential data process karne ke liye design ki gayi hain — ye ek internal hidden state maintain karti hain jo memory ki tarah kaam karta hai. Feedforward networks ke ulat, jo har input ko alag se treat karte hain, RNNs mein connections hote hain jo khud par wapas loop karte hain, jisse time steps ke across information persist ho sakti hai.
Space: O(T⋅dh) (backprop ke liye hidden states store karo)
Feedforward se comparison:
Feedforward: Ek input ke liye O(1), koi sequential dependency nahi
RNN: O(T) sequential operations, time ke across parallelize nahi ho sakta
Ye sequential nature RNN ki Transformers ke comparison mein key limitation hai.
Recall Ek 12 saal ke bachche ko samjhao
Socho tum ek detective story padh rahe ho. Har page tumhe ek clue deta hai. Ek normal robot brain (feedforward network) har page ko alag se dekhega aur jo pehle padha usse bhool jaayega — mystery solve karne ke liye bilkul bekar!
Ek RNN ek detective ki notebook ki tarah hai. Jab tum page 1 padhte ho, tum apni notebook mein important cheezein likhte ho. Page 2 par, tum NAYA clue padhte ho AUR apni notebook check karte ho ki pehle kya seekha tha. Tum is combined information se notebook update karte ho. Page 3? Same cheez — naya clue padho, notebook check karo, update karo.
Notebook "hidden state" (h) hai. Detective ka dimaag har page ke liye same thinking rules (weights W) use karta hai, lekin notebook ke contents badlte rehte hain jaise tum zyada seekhte ho. Last page tak, teri notebook mein POORI kitaab ke clues hain, jo tumhe kehne mein madad karte hain "The butler did it!"
Problem: Agar kitaab 1000 pages lambi hai, toh notebook page 1000 tak page 1 ki cheezein bhool sakti hai — yahi vanishing gradient problem hai. Behtar detectives (LSTM, GRU) ke paas special notebooks hoti hain jo zyada lambe time tak yaad rakh sakti hain!
RNNs mein hidden state ka kya purpose hai? :: Hidden state h(t) memory ki tarah kaam karta hai, jo saare pehle time steps ke baare mein information encode karta hai, jisse network sequence ke across context maintain kar sakta hai.
RNNs time steps ke across weights kyun share karte hain?
Weight sharing RNNs ko fixed number of parameters ke saath variable-length sequences handle karne deta hai, aur ek inductive bias provide karta hai ki sequence ke rules time ke saath nahi badalte (CNNs mein spatial weight sharing ke analogous).
RNNs mein vanishing gradients kya cause karta hai?
Backpropagation through time ke dauran, gradients mein Jacobians ke products hote hain ∏iWhhT⋅diag(tanh′). Agar ∣∣Whh∣∣<1, toh repeated multiplication gradients ko exponentially shrink kar deta hai, jisse long-term dependencies seekhna impossible ho jaata hai.
Many-to-one aur many-to-many RNN architectures mein kya fark hai?
Many-to-one ek input sequence process karta hai aur ek single output produce karta hai (jaise final hidden state use karke sentiment classification). Many-to-many ek input sequence process karta hai aur ek output sequence produce karta hai (jaise machine translation), potentially alag input/output lengths ke saath.
Har naye sequence ki shuruwat mein h(0)=0 initialize kyun karte hain?
Training examples independent hote hain. Pehle sequence ka hidden state carry over karne se spurious correlations banti hain, jisse network un patterns ko seekhne ki koshish karta hai jo alag sequences ke across actually exist nahi karte.
Truncated BPTT kya hai aur isko kyun use karte hain?
Truncated Backpropagation Through Time gradient computation ko full sequence ki jagah k time steps tak limit karta hai. Ye long sequences ke liye memory usage aur computation reduce karta hai, jabki pure sequence ke through forward propagation ab bhi allow karta hai.
RNN hidden state se output kaise produce karte hain?
Ek linear projection apply karo: y(t)=Whyh(t)+by, phir task-specific activation apply karo (classification ke liye softmax, regression ke liye kuch nahi). Isse hidden dimension output dimension se alag ho sakta hai.
Sequence length T ke liye RNN forward pass ki computational complexity kya hai?
O(T⋅dh2) jahan dh hidden dimension hai. Ye har time step par matrix multiplications ki wajah se hota hai. Feedforward networks ke ulat, RNN operations sequential hain aur time ke across parallelize nahi ho sakte.
RNN hidden state mein sigmoid ki jagah tanh activation kyun use karte hain?
tanh sigmoid ke [0,1] ki jagah [−1,1] range mein output deta hai (zero-centered), jo backpropagation ke dauran healthier gradients maintain karne mein madad karta hai aur hidden state mein bias shift issues rokta hai.