Build AI From Scratch

Hands-on, zero-black-box implementations of modern AI and Machine Learning fundamentals โ€” autograd engines, BPE tokenizers, neural networks โ€” built entirely in pure Python.

โœ… 69/69 Tests Passing ๐Ÿ Pure Python 3.13 โšก Zero Dependencies
Scroll to explore
8
Course Modules
69
Automated Checks
100%
Test Pass Rate
6
Live Browser Labs

Eight Modules, One Full Stack

Each module builds on the previous one โ€” from the math inside a single neuron to a quantized model served in production. All code is zero-black-box.

๐Ÿ“˜ Prefer a guided path? Nine courses, 138 chapters.

Part 1 โ€” Fundamentals: the 8 topics below as 8 chapters ร— 5 levels, analogy to expert view, with live labs.
Part 2 โ€” Applied: 15 chapters ร— 5 levels on shipping LLM systems โ€” structured output, tool calling, context engineering, vector DBs, RAG, reranking, agents, MCP, deterministic pipelines, evals, guardrails, caching, observability, fine-tuning.
Part 3 โ€” The Python Stack (interview edition): 16 chapters ร— 5 levels on NumPy, pandas, Matplotlib/Seaborn, SciPy, statsmodels, scikit-learn, XGBoost/LightGBM/CatBoost, SHAP, Optuna, PyTorch, Keras, Hugging Face, spaCy, OpenCV, time series and MLOps.
Part 4 โ€” ML Interviews & Production Systems: 17 chapters ร— 5 levels on the interview map, probability & stats, classical ML theory, DL architectures & training, recommenders, search/ranking, A/B testing, causal inference, ML system design, SQL, distributed training, production monitoring & drift, and responsible AI.
Part 5 โ€” Databases & Data Systems: 18 chapters ร— 5 levels on SQL, NoSQL, vector & graph databases with production depth โ€” data modeling, indexes & query planners, transactions & isolation, replication, sharding, CAP/PACELC, PostgreSQL, Redis/DynamoDB, MongoDB, Cassandra, LSM vs B-tree, the lakehouse, Elasticsearch, vector DBs, graph DBs, Kafka/CDC, datastore selection, and DB operations โ€” each ending in an interview drill.
Part 6 โ€” AI/ML System Design: 16 chapters ร— 5 levels on designing AI/ML systems at scale โ€” capacity math & SLOs, online/batch/streaming serving, the inference gateway, KServe/Triton/vLLM/TGI/BentoML, feature stores & training-serving skew, retrieval at scale, caching for AI, GPU autoscaling & backpressure, multi-region & fallback models, cost/perf tradeoffs, and two end-to-end walkthroughs.
Part 7 โ€” Production Deployment & Delivery: 16 chapters ร— 5 levels on shipping AI/ML โ€” containers & reproducibility, model/artifact registries, CI for ML, GitOps CD (Argo CD / Flux), progressive delivery (canary, blue-green, shadow traffic), Kubernetes for model workloads, managed inference, eval-in-CI release gates, rollback & kill switches, load testing, migrations, IaC, and supply-chain security.
Part 8 โ€” AI Observability & Production Metrics: 16 chapters ร— 5 levels on OpenTelemetry, Prometheus & Grafana, golden signals / RED / USE, SLOs & error budgets, LLM telemetry (tokens, cost/request, TTFT, cache-hit), tracing an agent request, eval-in-prod, drift & data quality, guardrail & safety metrics, dashboards, burn-rate alerting, AI-enriched ops, and cost observability / FinOps.
Part 9 โ€” Enterprise-Scale AI/ML in Production: 16 chapters ร— 5 levels on platform engineering & the paved road, multi-tenancy & quotas, model & data governance, security for AI systems, compliance (EU AI Act, NIST AI RMF, ISO/IEC 42001, SOC 2), responsible AI, FinOps at scale, reliability & cell architecture, LLMOps, org design, vendor portability, a reference architecture, and an enterprise-readiness checklist.

