AI & ML

Language Modeling and LLMs

Part of Language, level 5. About 29 hours of study across the topics below.

Create free account

Tokens and TokenizationNext-Token PredictionAutoregressive FactorizationThe Language-Modeling ObjectiveContext and ConditioningN-gram Language Models and SmoothingPerplexitySubword Tokenization: Byte-Pair EncodingGreedy DecodingTemperatureTop-k and Top-p SamplingRepetition and StructureStructured Output and Constrained DecodingScaling IntuitionPretrainingContext WindowsScaling Laws and Compute-Optimal TrainingLong-Context ModelingPretraining Data: Sourcing, Filtering, and MixturesPrompting and In-Context LearningLLM Failure ModesSupervised Fine-TuningPreference OptimizationAlignment ConceptsReward Models from Human PreferencesSynthetic Data and AI FeedbackRLHF: Policy Optimization with a KL PenaltyDirect Preference OptimizationReasoning Models and Test-Time Compute

1Modeling

  1. Tokens and TokenizationText into pieces: BPE intuition, vocabularies, and boundary consequences. 1–2 h
  2. Next-Token PredictionThe task that scales: context in, distribution over next tokens out. 1–2 h
  3. Autoregressive FactorizationJoint probability as a product of nexts: the chain rule behind generation. 1–2 h
  4. The Language-Modeling ObjectiveCross-entropy on text: the loss that trains next-token predictors, plus perplexity. 1–2 h
  5. Context and ConditioningWhat the model gets to see: context windows as the conditioning set. 1–2 h
  6. N-gram Language Models and SmoothingCounting-based next-word prediction, the sparsity problem, and smoothing that reserves mass for unseen events. 1–2 h
  7. PerplexityThe standard intrinsic measure of a language model: exponentiated average negative log-likelihood per token. 1–2 h
  8. Subword Tokenization: Byte-Pair EncodingLearning a vocabulary by merging frequent symbol pairs: the tokenizer most LLMs use and its side effects. 1–2 h

2Decoding

  1. Greedy DecodingAlways the argmax: the virtues and degeneracies of never gambling. 1–2 h
  2. TemperatureSharpen or flatten: the dial that reshapes sampling randomness. 1–2 h
  3. Top-k and Top-p SamplingPruning the tail: truncation rules that keep sampling honest and lively. 1–2 h
  4. Repetition and StructureDegeneration and its tethers: repetition penalties and structured generation. 1–2 h
  5. Structured Output and Constrained DecodingForcing generations to follow a grammar or schema by masking invalid tokens at each step. 1–2 h

3Scale

  1. Scaling IntuitionLoss falls with scale: what grows, what improves, and the caveats. 1–2 h
  2. PretrainingSelf-supervision at scale: data, objective, and what pretraining does and does not teach. 1–2 h
  3. Context WindowsLong context, real costs: memory, attention growth, and using the window well. 1–2 h
  4. Scaling Laws and Compute-Optimal TrainingLoss as a power law in parameters, data, and compute; how to split a compute budget between model size and tokens. 1–2 h
  5. Long-Context ModelingExtending context windows through position interpolation and efficient attention, and the lost-in-the-middle problem. 1–2 h
  6. Pretraining Data: Sourcing, Filtering, and MixturesWhere pretraining text comes from and how deduplication, quality filtering, and domain mixture shape the model. 1–2 h

4Use

  1. Prompting and In-Context LearningSteering a pretrained model with instructions and examples in the context window, without weight updates. 1–2 h
  2. LLM Failure ModesHallucination, sycophancy, brittleness: reading model failures structurally. 1–2 h

5Post Training

  1. Supervised Fine-TuningInstruction data shapes behavior: SFT as fine-tuning for following directions. 1–2 h
  2. Preference OptimizationLearning from comparisons: reward models, RLHF, and the DPO idea. 1–2 h
  3. Alignment ConceptsHelpful, honest, harmless: what alignment asks for and where it provably strains. 1–2 h
  4. Reward Models from Human PreferencesLearning a scalar score from pairwise human comparisons with a Bradley-Terry loss. 1–2 h
  5. Synthetic Data and AI FeedbackModels generating training data and critiques for other models, and the risks of feedback loops. 1–2 h
  6. RLHF: Policy Optimization with a KL PenaltyOptimising a language model against a reward model while a KL term keeps it close to the reference model. 1–2 h
  7. Direct Preference OptimizationSkipping the explicit reward model: a classification loss on preference pairs derived from the KL-regularised objective. 1–2 h
  8. Reasoning Models and Test-Time ComputeSpending more computation at inference, through long reasoning traces, sampling and verification, and RL on verifiable rewards. 1–2 h