Simple Machine Learning

What it means for a computer to learn, from a straight line through data to how large language models are built, trained, tuned and checked. Every model is written from scratch in NumPy first, then used from a library.

Each lesson lists the sources it follows, mostly the official Python, NumPy, scikit-learn and PyTorch documentation. See all sources.

Last updated

MThe capstone: A small language model, end to end: a tokeniser, a GPT-style transformer trained on a public-domain text, instruction tuning, an evaluation and a model card.

Stage 0: Python for data

Handle numbers in bulk: arrays, plots and tables, so the rest of the course has its tools.

  1. 0.1Why arrays Open
  2. 0.2Making and shaping arrays Open
  3. 0.3Reading parts of an array Open
  4. 0.4Maths on whole arrays Open
  5. 0.5Broadcasting Open
  6. 0.6Matrix multiplication with @ Open
  7. 0.7Random numbers Open
  8. 0.8Plotting with matplotlib Open
  9. 0.9Tables with pandas Open
  10. 0.10Notebooks and your own computer Open
  11. 0.PProject: a first look at data Open

Stage 1: The maths you need

Read and use every equation in the course: each idea as a picture first, then words, symbols and NumPy.

  1. 1.1Functions and graphs Open
  2. 1.2Vectors Open
  3. 1.3The dot product Open
  4. 1.4Matrices Open
  5. 1.5Eigenvectors, briefly Open
  6. 1.6Rates of change Open
  7. 1.7The chain rule Open
  8. 1.8Many inputs: partial derivatives and gradients Open
  9. 1.9Probability Open
  10. 1.10Distributions Open
  11. 1.11Information Open
  12. 1.PProject: maths you can run Open

Stage 2: What learning is

What a model is, what training does, and how to tell honestly whether a model is any good.

  1. 2.1What machine learning is Open
  2. 2.2Kinds of learning Open
  3. 2.3Data, features and labels Open
  4. 2.4Your first model: nearest neighbours Open
  5. 2.5Training and testing Open
  6. 2.6Overfitting and underfitting Open
  7. 2.7Loss functions Open
  8. 2.8Measuring classifiers Open
  9. 2.9Validation and cross-validation Open
  10. 2.10Data leakage and pipelines Open
  11. 2.11Measuring regressors Open
  12. 2.12Should you use machine learning? Open
  13. 2.PProject: a penguin classifier Open

Stage 3: Linear models

Train a model by gradient descent, by hand: the building blocks inside every neural network.

  1. 3.1A straight line through data Open
  2. 3.2The loss landscape Open
  3. 3.3Gradient descent Open
  4. 3.4Many features Open
  5. 3.5The exact answer: normal equations Open
  6. 3.6Batches: stochastic and mini-batch gradient descent Open
  7. 3.7Feature scaling and curves Open
  8. 3.8Regularisation: ridge and lasso Open
  9. 3.9Logistic regression Open
  10. 3.10Cross-entropy and maximum likelihood Open
  11. 3.11Many classes: softmax regression Open
  12. 3.PProject: a digit reader from scratch Open

Stage 4: Traditional models

Know the models that still win on tables of data, and when to reach for each.

  1. 4.1Preparing tables Open
  2. 4.2Feature engineering and extraction Open
  3. 4.3Naive Bayes Open
  4. 4.4Decision trees Open
  5. 4.5Ensembles and random forests Open
  6. 4.6Boosting Open
  7. 4.7Support vector machines Open
  8. 4.8Clustering with k-means Open
  9. 4.9Other clusters: DBSCAN, hierarchical, Gaussian mixtures Open
  10. 4.10Dimensionality reduction: PCA Open
  11. 4.11Maps of high-dimensional data: t-SNE and UMAP Open
  12. 4.12Anomaly detection Open
  13. 4.13Tuning a model Open
  14. 4.14Choosing a model, and applying it properly Open
  15. 4.15Which model for which task: a field guide Open
  16. 4.PProject: predict house prices Open

Stage 5: The first artificial neurons

Build the three classic neurons, and see exactly why one neuron can’t learn XOR.

  1. 5.1Brains and the first model neuron Open
  2. 5.2Rosenblatt’s perceptron Open
  3. 5.3Why the perceptron works Open
  4. 5.4Adaline Open
  5. 5.5Perceptron, Adaline, logistic regression Open
  6. 5.6XOR and the first AI winter Open
  7. 5.PProject: three neurons from scratch Open

