Let's build GPT: from scratch, in code, spelled out.
Andrej Karpathy14 HN recommenders · 2023–2025
8.2M views · tutorial · evergreen · Uploaded 2023-01-17
Andrej Karpathy builds a GPT from scratch in code, following Attention Is All You Need and GPT-2/3, in about two hours using PyTorch. He connects it to ChatGPT and assumes familiarity with his earlier makemore videos.
It is the go-to recommendation for learning how transformers and LLMs actually work, praised for its clarity and Karpathy's teaching.
2:25:52The spelled-out intro to neural networks and backpropagation: building micrograd
Andrej Karpathy
18:40But what is a neural network? | Deep learning chapter 1
3Blue1Brown
1:30:28AlphaGo - The Movie | Full award-winning documentary
Google DeepMind
27:14Transformers, the tech behind LLMs | Deep Learning Chapter 5
3Blue1Brown
51:22USENIX Security '18-Q: Why Do Keynote Speakers Keep Suggesting That Improving Security Is Possible?
USENIX
1:08:40Lecture 1 | Machine Learning (Stanford)
Stanford
5:58MarI/O - Machine Learning for Video Games
SethBling
3:31:24Deep Dive into LLMs like ChatGPT
Andrej Karpathy
20 comments from Hacker News
I recommend this video on the subject. "Let's build GPT: from scratch, in code, spelled out." [VIDEO]
Great compilation, would be great to see Vision Transformer (ViT) included. Andrej Karpathy's GPT video is a must have companion for this [VIDEO] I was going nuts trying to grok Key, Query,Position and Value until Andrej broke it down for me.
I remember Andrej mentioning in [1] that is a challenging part, what materials/lectures/papers have you found or what ideas on what to do about that so far for that? [1] [VIDEO]
Very impressive. Recently I watched this really amazing lecture on building GPT from scratch from Karpathy, I was blown away: [VIDEO]
I think you are taking a very major assumption that LLMs are deterministic infact they are exactly opposite. They are probabilistic systems. - They do not transpile Rough English to Deterministic English. Infact they do not do any transpiling at all. - LLMs learn the probabilities of words in the dataset for all contexts from that dataset (context is a ordered set of words). This is called training. - Once training is done, LLMs can generate text given a prompt and the probabilities that it has learned. The analogy of LLMs being auto-complete on steroids is very apt. - Whether the text generated by LLMs is factual or not is purely coincidental. I would highly recommend watching and working though the code (if possible) of NanoGPT by Andrej Karpathy. [VIDEO] A lot of things which seem like magic about LLMs will get demystified. Now one can argue that LLMs are showing human like reasoning/intelligence/sentience as an emergent behavior. This is hard to argue against because all these terms are extremely hard to define. IMO, the only emergent behavior that LLMs are showing is the output they generate looks like it might have been generated by a human which should not be surprising given that LLMs like ChatGPT has trained on a large amount of human written text available on internet.
Here are a few resources that might help get you started: 1. A thread explaining the internal working of transformers: [LINK] 2. Paper by DeepMind which provides pseudo-code for important algorithms for Transformer models: [LINK] 3. Another thread specifically on large language models: [LINK] Once again these are not courses per se, but do provide intuitive explanations for how transformers work. There is also the nanoGPT series of videos by Karpathy on youtube. First video here: [VIDEO]
I agree that Karpathy's YouTube video is an excellent resource for understanding Transformers from scratch. It provides a hands-on experience that can be particularly helpful for those who want to implement the models themselves. Here's the link to the video titled "Let's build GPT: from scratch, in code, spelled out": [VIDEO] Additionally, for more comprehensive resources on Transformers, you may find these resources useful: * The Illustrated Transformer by Jay Alammar: [LINK] * MIT 6.S191: Recurrent Neural Networks, Transformers, and Attention: [LINK] * Karpathy's course, Deep Learning and Generative Models (Lecture 6 covers Transformers): [LINK] ... These resources cover different aspects of Transformers and can help you grasp the underlying concepts and mechanisms better.
2-hour video posted a month or two ago in a comment here: "Let's build GPT: from scratch, in code, spelled out." [VIDEO] (I haven't gotten around to watching it yet)
Andrej Karpathy's 2 hour video and code is really good to understand the details of Transformers: "Let's build GPT: from scratch, in code, spelled out." [VIDEO]
Andrej Karpathy, the director of AI at tesla, published an AMAZING video about how the current models are built which I think everyone in the tech space should watch. It is intuitive, easy to follow and quite frankly the best video I have seen on the topic. Here is the link: [VIDEO] If you conclude, after watching this, that this is all intelligence is - namely cascading optimization and data structure problems chained in a row, then you and a fair number of people here wont ever find common ground. That is not to say that you're wrong, it just seems as if there is a missing component here that we haven't yet discovered.
I love all the series about writing your own X in 100 lines of code. It gives you the understanding of technology and removes a lot of unnecessary details. The great examples of this are 'A from-scratch tour of Bitcoin in Python' [LINK] and 'Let's build GPT: from scratch, in code, spelled out' [VIDEO] from Andrej Karpathy I wonder if anybody tried to collect all such projects together and built his own 'Internet in just 100 lines of code'
Those Computerphile videos[0] by Rob Miles helped me understand transformers. He specifically references the "Attention is all you need" paper. And for a deeper dive, Andrej Kharpaty has this hands-on video[1] where he builds a transformer from scratch. You can check-out his other videos on NLP as well they are all excellent. [0] [LINK] , [LINK] [1] [VIDEO]
There was this comment a couple of weeks ago ( [LINK] ). Perhaps also episode 7 of Karpathy’s “Neural Networks: From Zero to Hero” course ( [VIDEO] )
I initially thought this was his older video, but I see this video was published just an hour ago (from the time of this comment). I was thinking of this other video he had published early this year: "Let's build GPT: from scratch, in code, spelled out" [VIDEO] Karpathy is generally well-reputed as a good tutor, especially for complex topics in AI / ML.
Yes, it's doable. Your model won't be as large and as performant as a real large scale model, but you could train something. You could watch this for a start: [VIDEO]
+1, Andrey is an amazing educator! I'd also recommend his [VIDEO] and checking out his github repos. MinGPT, for example, implements a small gpt model that's compatible with HF API, whereas more modern nanoGPT shows how to use newer features such as flash attention. The quality of every video, every blog post is just so high.
That's... my point. You're agreeing with me. Siri and Alexa are bad . Very, very bad. They pretend to understand spoken English, but they don't , because they're just a huge set of hard-coded rules written out one-at-a-time by enormous numbers of very expensive developers. This is the 1990s approach to AI: Fuzzy logic, heuristics, solvers, dynamic programming, etc... That approach has been thoroughly blown out of the water by Transformers, which does all of that and much more with a thousand lines of code that can be banged out in a couple of hours by one guy while talking in a YouTube video: [VIDEO] Transformers will revolutionise this entire space, and more that don't even exist yet as a market. Take for example humanoid robots: Boston Dynamics has had the hardware working well enough for a decade, but not the software . You can't walk up to one of their robots, point at something, and tell the robot to complete a task. It can't understand what it is seeing, and can't understand English instructions. Programming that in with traditional AI methods would take man-millenia of effort, and might never work well enough . If we could speed up GPT-4o (the one with vision) to just 10x or 50x its current speed, with some light fine-tuning it could control a humanoid robot right now with a level of understanding comparable to C3P0 from Star Wars!
Excuse my ignorance, is this different from Andrej Karpathy [VIDEO] Anyway I will watch it tonight before bed. Thank you for sharing.
Attention is all you need and GPT-2 were well known at that point. Many might doubt whether this approach leads to "general" intelligence – depends on the definition. BTW, Karpathy has a nice video tutorial about building an LLM: [VIDEO]
The one you linked to is based on Karpathy's tutorial: [VIDEO] , except changing to train on tinystories in stead of Shakespeare. smolGPT also looks inspired by nanoGPT, also from Karpathy: [LINK]