Single-head attention ki representational capacity limited hoti hai. Q,K,V projections ka ek single set sirf ek type ka relationship pattern seekh sakta hai. Lekin language (aur zyaattar sequential data) mein ek saath kaafi saare structure types hote hain:
Syntactic dependencies (subject verb se agree karta hai)
Semantic relationships (synonym, antonyms)
Positional patterns (nearby words vs. distant context)
Co-reference (pronouns jo pehle ke nouns se link hote hain)
Multi-head attention (MHA) multiple representation subspaces parallel mein seekhta hai, jisme har head alag patterns mein specialize karta hai.
Lambi sequences ke liye jahan n≫dmodel, O(n2dmodel) attention term dominate karta hai. Isliye Transformers bahut lambi sequences (length 10,000+) ke saath struggle karte hain—sequence length mein quadratic!
Recall Ek 12-Saal-Ke Bachche Ko Explain Karo
Socho tum apne dost ki lambi kahani samajhne ki koshish kar rahe ho. Tum ek saath sab par focus nahi kar sakte, toh tumhara brain kuch smart karta hai: woh ek saath alag-alag tareekon se alag-alag parts par dhyan deta hai.
Tumhare brain ka ek hissa sunata hai ki kisne kya kiya (jaise "Alice ne ball throw ki").
Doosra hissa emotions sunata hai (jaise "woh excited thi").
Teesra hissa track karta hai ki cheezein kab hui (jaise "pehle... phir... aakhir mein...").
Multi-head attention waise hi kaam karta hai! Computer ke paas multiple "attention heads" hote hain (jaise tumhare brain ke alag-alag hisse), aur har ek text mein alag patterns par focus karta hai:
Head 1 un words ko connect kar sakta hai jo grammatically saath jaate hain ("the cat" → "sat").
Head 2 un words ko connect kar sakta hai jo similar cheezein mean karte hain ("happy" ← "joyful").
Head 3 nearby words ko connect kar sakta hai.
Har head ek special talent waale dost ki tarah hai—ek grammar mein great hai, ek feelings samajhne mein, ek order yaad rakhne mein. In saare doston ko saath kaam karwa ke (wahi "multi" part hai), computer kahani ko kahin behtar samajhta hai jaise ki sirf ek dost help kar raha ho!
Ant mein "concatenate and project" step waise hai jaise saare doston ko baith ke share karwana ki unhone kya notice kiya, taaki tumhe poori picture mile.
Linear Projections in Neural Networks: WQ,WK,WV,WO matrices kya karte hain
#flashcards/ai-ml
Single-head attention ke mukable multi-head attention ka primary advantage kya hai? :: Multi-head attention multiple representation subspaces parallel mein seekhta hai, jisse model ek saath alag types ke relationships (syntactic, semantic, positional) capture kar sakta hai. Ek single head ki representational capacity limited hoti hai.
h heads aur model dimension dmodel wale multi-head attention mein, har head ki dimension kya hoti hai?
Har head dimension dk=dv=dmodel/h mein operate karta hai. Yeh total computation constant rakhta hai jabki parallel specialization enable karta hai.
Har head ke liye alag projection matrices WiQ,WiK,WiV kyun use karte hain?
Alag projections har head ko same input se alag features seekhne dete hain. Agar saare heads identical projections use karein, toh woh identical attention patterns compute karenge, koi faayda nahi.
Head outputs ko sum karne ki jagah concatenate kyun karte hain?
Concatenation har head ki distinct information preserve karta hai. Summing patterns ko mix kar deta, aur har head ne jo specialized information seekhi hai woh kho jaati. Final WO projection phir seekh sakta hai ki heads ko optimally kaise combine karein.
Model dimension dmodel wale multi-head attention ka total parameter count kya hai?
4dmodel2 parameters: saare heads mein WQ,WK,WV projections ke liye 3dmodel2, plus output projection WO ke liye dmodel2.
Multi-head attention ki computational complexity kya hai?
Dominant term O(n2dmodel) hai jahan n sequence length hai, jo saari positions mein attention scores compute karne se aata hai. Yeh sequence length mein quadratic hai.
Multi-head attention mein final WO projection kyun exist karta hai?
WO model ko heads ke across information mix karne deta hai. Concatenation ke baad, heads abhi bhi alag "channels" mein hain—WO seekhta hai ki alag types ki attention (syntactic + semantic + positional) ko task ke liye optimally kaise combine karein.