Transformer Architecture
Explain and implement self-attention and the transformer block, and use pretrained encoder and decoder models from the Hugging Face ecosystem correctly.
4 objectives 6 steps about 145 min
Learn it step by step
Read the lessons in order, try the practice checks, then prove the skill with the knowledge check.
This skill page is a public outline. Its lessons and knowledge check appear here as subject-matter experts approve them.
Learning objectives
- Implement scaled dot-product and multi-head self-attention with causal masking in PyTorch and verify output shapes and masking behaviour.
- Explain the parts of a transformer block (embeddings, positional information, attention, feed-forward layers, residuals, layer normalization) and when to use encoder-only, decoder-only or encoder-decoder models.
- Explain subword tokenization, autoregressive decoding and its controls (greedy, temperature, top-k and top-p sampling, repetition, frequency and presence penalties, stop sequences) and how the KV cache and context length drive inference cost.
- Fine-tune a pretrained encoder (for example a BERT-family model) for text classification with Hugging Face Transformers and compare it with a classical baseline.
Lesson plan
6 steps, about 145 min · 5 of 5 lessons available so far
- Attention as Soft Lookup: Queries, Keys and Values Concept · 20 min
- Lab: Build Multi-Head Causal Self-Attention from Scratch Lab · 30 min
- Anatomy of a Transformer Block and the Three Model Families Concept · 25 min
- Tokens In, Tokens Out: Tokenizers, Decoding Controls and the KV Cache Concept · 25 min
- Lab: Fine-Tune a Pretrained Encoder for Classification Lab · 30 min
- Check: Inside the Transformer Knowledge check · 8 questions
Practise it
Implement a small decoder-only transformer in PyTorch and train it on a character-level corpus until its samples become coherent; separately, fine-tune a pretrained encoder from the Hugging Face Hub on a labeled text dataset and compare it with a TF-IDF plus logistic regression baseline.
Build it from scratch
Practice builds that exercise this skill by re-creating a real technology.
- Build your own Large Language ModelAdvanced · 30–60 h
References
Hard prerequisites
Unlocks
On these roadmaps
Progress and evidence for this skill are shared across all of them.