ML Grind

ML Grind - Learn Machine Learning by Building It

Free hands-on ML coding practice. Implement NumPy, neural networks, attention, and transformers in your browser. No setup or signup required.

Solve your first problem →

About 5 minutes · Basic Python · No signup

Choose your learning path

NumPy foundations → — Get comfortable with arrays, shapes, broadcasting, and matrix operations.

ML interview prep → — Practice core building blocks and explain how they work.

Build a transformer → — Work through attention and the components behind modern language models.

Seven days of ML coding → — One focused exercise per day. Start any time, follow at your own pace, and build a habit.

149 exercises across 21 sections

Foundations

NumPy Fundamentals → — Create, index, broadcast, reduce and reshape NumPy arrays: the operations every ML codebase is built on.

Python Basics for ML → — Warm up with vectorised NumPy: sum an array, multiply matrices and broadcast a vector across rows.

Einstein Summation (Einsum) → — Write sums, matrix products and batched multi-head attention as einsum index strings.

PyTorch Basics → — Tensors, autograd, modules, losses, optimizers and the training loop, plus the norms, activations and adapters of modern models: in idiomatic PyTorch or from scratch in NumPy.

Classical ML

Data Preprocessing → — Scale, impute, encode and split data without leaking the test set into training.

Supervised Learning → — Build the classic supervised learners from scratch: sigmoid and loss functions, linear and logistic regression, SVMs, k-NN, Naive Bayes, Ridge/Lasso, boosted stumps and bagged decision trees.

Unsupervised Learning → — Build k-means, PCA centring, Gaussian mixtures with EM and DBSCAN from scratch.

Model Evaluation → — Compute classification metrics, k-fold splits, ROC/AUC, PR curves and calibration error, with the edge cases done right.

Deep Learning

Deep Learning Basics → — ReLU, a batched dense layer and numerically stable softmax: the three pieces every neural network is built from.

Neural Networks → — Train an MLP from scratch: cross-entropy, a hand-written backward pass, Xavier/He init, batch norm, dropout and a masked, label-smoothed LM loss.

Optimization & Training → — Gradient clipping by global norm and mixed-precision dynamic loss scaling: the tricks that keep long training runs stable.

CNNs & Computer Vision → — Build CNN layers (convolution, pooling, flatten, a ResNet block) and the detection toolkit: IoU, NMS, focal and smooth L1 losses, and segmentation metrics.

Sequence Models → — Unroll a vanilla RNN with hand-written BPTT, then build single steps of PyTorch-compatible LSTM and GRU cells.

Transformers & LLMs

Transformer Architecture → — Build the Transformer from scratch: attention (multi-head, grouped-query, sliding-window), positional encodings, LayerNorm, tokenizers and the attention backward pass.

LLM Generation & Decoding → — Turn logits into text: temperature, top-k and nucleus sampling, repetition penalty, the KV cache, beam search and speculative decoding.

LLM Internals → — How production LLMs are built and measured: RMSNorm + SwiGLU blocks, FlashAttention's online softmax, mixture-of-experts routing and perplexity.

Representation Learning & Retrieval → — Learn and use embeddings: the CLIP contrastive loss, cosine top-k vector search, and BM25 + embedding hybrid retrieval for RAG.

Generative & RL

Generative Models → — Build the maths behind VAEs, VQ-VAEs, diffusion, classifier-free guidance and flow matching, from Gaussian KL to a full sampling step.

Reinforcement Learning → — From returns and Bellman backups through Q-learning, policy gradients, GAE and PPO to the reward-model, KL and DPO losses used to align LLMs.

Post-training & Efficiency → — GRPO with group-relative advantages and a k3 KL penalty, plus int8 absmax quantization: making a base model useful and cheap to serve.

Capstone

End-to-End Implementations → — Assemble full models from scratch: an MLP with hand-written backprop, a Transformer encoder, a VAE, a VQ-VAE, a DDPM, a CNN, a mini GPT and a tiny ViT, plus a Transformer bug hunt.