Tutorials

Code-first machine learning tutorials. Each starts with a working implementation, then explains why it works, with animated visualisations to build intuition before the maths.

Cover Image for Clinical Decision Support, Before and After Language Models

Clinical Decision Support, Before and After Language Models

Guideline-based decision support once meant hand-encoding rules that went stale. Retrieval removed that cost and moved the hard part to evaluation. Notes on a piece in Life Science Daily.

Cover Image for A3C: Asynchronous Advantage Actor-Critic in PyTorch

A3C: Asynchronous Advantage Actor-Critic in PyTorch

Build A3C from scratch in PyTorch: a critic cuts REINFORCE's gradient variance, and asynchronous workers train it without a replay buffer, on CartPole.

Cover Image for SVD for Recommender Systems: Matrix Factorisation in NumPy

SVD for Recommender Systems: Matrix Factorisation in NumPy

Build a recommender from scratch with the SVD: factorise a user-item ratings matrix, tune the rank, and beat mean baselines on real Jester data.

Cover Image for Next-Latent Prediction: Autoregression in Latent Space

Next-Latent Prediction: Autoregression in Latent Space

Predict the next continuous latent instead of the next token: build autoregression in latent space from scratch and see why the head makes or breaks it.

Cover Image for LLM Serving: Continuous Batching & PagedAttention

LLM Serving: Continuous Batching & PagedAttention

How vLLM serves hundreds of LLM requests at once: build continuous batching and a paged KV cache from scratch and watch GPU utilisation and throughput jump.

Cover Image for Time Series as Dynamical Systems: Delay Embedding

Time Series as Dynamical Systems: Delay Embedding

Reconstruct a chaotic attractor from a single time series with Takens delay embedding, then forecast it with simplex projection, from scratch in NumPy.

Cover Image for Beyond Attention: Linear Attention & Mamba SSMs

Beyond Attention: Linear Attention & Mamba SSMs

Build linear attention and a diagonal state-space model (Mamba) from scratch in PyTorch, and watch the O(n²) attention cost curve bend to O(n).

Cover Image for Hamiltonian Neural Networks: Physics as Inductive Bias

Hamiltonian Neural Networks: Physics as Inductive Bias

Build a Hamiltonian Neural Network from scratch in PyTorch: learn a scalar energy, take its symplectic gradient, and conserve energy where a plain MLP drifts.

Cover Image for Barriers to AI adoption, by firm size

Barriers to AI adoption, by firm size

The ONS asks UK businesses what has prevented or delayed them adopting AI. Expertise leads among firms of 10 or more employees, and reported barriers peak in the mid-market.

Cover Image for Business AI adoption in the UK, Europe and the US

Business AI adoption in the UK, Europe and the US

The ONS, Eurostat and the US Census Bureau each publish a business AI adoption rate. The three headline figures differ, and denominators explain most of the gap.

Cover Image for Anomaly Detection from Scratch: 3 Detectors Compared

Anomaly Detection from Scratch: 3 Detectors Compared

Build three unsupervised anomaly detectors from scratch: Isolation Forest, One-Class SVM and an autoencoder. See why ROC-AUC lies on imbalanced fraud data.

Cover Image for Parallel LLM Decoding: Speculative and Diffusion

Parallel LLM Decoding: Speculative and Diffusion

Autoregressive LLMs emit one token per pass. Build masked-diffusion and speculative decoders in NumPy to see how parallel decoding breaks the wall.

Cover Image for Graph Neural Networks from Scratch: Message Passing

Graph Neural Networks from Scratch: Message Passing

Build a graph neural network from scratch in NumPy, then watch a vanilla GCN lose to a graph-blind MLP on a fraud graph, and learn the fixes that recover it.

Cover Image for Vision Transformers from Scratch in PyTorch

Vision Transformers from Scratch in PyTorch

Build a Vision Transformer from scratch in PyTorch: patch embedding, class token, self-attention. Trained on CIFAR-10 and compared to a CNN.

Cover Image for Random Forests from Scratch: Bagging and OOB Error

Random Forests from Scratch: Bagging and OOB Error

One decision tree overfits wildly. Average a hundred on bootstrap samples with random feature subsets and you get the no-tuning workhorse of tabular ML.

Cover Image for Gradient Boosting: Fitting the Residuals, From Scratch to XGBoost

Gradient Boosting: Fitting the Residuals, From Scratch to XGBoost

