Vigyata.AI
Is this your channel?

L-9 Transformer Decoder Explained Step-by-Step | Masked Attention & Cross Attention

1.3K views· 73 likes· 45:36· Jan 13, 2026

In this video, we deep dive into the Transformer Decoder and understand how text is generated one token at a time. We start from the very beginning and explain: What is the input to the decoder Why decoder starts with the SOS token How embeddings and positional encoding are applied How Masked Multi-Head Self-Attention works step by step Why masking is needed and how future tokens are blocked How attention scores, softmax, and probabilities are computed Why the decoder also uses multiple attention heads What happens after masked attention (Add & Norm) How Cross-Attention connects decoder with encoder output How the final output goes through Linear + Softmax to generate the next token This lecture focuses on intuition, shapes, and math, making it easy to understand even if you are learning Transformers for the first time. 📸 Follow me on Instagram: @codewithaarohihindi 🔗 https://instagram.com/codewithaarohihindi 📧 You can also reach me at: aarohisingla1987@gmail.com 👍 Like 🔁 Share 🔔 Subscribe for more deep learning and AI lectures

About This Video

इस वीडियो में मैंने Transformer Decoder को बिल्कुल शुरुआत से end-to-end समझाया है—कि decoder text को one token at a time कैसे generate करता है। अभी तक हम encoder कर चुके थे और हमारे पास encoder output एक matrix आता है (जैसे मेरे example में 8 * 512), लेकिन मैंने साफ बताया कि encoder output decoder का direct input नहीं होता। Decoder की input वो tokens होते हैं जो decoder खुद generate करता है—पहले SOS (Start Of Sequence) token, फिर softmax से next token, फिर वो token input में add होकर अगला token generate करवाता है। इसी वजह से हर step पर decoder input की shape बदलती रहती है: 1*512, फिर 2*512, फिर 3*512… फिर मैंने decoder की तीन sub-layers का overview दिया: (1) Masked Multi-Head Self-Attention, (2) Encoder-Decoder Attention यानी Cross-Attention, और (3) Feed Forward Network—और हर layer के बाद Add & Norm क्यों जरूरी है (shape same होनी चाहिए ताकि element-wise addition हो सके)। Main focus मैंने masked attention पर रखा: query-key-value से attention matrix बनती है, फिर mask लगाकर future tokens block किए जाते हैं (negative infinity डालकर), और softmax के बाद masked positions की probability zero हो जाती है। साथ ही मैंने बताया कि multi-head (जैसे 8 heads) में यही computation parallel होता है, फिर concatenate करके linear projection (W_o) से final representation बनती है।

Frequently Asked Questions

🎬 More from Code With Aarohi Hindi