ai/from-scratch

Your path

Follow the path one lesson at a time, or explore freely and skip what you know. Skipping never counts as passing, and you can unskip anytime. If you skip a lesson, the ones after it recap what they need and give you the earlier lab's solution.

How you want to learn

Your progress

Loading your progress…

The road

One stone per lesson, a milestone sign at each stage. Every stone is a link.

The route in text

  1. Stage 0

    The math toolkit

    You build: pocket/stage0/ holds four working scripts, ending with probability.py, which fits a letter distribution to your notes and scores it by average negative log-likelihood against a uniform baseline.

  2. Stage 1

    How machines learn

    You build: pocket/stage1/ holds four working scripts, ending with fit_line.py, which fits the review-time line by gradient descent, passes a finite-difference gradient check and matches np.polyfit.

  3. Stage 2

    Neural networks from scratch

    You build: pocket/stage2/ holds neuron.py, tiny_grad.py, train_mlp.py and torch_mlp.py: an autograd you wrote, a tagger trained with it, and a PyTorch port verified to compute the same loss and gradients.

  4. Stage 3

    Language models from scratch

    You build: pocket/stage3/ holds a BPE tokenizer, a bigram baseline scoring 2.447 on the sample notes' validation text, an attention head checked against a hand calculation, and a 165,855-parameter GPT trained on your notes that beats the bigram and samples text in their style.

  5. Stage 4

    Building with LLM APIs

    You build: pocket/stage4/ holds first_call.py, prompt_spec.py, structured.py, and pocket.py, a CLI that streams an answer from all the notes in pocket/notes/, retries transient errors with backoff and jitter, caches the notes prefix, and logs usage for every call to stage4/usage.jsonl.

  6. Stage 5

    Retrieval and RAG

    You build: pocket/stage5/ holds a 192-chunk index of the sample notes, an answer script that passes six golden tests (two changed-over-time, four unanswerable) with checked citations, and a retrieval report with recall@3 and MRR for dense, BM25 and hybrid search.

  7. Stage 6

    Tools and agents

    You build: pocket/stage6/ holds tools.py, agent.py, guarded.py and pocket_mcp.py: an agent that decides when to search and read your notes, stops within set budgets, cannot write without your approval, and serves its note tools to any MCP host.

  8. Stage 7

    Evaluate and ship

    You build: pocket/stage7/ holds evals.py, judge.py, tracing.py and ship.py: per-category pass rates and refusal precision and recall on a golden set, a judge with a measured kappa, JSON Lines traces with cost and latency, and a SHIP_NOTE.md that records the launch decision. This closes the core path: you have trained a model with gradient descent, built a small transformer, built an LLM app with structured output, retrieval and tools, and you can evaluate, monitor and ship it on evidence. Stages 8 to 11 go deeper: production RAG, agentic patterns, agent testing, and deployment.

  9. Stage 8

    RAG in production

    You build: pocket/stage8/ holds ivf_index.py (an IVF index with a recall-versus-nprobe table), incremental_index.py (a hash-keyed index that re-embeds only changed chunks), query_and_rerank.py (rewriting, multi-query fusion and reranking scored on the golden questions) and assemble_context.py (a budgeted context assembler with context precision and recall).

  10. Stage 9

    Agentic AI patterns

    You build: pocket/stage9/ holds workflows.py, plan_reflect.py, memory.py and multi_agent.py: a gated router and chain, a planner with workers, replanning, and a capped critique loop, a memory store with compaction, and a lead with scoped subagents whose token cost you have measured.

  11. Stage 10

    Agent development: tests and reliability

    You build: pocket/stage10/ holds test_agent.py, trajectory_eval.py, tool_wrapper.py and checkpoint.py: a deterministic test suite for the loop, a trajectory scorer with pass@k and pass^k, an idempotent validated write tool, and a loop that pauses for approval and survives a crash without writing twice.

  12. Stage 11

    Deploying agents

    You build: pocket/stage11/ holds serve.py, sandbox.py, observe.py and rollout.py: Pocket's agent served as background runs with events, idempotent retries and cancellation, model-written code run under limits with secrets kept in the tool layer, every run traced as spans with per-user rate limits, budgets, a circuit breaker and alerts, and releases rolled out through a canary with an automatic rollback rule and a kill switch. This is the end of the path. You trained a model with gradient descent, built a small transformer, built an LLM app with structured output, added retrieval and made it production RAG, gave it tools, built agents and agentic patterns, tested and evaluated them, and deployed an agent as a service you can watch, limit and roll back.

Move or reset your progress

Progress lives in this browser only. Copy it out here and paste it into another browser to continue there.