examples
A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
A curated collection of runnable PyTorch code examples for vision, text, and reinforcement learning tasks, built as a hands-on cookbook for learning machine learning by Andrej Karpathy.
PyTorch Examples Explanation
This repository is a collection of working code examples that teach you how to build machine learning models using PyTorch, a popular open-source library for AI development. Think of it as a cookbook: instead of just reading instructions, you get actual recipes you can run, modify, and learn from. Each example tackles a different real-world problem—from recognizing handwritten digits to generating realistic images to predicting stock prices over time.
The examples cover three main areas. In vision (image tasks), you'll find code for recognizing objects in photos, upscaling blurry images to higher quality, and generating completely new images from scratch. In text, there are examples for predicting the next word in a sequence (language modeling), translating between languages, and understanding relationships between sentences. For reinforcement learning—where a computer learns by trial and error, like teaching a game-playing AI—there's an example of training a virtual pole-balancer.
Who would find this useful? Anyone learning machine learning from scratch would benefit from seeing working code for common tasks rather than just theory. Researchers experimenting with new ideas might use these examples as templates. Developers building AI features into applications can reference how to train models for specific problems. The examples range from beginner-friendly (like recognizing handwritten numbers) to more advanced (like adversarial networks that generate synthetic images), so there's something for different skill levels.
What makes this repository valuable is that it's officially curated by Andrej Karpathy, a well-respected AI researcher. The examples aren't toy demonstrations—they're the kinds of models used in production systems, just stripped down to their essential parts so you can understand how they work. Each example typically includes the code to train the model, parameters you can tweak, and explanations of what's happening behind the scenes.
Where it fits
- Learn to build an image recognition model by running the handwritten digit recognition example.
- Study a working language modeling or translation example to understand text-based deep learning.
- Use the reinforcement learning pole-balancer example as a template for training a game-playing AI.
- Reference stripped-down, production-style model code when adding AI features to an application.