Transformers and LLMs model token sequences by repeatedly mixing contextual information across positions. The useful mental model is: tokenization creates discrete symbols, attention moves information between symbols, and autoregressive training turns next-token prediction into a scalable learning signal.

Dimension conventions (used across the architecture):
| Symbol | Dimension |
|---|---|
| B | sequences in the batch |
| L | number of layers |
| T / S | sequence length (generated / context) |
| V | vocab size |
| D | hidden dimension |
| H | head dimension |
| F | MLP hidden dimension (usually ) |
| N | number of query heads, |
| K | number of key/value heads, in GQA |
| G | group size in GQA, |
A modern decoder block is: RMSNorm → attention (with RoPE, GQA) → residual → RMSNorm → SwiGLU FFN → residual. Parameter count is .
Core sequence:
- Tokenization - maps text into discrete tokens that the model can embed.
- Autoregressive Generation - generates one token at a time conditioned on previous tokens.
- Positional Encoding - gives the model access to order because attention alone is permutation-equivariant.
- Self-Attention - lets each token read from other tokens.
- Multi-Head Attention - runs several attention subspaces in parallel.
- Causal Masking - prevents positions from attending to future tokens during autoregressive training.
- Computational Complexity of Attention - explains the sequence-length bottleneck.
- Pretraining - trains broad capability from large-scale next-token prediction.
- Scaling Laws - describes empirical relationships among data, parameters, compute, and loss.
- Sampling and Decoding Strategies - controls generation from model probabilities.
- Supervised Fine-Tuning - adapts a pretrained model to demonstrations of desired behavior.
- LoRA - fine-tunes low-rank adapter matrices instead of all weights.
- RLHF Pipeline - trains against human preferences through a reward model and policy optimization.
- KL Penalty - constrains policy updates away from a reference model.
- Direct Preference Optimization - optimizes preferences without an explicit reward model.
- Chain-of-Thought Prompting - elicits intermediate reasoning tokens.
- ReAct - interleaves reasoning and tool actions.
- Test-Time Compute - spends more inference compute for better answers.
- Self-Improvement in LLMs - studies model-generated data, feedback, and iterative improvement loops.
- LLMs as RL Agents - views language models as policies acting through text or tools.
How the pieces fit:
- Tokenization and embeddings define the input representation.
- Positional encoding, self-attention, multi-head attention, and causal masks define the transformer block's sequence computation.
- Complexity analysis explains why long context is expensive.
- Pretraining and scaling laws explain why next-token prediction can produce broad competence.
- Sampling controls behavior at inference time.
- SFT, LoRA, RLHF, KL penalties, and DPO are post-training methods.
- Chain-of-thought, ReAct, test-time compute, and self-improvement concern inference-time or iterative behavior.
Core equations to keep active:
- Autoregressive factorization:
- Attention:
- Causal mask: set attention logits to for future positions.
- Pretraining loss:
- Attention complexity: standard self-attention costs in sequence length .
- LoRA update: with low-rank .
- KL-regularized objective:
- DPO preference term:
See also: Neural Networks, Reinforcement Learning, Systems and Scaling