Parts 1โ€“5 build the primitives from scratch. Parts 6โ€“9 teach the industry-standard stack โ€” Kubernetes, OpenTelemetry, Prometheus, Argo, Terraform, KServe โ€” configured and operated, not reimplemented.

Part 1 โ€” Fundamentals โ†’ Part 2 โ€” Applied โ†’ Part 3 โ€” Python Stack โ†’ Part 4 โ€” Interviews & Prod โ†’ Part 5 โ€” Databases โ†’ Part 6 โ€” System Design โ†’ Part 7 โ€” Deployment โ†’ Part 8 โ€” Observability โ†’ Part 9 โ€” Enterprise Scale โ†’
1
Micrograd โ€” Autograd Engine
Backpropagation โ€ข Neural Networks โ€ข Gradients

Build an automatic differentiation engine from 200 lines. Understand how gradients flow backward through a computation graph, then build a full MLP that reaches 100% accuracy on a toy dataset.

Step 1 Step 2 Step 3 Guide
2
BPE Tokenizer
Text โ†’ Numbers โ€ข Compression โ€ข UTF-8

Build a Byte-Pair Encoding tokenizer from scratch. Understand how text becomes numbers, how tokens carry meaning, and why fewer tokens = lower bills.

Step 1 Step 2 Step 3 Guide
3
Interactive Lab
Visual Playground โ€ข Scenario Tests

Everything made touchable. A browser playground with live neuron sliders, BPE visualizer, cost calculator, and 46 automated checks over 15 real-world scenarios.

Open Playground Lab Guide
4
Attention โ€” The Transformer Heart
Self-Attention โ€ข Softmax โ€ข Causal Masks

The mechanism inside GPT. Score every token against every other token, softmax the scores into percentages, and mix meanings โ€” then train a mini transformer end-to-end with your own engine.

Step 1 Step 2 Step 3 Guide
5
Matrix Multiplication Kernel
Naive to Tiled to Strassen and n3 flops

The operation every GPU runs billions of times per second. Build it four ways: naive, cache-tiled, Strassen divide-and-conquer, then matvec (which is exactly one attention head). Watch each algorithm agree and see why the loop order changes everything.

Step 1 Step 2 Step 3 Step 4 Guide
6
Embeddings & Vector Search
Cosine โ€ข Word2Vec โ€ข LSH / ANN

Meaning as geometry. Show king โˆ’ man + woman โ‰ˆ queen, learn word vectors from scratch with skip-gram, then build a locality-sensitive hash that keeps ~90% recall while scoring 9ร— fewer vectors โ€” the trick inside FAISS.

Step 1 Step 2 Step 3 Guide
7
Prompting, RAG & Agents
Templates โ€ข Retrieval โ€ข ReAct loop

Everything around the model. Five prompt templates measured head-to-head, a mini-RAG that retrieves, grounds and cites (and refuses when it should), then a ReAct agent chaining lookup + calc tools with a full trace.

Step 1 Step 2 Step 3 Guide
8
Fine-tuning & RLHF
LoRA โ€ข Reward model โ€ข DPO

Changing the weights, built on the Phase 1 engine. A rank-1 LoRA patch fits a correction while training a fraction of the weights; a Bradley-Terry reward model recovers human taste from comparisons; DPO moves a policy onto preferences with no RL loop.

Step 1 Step 2 Step 3 Guide
9
Quantization & Serving
INT8 โ€ข KV-cache โ€ข Continuous batching

Making it cheap to run. INT8 per-channel quantization (4ร— smaller, ~1% error), a KV-cache that turns O(nยฒ) decoding into O(n) (~150ร— fewer FLOPs), and continuous batching that doubles GPU utilisation on the same lanes.

Step 1 Step 2 Step 3 Guide

Interactive Playground

A zero-install browser lab โ€” one HTML file, no server, no dependencies. Everything runs live, even offline.

๐Ÿง 
Live Neuron Trainer
Gradient descent โ€ข Real-time

Drag the sliders and watch a single neuron learn โ€” the loss falls, the gradient flows, and the weights update in real time.

