Transformers and Attention Mechanisms
How does a Transformer process information and learn relationships between elements in a sequence?
You will learn
Hands-on: Build a small character-level Transformer in PyTorch, train it on Tiny Shakespeare, and inspect its attention and generated text.
Learning route: Lessons 6.1–6.6, including architecture history, vision and multimodal applications, and weight tying, are covered in class.
Lessons
-
Lesson 6.1: Understanding the Transformer Architecture
What is a Transformer, as a whole, and how does information flow through it?
Not started Start -
Lesson 6.2: Preparing Inputs for a Transformer
How does raw text become the input tensors a Transformer learns from?
Not started Start -
Lesson 6.3: Understanding Attention
How does attention let each token gather information from the others?
Not started Start -
Lesson 6.4: The Transformer Block
What is inside a Transformer block, and why does each part matter?
Not started Start -
Lesson 6.5: Building a Decoder-Only Transformer
How do the components assemble into a complete language model, and how do we know it is built correctly?
Not started Start -
Lesson 6.6: How Transformers Learn and Generate Text
How does a Transformer learn from text, and how does it turn what it learned into new text?
Not started Start
Module challenge
Module 6 challenge: Transformers and Attention Mechanisms
8 scenario questions that mix ideas from all 6 lessons. One question at a time, an explanation after each, and your score at the end. Pass mark 75%, so 6 of 8.
Best after you have practised all 6 lessons.
What does a Transformer block return for each input token?
A vector enriched by permitted context, with the same model width. Reread Lesson 6.1, section 1.
Why split continuous text before sampling training windows?
It prevents overlapping windows from crossing the train-validation boundary. Reread Lesson 6.2, section 1.
What does an attention weight express in this layer?
How much of a value vector is mixed into a query's output. Reread Lesson 6.3, section 1.
Why keep a block's input and output shapes equal?
The residual additions and stacking need compatible vector shapes. Reread Lesson 6.4, section 1.
What completes the language model after the stack of pre-norm blocks?
A final norm and a projection to vocabulary logits. Reread Lesson 6.5, section 1.
What differs between the training and generation loops?
Training uses known histories and updates weights; generation chooses tokens from its evolving history. Reread Lesson 6.6, section 1.
Which computation can causal Transformer training parallelise?
Predictions at known input positions in a training window. Reread Lesson 6.1, section 2.
Can this character-based BPE encode an unseen character automatically?
No; fallback is limited to known characters unless another policy is provided. Reread Lesson 6.2, section 2.