// zero dependencies. just math.

no-magic

Single-file, zero-dependency Python implementations of the algorithms that power modern AI. Every script runs with python script.py — no frameworks, no abstractions.

—
Algorithms
0
Dependencies
—
Tiers
—
Stars
—
Forks

Browse by Tier

Four progressive tiers. Pick the one matching what you want to learn next, or jump into the full catalog.

Learning Paths

Structured tracks through the collection. Pick one based on your interest or time budget.

01
Weekend Sprint: Transformers
From raw text to self-attention. Tokenization, embeddings, RNNs, GPT, and BERT.
~4 hrs6 scripts
02
Weekend Sprint: Alignment
Steering model behavior post-training. LoRA, DPO, PPO, and RLHF.
~3 hrs5 scripts
03
Deep Dive: Modern Inference
Making models fast and small. Efficient attention, RoPE, KV-cache, paging, quantization, decoding and state-space models.
~7 hrs12 scripts
04
Deep Dive: Generative Models
How models create new data. VAEs, GANs, and diffusion.
~4 hrs3 scripts
05
Deep Dive: Retrieval & Search
Connecting models to external knowledge. Embeddings, RAG pipelines, and tokenization.
~3 hrs3 scripts
06
Agent Algorithms
Search and reasoning for autonomous agents. MCTS and ReAct.
~3 hrs2 scripts
07
Full Curriculum
The longest track: 36 of the 48 scripts in dependency order.
~22 hrs36 scripts

The constraint is the product

One file per algorithm

No local imports, no utils.py, no companion files. Everything in one place.

Zero dependencies

Python standard library only. If it needs pip install, it doesn't belong here.

One command, no setup

python script.py runs the whole program. Most scripts train, either one model followed by inference or variants compared side by side; a few run untrained mechanisms or non-learning algorithms. Each script's kind is recorded in no-magic/docs/catalog.json; this site does not display it yet. Some scripts download a small names dataset on first run.

Comments are the curriculum

30-40% comment density. Math-to-code mappings. Why, not what. Read top-to-bottom like a tutorial.

Reproducible by default

random.seed(42) at the top of every script. Same input, same output, every time.

Under 10 minutes on CPU

The target for every script is a laptop CPU in under 10 minutes. No GPU required. No cloud. Recorded timings are historical (some, such as RAG at 12m 30s and RNN vs. GRU at 18m 30s, exceeded the target), and there is no current full-corpus runtime check.

The Ecosystem

Tom Mathews
Created by
Tom Mathews
Building tools that make AI algorithms transparent and accessible.