โœ‚๏ธ
BPE Tokenizer Lab
Merge rules โ€ข Compression

Type any text and watch the byte-pair encoding tokenizer split it, merge it, and count the tokens โ€” and what those tokens cost.

๐Ÿ’ฐ
API Cost Calculator
Token pricing โ€ข Real rates

See why fewer tokens mean lower bills โ€” compare API costs across model sizes with realistic per-token pricing.

๐Ÿ‘€
Attention Visualizer
Softmax weights โ€ข Live

The famous "the animal didn't cross the street because itโ€ฆ" โ€” click an ending and watch REAL attention weights re-route.

๐ŸŒก๏ธ
Temperature Explorer
Sampling โ€ข Creativity dial

ChatGPT's creativity knob exposed: drag the temperature and watch the next-word distribution sharpen or melt.

๐Ÿงฎ
Context Cost (O(nยฒ))
Why long context is expensive

Every token scores every token: drag the context length and watch the pairwise-score count explode quadratically.

7-Minute Quick Start

No setup needed โ€” everything runs locally with just Python 3.13. Follow these steps:

1
Clone the repository
Get the full curriculum on your machine.
git clone https://github.com/satyabhan007/AI-ML.git
cd AI-ML
2
Run the scenarios tester
Verifies all 46 checks โ€” every layer unit-tested, all 15 scenarios green โ€” in seconds.
python lab/scenarios_tester.py
3
Open the interactive playground
Double-click lab/playground.html โ€” no server needed.
โ†“ Clone on GitHub Read the Guides

Documentation Index

Every concept is explained three ways โ€” plain English, deep math, and visual diagrams.

Guide Topic What You Get
REPORT.md Autograd & Backprop 1800+ line reference manual โ€” engine internals, math proofs, examples
BEGINNER_GUIDE.md Neural Nets 101 Plain-English analogies โ€” shower thermostat, soup tasting, golf in fog
VISUAL_GUIDE.md Graph Walkthroughs ASCII & visual diagrams of DAG backward passes and chain rule flow
MINDMAPS.md Conceptual Maps Memory aids and system maps for rapid revision
DEEP_EXPLANATION.md Line-by-Line Math Every formula broken down with worked numbers and exercises
Tokenizer Guide BPE Tokenization LEGO analogy, merge trees, compression ratios, UTF-8 handling
AI_ENGINEERING_NOTES.md Learning Roadmap 20+ project roadmap from autograd to LLMs and AI agents
attention.py Attention Core Softmax, โˆšd scaling, causal masks, positional encoding โ€” pure Python
Attention Guide Transformers 101 Everyday analogies for queries, keys, values โ€” and the O(nยฒ) bill
matmul.py Matrix Multiplication Naive โ†’ tiled โ†’ Strassen โ†’ mat-vector โ€” the kernel behind every layer
MatMul Guide GPU Kernel Intuition Why matmul is 80% of a forward pass, and how tiling cuts memory traffic
Embeddings Guide Meaning as Geometry Cosine similarity, skip-gram training, and LSH for billion-scale search
RAG & Agents Guide Using the Model Prompt templates, retrieval + grounding + refusal, and the ReAct agent loop
Fine-tuning Guide Teaching the Model LoRA vs full fine-tune, Bradley-Terry reward models, and DPO without RL
Serving Guide Shipping It INT8 quantization, KV-cache O(n) decoding, continuous batching, roofline

Keep Learning

Nine courses built into this repo โ€” Parts 1โ€“5 from scratch, Parts 6โ€“9 on the industry-standard production stack โ€” then go deeper with Anthropic's official training.

๐Ÿง 
Course ยท Part 1 โ€” Fundamentals
This repo ยท 8 chapters ร— 5 levels

Autograd โ†’ tokenization โ†’ GPUs โ†’ attention โ†’ embeddings โ†’ RAG/agents โ†’ RLHF โ†’ serving. Built from scratch, with live labs.

Open Part 1
๐Ÿ“—
Course ยท Part 2 โ€” Applied
This repo ยท 15 chapters ร— 5 levels

