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.
51 problems
-
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.
Lab coming soon -
Vectorized pairwise distances
Build whole Euclidean and cosine distance matrices from one matrix product, and survive zero vectors and rounding below zero.
Lab coming soon -
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.
-
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.
-
Logistic regression from scratch
A numerically stable sigmoid, the binary cross-entropy loss, its gradient and a training loop that records the loss.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
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.
-
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.
Lab coming soon -
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.
Lab coming soon -
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.
-
Stable softmax and cross-entropy
Batched softmax and mean cross-entropy with its gradient, written so huge logits neither overflow nor produce infinities.
-
SGD with momentum
One momentum update, then a loop that minimises a quadratic with and without Nesterov lookahead.
-
Adam and AdamW step
A single Adam update with bias correction, and the AdamW variant that applies weight decay separately, as a pure function.
Lab coming soon -
Inverted dropout
Drop units at random during training and rescale the rest, with a seeded generator and a matching backward pass.
-
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.
Lab coming soon -
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.
-
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.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
BM25 ranking
Score tokenised documents against a query with inverse document frequency, term saturation and length normalisation, then rank them.
Lab coming soon -
Train a character bigram language model
Learn a table of next-character scores until held-out likelihood beats a model that ignores context.
Lab coming soon -
Scaled dot-product attention with a mask
Batched attention with an optional mask, including the causal mask a text decoder uses.
Lab coming soon -
Grouped-query attention
Let many query heads share a few key and value groups, and convert a multi-head checkpoint by pooling its heads.
Lab coming soon -
Split heads, merge heads, multi-head attention
Reshape a batch into heads and back, then run multi-head self-attention with given projection matrices.
Lab coming soon -
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.
-
Rotary position embedding
Rotate pairs of query and key coordinates by an angle that grows with position, so attention scores depend only on distance.
Lab coming soon -
LayerNorm and RMSNorm
The two normalisation layers transformers use, over the last axis, with the small constant in the right place.
-
Sweep the sampling temperature
Measure how temperature reshapes a next-token distribution: its entropy, its favourite token and how many tokens top-p keeps.
-
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.
Lab coming soon -
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.
Lab coming soon -
Fixed-capacity KV cache
Append keys and values to a preallocated cache, attend one query over the filled part, and refuse to overflow.
Lab coming soon -
Tiled attention with an online softmax
Compute exact attention block by block with a running maximum and sum, never forming the full score matrix.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
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.
-
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.
-
Generalized advantage estimation
Temporal-difference errors blended into advantages with a discount and a trace parameter, handling episode ends and a bootstrap value.
Lab coming soon -
PPO clipped surrogate loss
The clipped policy-gradient loss from new and old log-probabilities, the fraction of clipped steps, and the gradient.
Lab coming soon -
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.
Lab coming soon -
DPO loss and implicit rewards
The direct preference loss, the implicit rewards it defines and its gradient, from policy and reference log-probabilities.
Lab coming soon -
Symmetric int8 quantization
Scale weights to eight-bit integers per tensor and per row, convert them back, and treat an all-zero row safely.
Lab coming soon -
Sweep the quantization bit width
Quantise outlier-heavy weights from two to eight bits and compare per-tensor with per-row scaling.
Lab coming soon -
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.
-
LoRA linear layer
A frozen layer plus a trainable low-rank correction, merged back into one matrix, with the parameter count.
-
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.
Lab coming soon -
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.
Lab coming soon -
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.
Lab coming soon -
Reciprocal rank fusion
Merge several ranked lists into one by summing reciprocal ranks, with optional weights and a deterministic tie rule.
No problem matches these filters.
