Drills for every week
Practice
Reading a note takes an hour. Owning it takes problems. Every week here has hand problems, coding drills and a project milestone.
How to use this page
- By hand first. Paper and pen, no computer. These are the small calculations interviewers ask you to do on a whiteboard. Check your answers with code afterwards, never before.
- Then code. Type every drill yourself in a fresh file. Before running, write down what you expect to see. When reality differs, that gap is the lesson.
- Saturday is the milestone. Each week moves the current project forward. The milestone is done when it runs and has a test.
- Keep a mistakes file. One line per mistake: what you got wrong and the rule that fixes it. Reread it every Sunday. It becomes your best revision document.
Vectors, matrices and linear regression
Notes this week. ML: What machine learning is: data, model, loss, optimizer · Math: Functions, exponents and logarithms · Math: Vectors and the dot product · ML: Linear regression · Math: Matrices, matrix multiplication and shapes · Math: Norms, distance and cosine similarity · ML: Feature scaling, normalization and encoding.
By hand
- Compute ten dot products of small vectors (2 to 4 numbers) and say for each whether the vectors point roughly the same way, opposite ways or at right angles.
- Multiply a 2×3 matrix by a 3×2 matrix, then by a 3×1 column. Write the shape of the result before you compute it, every time.
- Given ten random matrix shapes, decide which pairs can be multiplied and in which order; write the output shape.
- Compute cosine similarity between three pairs of vectors by hand. Change one number and predict whether the similarity rises or falls.
- Simplify ten expressions using exponent and logarithm rules: log(ab), log(a/b), log(a^n), e^(ln x), and log base change.
- Fit a line by eye to five points on paper, then compute the mean squared error of your line.
Code
- In NumPy, implement dot product, matrix multiplication and cosine similarity with plain loops, then assert they match np.dot, @ and the vector formula.
- Write a function that checks whether two arrays can be matrix-multiplied and returns the output shape, with tests.
- Load a small dataset (the diabetes or California housing set from scikit-learn). Compute mean, min and max of each column. Scale the columns to zero mean and unit variance by hand.
- Fit linear regression three ways: the closed-form normal equation in NumPy, scikit-learn’s LinearRegression, and a hand-written loop that tries random slopes and keeps the best. Compare the coefficients.
- Plot the loss of a one-feature linear regression as a function of the slope. Find the minimum by eye, then by code.
Saturday milestone
Project 0: create the repository, a package layout with tests, and a working LinearRegression class (normal equation) with a test against scikit-learn.
Problem sets and sources
Derivatives, gradients and gradient descent
Notes this week. Math: Derivatives: slope and rate of change · ML: Loss functions: MSE, MAE and log loss · Math: Partial derivatives and the gradient · ML: Gradient descent: batch, stochastic and mini-batch · Math: The chain rule · ML: Overfitting, underfitting and the bias–variance trade-off.
By hand
- Differentiate twenty simple functions: polynomials, e^x, ln x, 1/x, and products and quotients of them.
- For f(x, y) = x²y + 3y, compute both partial derivatives and the gradient at (1, 2). Draw the arrow on a sketch.
- Apply the chain rule to ten nested functions, including sigmoid(3x + 1) and (2x + 1)⁵. Write every intermediate step.
- Compute the derivative of mean squared error with respect to the slope for a two-point dataset, by hand.
- Run three steps of gradient descent by hand on f(x) = (x − 3)² from x = 0 with learning rate 0.1, then with learning rate 1.1. Explain what happened in the second case.
- Sketch what overfitting and underfitting look like on a scatter plot, and label which has high bias and which has high variance.
Code
- Write a numerical derivative function using (f(x + h) − f(x − h)) / 2h and check your hand answers from the by-hand list.
- Implement gradient descent for one-feature linear regression in NumPy. Plot the loss per step for learning rates 0.001, 0.01, 0.1 and 1.0.
- Extend it to many features using matrix form. Compare with the normal equation from Week 1.
- Implement batch, stochastic and mini-batch gradient descent; plot all three loss curves on one chart.
- Fit polynomials of degree 1, 3 and 15 to 20 noisy points. Plot train and test error against degree.
Saturday milestone
Project 0: gradient-descent trainer with pluggable loss, learning-rate schedule and loss logging; MSE and MAE losses with tests on their gradients.
Problem sets and sources
Probability, logistic regression and evaluation
Notes this week. Math: Mean, median, variance and standard deviation · Math: Probability, conditional probability and Bayes’ theorem · ML: Logistic regression and the sigmoid · Math: Distributions, expectation and the normal distribution · ML: Evaluation metrics: accuracy, precision, recall, F1, ROC-AUC · Math: Maximum likelihood: where loss functions come from · ML: Train, validation, test and cross-validation · ML: Regularization: L1, L2 and early stopping.
By hand
- Compute mean, median, variance and standard deviation of three small lists. Add one outlier and recompute: which changed most?
- Solve five Bayes’ theorem problems, including the classic medical test with a 1% base rate and a 95% accurate test.
- Compute the expected value and variance of a die roll and of a biased coin.
- Evaluate sigmoid(z) for z = −4, −1, 0, 1, 4 by hand, and log loss for predictions 0.9, 0.5 and 0.1 when the true label is 1.
- Fill in a confusion matrix from a list of 20 predictions and labels, then compute accuracy, precision, recall and F1.
- Draw an ROC curve from five thresholds on a tiny dataset.
- Explain in writing why maximizing likelihood for a yes/no model gives the log-loss formula.
Code
- Simulate 10,000 coin flips and dice rolls; compare sample means and variances with the formulas.
- Implement logistic regression in NumPy with gradient descent on the breast-cancer dataset. Compare the accuracy with scikit-learn.
- Implement accuracy, precision, recall, F1 and ROC-AUC from scratch; check against scikit-learn.metrics.
- Write k-fold cross-validation from scratch and use it to pick the learning rate.
- Plot the normal distribution for three different means and standard deviations; shade one standard deviation.
Saturday milestone
Project 0: LogisticRegression class, a metrics module and a cross-validation helper, each tested against scikit-learn.
Problem sets and sources
Entropy, regularization, similarity models and trees
Notes this week. Math: Entropy, cross-entropy and KL divergence · ML: kNN and k-means: learning from similarity · Math: Eigenvectors and SVD, only as much as PCA and LoRA need · ML: PCA and dimensionality reduction · ML: Decision trees, random forests and gradient boosting · ML: SVM and Naive Bayes at interview depth · ML: Class imbalance, data leakage and other traps · Math: Math you can skip, and what to say if it comes up.
By hand
- Compute the entropy of a fair coin, a 90/10 coin and a fair die in bits.
- Compute cross-entropy and KL divergence between p = (0.5, 0.5) and q = (0.9, 0.1), both ways round. Note which is smaller.
- Write the L1 and L2 regularized loss for a two-weight model and compute the gradient of each penalty. Say in words why L1 makes weights exactly zero.
- Classify three new points by hand with kNN (k = 3) on a ten-point dataset; then run two iterations of k-means with k = 2.
- Compute the information gain of one split in a tiny decision tree.
- Given a dataset with 99% negatives, explain why 99% accuracy can be useless, and name two metrics that would expose it.
Code
- Implement kNN and k-means in NumPy; check against scikit-learn on the iris dataset.
- Implement PCA with NumPy’s SVD; project the iris data to two dimensions and plot it coloured by class.
- Add L2 regularization to your logistic regression; plot weight sizes against the regularization strength.
- Train a decision tree, a random forest and gradient boosting with scikit-learn on one tabular dataset; compare cross-validated scores and training time.
- Create a deliberately leaky feature (one computed from the label) and watch the validation score become suspiciously perfect. Then remove it.
Saturday milestone
Project 0: kNN, k-means and PCA added to the library. Tabular case study started: a Kaggle dataset with a clean split, a baseline and a results table.
Problem sets and sources
- Kaggle, House Prices: a tabular regression case study
- Kaggle Learn: short hands-on courses
- scikit-learn user guide — Read the page for each algorithm you implement.
- Deep-ML: machine-learning coding problems, LeetCode style — Do the easy linear algebra and ML problems from this week on.
Neurons, backpropagation and softmax
Notes this week. DL: What is a neural network? · DL: Backpropagation: how networks learn · DL: Logits, softmax and cross-entropy · DL: Build a neural network in NumPy, end to end.
By hand
- Run the walk neuron and the XOR network from the neural-network note by hand on new inputs.
- Count the parameters of three small networks drawn on paper.
- Backpropagate by hand through a two-layer network with one hidden neuron, writing every local derivative.
- Compute softmax of (2, 1, 0) and the cross-entropy against each possible true class.
- Derive the gradient of cross-entropy with softmax with respect to the logits, and check it equals prediction minus target.
Code
- Rewrite micrograd from Karpathy’s video from memory: a scalar Value class with backward().
- Implement a two-layer network in NumPy with manual backprop; train it on XOR and then on a two-moons dataset.
- Check every gradient with a numerical gradient check.
- Implement softmax safely (subtract the maximum) and show what happens without the subtraction for large logits.
Saturday milestone
Project 0: a NumPy MLP with configurable layers trained on MNIST digits to above 95% test accuracy, with a gradient check in the tests.
Problem sets and sources
Optimizers, PyTorch and regularization
Notes this week. DL: Optimizers: SGD with momentum, Adam, AdamW and the learning rate · DL: PyTorch essentials: tensors, autograd, the training loop · DL: Dropout, BatchNorm, LayerNorm and weight decay · DL: CNNs, RNNs and LSTMs: what they are and why attention replaced them.
By hand
- Run three steps of SGD with momentum and three of Adam by hand on f(x) = x², tracking every running average.
- Write the LayerNorm formula and apply it to the vector (1, 2, 3, 6).
- Explain dropout at train time and at test time, including the scaling, in writing.
- Draw a convolution of a 3×3 filter over a 5×5 image and give the output size; then do it with padding 1.
Code
- Reimplement your NumPy MLP in PyTorch with nn.Module, then train it with SGD, SGD+momentum, Adam and AdamW; plot the four loss curves.
- Add dropout and weight decay; compare train and test accuracy with and without them.
- Add LayerNorm and BatchNorm; measure the effect on training speed.
- Write a learning-rate finder: increase the learning rate each step and plot loss against learning rate.
- Train a tiny character-level RNN on a short text, generate text, and note where it fails. This is the motivation for attention.
Saturday milestone
Project 0 complete: NumPy and PyTorch MLPs with a README comparing optimizers and regularization on MNIST. Write the resume bullet.
Problem sets and sources
Tokens, embeddings and the attention idea
Notes this week. LLM internals: What is an LLM? Pretraining, fine-tuning and the big picture · LLM internals: Tokenization and byte-pair encoding (BPE) · LLM internals: Token embeddings: turning IDs into vectors · LLM internals: Positional encoding: telling the model about word order · LLM internals: Preparing data: sliding windows and next-token prediction · LLM internals: Self-attention, the simple version.
By hand
- Run three merges of byte-pair encoding by hand on a short string.
- Given a 5-word vocabulary and 3-dimensional embeddings, look up a sentence and write the resulting matrix and its shape.
- Compute a simplified attention: three 2-dimensional vectors, dot products, softmax, weighted sum.
Code
- Implement BPE training and encoding from scratch; compare the token count with tiktoken on the same paragraph.
- Build the sliding-window dataset and data loader; print input and target pairs and check them by eye.
- Implement simplified self-attention (no trainable weights) in PyTorch with loops, then with matrix operations; assert equal.
Saturday milestone
Project 1: tokenizer and data pipeline done, with tests.
Full attention and the transformer block
Notes this week. LLM internals: Scaled dot-product attention: queries, keys and values · LLM internals: Causal masking and attention dropout · LLM internals: Multi-head attention · LLM internals: LayerNorm, GELU, feed-forward layers and residual connections · LLM internals: The transformer block and the full GPT architecture · LLM internals: Counting parameters and weight tying.
By hand
- Write the shapes of Q, K, V, the score matrix and the output for batch 2, 4 tokens, 8 dimensions, 2 heads.
- Explain why scores are divided by the square root of the key dimension, with a numerical example.
- Count the parameters of one GPT-2 small transformer block.
Code
- Implement causal multi-head attention from memory, then the full transformer block and the GPT model.
- Write a parameter-count test that reproduces 124M for the GPT-2 small configuration.
- Visualize an attention map for a short sentence.
Saturday milestone
Project 1: full model forward pass works; parameter count matches GPT-2 small.
Training, decoding and fine-tuning
Notes this week. LLM internals: Pretraining: the training loop, cross-entropy and perplexity · LLM internals: Decoding: greedy, temperature, top-k and top-p · LLM internals: Loading pretrained GPT-2 weights · LLM internals: Fine-tuning for classification · LLM internals: Instruction fine-tuning · LLM internals: Encoder, decoder, encoder–decoder: BERT vs GPT vs T5.
By hand
- Compute perplexity from a cross-entropy loss of 2.3, and explain what it means in words.
- Apply temperature 0.5 and 2.0 to the logits (2, 1, 0) and compute the new probabilities.
- Walk through top-k and top-p sampling on a five-token distribution.
Code
- Write the pretraining loop with warmup, cosine decay and gradient clipping; train on TinyStories on a free GPU.
- Implement greedy, temperature, top-k and top-p decoding.
- Load GPT-2 weights into your model and fine-tune it as a classifier and then on instructions.
Saturday milestone
Project 1 complete with a README and generated samples.
Modern architecture, LoRA and quantization
Notes this week. Modern: From GPT-2 to modern LLMs: pre-norm, RMSNorm, SwiGLU, grouped-query attention · Modern: Rotary position embeddings (RoPE) · Modern: The KV cache: why generation is fast · Modern: Quantization: 16-bit, 8-bit, 4-bit and GGUF · Modern: LoRA, QLoRA and parameter-efficient fine-tuning · Modern: Teaching preferences: RLHF and DPO · Modern: Context windows and reasoning models · Modern: Prompting vs RAG vs fine-tuning: how to choose.
By hand
- Count the parameters LoRA adds to a 768×768 layer at rank 8, and the percentage of the original.
- Convert four float values to 8-bit integers with a scale and zero point, then back; compute the error.
- Explain the KV cache with a diagram, and compute its memory for a given model and sequence length.
Code
- Implement LoRA from scratch on your Project 1 model and fine-tune only the adapters.
- Add a KV cache to your model and measure tokens per second before and after.
- Run the full QLoRA fine-tune, convert to GGUF, and run it on your CPU.
Saturday milestone
Project 2 complete with a before-and-after results table.
Embeddings, vector search and retrieval
Notes this week. RAG: Text embeddings and semantic similarity · RAG: Vector databases and approximate nearest neighbour search (HNSW, IVF) · RAG: Chunking strategies · RAG: Retrieval: BM25, dense, hybrid search and rank fusion · RAG: Reranking with cross-encoders.
By hand
- Rank five short documents against a query by cosine similarity on tiny hand-made embeddings.
- Compute BM25 for one query term over three documents.
- Combine two rankings with reciprocal rank fusion by hand.
Code
- Embed a corpus, build a brute-force search, then an HNSW index; compare recall and speed.
- Implement BM25 and hybrid search with rank fusion.
- Add a cross-encoder reranker and measure recall@k before and after.
Saturday milestone
Project 3: corpus ingested, golden set written, baseline retrieval measured.
The RAG pipeline and its evaluation
Notes this week. RAG: The RAG pipeline end to end · RAG: Advanced RAG: query rewriting, HyDE, multi-hop, GraphRAG, agentic RAG · RAG: Evaluating RAG: recall@k, MRR, nDCG, faithfulness · RAG: RAG failure modes and how to debug them.
By hand
- Compute recall@3, MRR and nDCG for three queries by hand.
- Design a chunking strategy for a code base and for a legal contract, and justify the difference.
Code
- Assemble the full pipeline with citations and streaming.
- Build an LLM judge for faithfulness and validate it against 50 of your own labels.
- Run the ablation table: chunk size, hybrid on/off, reranker on/off.
Saturday milestone
Project 3 complete with a results table and a failure-mode section in the README.
Prompting, tools and the agent loop
Notes this week. Agents: Prompt engineering that survives production · Agents: Context engineering: what goes in the window · Agents: Structured output and function (tool) calling · Agents: The agent loop and ReAct · Agents: Workflows vs agents: routing, orchestrator–workers, evaluator–optimizer.
By hand
- Rewrite a vague prompt into a production prompt with role, constraints, format and examples.
- Draw the agent loop and label where failures can happen at each arrow.
Code
- Write the agent loop with no framework: model call, tool call, result, repeat, with a step budget.
- Add structured output with a schema and retries on validation failure.
Saturday milestone
Project 4: the bare agent completes five of your test tasks.
MCP, memory and security
Notes this week. Agents: Model Context Protocol (MCP) · Agents: Agent memory: short-term, long-term, compaction · Agents: Multi-agent systems: when they help and when they hurt · Agents: Prompt injection and agent security.
By hand
- Write three prompt-injection attacks against your own agent and a defence for each.
- Design a memory scheme for a week-long task: what is kept, summarized and dropped.
Code
- Build an MCP server exposing your tools and connect the agent to it.
- Add compaction and a simple long-term memory; run a long task.
- Run the injection attacks against the agent and fix what breaks.
Saturday milestone
Project 4: 30 test tasks with a measured success rate.
Evals, cost and serving
Notes this week. Prod: Evals: golden sets, metrics and regression testing · Prod: LLM-as-judge: how to trust a model grading a model · Prod: Hallucination: causes, detection, mitigation · Prod: Guardrails and safety layers · Prod: Cost and latency: caching, batching, streaming, model routing · Prod: Serving LLMs: time to first token, throughput, continuous batching · Prod: Observability and tracing.
By hand
- Design an eval set for a feature of your choice: what is measured, how labels are made, what regression means.
- Estimate monthly cost for a feature at a given traffic, token count and model price; then halve it on paper.
Code
- Add tracing to the agent so every run can be inspected step by step.
- Add prompt caching and model routing; report cost and latency before and after.
- Add guardrails: input checks, tool permission limits and output validation.
Saturday milestone
Project 4 complete with a cost, latency and success-rate report.
Interview drill
Notes this week. Interview: A framework for LLM system design rounds · Interview: Design: a customer support assistant · Interview: Design: enterprise document search at scale · Interview: Design: a coding assistant · Interview: The ML coding round: attention, BPE and sampling from memory · Interview: Question bank: math, ML and DL fundamentals · Interview: Question bank: applied AI engineering · Interview: Talking about your projects.
By hand
- Answer one question-bank section per day out loud, timed, without notes.
- Do one full system-design run per day on paper: 45 minutes, one of the three worked designs or a new prompt.
- Write and rehearse the two-minute story for each project.
Code
- From memory, in under 20 minutes each: scaled dot-product attention, BPE merge step, top-p sampling, logistic regression with gradient descent, k-means.
- Solve ten Deep-ML problems under time pressure.
Saturday milestone
All project READMEs polished; resume bullets written with measured numbers.