YouTube2Text

I Trained an LLM on 1.1M YouTube Videos — Transcript

by Green Code · 3,202 words · 466 segments · language en · Watch on YouTube

Full transcript

  1. 0:00This is an LLM, and this is a YouTube
  2. 0:02video. And today we're going to train an
  3. 0:04LLM from scratch on 1.1 million YouTube
  4. 0:08video transcripts. You see, all of these
  5. 0:10LLMs are trained on the entire internet.
  6. 0:13Code, math, books, everything is in
  7. 0:15there. Your mom's lasagna recipes
  8. 0:17probably in there. And training them
  9. 0:18costs millions of dollars. But I've
  10. 0:20always wondered, what would happen if
  11. 0:22you trained an LLM on just YouTube
  12. 0:24videos and nothing else? Well, today
  13. 0:26we're going to find out. We're going to
  14. 0:27train three identical LLMs. One on 1.1
  15. 0:30million YouTube video transcripts,
  16. 0:32another one on all of Wikipedia, and
  17. 0:34then another one only trained on Stack
  18. 0:36Exchange. And after we train them, we're
  19. 0:38going to ask them questions, put them
  20. 0:40through science exams, test their
  21. 0:41capabilities with trust me bro
  22. 0:43benchmarks, and ultimately see if they
  23. 0:45make any sense at all. And my budget is
  24. 0:47$100. I have no idea if this is even
  25. 0:50possible, but there's only one way to
  26. 0:52find out. However, we have a few
  27. 0:55problems.
  28. 0:57Like how do I get this data? Like it's a
  29. 0:59lot of data. Like how am I getting 1.1
  30. 1:01million YouTube videos?
  31. 1:04AI companies have billions of dollars. I
  32. 1:07have $100. So I have to make my code
  33. 1:10mega fast. And currently it's it's not
  34. 1:13fast. Cool. Let's look at problem number
  35. 1:15one, getting the data. And as far as I
  36. 1:17see it, there's two options. Option A is
  37. 1:20downloading hundreds of thousands of
  38. 1:22YouTube videos, extracting their MP3
  39. 1:23files, and then using Whisper and a
  40. 1:25bunch of compute to transcribe
  41. 1:26everything they say into text. Option B
  42. 1:29is Well, someone already did that, so
  43. 1:31all I have to do really is to click
  44. 1:33download.
  45. 1:34I choose option B. And check it out. We
  46. 1:36have 1.1 million YouTube videos in a
  47. 1:38single txt file. It's kind of insane to
  48. 1:41be honest. We have kind of economy
  49. 1:42videos, daily blogs, chess videos,
  50. 1:45Arduino tutorials. We have a 1-hour
  51. 1:47lecture of discrete time dynamics. I
  52. 1:49don't know what that means, but we have
  53. 1:51everything you can imagine and even
  54. 1:52more. And before anyone comments, oh,
  55. 1:55Green Code is stealing people's work, he
  56. 1:57must be evil. First of all, chillax.
  57. 1:59Second of all, single YouTube video in
  58. 2:01this dataset was released under the
  59. 2:03Creative Commons license, which is
  60. 2:05really awesome. And this is all thanks
  61. 2:07to the Common Pile, which is an 8
  62. 2:10terabyte dataset of public domain and
  63. 2:12openly licensed text from where I got
  64. 2:14all these YouTube video transcripts. And
  65. 2:16actually, this is also where I got my
  66. 2:18Stack Overflow and Stack Exchange data,
  67. 2:21which is also open license. And if you
  68. 2:23don't know what Stack Overflow is, it's
  69. 2:24pretty much how everyone was able to
  70. 2:26code before AI. Anyway, I also decided
  71. 2:28to download the most recent Wikipedia
  72. 2:30dump, use Wiki Extractor to filter out
  73. 2:32all this junk, write a Python script to
  74. 2:34remove all these XML tags, and that's
  75. 2:36how I got all of Wikipedia in a single
  76. 2:38txt file. That took me a whole day to do
  77. 2:41for 5 seconds of this video. I love my
  78. 2:43life.
  79. 2:44Nice. Now we have all this data and my
  80. 2:46computer is barely alive, but that's it
  81. 2:48for problem number one. All we have to
  82. 2:49do now is make the code fast, make
  83. 2:52computer go brr. And currently, it's not
  84. 2:54fast. You see, this video is part of a
  85. 2:56series where I'm trying to build my own
  86. 2:58LLM from scratch. I'm calling it Anton,
  87. 3:01and my goal is to build Anton into a 1
  88. 3:03billion parameter model by the end of
  89. 3:05the series. So far, we have built and
  90. 3:07trained Anton only using NumPy, which is
  91. 3:09awesome to understand all the math
  92. 3:11behind training and building LLMs, but
  93. 3:13it also means that all the training
  94. 3:14happens on the CPU, which me no likey.
  95. 3:18So we got to make it faster. By the way,
  96. 3:20you might be wondering why I'm even
  97. 3:22doing this. Like what's the point of
  98. 3:23building my own LLM from scratch? Well,
  99. 3:25there's three reasons. One, because it's
  100. 3:27fun. Two, because ever since all of
  101. 3:28these AIs came out, I've always wondered
  102. 3:31how hard would it be to do this myself.
  103. 3:33And three, to raise money for charity.
  104. 3:35So far, you guys and some very cool
  105. 3:37sponsors have raised $20,000 for cancer
  106. 3:40research, which is just awesome. So if
  107. 3:42you like these videos, please consider
  108. 3:44donating. But first, we need computer to
  109. 3:46go brr. Let's do some quick maths. You
  110. 3:48see, 1.1 million YouTube video
  111. 3:50transcripts is about half a million
  112. 3:51hours of content, which is about 5
  113. 3:53billion tokens. With the NumPy code, we
  114. 3:56were training at about 500 tokens per
  115. 3:58second on the CPU. So 5 billion divided
  116. 4:01by 500 is about 10 million seconds,
  117. 4:04which is 4 months. And that's for Anton
  118. 4:06version one, which we trained in the
  119. 4:08last video. In this video, we're
  120. 4:09training Anton version two, which is
  121. 4:11about 80 times bigger. So with the
  122. 4:13current code, it would take like 20
  123. 4:15years. We need GPUs, which will make
  124. 4:18everything faster. And to use a GPU, we
  125. 4:21need to use PyTorch, which is one of the
  126. 4:23best deep learning libraries out there.
  127. 4:25So all I have to do now is convert my
  128. 4:27entire codebase from NumPy to PyTorch.
  129. 4:30Yay. This is easier than it sounds. The
  130. 4:32syntax is pretty similar. For example,
  131. 4:34this is a linear layer implemented in
  132. 4:36NumPy versus PyTorch. It's kind of the
  133. 4:38same. However, I have a few rules when
  134. 4:41using PyTorch. Rule number one, we're
  135. 4:43not using PyTorch pre-built layers.
  136. 4:45We're building our own. Rule number two,
  137. 4:47we're not using PyTorch pre-built
  138. 4:49optimizers. We're building our own. Rule
  139. 4:52number three, we're not using PyTorch
  140. 4:54flash attentions. We are building I I
  141. 4:56think you get the idea. We're building
  142. 4:57as much as possible from scratch cuz
  143. 4:59honestly doing optimizer equals
  144. 5:01torch.atom is mega boring. Like to
  145. 5:04replace the single line of code, I had
  146. 5:07to write 60 lines of my own code
  147. 5:09implementing Adam W from scratch. The
  148. 5:12one thing I'm letting PyTorch do is
  149. 5:14autograd because that means all the
  150. 5:16gradients are computed automatically. So
  151. 5:19instead of me having to rewrite all this
  152. 5:21math and manually calculate every single
  153. 5:23gradient, which is a pain in the ass,
  154. 5:25all I have to do is define the forward
  155. 5:27pass and PyTorch does the rest. So in
  156. 5:30just 300 lines of PyTorch and like a
  157. 5:33day, I was able to recreate pretty much
  158. 5:35everything we had done in NumPy. And
  159. 5:37just by using PyTorch and a really basic
  160. 5:40GPU, we should get about 10,000 tokens
  161. 5:43per second when training, which means
  162. 5:44we'll finish training the 5 billion
  163. 5:46YouTube tokens in about a week. So just
  164. 5:49by using PyTorch and a GPU, we've gone
  165. 5:52from 20 years to like a week. But that's
  166. 5:54not good enough. We can make this even
  167. 5:56faster and better because I want Anton
  168. 5:59to be the best YouTuber ever. I want him
  169. 6:01to be better than Mr. Beast. And for
  170. 6:03that, I got to mess around with his
  171. 6:05brain a little bit. I have to change its
  172. 6:07architecture. In Anton version one, we
  173. 6:09built something pretty similar to the
  174. 6:11original GPT architecture. But nowadays,
  175. 6:13this architecture is a bit unk. It's
  176. 6:15kind of like a bent-edge car. It's
  177. 6:17pretty and it works, but I want Anton to
  178. 6:19be giga brain. I want Anton to be a
  179. 6:22freaking Lamborghini. So let's replace
  180. 6:25some parts. For example, the classic
  181. 6:27cosine sine positional embeddings work,
  182. 6:29but the hottest new positional
  183. 6:31embeddings are rotary positional
  184. 6:33embeddings or rope. They work by taking
  185. 6:36into account relative distance between
  186. 6:37tokens rather than their absolute
  187. 6:39positions, and they generalize better to
  188. 6:41longer context sizes. And YouTube
  189. 6:43videos, I swear they keep getting
  190. 6:44longer, so handling longer context sizes
  191. 6:46is important. Cool, let's swap that.
  192. 6:48Let's also change the feed forward
  193. 6:50linear layer for something cooler. In
  194. 6:52the last few years, a ton of variants
  195. 6:53have been proposed. In Anton version
  196. 6:55one, I used FFN Relu, but now there's
  197. 6:57FFN Gelu, FFN Swish, FFN Glue by linear
  198. 7:01Gelu Swish Glue
  199. 7:03I don't even know how to pronounce these
  200. 7:05anymore. Anyway, the one that works the
  201. 7:06best for LLMs is Swi Glue, which is
  202. 7:08pretty much the same as FFN Relu, but
  203. 7:11uses gating and a more fancy activation
  204. 7:13function. You may ask, why does this
  205. 7:15work better? And to that, I respond by
  206. 7:17quoting the original paper's
  207. 7:19explanation. We offer no explanation as
  208. 7:21to why these architectures seem to work.
  209. 7:23We attribute their success as all else
  210. 7:25to the divine benevolence. Aka, they
  211. 7:28have zero freaking clue, but it works,
  212. 7:30so say no more. I also replaced layer
  213. 7:32norm with RMS norm, which is faster and
  214. 7:34uses less parameters cuz remember, every
  215. 7:36second we save is another couple of
  216. 7:38YouTube videos Anton could be watching.
  217. 7:40But by far, the hardest part of this
  218. 7:42whole project was to optimize multi-head
  219. 7:45attention. You see, multi-head attention
  220. 7:47is the communication phase of a GPT.
  221. 7:49It's what makes this whole thing work.
  222. 7:51It's like the motor of the car, but by
  223. 7:53default, it's also mega slow, and it has
  224. 7:55to compute all these super large
  225. 7:57matrices that completely crash our
  226. 7:59precious GPU memory. So we need flash
  227. 8:02attention, which optimizes the out
  228. 8:05of multi-head attention and makes GPU go
  229. 8:08Normally, this is one line of PyTorch,
  230. 8:10but I'm stupid and I decided that it
  231. 8:12would be a fantastic idea to spend two
  232. 8:14weeks learning how to design my own GPU
  233. 8:16kernels and writing 600 lines of code
  234. 8:18implementing Flash Attention from
  235. 8:20scratch. And I cannot tell you how hard
  236. 8:22this was. I had to learn Triton, profile
  237. 8:25GPU memory activations, learned about
  238. 8:27mixed precision training, and all in
  239. 8:29all, it's still slower than PyTorch, but
  240. 8:31it actually uses the same GPU memory as
  241. 8:34the PyTorch version, which is honestly
  242. 8:35the main thing. And after all of those
  243. 8:37optimizations and when using an A100
  244. 8:39GPU, we get 130 tokens a second, which
  245. 8:43means training will finish in about 8
  246. 8:45hours. And now look at Anton. He's fast.
  247. 8:47He's even more gigabrain and he's ready
  248. 8:49to be trained on 1.1 million YouTube
  249. 8:52videos. We got the data. We made
  250. 8:54computer go brr and now it's training
  251. 8:56time, baby. We're going to train three
  252. 8:58different Antons with the same
  253. 8:59architecture on YouTube videos,
  254. 9:01Wikipedia, and Stack Overflow. And then
  255. 9:03we're going to see which Anton is the
  256. 9:05best and if data even matters that much.
  257. 9:07While this trains, I want to show you
  258. 9:08how I was even able to train Anton on
  259. 9:11GPUs because normally it's very hard and
  260. 9:13very expensive. But luckily, for all my
  261. 9:15training runs, I use Modal who are
  262. 9:17sponsoring this episode and this whole
  263. 9:19series. They made my life so much easier
  264. 9:22and I could not have done it without
  265. 9:23them. So please go check them out
  266. 9:25because they deserve it. They already
  267. 9:26donated $15,000 to the charity
  268. 9:29fundraiser and they're the ones giving
  269. 9:31me $5,000 in compute credits so I can
  270. 9:34create the series in the first place.
  271. 9:36And Modal is so cool. They are a
  272. 9:38serverless AI platform. You can do
  273. 9:40training, inference, user sandboxes, and
  274. 9:42you only pay for what you use. So for
  275. 9:44example, when I was debugging Flash
  276. 9:46Attention, I would run my code on a GPU.
  277. 9:48It would crash 3 seconds later because
  278. 9:50I'm a bad programmer, but with Modal, I
  279. 9:52would only pay a few cents. On a
  280. 9:54traditional cloud provider, debugging
  281. 9:56this would have cost me a fortune
  282. 9:57because you pay for every second the
  283. 9:59server is up. And because I only paid
  284. 10:01for the seconds I used, I got to test my
  285. 10:03code on A100, which is a $20,000 GPU.
  286. 10:07And guess what? The models we're
  287. 10:09training right now will cost less than
  288. 10:11$30 each. And Motel gives you $30 of
  289. 10:14free credits every month just by signing
  290. 10:16up. So you can literally recreate one of
  291. 10:18these models for free just by signing up
  292. 10:20to Motel. The link is in the
  293. 10:22description. Plus Motel is an inference
  294. 10:24provider, so you can run the latest open
  295. 10:26weights model like DeepSeek and Kimi and
  296. 10:28plug them straight into tools like Codex
  297. 10:30or Open Code. They're super easy to use,
  298. 10:32really easy to scale, and they're the
  299. 10:34only compute provider that believed in
  300. 10:36this project. So seriously, thank you so
  301. 10:38much, Motel. And now, ladies and gents,
  302. 10:40let me introduce you to Anton version
  303. 10:42two. 230 million parameters, 1,024
  304. 10:45embedding dimension, 12 transformer
  305. 10:47blocks, 1,024 tokens of context.
  306. 10:49Training on 5 billion tokens of YouTube
  307. 10:51cost me around $27. Training on 5
  308. 10:54billion tokens of Stack Exchange and
  309. 10:55Stack Overflow cost me 29 and Wikipedia
  310. 10:5831 for a grand total of $90. Nice. Cool.
  311. 11:02Let's make Anton complete the sentence
  312. 11:04and let's see what it says.
  313. 11:05>> Hi. My name is Anton. I'm a PhD student
  314. 11:08at the University of Exeter in Scotland,
  315. 11:10where I specialize in computer science
  316. 11:12and technology.
  317. 11:14>> You know what? That's not too bad. Okay,
  318. 11:15Exeter is not in Scotland. It's actually
  319. 11:18on the complete other side of the UK,
  320. 11:20but that's okay. Let's check on
  321. 11:21Wikipedia, Anton.
  322. 11:22>> Hi. My name is Anton. It is an
  323. 11:24amalgamation of two old German names,
  324. 11:27Bünde and Her. The German Her refers to
  325. 11:31the former Her, a hill of oak forest
  326. 11:33near the town of Herhausen, which became
  327. 11:35famous as Her in English.
  328. 11:37>> Okay. This one is interesting. I don't
  329. 11:39know what to say to that, but it it's
  330. 11:41normal because it was trained on just
  331. 11:43Wikipedia. So all it knows is to write
  332. 11:45Wikipedia pages. All right, let's see
  333. 11:47Stack Overflow.
  334. 11:47>> Hi. My name is Anton. I just wanted to
  335. 11:50say thank you for the response. It was
  336. 11:52very well thought out and I am happy for
  337. 11:54all the help I can get.
  338. 11:56>> I mean, yeah, this one makes sense
  339. 11:57grammar-wise, but you can obviously tell
  340. 11:59that it's just been trained on Stack
  341. 12:00Overflow, which is a forum where people
  342. 12:02ask questions. Okay, wait, wait, wait.
  343. 12:04Let's ask YouTube Anton, should I like
  344. 12:06this video and subscribe to Green Code?
  345. 12:08>> If you have not yet subscribed to my
  346. 12:10channel, please do so.
  347. 12:11>> All I'm going to say to that
  348. 12:12>> is that the subscribe button is right
  349. 12:14there. However, this is obviously cute
  350. 12:16and really funny, but it left me
  351. 12:18wondering, what would happen if we
  352. 12:20trained a single Anton on all of these
  353. 12:22data combined? Well, that's exactly what
  354. 12:25I did, and I'm proud to announce Anton
  355. 12:272.1, the same architecture as before,
  356. 12:29but this time trained on 15 billion
  357. 12:31tokens. And I trained on YouTube,
  358. 12:33Wikipedia, Stack Overflow, but also on a
  359. 12:35bunch of open source books, science
  360. 12:37articles, and even the Creative Commons
  361. 12:39Common Crawl. And yeah, it did cost me
  362. 12:41$60, which is a bit over budget, but
  363. 12:43just count it as a bonus round, okay? I
  364. 12:45trained it on an H100 for 15 hours. And
  365. 12:48now that we have all these models, it's
  366. 12:50time for the Trust Me Bro Benchmarks.
  367. 12:53And the point of benchmarks is to
  368. 12:54evaluate our LLMs and run their
  369. 12:56performance. For example, we have the
  370. 12:58SciQ Benchmarks, which contains
  371. 13:00thousands of science exam questions, or
  372. 13:02the Social IQa, which tests for social
  373. 13:05common sense intelligence. But before we
  374. 13:07look at the results, if you were to
  375. 13:09start using these models yourself, you
  376. 13:11would realize pretty quickly that
  377. 13:12they're kind of dumb. For example, this
  378. 13:14is me asking GPT-2 and Anton 2.1, what
  379. 13:18is 2 + 2? Which yeah, it didn't go so
  380. 13:20well. But for a model below a billion
  381. 13:22parameters, this is kind of normal,
  382. 13:24especially if you spend less than $100
  383. 13:26training them. So how were they able to
  384. 13:28answer all of these questions? Well,
  385. 13:30instead of asking the model directly,
  386. 13:32what is the answer, I use the
  387. 13:33probability Anton predicts for each of
  388. 13:35the tokens of each option, and then I
  389. 13:37choose the option with the highest log
  390. 13:39likelihood. This is actually a really
  391. 13:41common practice when evaluating small
  392. 13:43models because again, they're they're
  393. 13:44kind of really dumb at this scale. But
  394. 13:46anyways, here are the results for the
  395. 13:48Trust Me Bro Benchmarks. And as you can
  396. 13:49see, Anton 2.1 beats all the previous
  397. 13:52models, which makes sense, right? It's
  398. 13:54trained on triple the data. For science
  399. 13:55questions, it beats YouTuber Anton by a
  400. 13:58lot. For example, question 22 of the
  401. 14:00SciQ Benchmarks.
  402. 14:02>> What happens when mammals raise their
  403. 14:03hair with tiny muscles in the skin? A,
  404. 14:05bleeding. B, balding. C, bruising. D,
  405. 14:09goosebumps.
  406. 14:10>> Well, all the Antons said goosebumps,
  407. 14:12which is the correct answer, but
  408. 14:13YouTuber Anton said A, bleeding. But on
  409. 14:16the other hand, with everyday speech
  410. 14:18benchmarks like swag, it actually
  411. 14:20outperforms Wikipedia and Stack
  412. 14:22Overflow. For example, in this question
  413. 14:24of common sense reasoning, only YouTuber
  414. 14:26Anton and Anton 2.1 got the correct
  415. 14:28answer. And here we clearly see how
  416. 14:31important the training data is because
  417. 14:33remember, all these models had the exact
  418. 14:35same architecture. The only difference
  419. 14:37was data. But what about comparing Anton
  420. 14:39to other GPT models? Well, as you can
  421. 14:41see here, for 60 bucks, Anton 2.1 is
  422. 14:44roughly at the GPT 2 small level, which
  423. 14:47was reportedly trained on 100 billion
  424. 14:49tokens. Granted, Anton is almost double
  425. 14:52the size, but for $60, only being
  426. 14:54trained on 15 billion tokens and trained
  427. 14:56on only open licensed data unlike GPT 2,
  428. 14:59I would say that's pretty good. Now, if
  429. 15:01you compare it to GPT 3 small, it's a
  430. 15:03different story. But Anton actually
  431. 15:04beats GPT 3 in some science benchmarks,
  432. 15:07which makes me really proud of my son.
  433. 15:08And guys, we did it. We trained Anton on
  434. 15:101.1 million YouTube videos on Wikipedia
  435. 15:13and Stack Overflow. Honestly, I think we
  436. 15:15got some pretty fun results at this
  437. 15:17scale. But what happens if instead of
  438. 15:19spending $100 on pre-training, I use the
  439. 15:21$5,000 in compute credits that model has
  440. 15:24given me? What if we teach Anton to
  441. 15:26actually answer our questions? What if
  442. 15:28we train Anton on multiple GPUs instead
  443. 15:30of one? And what if we make Anton a 1
  444. 15:33billion parameter model? Well, that's
  445. 15:35exactly what we're going to do in the
  446. 15:36next episode. And if you like these
  447. 15:38videos, please consider donating to the
  448. 15:40fundraiser. Oh yeah, and if we reach
  449. 15:42$30,000, I'll upload all the code and
  450. 15:44all the models to Hugging Face. And if
  451. 15:46you donate $50 or more, I'll put your
  452. 15:48name at the end of the video. And if you
  453. 15:50don't have the means to donate, please
  454. 15:51go check out model.com. Without them, I
  455. 15:54would not be making this video. Thank
  456. 15:55you so much to everyone who has already
  457. 15:58donated. Thank you DR for almost
  458. 16:00donating €1,000. You are awesome. Thank
  459. 16:03you Mareli as well for 200. Thank you to
  460. 16:05this anonymous goat. Thank you Michael.
  461. 16:08Thank you Dennis. Thank you Armando.
  462. 16:10Thank you Alex. Thank you Samuel. Thank
  463. 16:12you Soham. Thank you Ryan and thank you
  464. 16:14to everyone else who donated. Thank you
  465. 16:15for watching and I'll see you in the
  466. 16:17next one.

About this transcript

This page contains the full transcript of I Trained an LLM on 1.1M YouTube Videos by Green Code, generated from the public captions YouTube serves with the video. The transcript has 3,202 words across 466 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.