Structured output, tool calling, context engineering, vector DBs, RAG, reranking, agents, MCP, deterministic pipelines, evals, guardrails, caching, observability, fine-tuning.

Open Part 2
๐Ÿ“™
Course ยท Part 3 โ€” Python Stack
This repo ยท 16 chapters ร— 5 levels ยท interview edition

NumPy, pandas, Matplotlib/Seaborn, SciPy, statsmodels, scikit-learn, XGBoost/LightGBM/CatBoost, SHAP, Optuna, PyTorch, Keras, Hugging Face, spaCy, OpenCV, time series, MLOps โ€” every chapter ends in an interview drill.

Open Part 3
๐Ÿ“•
Course ยท Part 4 โ€” Interviews & Production
This repo ยท 17 chapters ร— 5 levels ยท deep interview drills

The ML interview map, probability & stats, bias/variance, trees/SVM/kNN, clustering, feature engineering, DL architectures & training, recommenders, search & ranking, A/B testing, causal inference, ML system design, SQL, distributed training, production monitoring & drift, responsible AI.

Open Part 4
๐Ÿ““
Course ยท Part 5 โ€” Databases
This repo ยท 18 chapters ร— 5 levels ยท production + interviews

SQL, NoSQL, vector & graph databases with production depth: data modeling, indexes & query planners, transactions & isolation, replication, sharding, CAP/PACELC, PostgreSQL, Redis/DynamoDB, MongoDB, Cassandra, LSM vs B-tree, the lakehouse, Elasticsearch, vector DBs, graph DBs, Kafka/CDC, datastore selection, DB operations. Two production scenarios per chapter.

Open Part 5
๐Ÿ—๏ธ
Course ยท Part 6 โ€” AI/ML System Design
This repo ยท 16 chapters ร— 5 levels ยท standard, not from-scratch

Capacity math & SLOs, online/batch/streaming serving, the inference gateway, KServe/Triton/vLLM, feature stores & training-serving skew, retrieval at scale, caching for AI, GPU autoscaling & backpressure, multi-region & fallback models, cost/perf tradeoffs, plus two end-to-end design walkthroughs.

Open Part 6
๐Ÿš€
Course ยท Part 7 โ€” Deployment & Delivery
This repo ยท 16 chapters ร— 5 levels ยท standard, not from-scratch

Containers & reproducibility, model/artifact registries, CI for ML, GitOps CD (Argo CD / Flux), progressive delivery (canary, blue-green, shadow traffic), Kubernetes for model workloads, managed inference, eval-in-CI release gates, rollback & kill switches, load testing, migrations, IaC, supply-chain security.

Open Part 7
๐Ÿ“ก
Course ยท Part 8 โ€” AI Observability
This repo ยท 16 chapters ร— 5 levels ยท standard, not from-scratch

OpenTelemetry, Prometheus & Grafana, golden signals / RED / USE, SLOs & error budgets, LLM telemetry (tokens, cost/request, TTFT, cache-hit), tracing an agent request, eval-in-prod, drift & data quality, guardrail & safety metrics, dashboards, burn-rate alerting, AI-enriched ops, and cost observability / FinOps.

Open Part 8
๐Ÿข
Course ยท Part 9 โ€” Enterprise Scale
This repo ยท 16 chapters ร— 5 levels ยท standard, not reinvented

Platform engineering & the paved road, multi-tenancy & quotas, model & data governance, security for AI systems, compliance (EU AI Act, NIST AI RMF, ISO/IEC 42001, SOC 2), responsible AI, FinOps at scale, reliability & cell architecture, LLMOps, org design, vendor portability, a reference architecture, and a readiness checklist.

Open Part 9
๐ŸŽ“
Claude 101
External ยท academy.claude.com

Anthropic's introduction to working with Claude โ€” prompting fundamentals and core concepts.

Go to course โ†—
๐Ÿค
Introduction to Claude Cowork
External ยท academy.claude.com

Anthropic's course on collaborating with Claude on real work.

Go to course โ†—