// machine learning, in the browser

Six small ML demos, each with the maths behind it

Every demo runs entirely client-side: the retrieval, the attention weights, the optimiser steps and the clustering are computed in JavaScript as you interact. Each one has its own page with the demo on the left and the theory on the right.

01 / Retrieval-augmented generation

RAG document Q&A

Type a question, watch TF-IDF retrieval rank a small knowledge base by cosine similarity, and see an answer grounded in the top passages.

TF-IDFcosine similarityRAG Open the demo →
02 / Transformer self-attention

Attention visualizer

Type a sentence and see the Q·Kᵀ scores turn into a softmax heatmap, with a causal mask and a temperature control.

scaled dot-product attentionsoftmaxcausal mask Open the demo →
03 / Parameter-efficient fine-tuning

LoRA calculator

Pick a model and a rank and see how many parameters LoRA trains and how much GPU memory full fine-tuning, LoRA and QLoRA need.

low-rank adaptersQLoRAmemory accounting Open the demo →
04 / Optimisers on a loss surface

Gradient descent playground

SGD, momentum and Adam race across a non-convex loss surface while you change the learning rate.

SGDmomentumAdam Open the demo →
05 / Unsupervised segmentation

K-means clustering

Click to add points or generate blobs, choose k, and step through Lloyd's algorithm with k-means++ initialisation.

Lloyd's algorithmk-means++silhouette Open the demo →
06 / A classifier from scratch

Naive Bayes sentiment

A log-odds lexicon classifier with negation handling: every word becomes a chip that shows how it pushed the verdict.

Bayes' theoremlog-oddsLaplace smoothing Open the demo →

How it is built