Deep Dive into LLMs like ChatGPT

Andrej Karpathy

Andrej Karpathy's 3.5-hour guide to how ChatGPT-style models are built and where they fail

The former OpenAI founding member walks a general audience through pretraining, fine-tuning and reinforcement learning, and explains why models hallucinate, miscount and need tokens to think.

In a video of about three and a half hours, Andrej Karpathy, a founding member of OpenAI and former head of AI at Tesla, explains how large language models like ChatGPT are made. He goes through the full training pipeline, then turns to what he calls the models' "psychology": why they make things up, where they fail and how to use them well. His advice is blunt: use them as tools, check their work and own the result.

Pretraining: from web pages to a base model

The first stage starts with a huge, heavily filtered copy of the internet. Karpathy uses Hugging Face's FineWeb dataset as an example: about 44 terabytes of text, roughly 15 trillion tokens, after filtering out spam, malware sites, personal data and low-quality pages. Text is converted into tokens, short chunks of characters, using byte pair encoding. GPT-4 uses a vocabulary of 100,277 of them.

A neural network then learns to predict the next token from the ones before it. Its billions of parameters are nudged after each guess. The output is a base model, which he calls an "internet document simulator". He demonstrates this with Meta's Llama 3.1 405B base model: asked "what is 2 plus 2", it simply rambles on, and it recites a Wikipedia entry on zebras almost word for word.

Playground interface showing a base model continuing a text prompt with generated tokens.
Prompting Llama 3.1 405B base model, which continues text like autocomplete instead of answering questions.

He also compares costs. Training GPT-2 in 2019 was estimated at about $40,000. He reproduced it in about a day for around $600, thanks to better data, faster hardware and better software. The scramble for Nvidia GPUs, he says, is a race to predict the next token faster.

Post-training: how a base model becomes an assistant

To get an assistant, the same training algorithm runs on a new dataset: conversations. These were originally written by human labelers following long instruction documents, as in OpenAI's InstructGPT work, and are now often drafted by other models and edited by people. His framing is that ChatGPT's answer is a statistical simulation of an expert human labeler, not a researcher with infinite intelligence.

Hallucination follows from this. Training answers always sound confident, so the model imitates that tone even when it does not know. The fix described in Meta's Llama 3 paper is to quiz the model, find what it gets wrong, and add training examples where the right answer is "I don't know". Tools such as web search add a second fix. Knowledge in the parameters is a vague recollection, while text in the context window is working memory.

Models need tokens to think

Each token gets only a fixed, small amount of computation. A good answer to a word problem therefore spreads its reasoning over many tokens instead of jumping to the result. Karpathy shows ChatGPT failing a harder sum when told to answer in one token. For arithmetic and counting he advises asking the model to use code. Models see tokens, not letters, so spelling tasks are also weak. He calls the resulting gaps "Swiss cheese" capability, citing the model that sometimes says 9.11 is bigger than 9.9.

Two candidate answers to an apples and oranges word problem compared on screen.
Why models need tokens to think: spreading a word problem's reasoning across many tokens.

Reinforcement learning and DeepSeek-R1

He likens the third stage to practice problems at the end of a textbook. The model attempts a problem many times and trains on the attempts that reach the known answer. He walks through the DeepSeek paper on DeepSeek-R1, where this approach produced long chains of thought with self-checking and backtracking that no human wrote. He contrasts it with AlphaGo, whose Move 37 was a play no human expert would make.

For tasks without a checkable answer, such as joke writing, labs use reinforcement learning from human feedback. A separate reward model imitates human rankings. He argues this is not true reinforcement learning, because the reward model can be gamed and the process must be stopped after a few hundred steps.

Diagram of a prompt branching into many solution attempts, some marked green as correct and others red.
Reinforcement learning: many attempts per prompt, with correct solutions reinforced and incorrect ones discarded.

What comes next and where to find models

He expects models to become multimodal by tokenizing audio and images, and to run longer tasks as agents under human supervision. He lists LM Arena, the AI News newsletter and X for keeping up. He also points to Together AI for open models, Hyperbolic for base models and LM Studio for local use. In his own work, he says, most queries go to GPT-4o, and he reaches for reasoning models only on hard math and code.

Questions and answers

What is Andrej Karpathy's Deep Dive into LLMs like ChatGPT?

Andrej Karpathy's Deep Dive into LLMs like ChatGPT is a video of about three and a half hours that explains for a general audience how large language models like ChatGPT are made. Karpathy, a founding member of OpenAI and former head of AI at Tesla, covers the full training pipeline and where the models fail.

How does Andrej Karpathy say ChatGPT-style models are trained?

Andrej Karpathy describes three stages: pretraining, post-training and reinforcement learning. Pretraining teaches a network to predict the next token from filtered internet text. Post-training reruns the algorithm on conversations to make an assistant. Reinforcement learning has the model practice problems and train on attempts that reach the known answer.