Boosting fits weak trees to the errors so far, one at a time. We animate the residual loop, derive it as gradient descent in function space, then XGBoost.

Cover Image for Continual Learning: Training Neural Networks That Do Not Forget

Continual Learning: Training Neural Networks That Do Not Forget

Fine-tune a network on a new task and it erases the old. See catastrophic forgetting on split-MNIST, then fix it with Elastic Weight Consolidation and replay.

Cover Image for Tabular Foundation Models: How TabPFN Predicts Without Training

Tabular Foundation Models: How TabPFN Predicts Without Training

TabPFN is a transformer pre-trained on millions of synthetic datasets that predicts in one forward pass: no training. Benchmarked against XGBoost.

Cover Image for Shrinking the KV Cache: MQA, GQA, and Multi-Head Latent Attention

Shrinking the KV Cache: MQA, GQA, and Multi-Head Latent Attention

The KV cache is LLM serving's memory wall. MQA, GQA, and DeepSeek's Multi-Head Latent Attention shrink it 2 to 8x. We train all four and measure the cost.

Cover Image for On-Policy Distillation: When Self-Generated Data Wins

On-Policy Distillation: When Self-Generated Data Wins

On-policy distillation (GKD) vs off-policy SeqKD, from scratch in PyTorch. See exactly when training on a model's own output beats copying teacher transcripts.

Cover Image for JEPA from Scratch: Predicting in Latent Space

JEPA from Scratch: Predicting in Latent Space

Build a Joint-Embedding Predictive Architecture in PyTorch. Predict in latent space, watch representation collapse, and learn LeCun's world-model bet.

Cover Image for LoRA from Scratch: Why LLM Fine-Tuning Got 1000x Cheaper

LoRA from Scratch: Why LLM Fine-Tuning Got 1000x Cheaper

LoRA and QLoRA in pure PyTorch. Why low-rank adapters need 1000x fewer params, and how 4-bit base quantisation lets you fine-tune 65B models on one GPU.

Cover Image for Mixture of Experts in LLMs: From Switch to DeepSeek-V3

Mixture of Experts in LLMs: From Switch to DeepSeek-V3

Sparse MoE in PyTorch from scratch. Top-k routing, Switch Transformer load balancing, Mixtral, DeepSeek. Why MoE scales LLM parameters without scaling FLOPs.

Cover Image for Stacking and Ensemble Methods in Python

Stacking and Ensemble Methods in Python

Bagging, AdaBoost, gradient boosting, stacking, and mixture of experts from scratch in NumPy, with XGBoost benchmarked. Why ensembles still win on tabular data.

Cover Image for Probabilistic PCA, EM-PCA, Bayesian PCA, Factor Analysis

Probabilistic PCA, EM-PCA, Bayesian PCA, Factor Analysis

Probabilistic PCA as a latent variable model. EM-PCA, Bayesian PCA with ARD that picks dimensionality automatically, and Factor Analysis. From scratch in NumPy.

Cover Image for Gibbs and Slice Sampling: Two Cures for Random-Walk MCMC

Gibbs and Slice Sampling: Two Cures for Random-Walk MCMC

Gibbs sampling exploits conditionals; slice sampling adapts step size. Both cure random-walk Metropolis on correlated targets, with Python and animations.

Cover Image for Sampling Methods Compared: Inverse-CDF, Rejection, Importance

Sampling Methods Compared: Inverse-CDF, Rejection, Importance

Hands-on guide to Monte Carlo sampling: inverse-CDF, Box-Muller, rejection, and importance sampling, with Python code, animations, and a decision matrix.

Cover Image for Approximate Inference: From MCMC to Variational Bayes

Approximate Inference: From MCMC to Variational Bayes

Derive variational Bayesian linear regression in NumPy, compare it to PyMC NUTS on the same dataset, and watch the lower bound pick the true polynomial degree.

Cover Image for Bayesian Networks for Clinical Decision Support

Bayesian Networks for Clinical Decision Support

Build a Bayesian network in pgmpy from a toy lung-cancer dataset. Parameter learning, d-separation, structure search, causality.

Cover Image for Relevance Vector Machine vs SVM in Python

Relevance Vector Machine vs SVM in Python

Build a relevance vector machine from scratch. The RVM gives sparser, calibrated alternatives to the SVM via ARD priors and evidence maximisation.

Stay in the loop

Get notified when new tutorials and deep-dives are published. No spam, unsubscribe anytime.

Blog FAQ

Questions about these tutorials and write-ups