NanoGPT is a minimalistic yet powerful reimplementation of GPT-style transformers created by Andrej Karpathy for educational and research use. It distills the GPT architecture into a few hundred lines of Python code, making it far easier to understand than large, production-scale implementations. The repo is organized with a training pipeline (dataset preprocessing, model definition, optimizer, training loop) and inference script so you can train a small GPT on text datasets like Shakespeare or custom corpora. It emphasizes readability and clarity: the training loop is cleanly written, and the code avoids heavy abstractions, letting students follow the architecture step by step. While simple, it can still train non-trivial models on modern GPUs and generate coherent text. The project has become widely used in tutorials, courses, and experiments for people learning how transformers work under the hood.

Features

  • Compact GPT transformer implementation in plain Python/PyTorch
  • Data preprocessing pipeline for text datasets (e.g. Shakespeare)
  • Training loop with clear optimizer and scheduler setup
  • Inference script for text generation after training
  • Readable, educational codebase (few hundred lines)
  • Supports running on modern GPUs for small to mid-sized models

Project Samples

Project Activity

See All Activity >

Categories

Research

License

MIT License

Follow nanoGPT

nanoGPT Web Site

You Might Also Like
Gen AI apps are built with MongoDB Atlas Icon
Gen AI apps are built with MongoDB Atlas

The database for AI-powered applications.

MongoDB Atlas is the developer-friendly database used to build, scale, and run gen AI and LLM-powered apps—without needing a separate vector database. Atlas offers built-in vector search, global availability across 115+ regions, and flexible document modeling. Start building AI apps faster, all in one place.
Start Free
Rate This Project
Login To Rate This Project

User Reviews

Be the first to post a review of nanoGPT!

Additional Project Details

Operating Systems

Windows

Programming Language

Python

Related Categories

Python Research Software

Registered

2025-10-01