PIXELBANKv8.2.1
Menu
Back to NLP Study Plan
Week 6

Chapter 6: Attention Mechanisms

Master the attention mechanism from Bahdanau alignment scores to the full Transformer architecture. Learn self-attention, multi-head attention, positional encoding, and the encoder-decoder framework that powers modern NLP.

Chapter Overview

Attention mechanisms solved the fundamental bottleneck of sequence-to-sequence models: compressing an entire input sequence into a single fixed-length vector. Instead of forcing the encoder to pack everything into one representation, attention allows the decoder to dynamically focus on different parts of the input at each generation step. This simple idea --- letting the model learn where to look --- transformed machine translation and laid the groundwork for the Transformer.

The Transformer architecture, introduced in "Attention Is All You Need" (Vaswani et al., 2017), took this further by replacing recurrence entirely with self-attention. Each token in a sequence attends to every other token, computing relevance scores via query-key-value projections. Multi-head attention runs several attention functions in parallel, capturing different types of relationships. Combined with positional encodings, layer normalization, and residual connections, this produces a highly parallelizable architecture that scales to massive datasets.

This chapter traces the evolution from additive (Bahdanau) attention through scaled dot-product self-attention to the full Transformer encoder-decoder. You will also study the major variants --- BERT, GPT, and T5 --- that adapt the Transformer to different tasks by choosing which blocks to keep and how to mask attention.

Chapter Roadmap

Click any topic to jump in

1
Attention Basics

Alignment scores, softmax weighting, and context vectors — the core attention computation.

Attending within a sequence

Self-attention and parallel heads for richer representations

2
Self-Attention

Query-key-value projections and scaled dot-product attention within a single sequence.

3
Multi-Head Attention

Running parallel attention heads to capture different relationship types simultaneously.

Adding position awareness
4
Positional Encoding

Injecting position information into permutation-invariant attention via sinusoidal or learned encodings.

The full architecture and its variants

Assembling components into complete models

5
Transformer Architecture

Residual connections, layer normalization, and FFN layers assembled into the full Transformer.

6
Transformer Variants

BERT (encoder-only), GPT (decoder-only), T5 (encoder-decoder), and efficient approximations.

Sign up to unlock this chapter

This chapter is part of PixelBank Premium. Create a free account, then upgrade to read the full lesson — concepts, walkthroughs, and exercises.