AI and ML FoundationsVol. 14A · Part XIV
0 / 0

Shelves / AI and ML Foundations

AI·159

AI and ML Foundations Projects

Eight build-it-yourself projects that take you from a line fitted by hand to a small language model you trained, adapted and evaluated yourself: a from-scratch learning toolkit, an honest tabular model, a data-quality pipeline, a neural network library and its PyTorch twin, a vision model with measured inductive bias, a tokenizer for your languages, a tiny GPT trained end to end, and a fine-tuning and evaluation study, each with milestones, measurable definitions of done and stretch goals.

12 topics · ~6 min read · 5-question quiz
Updated Suggest a correction

How to approach the projects

From first principles to a model you understand completely

The labs in this volume measured one idea at a time. These projects join them up, building up to a small language model you trained, tokenized, decoded, adapted and evaluated yourself, so that every number a large model's paper reports means something concrete to you. Everything runs on a laptop CPU (a GPU only makes the last projects faster): NumPy, pandas, scikit-learn, XGBoost, PyTorch and Hugging Face tokenizers. Use data you're allowed to use: scikit-learn's bundled datasets, public-domain text, your own writing, or this textbook's text.

# Project Main chapters Roughly
1 A from-scratch learning toolkit Start Here, 143–147 1 week
2 An honest tabular model 148, 149 1 week
3 A data-quality pipeline 150 1 week
4 A neural network library and its PyTorch twin 151, 152 1–2 weeks
5 A vision model with measured inductive bias 153 1 week
6 A tokenizer for your languages 155 a weekend
7 A tiny GPT, end to end 154, 156, 157 2 weeks
8 Adapting and evaluating your model 158 1–2 weeks

New to the field? Do them in order; each reuses the last. Experienced? Do projects 7 and 8, and treat 1–6 as checks on the parts you haven't implemented yourself.

The working method

  1. Hold data out, always, and report error bars (chapter 147).
  2. Start with a baseline and change one thing at a time.
  3. Seed everything and record versions so every number can be reproduced.
  4. Verify by a second route: gradients by finite differences, metrics by hand on small cases, library results against your own implementation.
  5. Write a README per project with plots, numbers and what surprised you.

The eight projects

Project 1: a from-scratch learning toolkit

Goal. Linear regression, logistic regression and k-means written in NumPy, checked against scikit-learn.

Milestones. Vectorised implementations with gradient descent and closed forms where they exist → gradient checks by finite differences → L2 regularisation → a learning-rate sweep showing convergence and divergence → bootstrap confidence intervals for every reported metric.

Done when. Your coefficients match scikit-learn's to 1e-4 on the diabetes and breast-cancer datasets; your gradient check passes with relative error below 1e-6; every plotted metric has an error bar.

Stretch. Add mini-batch SGD with momentum and Adam, and reproduce chapter 146's ill-conditioned-valley experiment with each.

Project 2: an honest tabular model

Goal. The best defensible model for a tabular problem, with evaluation a sceptic would accept.

Milestones. Baseline → scikit-learn pipelines with preprocessing inside CV → logistic regression, random forest and XGBoost with nested CV → metrics chosen for the problem (PR-AUC and cost-based thresholds if imbalanced) → calibration → slice analysis by meaningful groups → a deliberate leakage test.

Done when. The report states the baseline, the chosen model with error bars, the threshold and its expected cost, the calibration curve, the worst-performing slice, and evidence that a planted leaky feature is detected by your process.

Stretch. A paired comparison (per-fold differences) showing whether the winning model is actually better than the runner-up.

Project 3: a data-quality pipeline

Goal. Validation that catches bad data before training and before serving.

Milestones. A schema (types, ranges, allowed categories, missing-value rates) derived from training data → checks run on every new batch → drift scores (PSI) per feature → near-duplicate detection across train/test splits → label-noise estimation with out-of-fold predictions.

Done when. Planted problems are each caught: a unit change, a new category, a 20% missing-value spike, a 5% train–test duplicate rate and 10% flipped labels; normal week-to-week variation raises no alert.

Stretch. Feed served features back into the training set with point-in-time correctness and show the validator's results on both.

Project 4: a neural network library and its PyTorch twin

