Andrej Karpathy fits GPT into 243 lines of pure Python
Andrej Karpathy has released microGPT, a complete implementation of the transformer architecture in 243 lines of pure Python with no external dependencies. The project handles both training and inference, exposing the math behind large language models down to the last operation. Karpathy calls it an "art project," but what he has actually built is the most compact and transparent textbook on GPT architecture available. For anyone who wants to understand how language models really work, it is the best place to start.
AI-processed from Habr AI; edited by Hamidun News
There is a particular genre of programming that sits closer to poetry than to engineering. You take an extremely complex system and compress it down to its absolute essence, stripping away everything superfluous until only pure math and logic remain. That is exactly what Andrej Karpathy, an OpenAI co-founder and former head of AI at Tesla, did in February 2026 when he published microGPT: a complete implementation of the transformer architecture that trains and generates text in 243 lines of pure Python.
To appreciate the scale of this achievement, you need some context. Modern language models like GPT-4 or Claude involve tens of billions of parameters, thousands of GPUs, months of training, and codebases maintained by hundreds of engineers. Behind all that industrial muscle, it's easy to forget that the foundation is a relatively elegant mathematical construction, described in the famous 2017 paper "Attention Is All You Need." Karpathy took that construction and showed that it fits entirely on a few screens of code — no PyTorch, no NumPy, not a single external library.
MicroGPT implements every key component of the transformer architecture: tokenization, positional encoding, self-attention, the forward pass through fully connected layers, normalization, and backpropagation for training. Every mathematical operation is done by hand — matrix multiplication, softmax, activation functions. That means anyone with a basic grasp of linear algebra and Python can open the file and trace the entire path from input text to generated token without running into framework abstractions.
Karpathy modestly calls microGPT an "art project," and the label is more accurate than it might seem. This is not a tool for practical use: a model trained this way won't hold meaningful conversations and won't replace ChatGPT. Pure Python without optimized libraries runs several orders of magnitude slower than specialized frameworks. But the project's value lies somewhere else entirely. It demystifies a technology that is shaping the modern world.
This approach isn't new for Karpathy. He has long been recognized as one of the best popularizers of deep learning. His Stanford course on neural networks became a classic, and his YouTube series "Neural Networks: Zero to Hero" has helped tens of thousands of people learn the fundamentals. MicroGPT continues that line but raises the bar: where Karpathy previously explained architectures using PyTorch, he has now removed the last layer of abstraction. Nothing stands between the reader and the math of the transformer.
The implications reach beyond education. The AI industry is going through a paradoxical moment: the technology is becoming ever more influential, yet ever more opaque. Companies are closing off their models and publishing fewer and fewer technical details, while the gap between those who build AI and those who use it keeps widening. In that context, projects like microGPT serve a crucial function: they bring a fundamental understanding of the technology back into the public sphere. When a politician, a journalist, or simply a curious engineer from an adjacent field wants to understand what GPT really is, 243 lines of code give a more honest answer than any marketing document.
There's a practical side, too. For early-career researchers and students, microGPT is an ideal sandbox. You can modify the attention mechanism and see what happens. You can swap the activation function, experiment with the context window size, or add your own variant of positional encoding. When all the code is in front of you and every line makes sense, experimentation stops being black magic and becomes the scientific method.
Ultimately, microGPT is a reminder that behind the trillion-dollar valuations of AI companies and the talk of artificial superintelligence lies math that fits on a few pages. Scale and compute turn that math into something astonishing, but the core remains understandable. And as long as there are people like Karpathy willing to spend their time making the complex simple, the industry has a chance to remain not only powerful but also transparent.
- Nov 1, 2026Local models lose to Opus and Codex: 0.21 on a MacBook versus 1.00 for Codex
- Nov 1, 2026Kimi scores 96.2% on a 1C database analytics test and emerges as a fallback if Claude access is blocked
- Nov 1, 2026OpenAI Rewrites GPT Behavior Rules: Five Values and a Chain of Command
- Nov 1, 2026Google admits AI Mode cuts search revenue, shares fall 15%
Test Frontier LLMs & Autonomous Agents in One Workspace
Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.
The AI world, distilled — once a week
Seven stories that actually mattered, hand-picked. No noise, no reposts, no press releases.
Done! Check your inbox for a confirmation.