Course
ML interview course: interactive lessons
121 short interactive lessons (about 34 hours in all) that teach the ideas ML interviews test, from classical models and deep learning to LLMs, reinforcement learning and ML system design. Each lesson lists what you will learn and what to take first.
Start here
The job and the interviews
- Why ML engineeringSay what an ML engineer does and the five steps in the life of a model7 min
- Getting the jobDescribe the steps of the hiring process and how long it takes6 min
Chapter 1: Classical ML
Your first model, end to end
- Welcome to Classical ML: a model from start to finishName the five steps of machine learning work7 min
- Framing: what to predict, for whom, when, and what to beatTranslate a product goal into a label, prediction unit and prediction time24 min
- Fitting a line: what 'best fit' means and how to read the slopeSay what least squares minimizes and read a fitted slope20 min
- The exact best line: two equations, and MAEFind the best line exactly by solving two equations in two unknowns20 min
- From a line to a probability: the sigmoidExplain why a sigmoid turns a line into a probability7 min
- Training logistic regression: log loss, its gradient, and why not squared errorCompute log loss and the gradient (p - y) x for one example7 min
- Thresholds, precision and recall: the cut-off is a product decisionBuild a confusion matrix and compute precision, recall and F116 min
- Honest splits and leakage: random, group and time-basedPick random, group or time-based splits for a dataset18 min
Making it work on new data
- Overfitting and the bias-variance decompositionState the bias-variance decomposition of squared error21 min
- Learning curves: is it bias or variance, and which fix?Read a learning curve as high bias or high variance7 min
- Cross-validation and choosing settingsRun k-fold and stratified k-fold and say what each fold estimates7 min
- Regularization: ridge vs lasso and soft-thresholdingExplain the L1 versus L2 geometry and soft-thresholding16 min
- Tuning the penalty: cross-validation and the one-standard-error ruleChoose the penalty strength by CV with the one-standard-error rule14 min
- Elastic net: when two features carry the same signalWrite the elastic-net gradient step and say why it handles correlated features14 min
- Features: turning categories into numbersChoose one-hot, ordinal or hashed encoding by cardinality14 min
- Features: scaling and missing valuesPick standardization or min-max scaling and know which models need it15 min
- Preprocessing leakage and train-serve skewFit transforms inside cross-validation folds7 min
Beyond straight lines
- Decision trees: greedy splitsCompute Gini impurity, entropy and information gain19 min
- Bagging and random forestsExplain bootstrap sampling and feature subsampling25 min
- Gradient boostingExplain boosting as small gradient steps on residuals21 min
- Two simple baselines: k-nearest neighbours and Naive BayesPredict with kNN and explain why distances lose meaning in high dimensions17 min
- Support vector machines: margins and hinge lossCompute a margin and hinge loss for a soft-margin SVM16 min
Can you trust the output?
- ROC, PR curves and AUCTrace an ROC curve and compute AUC15 min
- Calibration and class imbalanceMeasure calibration with expected calibration error20 min
- Prediction intervals and conformal predictionTell a confidence interval from a prediction interval and say why the second is wider18 min
- Explaining a model: permutation importance and SHAPCompute permutation importance on held-out data17 min
No labels, and time
- Clustering: k-means, restarts and k-means++Run Lloyd's algorithm and explain why restarts matter15 min
- Gaussian mixtures, EM and the silhouetteExplain EM as soft k-means15 min
- PCA: keeping the most spreadSay what a principal component is7 min
- Capstone: churn with survival analysisExplain censoring and why dropping censored rows biases the answer16 min
Chapter 2: Deep learning
Neural networks and backpropagation
- Forward pass: layers, activations and shapesWrite a two-layer MLP forward pass with correct shapes20 min
- Softmax, cross-entropy and the stable log-sum-expDerive the gradient of softmax cross-entropy with respect to logits19 min
- Backprop by hand on a two-layer MLPDerive weight and bias gradients for a two-layer MLP18 min
Optimizers, normalization and training stability
- SGD, momentum and the learning rateCompute a plain gradient step using a learning rate15 min
- Adam, AdamW and schedulesWrite one AdamW update including bias correction15 min
- Normalization: BatchNorm, LayerNorm and RMSNormImplement LayerNorm and RMSNorm forward passes18 min
- Initialization: He and Glorot from variance preservationChoose He or Glorot initialization from variance preservation18 min
- Debugging training: NaNs, loss spikes, clipping and mixed precisionTriage NaNs and loss spikes with gradient norms and clipping17 min
Why big networks generalize
- Why big nets generalize: double descentDescribe the double-descent curve and where the interpolation threshold sits18 min
- Batch size: gradient noise and scaling the learning rateExplain how gradient noise shrinks with batch size, roughly as one over its square root18 min
CNNs and computer vision
- Convolutions, residual blocks and conv arithmeticCompute conv output shapes, parameters and FLOPs20 min
- Detection metrics: IoU, NMS and mAPCompute IoU between two boxes20 min
- CNNs vs ViTs and transfer learningCompute a ViT's patch-embedding parameters and token count20 min
Sequence models and contrastive embeddings
- RNNs, LSTMs and why gradients vanishWrite an LSTM cell forward pass7 min
- Contrastive learning: word2vec, InfoNCE and CLIPWrite the InfoNCE loss with in-batch negatives7 min
- Why transformers replaced RNNs: parallelism and teacher forcingCompare RNN, CNN and self-attention on path length and parallelism22 min
Learning on graphs
- Graphs as matrices: PageRank and spectral clusteringWrite a small graph as adjacency, degree and normalized adjacency matrices20 min
- Graph neural networks: message passing and link predictionRun one message-passing step by hand on a small graph16 min
Generative models: VAEs, diffusion and GANs
- From autoencoders to VAEs: the ELBO and reparameterizationWrite the VAE loss with a Gaussian KL term7 min
- Diffusion: noise forward, denoise backwardSample $x_t$ directly from $x_0$ with the closed-form forward process20 min
- VAE vs GAN vs diffusion: quality, diversity, cost and FIDExplain the GAN minimax game and mode collapse20 min
Chapter 3: LLM foundations
Tokens and embeddings
- Subword tokens and byte-pair encodingLearn BPE merges from a toy corpus16 min
- Next-token probabilities: cross-entropy and perplexityBuild shifted input/target pairs for next-token training17 min
- Tokenizer failure modes, special tokens and vocabulary sizeExplain why digits and rare words tokenize badly16 min
Attention and the transformer
- Scaled dot-product attentionCompute attention outputs by hand for a small example18 min
- Causal masks and multi-head attentionBuild causal and padding masks and apply them before softmax18 min
- The transformer block: shapes, parameters and quadratic costAssemble a pre-norm decoder block forward pass18 min
Modern LLM architectures
- What changed since 2017: RMSNorm, SwiGLU and RoPEExplain why modern decoders use RMSNorm16 min
- Reading past the training length: RoPE scaling and YaRNExplain why RoPE models break past their training length15 min
- KV-sharing attention: MQA, GQA and MLACompute KV bytes per token for MHA, GQA, MQA and MLA16 min
- Mixture of experts: routing, balance, total vs active paramsImplement top-k routing with a load-balancing auxiliary loss16 min
Pretraining at scale
- Pretraining data: dedup, quality filters and contaminationDetect near-duplicate documents with MinHash16 min
- Scaling laws: how big a model for your compute budgetEstimate training FLOPs with C = 6ND15 min
- The training bill: memory per parameter and GPU timeEstimate memory for weights, gradients and optimizer states12 min
- Parallelism: data, tensor, pipeline and ZeRO/FSDPCompute ring all-reduce volume and time22 min
Chapter 4: LLM inference
Decoding and sampling
- Greedy, beam, top-k and top-p decodingImplement greedy and beam search16 min
- Temperature and entropy: how sampling reshapes the distributionCompute a distribution and its entropy at several temperatures18 min
- Repetition, penalties, constrained decoding and determinismApply repetition, frequency and presence penalties and stop sequences18 min
The inference cost model
- Prefill vs decode on the rooflineCompute arithmetic intensity and place an op on the roofline18 min
- FlashAttention: tiled online softmax and memory trafficExplain how FlashAttention's tiled online softmax cuts memory traffic24 min
- The KV cache and its memoryImplement a KV cache for autoregressive decoding18 min
- Latency metrics and GPU sizing: TTFT, ITL, throughput, goodputCompute TTFT, ITL and tokens per second from a token timeline20 min
Serving optimizations
- Continuous batching and paged KV memorySimulate continuous versus static batching throughput18 min
- Prefix caching and cache-aware routingCompute prefix-cache hit rate and its effect on TTFT25 min
- Speculative decoding: the accept rule and expected speedupImplement the accept/reject rule that preserves the target distribution18 min
Quantization
- Scale, zero point and granularityCompute symmetric and asymmetric scale and zero point22 min
- Quantization: rounding error, signal-to-noise and faster decodingEstimate quantization noise and SNR from bit width14 min
- Did quantizing hurt the model? KL divergence, top-1 agreement and perplexityCheck quality with KL divergence, top-1 agreement and perplexity delta16 min
- Choosing a method: weight-only, W8A8, FP8, GPTQ, AWQ, SmoothQuantExplain why activation outliers break INT8 and how SmoothQuant fixes them21 min
Chapter 5: Reinforcement learning and post-training
Reinforcement learning basics
- MDPs: discounted returns and the Bellman expectation equationCompute a discounted return and explain what the discount factor does15 min
- Value iteration and the greedy policyRun value iteration and read the greedy policy off the values18 min
- Learning from experience: TD error, Q-learning and SARSACompute a TD error and a TD(0) update by hand18 min
- Bandits: regret, epsilon-greedy and UCBExplain regret and why pure greedy play can get stuck16 min
- Thompson sampling: picking by sampling your beliefsRun one Thompson sampling step with Beta posteriors14 min
Fine-tuning: SFT and PEFT
- Prompt, RAG or fine-tune?Pick prompting, RAG, fine-tuning or a mix from a scenario24 min
- SFT: chat templates and masked lossFormat a conversation with a chat template19 min
- LoRA and QLoRA: low-rank updates and memory mathImplement a LoRA linear layer and merge it into the base weight23 min
Preference alignment
- From demonstrations to preferences: reward modelsWrite the Bradley-Terry pairwise loss19 min
- RLHF: PPO with a KL leashWrite PPO's clipped surrogate objective20 min
- DPO and its familyDerive the DPO loss from the KL-constrained objective16 min
RL for reasoning
- Policy gradient for LLMs: reward correct answersDerive the REINFORCE gradient estimator24 min
- GRPO: group-relative advantages and the KL estimatorCompute group-normalized advantages16 min
- RL pitfalls: all-fail groups, entropy collapse and contaminated evalsExplain why all-fail and all-pass groups produce no learning signal18 min
Chapter 6: LLM applications
Prompting and guardrails
- Structured output: JSON schemas, constrained decoding and repairSpecify an output contract as a JSON schema7 min
- Prompt injection, jailbreaks and guardrail layersDistinguish direct from indirect prompt injection16 min
Retrieval and search
- Embeddings and dense retrievalEmbed, normalize and search a small corpus by cosine similarity20 min
- Hybrid retrieval and reranking: BM25, RRF and cross-encodersImplement BM25 scoring22 min
- ANN indexes: HNSW and IVF-PQ trade-offsExplain how HNSW searches a layered graph7 min
RAG pipelines
- RAG pipeline: chunking and indexingChoose chunk size and overlap for a document type22 min
- RAG vs fine-tuning vs long contextCompare the three options on freshness, cost, latency and citations20 min
Evaluating LLM systems
- Golden sets and LLM-as-judgeBuild a golden set that covers key slices and edge cases20 min
- RAG and hallucination metricsCompute recall@k and MRR for retrieval18 min
- Statistics of small evals: CIs, pass@k and EloCompute a confidence interval or paired test for an eval difference20 min
Agents
- An agent is an LLM in a loop with toolsTrace a thought-action-observation loop16 min
- Workflows vs agents: planning, memory and multi-agent orchestrationChoose between a fixed workflow and an autonomous agent18 min
Chapter 7: ML system design and experiments
The design framework
- The ML system design skeletonRun the skeleton on an unfamiliar prompt in order15 min
- Back-of-envelope: QPS, storage and latency budgetsConvert daily users into peak QPS16 min
Fraud and risk systems
- Fraud and abuse: adversarial, imbalanced, delayed labelsFrame a fraud problem with label delay and feedback in mind7 min
- Cost-weighted thresholds and review capacityPick a threshold that minimizes expected cost18 min
Search and ads
- Search ranking: retrieval, multi-stage ranking and NDCGDesign a retrieval + ranking + re-ranking funnel with latency budgets18 min
- Ads click prediction: pCTR, calibration and expected valueRank ads by pCTR times bid and explain why calibration matters16 min
Recommendation systems
- Candidate generation: two-tower and matrix factorizationExplain matrix factorization from implicit feedback22 min
- Ranking and re-ranking: multi-objective, diversity, cold startCombine multiple predicted objectives into a ranking score21 min
GenAI system design
- BOTEC for LLM products: tokens, GPUs and cost per requestEstimate cost per 1,000 requests from token counts and prices20 min
A/B testing
- A/B design: randomization unit, metrics and guardrailsChoose the randomization unit and match the analysis unit to it20 min
- Sizing: power, minimum detectable effect and durationCompute sample size per arm for a proportion metric21 min
- Many metrics, many tests: Bonferroni, Holm and BHExplain why testing 20 metrics at 0.05 makes a false win likely16 min
- Pitfalls: SRM, peeking, interference and multiple metricsDetect sample-ratio mismatch with a chi-square test19 min
- Variance reduction with CUPEDCompute the CUPED-adjusted metric and optimal theta20 min