What is the core job of the self-attention mechanism in a Transformer?
- It compresses the whole sequence into one fixed-length context vector before the feed-forward layers
- It lets each token gather information from other tokens, weighted by learned relevance
- It applies a fixed convolution kernel across each token and its immediate neighbours
- It carries a recurrent hidden state forward from the first token to the last
Why
Self-attention allows each token in a sequence to compute a weighted combination of all other tokens, where the weights reflect learned relevance scores derived from the content itself. This means every token's output representation is context-dependent, incorporating information from anywhere in the sequence in a single computational step. The relevance weights are produced by comparing Query and Key vectors through dot products, making them dynamic and input-specific rather than fixed or predetermined. This content-based weighting is the fundamental distinction between attention and older, more rigid aggregation methods. Option A describes the fixed-length context vector bottleneck of early sequence-to-sequence models, which was precisely the limitation that attention mechanisms were invented to overcome, since compressing an entire sentence into one vector loses information. Option B describes a convolution, where the kernel weights are fixed parameters learned during training and applied uniformly regardless of input content, covering only a local neighborhood rather than the full sequence. Option D describes recurrent processing, where a hidden state is passed sequentially from one token to the next, creating the serial dependency that makes RNNs slow to train and prone to forgetting distant context. The fully parallel, content-dependent nature of self-attention is what enables Transformers to be trained efficiently on modern hardware while capturing long-range dependencies. This mechanism is the foundation of virtually every modern large language model and understanding it is essential for grasping how these models represent and manipulate meaning.