Stage 6: Neural networks

Derive backpropagation by hand, write it in NumPy, then write simplenet, a small autograd library.

  1. 6.1Layers of neurons Open
  2. 6.2Activation functions Open
  3. 6.3What networks can draw Open
  4. 6.4Backpropagation by hand Open
  5. 6.5A network in NumPy Open
  6. 6.6Computational graphs Open
  7. 6.7Build simplenet, part 1: scalars Open
  8. 6.8Build simplenet, part 2: tensors Open
  9. 6.9Training on digits Open
  10. 6.PProject: MNIST with your own library Open

Stage 7: Deep learning in practice

Train deep networks reliably in PyTorch, with each trick shown fixing a specific failure.

  1. 7.1PyTorch on your computer Open
  2. 7.2Autograd, nn.Module and the training loop Open
  3. 7.3Optimisers Open
  4. 7.4Learning rate schedules Open
  5. 7.5Vanishing and exploding gradients Open
  6. 7.6Initialisation Open
  7. 7.7Normalisation Open
  8. 7.8Regularisation for deep nets Open
  9. 7.9Residual connections Open
  10. 7.10Debugging training Open
  11. 7.11Experiments and reproducibility Open
  12. 7.12Hardware, speed and mixed precision Open
  13. 7.PProject: a Fashion-MNIST classifier in PyTorch Open

Stage 8: Convolutional networks

Understand how networks see, from one multiply-add of a convolution to ResNet, detection and segmentation.

  1. 8.1Images as numbersNot written yet
  2. 8.2ConvolutionNot written yet
  3. 8.3Stride, padding, channelsNot written yet
  4. 8.4Pooling and the full CNNNot written yet
  5. 8.5What CNNs learnNot written yet
  6. 8.6The ImageNet yearsNot written yet
  7. 8.7Transfer learningNot written yet
  8. 8.8Efficient CNNsNot written yet
  9. 8.9Object detectionNot written yet
  10. 8.10SegmentationNot written yet
  11. 8.PProject: a CNN for CIFAR-10Not written yet

Stage 9: Sequences

Process text, sound and time series in order, and meet attention as the fix for a real problem.

  1. 9.1Sequences and orderNot written yet
  2. 9.2Recurrent networksNot written yet
  3. 9.3Backpropagation through timeNot written yet
  4. 9.4LSTMNot written yet
  5. 9.5GRU, and RNNs in PyTorchNot written yet
  6. 9.6Sequence to sequenceNot written yet
  7. 9.7The first attentionNot written yet
  8. 9.PProject: a character-level text generatorNot written yet

Stage 10: Transformers

Understand the transformer completely, from one attention head by hand to a full block in PyTorch.

  1. 10.1Attention without recurrenceNot written yet
  2. 10.2Self-attention in NumPyNot written yet
  3. 10.3MasksNot written yet
  4. 10.4Multi-head attentionNot written yet
  5. 10.5PositionsNot written yet
  6. 10.6The transformer blockNot written yet
  7. 10.7Encoder, decoder, and bothNot written yet
  8. 10.8Build a transformer in PyTorchNot written yet
  9. 10.9The cost of attentionNot written yet
  10. 10.10Vision TransformersNot written yet
  11. 10.11Mixture of expertsNot written yet
  12. 10.PProject: a transformer that sorts and addsNot written yet

Stage 11: Natural language processing

Turn text into numbers and back, in English and Filipino, from counting words to fine-tuning BERT.

  1. 11.1Text as dataNot written yet
  2. 11.2Bag of words and TF-IDFNot written yet
  3. 11.3Language models with n-gramsNot written yet
  4. 11.4Subword tokenisationNot written yet
  5. 11.5Word embeddingsNot written yet
  6. 11.6Text classification with neural networksNot written yet
  7. 11.7Contextual embeddings and BERTNot written yet
  8. 11.8Fine-tuning a pretrained modelNot written yet
  9. 11.9Tagging: parts of speech and named entitiesNot written yet
  10. 11.10Translation, summarisation and their metricsNot written yet
  11. 11.11Sentence embeddings and semantic searchNot written yet
  12. 11.PProject: Filipino and English sentimentNot written yet

Stage 12: Audio

