How Andrej Karpathy Built a Working Transformer in 243 Lines of Code
AI-generated summary of reporting by Analytics Vidhya Gen AI Blog. Read the original for the full story.
Why it matters
Very little changes for practitioners, this is an educational teaching artifact that strips transformers down to readable pure Python, useful for learning, not for production.
AI researcher Andrej Karpathy released microGPT, a working version of GPT (the technology behind chatbots like ChatGPT) written in just 243 lines of Python code with no extra libraries. It shows every mathematical step of how the model learns and generates text, instead of hiding them inside big frameworks like PyTorch. It trains a model that can produce believable names. The trade-off is speed: it is purely educational and runs extremely slowly.
Karpathy's microGPT is a teaching tool, not a product: a minimal GPT-2-style model in 243 dependency-free Python lines. Teams gain no production capability from it, and training that takes seconds in PyTorch reportedly takes about three hours here on a CPU. Its value is onboarding and demystification for engineers new to how large language models actually work. No pricing, licensing or availability constraints are mentioned.
microGPT implements a simplified GPT-2 architecture in 243 lines of pure, dependency-free Python: a hand-rolled autograd engine using a scalar Value class, character-level token and positional embeddings, multi-head self-attention with 1/sqrt(head_dim) scaling, feed-forward blocks using ReLU² instead of GeLU, no bias terms, and a from-scratch Adam optimizer with bias correction. Training runs 500 steps, predicting next characters; inference uses temperature sampling. It can load GPT-2 state dicts. Limitations: pure-Python scalar math, no GPU or NumPy, roughly three hours training where PyTorch takes seconds.
Read the original
This summary exists to save you time, not to replace the source.
Key terms
microGPT GPT-2 PyTorch GitHub NumPy TensorFlow Adam optimizer
Was this summary useful?
One click, anonymous. It tells us which summaries to re-run.
Related reading
Code-driven AI illustrations are more useful than images from dedicated image models
Code-driven AI illustrations let designers edit assets directly in code, saving time on iteration and ensuring consistency, which is a game-changer for teams that need rapid, reusable visual content.
datasette-charts 0.5a0
Datasette Charts 0.5a0 adds calendar heatmaps, box plots and active-over-time charts, enabling richer data visualisation directly in the browser without extra libraries.
A hierarchical note-taking app for building large personal knowledge bases
Trilium lets users build and navigate massive personal knowledge bases without duplicating content, saving time on organization and retrieval.
Desktop apps in Go with native UI or web frontend
Go developers can now ship cross-platform desktop and mobile apps in a single small binary without cgo or heavy runtimes, cutting build complexity and deployment size.
OpenBitFun: an agent workspace with four harness modes and phone remote control
OpenBitFun lets agents run on any machine and be controlled from a phone, eliminating the need to choose between local power and remote access, saving developers time switching contexts.