Back to browse
Microgpt-ts – Full GPT in 500 lines of TypeScript, zero dependencies

Microgpt-ts – Full GPT in 500 lines of TypeScript, zero dependencies

by sdubois·Feb 24, 2026·3 points·2 comments

AI Analysis

●●SolidWizardryBig BrainShip It

Karpathy's minigpt ported to TS, readable code instead of brevity Olympics.

Strengths
  • Live loss curves + token-by-token probability inspection let you debug training interactively.
  • Preset datasets (baby names, Pokemon) lower friction for playground exploration.
  • Readable code (named helpers, typed) trades 500→800 lines for genuine legibility.
Weaknesses
  • Educational toy; no architectural novelty beyond Karpathy's original Python version.
  • Flat performance vs. server-side training; toy datasets only, not production learnable.
Category
Target Audience

ML students, educational content creators, browser-based ML enthusiasts

Similar To

Karpathy's minigpt (Python original) · TensorFlow.js · ONNX.js

Post Description

I ported Karpathy's microgpt [1] to TypeScript. It implements a complete GPT-2 architecture (autograd, tokenizer, multi-head attention, RMSNorm, and Adam optimizer), all in ~500 lines with zero runtime dependencies. It runs natively in the browser, no Python runtime or backend needed.

You can try it in the playground: https://microgpt-ts.vercel.app/playground

There are preset datasets (baby names, Pokemon, company names, movie titles, etc.) or you can paste your own text. The playground shows live loss curves as the model trains, and you can step through generation one token at a time to see the probability distribution at each step.

One difference from Karpathy's original is style. His microgpt is a single Python script optimized for brevity. This version splits the code into a few small files, types everything, and uses named helper functions (dotProduct, transpose, mean) instead of terse one-liners. The tradeoff is a bit more code, but it's easier to read and follow.

I built it up following the same progression as the blog post: bigram count table, then MLP with manual gradients, then autograd, single-head attention, multi-head + layer loop, and finally Adam. Each step is a separate PR and tag on GitHub [2] so you can follow along or check out any snapshot.

[1] https://karpathy.github.io/2026/02/12/microgpt/

[2] https://github.com/dubzdubz/microgpt-ts

Similar Projects

AI/ML●●●Banger

Andrej Karpathy's microgpt.py to C99 microgpt.c – 4,600x faster

Pure C99 GPT with SIMD beats Python 4,600x; drop two files into any project.

WizardryZero to One
Ajay__soni
4034mo ago
Education●●Solid

How-to-train-your-GPT. Every line commented

Explains attention mechanisms to five-year-olds while building LLaMA 3 from scratch.

CozyNiche Gem
mateenah
401mo ago
Education●●Solid

Interactive visualizer for Karpathy's 243-line microGPT

Type a name and you can literally watch characters turn into IDs, 16‑dim embeddings get added with positional encodings, and causal attention matrices animate per head — all matched numerically to Karpathy's 244‑line microGPT. The implementation is pure TypeScript (no ML libs) and includes a helpful scrollable sidebar with the reference math, which makes this an excellent, low‑friction learning tool — more pedagogical deep dive than research innovation.

Rabbit HoleNiche GemEye Candy
Sayyed23
114mo ago
AI/ML●●●Banger

MicroGPT-C – C99 GPT for Edge Training and Tiny Model Pipelines

Karpathy's microgpt in C99, proves tiny coordinated models beat single large models on logic.

WizardryBig Brain
Ajay__soni
103mo ago