Turn sound into features a model can learn from, and understand how modern speech recognisers work.

  1. 12.1Sound as numbersNot written yet
  2. 12.2Frequencies and the Nyquist limitNot written yet
  3. 12.3The Fourier transformNot written yet
  4. 12.4SpectrogramsNot written yet
  5. 12.5Mel spectrograms and MFCCsNot written yet
  6. 12.6Classifying soundsNot written yet
  7. 12.7Keyword spottingNot written yet
  8. 12.8Speech recognition and CTCNot written yet
  9. 12.9Self-supervised speech: wav2vec 2.0Not written yet
  10. 12.10WhisperNot written yet
  11. 12.11Music and making soundNot written yet
  12. 12.PProject: a voice command appNot written yet

Stage 13: Large language models

How an LLM is made and used: pretraining, sampling, instruction tuning, and building on one responsibly.

  1. 13.1From GPT to todayNot written yet
  2. 13.2PretrainingNot written yet
  3. 13.3Scaling lawsNot written yet
  4. 13.4Decoding and samplingNot written yet
  5. 13.5Inference: KV cache, batching and memoryNot written yet
  6. 13.6From base model to assistant: instruction tuningNot written yet
  7. 13.7Learning from preferences: RLHF and DPONot written yet
  8. 13.8Prompting and in-context learningNot written yet
  9. 13.9Retrieval-augmented generationNot written yet
  10. 13.10Tools and agentsNot written yet
  11. 13.11Reasoning modelsNot written yet
  12. 13.12Efficient fine-tuning: LoRA and QLoRANot written yet
  13. 13.13Quantisation and small modelsNot written yet
  14. 13.14Evaluating LLMsNot written yet
  15. 13.15Hallucination, safety and looking insideNot written yet
  16. 13.PProject: train a small GPTNot written yet

Stage 14: Generative models

How models make new images and sounds, from autoencoders to diffusion, and how text steers them.

  1. 14.1AutoencodersNot written yet
  2. 14.2Variational autoencodersNot written yet
  3. 14.3GANsNot written yet
  4. 14.4Diffusion: adding noiseNot written yet
  5. 14.5Diffusion: learning to denoiseNot written yet
  6. 14.6CLIP: joining text and imagesNot written yet
  7. 14.7Text to imageNot written yet
  8. 14.8Flow matching and what’s nextNot written yet
  9. 14.PProject: a tiny diffusion modelNot written yet

Stage 15: Learning by doing: reinforcement learning

Learn from rewards, from a grid world solved by hand to PPO and the ideas behind AlphaGo.

  1. 15.1Agents, rewards and banditsNot written yet
  2. 15.2Markov decision processesNot written yet
  3. 15.3Values and the Bellman equationNot written yet
  4. 15.4Q-learningNot written yet
  5. 15.5Deep Q-networksNot written yet
  6. 15.6Policy gradients and PPONot written yet
  7. 15.7Search and self-play: AlphaGo and AlphaZeroNot written yet
  8. 15.PProject: teach an agent to balance a poleNot written yet

Stage 16: More model families

Short lessons on families a practitioner will meet: graphs, time series, recommenders and state-space models.

  1. 16.1Graph neural networksNot written yet
  2. 16.2Time series and forecastingNot written yet
  3. 16.3Recommender systemsNot written yet
  4. 16.4State-space modelsNot written yet
  5. 16.5Self-supervised learning for imagesNot written yet

Stage 17: Responsible machine learning

Build models that are fair, explainable, private, robust, documented and lawful, and know when not to build one.

  1. 17.1Where bias comes fromNot written yet
  2. 17.2Measuring fairnessNot written yet
  3. 17.3Explaining predictionsNot written yet
  4. 17.4PrivacyNot written yet
  5. 17.5Robustness and adversarial examplesNot written yet
  6. 17.6Documenting models and dataNot written yet
  7. 17.7Energy and costNot written yet
  8. 17.8Deploying and monitoringNot written yet
  9. 17.9Rules and lawsNot written yet

Capstone

Build a small language model end to end, and document it like a real release.

  1. C.1The planNot written yet
  2. C.2The tokeniserNot written yet
  3. C.3The modelNot written yet
  4. C.4PretrainingNot written yet
  5. C.5GeneratingNot written yet
  6. C.6Teaching it to follow instructionsNot written yet
  7. C.7PreferencesNot written yet
  8. C.8EvaluationNot written yet
  9. C.9Shrinking and sharingNot written yet
  10. C.10The model cardNot written yet