Goal. A minimal autograd engine and MLP library in NumPy, matched by a PyTorch implementation.

Milestones. A scalar or tensor autograd engine with backpropagation → Linear, ReLU, softmax-cross-entropy, SGD and Adam → training on digits → the same model in PyTorch with identical initialisation → a comparison of losses step by step.

Done when. Both implementations reach the same accuracy on digits, losses match to 1e-5 for the first 100 steps with identical seeds and batches, and every operation in your engine passes a gradient check.

Stretch. Add dropout and batch norm to your engine, including train/eval modes, and reproduce chapter 152's "forgot eval()" bug.

Project 5: a vision model with measured inductive bias

Goal. Show, with numbers, what convolution, pooling and augmentation buy.

Milestones. MLP and CNN on digits (or a small public image set) → shift tests as in chapter 153 → anti-aliased pooling → augmentation → parameter counts, training time and receptive-field calculations.

Done when. A table shows accuracy at shifts 0–3 px for MLP, CNN, CNN + blur-pool and CNN + augmentation, with error bars across 3 seeds, and you can explain each column's pattern.

Stretch. A small Vision Transformer (patch embedding + 2 Transformer blocks) in the same table, with the data requirement it reveals.

Project 6: a tokenizer for your languages

Goal. A tokenizer that treats every language you care about fairly.

Milestones. A corpus mixing English with Hindi, Telugu or the languages you use (text you have the right to use) → BPE and Unigram tokenizers at several sizes → fertility (tokens per word) per language → digit handling → round-trip and Unicode normalisation tests.

Done when. Fertility for each target language is within 1.5× of English at your chosen size, numbers split predictably, and every test string round-trips exactly.

Stretch. Measure how a GPT trained with your tokenizer (project 7) compares in validation loss per character against one trained with an English-only tokenizer.

Project 7: a tiny GPT, end to end

Goal. A small decoder-only Transformer you wrote, trained and can explain line by line.

Milestones. Attention with a causal mask and a causality unit test → a block with pre-layer-norm and residuals → the model with tied embeddings → a training loop with warm-up, cosine decay, gradient clipping and validation → decoding with temperature, top-k and top-p → a KV cache.

Done when. Validation loss beats a bigram baseline by a clear margin; the causality test passes; decoding settings change diversity and repetition as chapter 157 measured; the KV cache makes generating 256 tokens at least 3× faster than recomputing.

Stretch. Replace learned positions with RoPE and the MLP with SwiGLU, and compare validation loss at equal parameters.

Project 8: adapting and evaluating your model

Goal. Measure what scale, fine-tuning and LoRA do to your model, honestly.

Milestones. A mini scaling study (4 sizes, equal steps) → full fine-tuning on a domain subset → LoRA at ranks 4, 8 and 32 → forgetting measured on general text → a small task evaluation (e.g. completing definitions from the glossary) scored automatically.

Done when. A plot shows validation loss against parameters; a table shows domain and general loss for base, full fine-tune and each LoRA rank with trainable-parameter counts; the task evaluation has at least 100 items and error bars.

Stretch. Instruction-tune on 200 question–answer pairs you write, and compare base and tuned models' answers on 50 held-out questions with a rubric.

Tracking your progress

Portfolio checklist

Keep code, configs, seeds, logs and plots in Git with a README per project. AI evidence is numbers you can reproduce: "NumPy logistic regression matches scikit-learn to 1e-5; tabular model PR-AUC 0.41 ± 0.03 vs baseline 0.02, leakage test caught; 5 planted data faults caught, 0 false alarms in 8 weeks; my autograd matches PyTorch to 1e-6; CNN keeps 96% at 3-px shifts with blur-pool; Hindi fertility 1.9 vs English 1.4; tiny GPT val loss 3.9 vs bigram 5.6; LoRA r=8 gets a third of full fine-tuning's gain with 4.5% of the parameters and 40% of the forgetting" is what makes the portfolio credible.

Mapping to mastery levels

Completing projects 1–3 with their checks puts you at L2 across the volume. Doing their stretch goals and explaining every mechanism is L3–L4. Designing and defending projects 4–8 (your own autograd, architectures with measured biases, a tokenizer, a trained and adapted language model with an evaluation) is L5 work, the level ML engineering and applied-research interviews probe.