Why do ChatGPT-style models hallucinate, according to Andrej Karpathy?

Andrej Karpathy says models hallucinate because training answers always sound confident, so the model copies that tone even when it does not know. Meta's Llama 3 paper describes a fix: quiz the model, find its errors, and add examples where the right answer is "I don't know". Web search tools add a second fix.

How much data is used to pretrain a model in Andrej Karpathy's example?

Andrej Karpathy uses Hugging Face's FineWeb dataset as his example. After filtering out spam, malware sites, personal data and low-quality pages, it holds about 44 terabytes of text, roughly 15 trillion tokens. GPT-4 uses a vocabulary of 100,277 tokens, created with byte pair encoding.

How should businesses use LLMs like ChatGPT, based on Andrej Karpathy's advice?

Andrej Karpathy advises using large language models as tools, checking their work and owning the result. He says models need many tokens to reason, so for arithmetic and counting people should ask the model to use code. He notes spelling is weak because models see tokens, not letters.

How much cheaper is it to train GPT-2 now, according to Andrej Karpathy?

Andrej Karpathy says training GPT-2 in 2019 was estimated at about $40,000, while he reproduced it in about a day for around $600. He credits better data, faster hardware and better software for the drop in cost.

From the YouTube description

This is a general audience deep dive into the Large Language Model (LLM) AI technology that powers ChatGPT and related products. It is covers the full training stack of how the models are developed, along with mental models of how to think about their "psychology", and how to get the best use them in practical applications. I have one "Intro to LLMs" video already from ~year ago, but that is just a re-recording of a random talk, so I wanted to loop around and do a lot more comprehensive version.

Instructor
Andrej was a founding member at OpenAI (2015) and then Sr. Director of AI at Tesla (2017-2022), and is now a founder at Eureka Labs, which is building an AI-native school. His goal in this video is to raise knowledge and understanding of the state of the art in AI, and empower people to effectively use the latest and greatest in their work.
Find more at https://karpathy.ai/ and https://x.com/karpathy

Chapters
00:00:00 introduction
00:01:00 pretraining data (internet)
00:07:47 tokenization
00:14:27 neural network I/O
00:20:11 neural network internals
00:26:01 inference
00:31:09 GPT-2: training and inference
00:42:52 Llama 3.1 base model inference
00:59:23 pretraining to post-training
01:01:06 post-training data (conversations)
01:20:32 hallucinations, tool use, knowledge/working memory
01:41:46 knowledge of self
01:46:56 models need tokens to think
02:01:11 tokenization revisited: models struggle with spelling
02:04:53 jagged intelligence
02:07:28 supervised finetuning to reinforcement learning
02:14:42 reinforcement learning
02:27:47 DeepSeek-R1
02:42:07 AlphaGo
02:48:26 reinforcement learning from human feedback (RLHF)
03:09:39 preview of things to come
03:15:15 keeping track of LLMs
03:18:34 where to find LLMs
03:21:46 grand summary

Links
- ChatGPT https://chatgpt.com/
- FineWeb (pretraining dataset): https://huggingface.co/spaces/HuggingFaceFW/blogpost-fineweb-v1
- Tiktokenizer: https://tiktokenizer.vercel.app/
- Transformer Neural Net 3D visualizer: https://bbycroft.net/llm
- llm.c Let's Reproduce GPT-2 https://github.com/karpathy/llm.c/discussions/677
- Llama 3 paper from Meta: https://arxiv.org/abs/2407.21783
- Hyperbolic, for inference of base model: https://app.hyperbolic.xyz/
- InstructGPT paper on SFT: https://arxiv.org/abs/2203.02155
- HuggingFace inference playground: https://huggingface.co/spaces/huggingface/inference-playground
- DeepSeek-R1 paper: https://arxiv.org/abs/2501.12948
- TogetherAI Playground for open model inference: https://api.together.xyz/playground
- AlphaGo paper (PDF): https://discovery.ucl.ac.uk/id/eprint/10045895/1/agz_unformatted_nature.pdf
- AlphaGo Move 37 video: https://www.youtube.com/watch?v=HT-UZkiOLv8
- LM Arena for model rankings: https://lmarena.ai/
- AI News Newsletter: https://buttondown.com/ainews
- LMStudio for local inference https://lmstudio.ai/

- The visualization UI I was using in the video: https://excalidraw.com/
- The specific file of Excalidraw we built up: https://drive.google.com/file/d/1EZh5hNDzxMMy05uLhVryk061QYQGTxiN/view?usp=sharing
- Discord channel for Eureka Labs and this video: https://discord.gg/3zy8kqD9Cp

Educational Use Licensing
This video is freely available for educational and internal training purposes. Educators, students, schools, universities, nonprofit institutions, businesses, and individual learners may use this content freely for lessons, courses, internal training, and learning activities, provided they do not engage in commercial resale, redistribution, external commercial use, or modify content to misrepresent its intent.

Watch on YouTube

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.