Unit 1 of 7 · about 3 hours · explain
Embeddings, positions and the vocabulary axis
Token IDs select rows; their numerical order carries no meaning. Position representations supply information that a token lookup alone cannot provide.
You'll be able to
- Explain embedding lookup with a table and trace token IDs to vectors.
- Distinguish learned absolute positions, fixed sinusoidal positions and relative-position schemes.
- Explain why computing an encoding beyond the training length does not prove useful length extrapolation.
Covers
Read
In this order, only the parts listed
0 of 2 done
- Token embedding lookupModern LLM Notebook - decoder construction path
Section 2, Embedding Lookup, including the end-to-end training demo
Skip the model configuration survey and section 3's corpus training and t-SNE demo.
- Absolute and sinusoidal positionsModern LLM Notebook - decoder construction path
Sections 1 to 3, then Appendix: Extrapolation of Sinusoidal Position Encoding
Read the relative-position vocabulary in the appendix; leave interpolation and long-context methods for later.
Focus on
- The vocabulary axis indexes rows. A integer tensor gathers vectors without allocating a one-hot tensor.
- Repeated IDs select identical vectors before position information or contextual layers are applied.
- Learned and sinusoidal encodings are absolute-position representations. RoPE changes and rather than adding a position vector to the input.
Common mistakes · 2
- Treating adjacent token IDs as similar numbers. IDs are labels, not coordinates.
- Calling sinusoidal encoding a guarantee of long-context accuracy. Its formula extends; the learned model's behavior may not.
Try it yourself
Closed-book, before checking anything
[2, 0, 2], and add distinct position vectors. Explain which two vectors match before the addition and why they need not match afterward.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.With , and IDs shaped , what are the table and output shapes?Answer
The table is , the output is , and the table has 32,000 parameters.
2.Does moving a token to another position change its raw lookup vector?Answer
No. The same ID selects the same row. Position addition or later contextual processing can change its representation.
3.Is sinusoidal encoding relative just because it can express offsets?Answer
No. It assigns a vector to each absolute position. Trigonometric identities let fixed offsets relate those vectors; RoPE instead writes a relative rotation into dot products.
Practice
- Modern LLM Notebook: Exercise 1, Embedding Lookup
Exercises: Exercise 1, Embedding Lookup; complete the lookup and pass its exact-equality assertion
- Modern LLM Notebook: Exercise 1, Adding Position Encoding
Exercises: Exercise 1, Adding Position Encoding; add the position vectors and pass the repeated-token assertion
You're done when
Both named exercises pass, and you explain the lookup shapes and the three position families without notes.
Only when you can do this without notes.
Leads to
Notes
Resources · 1 for this unit, 5 more in the section
- Modern LLM Notebook - decoder construction pathWalking Labs · primary
Work through English notebooks 03-embedding, 04-position-encoding, 05-transformer-block, 06-mini-gpt and the selected normalization, RoPE, GQA and SwiGLU comparisons in 08-gpt2-to-modern-models. Re-derive shapes and rerun with changed dimensions.
Also in this section
- LLMs from Scratch companion - attention and GPT constructionSebastian Raschka · required
Use the ch03 attention notebooks and ch04 model code. Rebuild the model without a high-level Transformer module and compare one forward and backward path with an independent small reference.
- Stanford CS336 Assignment 1 - model contractStanford University · required
Use the named linear, embedding, rmsnorm, positionwise_feedforward, rope, softmax, scaled_dot_product_attention, multihead_self_attention, transformer_block, transformer_lm and transformer_accounting specifications and public tests. Keep implementation independent and respect the course AI and honor-code boundary.
- PyTorch scaled dot product attention referencePyTorch · support
Use the functional contract only after the explicit attention oracle passes. Transfer identical weights and masks, compare outputs and gradients, and explain dtype, causal and dropout behavior from the documented semantics.
- Deep-ML candidate - three transformer closing drillsDeep-ML · optional
After the platform quality sample passes, attempt at most problems 490, 53 and 904 as changed-prompt drills for attention shapes and multi-head composition. Preserve independent tests; a judge result does not replace the section checkpoint.
- nanoGPT - residual projection initializationAndrej Karpathy · support
Read
model.py:MLP,Block,GPT.__init__'s special scaled initialization ofc_proj.weight, andGPT._init_weights. Contrast the depth-dependent residual initialization with CS336's component initialization; do not adopt the training or generation code.