Get started

Practice problems.

51 coding problems in Python and numpy, from a single loss function to a whole training loop. 16 problems have a graded lab you can open now; the rest are on their way. Each lab runs your code in a real terminal and checks the answers, not the wording.

Kind
Level
Topic
Lab

51 problems

  1. ImplementMediumMath foundations25 min
    Power iteration for the top eigenpair

    Find the dominant eigenvalue and eigenvector of a symmetric matrix by repeated multiplication, with a tolerance, an iteration cap and a sign convention.

    • eigenvalues
    • linear-algebra
    • svd
    Lab coming soon
  2. ImplementMediumMath foundations20 min
    Vectorized pairwise distances

    Build whole Euclidean and cosine distance matrices from one matrix product, and survive zero vectors and rounding below zero.

    • distances
    • vectorization
    • cosine-similarity
    Lab coming soon
  3. ImplementEasyClassical ML20 min
    Linear regression by gradient descent

    Write the squared-error loss, derive its gradients for the weights and the bias, and run the descent loop while logging the cost.

    • linear-regression
    • gradient-descent
    • gradients
  4. Train a modelEasyClassical ML25 min
    Train softmax regression on four blobs

    Train a multi-class linear classifier on four clusters until it hits an accuracy and log-loss target on points it never saw.

    • softmax
    • logistic-regression
    • log-loss
  5. ImplementMediumClassical ML25 min
    Logistic regression from scratch

    A numerically stable sigmoid, the binary cross-entropy loss, its gradient and a training loop that records the loss.

    • logistic-regression
    • classification
    • numerical-stability
    Lab coming soon
  6. ImplementHardClassical ML35 min
    Gini impurity and the best split

    Measure how mixed a set of labels is, then search every feature and threshold for the split that separates them best, with a fixed rule for ties.

    • decision-trees
    • gini-impurity
    • search
    Lab coming soon
  7. ImplementMediumClassical ML25 min
    K-means assignment and update

    Assign points to their nearest centre, move the centres, handle empty clusters and equal distances, and stop when assignments settle.

    • clustering
    • k-means
    • vectorization
    Lab coming soon
  8. ExperimentMediumClassical ML30 min
    Measure bias and variance

    Fit polynomials of rising degree to many resampled training sets and report bias squared, variance and test error for each degree.

    • bias-variance
    • overfitting
    • model-selection
    Lab coming soon
  9. Train a modelEasyDeep learning30 min
    Train a 2-4-1 network on XOR

    Add a hidden layer and backpropagation so a tiny sigmoid network learns the one pattern a straight line cannot.

    • mlp
    • backpropagation
    • xor
  10. ImplementHardDeep learning40 min
    Backpropagation through a two-layer MLP

    A forward pass that caches what it needs and a backward pass that returns the gradient of every weight and bias.

    • backpropagation
    • gradients
    • chain-rule
    Lab coming soon
  11. Train a modelMediumDeep learning35 min
    Fit a sine curve with a tanh network

    Train a small tanh network on noisy samples of a sine wave until it tracks the true curve closely on held-out points.

    • regression
    • mlp
    • tanh
    Lab coming soon
  12. Method from a paperEasyDeep learning20 min
    Focal loss

    Down-weight easy examples so rare, hard ones drive learning: the binary and multi-class forms, computed stably from logits, plus a gradient.

    • loss-functions
    • focal-loss
    • class-imbalance
  13. ImplementEasyDeep learning20 min
    Stable softmax and cross-entropy

    Batched softmax and mean cross-entropy with its gradient, written so huge logits neither overflow nor produce infinities.

    • softmax
    • loss-functions
    • numerical-stability
  14. ImplementEasyDeep learning20 min
    SGD with momentum

    One momentum update, then a loop that minimises a quadratic with and without Nesterov lookahead.

    • optimizers
    • momentum
    • gradient-descent
  15. ImplementMediumDeep learning25 min
    Adam and AdamW step

    A single Adam update with bias correction, and the AdamW variant that applies weight decay separately, as a pure function.

    • optimizers
    • adam
    • weight-decay
    Lab coming soon
  16. ImplementEasyDeep learning15 min
    Inverted dropout

    Drop units at random during training and rescale the rest, with a seeded generator and a matching backward pass.

    • dropout
    • regularization
    • gradients
  17. ImplementHardDeep learning45 min
    Batch normalization forward and backward

    Training and inference forward passes with running statistics, and the full backward pass for the input, the scale and the shift.

    • batch-norm
    • normalization
    • backpropagation
    Lab coming soon
  18. ExperimentEasyDeep learning20 min
    Sweep the learning rate

    Run descent at eight step sizes, find the best and the first that blows up, and compare with the stability limit of the loss.

    • learning-rate
    • gradient-descent
    • optimization
  19. Train a modelMediumDeep learning45 min
    Train a tanh network on two spirals

    Train a deeper tanh network with mini-batch Adam to separate two interleaved spirals on held-out points.

    • mlp
    • adam
    • mini-batch
    Lab coming soon
  20. Method from a paperMediumComputer vision30 min
    CLIP symmetric contrastive loss

    Normalise image and text embeddings, score every pair with a temperature, and compute the loss in both directions plus its gradient.

    • contrastive-learning
    • loss-functions
    • gradients
    Lab coming soon
  21. ImplementHardLanguage and retrieval45 min
    Beam search with EOS and length normalization

    Keep the best partial sequences at every step, finish them at the end token, and rank finished ones with a length penalty.

    • beam-search
    • decoding
    • seq2seq
    Lab coming soon
  22. ImplementMediumLanguage and retrieval25 min
    BM25 ranking

    Score tokenised documents against a query with inverse document frequency, term saturation and length normalisation, then rank them.

    • bm25
    • information-retrieval
    • ranking
    Lab coming soon
  23. Train a modelMediumLanguage and retrieval40 min
    Train a character bigram language model

    Learn a table of next-character scores until held-out likelihood beats a model that ignores context.

    • language-model
    • bigram
    • cross-entropy
    Lab coming soon
  24. ImplementMediumTransformers25 min
    Scaled dot-product attention with a mask

    Batched attention with an optional mask, including the causal mask a text decoder uses.

    • attention
    • masking
    • softmax
    Lab coming soon
  25. Method from a paperMediumTransformers30 min
    Grouped-query attention

    Let many query heads share a few key and value groups, and convert a multi-head checkpoint by pooling its heads.

    • attention
    • gqa
    • kv-cache
    Lab coming soon
  26. ImplementMediumTransformers30 min
    Split heads, merge heads, multi-head attention

    Reshape a batch into heads and back, then run multi-head self-attention with given projection matrices.

    • multi-head-attention
    • reshape
    • attention
    Lab coming soon
  27. ImplementEasyTransformers15 min
    Sinusoidal positional encoding

    Build the table of sines and cosines that tells a transformer where each token sits, and add it to a batch of embeddings.

    • positional-encoding
    • embeddings
  28. ImplementMediumTransformers25 min
    Rotary position embedding

    Rotate pairs of query and key coordinates by an angle that grows with position, so attention scores depend only on distance.

    • positional-encoding
    • rope
    • attention
    Lab coming soon
  29. ImplementEasyTransformers15 min
    LayerNorm and RMSNorm

    The two normalisation layers transformers use, over the last axis, with the small constant in the right place.

    • layer-norm
    • rms-norm
    • normalization
  30. ExperimentEasyTransformers20 min
    Sweep the sampling temperature

    Measure how temperature reshapes a next-token distribution: its entropy, its favourite token and how many tokens top-p keeps.

    • sampling
    • temperature
    • entropy
  31. ImplementMediumTransformers30 min
    Temperature, top-k and top-p sampling

    Scale logits, keep the top-k or top-p mass, renormalise and draw one token with a seeded generator.

    • sampling
    • decoding
    • softmax
    Lab coming soon
  32. Method from a paperMediumTransformers30 min
    Top-k MoE gating and the Switch load-balancing loss

    Route each token to its top experts with renormalised gates and add the auxiliary loss that keeps experts evenly used.

    • mixture-of-experts
    • routing
    • load-balancing
    Lab coming soon
  33. ImplementMediumTransformers25 min
    Fixed-capacity KV cache

    Append keys and values to a preallocated cache, attend one query over the filled part, and refuse to overflow.

    • kv-cache
    • attention
    • inference
    Lab coming soon
  34. Method from a paperHardTransformers40 min
    Tiled attention with an online softmax

    Compute exact attention block by block with a running maximum and sum, never forming the full score matrix.

    • attention
    • flash-attention
    • numerical-stability
    Lab coming soon
  35. Method from a paperHardTransformers35 min
    Speculative decoding: accept, reject and resample

    The acceptance rule and residual distribution that make a fast draft model produce exactly the target model's output distribution.

    • speculative-decoding
    • sampling
    • probability
    Lab coming soon
  36. Method from a paperMediumGenerative models30 min
    DDPM noise schedule, closed form noising and posterior

    Build the noise schedule, jump to any noising step in closed form, and compute the posterior used to denoise one step.

    • diffusion
    • ddpm
    • noise-schedule
    Lab coming soon
  37. Method from a paperMediumGenerative models25 min
    Rectified flow loss and Euler sampler

    Interpolate along straight paths, regress the velocity with the flow-matching loss, and sample by integrating with Euler steps.

    • rectified-flow
    • flow-matching
    • ode-solvers
    Lab coming soon
  38. ImplementEasyReinforcement learning15 min
    Q-learning and SARSA updates

    The two tabular update rules, with the terminal-step case, and an epsilon-greedy action picker with a fixed tie rule.

    • q-learning
    • sarsa
    • exploration
  39. ImplementEasyReinforcement learning15 min
    Discounted returns with episode ends

    Reward-to-go for one episode and for several joined episodes where returns must not leak across the end, plus normalisation.

    • returns
    • policy-gradients
  40. ImplementMediumReinforcement learning25 min
    Generalized advantage estimation

    Temporal-difference errors blended into advantages with a discount and a trace parameter, handling episode ends and a bootstrap value.

    • advantages
    • actor-critic
    • ppo
    Lab coming soon
  41. ImplementMediumReinforcement learning25 min
    PPO clipped surrogate loss

    The clipped policy-gradient loss from new and old log-probabilities, the fraction of clipped steps, and the gradient.

    • ppo
    • policy-gradient
    • gradients
    Lab coming soon
  42. Method from a paperMediumReinforcement learning30 min
    GRPO group advantages and clipped objective

    Normalise rewards within a group of answers, estimate the divergence from a reference model, and compute the clipped objective per answer.

    • grpo
    • policy-gradient
    • kl-divergence
    Lab coming soon
  43. Method from a paperMediumTraining and alignment25 min
    DPO loss and implicit rewards

    The direct preference loss, the implicit rewards it defines and its gradient, from policy and reference log-probabilities.

    • dpo
    • alignment
    • loss-functions
    Lab coming soon
  44. ImplementMediumTraining and alignment20 min
    Symmetric int8 quantization

    Scale weights to eight-bit integers per tensor and per row, convert them back, and treat an all-zero row safely.

    • quantization
    • int8
    • inference
    Lab coming soon
  45. ExperimentMediumTraining and alignment30 min
    Sweep the quantization bit width

    Quantise outlier-heavy weights from two to eight bits and compare per-tensor with per-row scaling.

    • quantization
    • inference
    • outliers
    Lab coming soon
  46. ImplementEasyLLM engineering15 min
    Cosine similarity top-k search

    Normalise embeddings, score queries against documents with one matrix product and return the best k with a fixed tie rule.

    • embeddings
    • vector-search
    • retrieval
  47. ImplementEasyLLM engineering15 min
    LoRA linear layer

    A frozen layer plus a trainable low-rank correction, merged back into one matrix, with the parameter count.

    • lora
    • fine-tuning
    • linear-algebra
  48. ExperimentMediumServing30 min
    Read an SGLang sweep on an L4

    Given benchmark runs of an inference server on one GPU, find where throughput saturates, where the latency target breaks, and what lower precision buys.

    • serving
    • benchmarking
    • goodput
    Lab coming soon
  49. ImplementHardBuilding blocks50 min
    Parse and validate tool calls

    Pull tool calls out of a raw model reply and check their arguments against a schema, reporting errors with a path to the bad field.

    • tool-calling
    • json-schema
    • parsing
    Lab coming soon
  50. ImplementMediumBuilding blocks30 min
    BPE pair counts and merges

    Count adjacent symbol pairs, pick the best with a fixed tie rule, merge without overlaps, and learn a list of merges.

    • tokenization
    • bpe
    • subwords
    Lab coming soon
  51. ImplementEasyBuilding blocks12 min
    Reciprocal rank fusion

    Merge several ranked lists into one by summing reciprocal ranks, with optional weights and a deterministic tie rule.

    • rank-fusion
    • hybrid-retrieval
    • ranking