YouTube2Text

YouTube transcript (114i2Kz-LZA) — Transcript

13,846 words · 2,190 segments · language en · Watch on YouTube

Full transcript

  1. 0:06Hello everyone and welcome to CME 295
  2. 0:10transformers and large language models.
  3. 0:13My name is Afin and I'll be teaching
  4. 0:15this class with Shervin who's in the
  5. 0:18back. So before we start, I just want to
  6. 0:21say a few words about ourselves.
  7. 0:25So Shervin and I are twin brothers and
  8. 0:28we have very similar backgrounds.
  9. 0:31So we both went to a school in France
  10. 0:33called Central Pari and then we came to
  11. 0:35the US for grad school. So on my end I
  12. 0:39went to MIT and then Shervin came here
  13. 0:41at Stanford in the ICM department and
  14. 0:44then after that we both went to the tech
  15. 0:47industry. So we first both went to Uber
  16. 0:51and then we went to Google and now we're
  17. 0:54both at Netflix.
  18. 0:56So Shervin and I,
  19. 1:00we like LLMs. So we've been working in
  20. 1:04the field of LLM, I would say since the
  21. 1:06early 2020s. And so that's one of the
  22. 1:08reasons why we're so lucky to be
  23. 1:10teaching this class. We've been teaching
  24. 1:13it since 2021 under various formats. But
  25. 1:17as attention gained towards LLM, we have
  26. 1:21actually made it an actual Stanford
  27. 1:24class since last year. And this session
  28. 1:28is the third instance.
  29. 1:31And so if you're here wondering if this
  30. 1:34class is good for you. So the goal of
  31. 1:37this class is to tell you how LLM's work
  32. 1:40and in particular understand the
  33. 1:43underlying mechanism of its
  34. 1:47architecture. So we're going to see the
  35. 1:48transformer but also how LLM are
  36. 1:52trained, how we can use them, where what
  37. 1:55they're good at, what they're not good
  38. 1:56at.
  39. 1:58So hopefully you'll be able to get a
  40. 2:00sense of all of that in this class.
  41. 2:03And in terms of the target audience, I
  42. 2:06would say it's a pretty wide audience.
  43. 2:08So in case you want to go and be a
  44. 2:12research scientist, I would say it could
  45. 2:14be a great class to just open up the set
  46. 2:16of things that you are able to see in
  47. 2:19terms of you know what are the different
  48. 2:20techniques that are being used, what are
  49. 2:22the different uh applications and and so
  50. 2:26on. So I think that's one. The second
  51. 2:29one is if you want to do a personal
  52. 2:32project. So nowadays coding agents are
  53. 2:35everywhere and so if you want to just
  54. 2:38take one tool and just do something, you
  55. 2:40should probably know what the coding
  56. 2:42agent is good at and not good at. And
  57. 2:45third, I would say no matter your role,
  58. 2:49there's a growing need of being literate
  59. 2:52in AI. So there's this term called AI
  60. 2:55literacy.
  61. 2:56So no matter where you work and your
  62. 3:00role, I would say just knowing how these
  63. 3:02tools work are be is becoming
  64. 3:05increasingly important.
  65. 3:07So if you feel like you're in one of
  66. 3:09these categories, this class may be good
  67. 3:11for you. And in terms of the
  68. 3:14prerequisites, I would say if you have
  69. 3:18some foundations in linear algebra, if
  70. 3:20you know what a matrix is, how we do
  71. 3:22multiplications,
  72. 3:23then that would be great along with some
  73. 3:26basics in ML. So for instance, what is a
  74. 3:28loss function? What is a neural network?
  75. 3:31What is an embedding? Although we will
  76. 3:33be seeing that uh in the class, but it's
  77. 3:36good to have those I would say
  78. 3:38beforehand.
  79. 3:41Make sense?
  80. 3:43Okay, cool. Uh, so you may or may not
  81. 3:46know that uh, this class is being
  82. 3:50recorded. So you can see the camera in
  83. 3:51the back. It was actually recorded last
  84. 3:54year. So you may be wondering, well,
  85. 3:56what is the point in attending the
  86. 3:58lecture if it was already recorded? So
  87. 4:00the field is moving so quickly that
  88. 4:04there's been so many new things that
  89. 4:06have come up since last year. And
  90. 4:09actually one of the goals of this class
  91. 4:12is to incorporate all the advances that
  92. 4:15have happened. So I'll name a few. So
  93. 4:18there has been uh
  94. 4:21some progress on the post-raining side.
  95. 4:23So for instance on policy distillation
  96. 4:26if you've heard of it uh of course AI
  97. 4:28agents so coding agents and so on and uh
  98. 4:33new paradigms of LLM. So traditionally
  99. 4:36it was predicting tokens one at a time
  100. 4:39but nowadays there's been an increasing
  101. 4:43number of models that have approached
  102. 4:45things differently. So from the
  103. 4:46diffusion perspective
  104. 4:48uh among other things.
  105. 4:51So long story short if you're attending
  106. 4:53this class and you're preparing for
  107. 4:55exams please look at this year's
  108. 4:57lectures because they will be quite
  109. 4:59different
  110. 5:01uh in terms of the logistics. So I'm so
  111. 5:05happy to see you know so many of you on
  112. 5:07a Friday afternoon. So it will be uh
  113. 5:10every Friday from 3:30 to 5:20. It will
  114. 5:14be in this class
  115. 5:17and then uh it is a twounit class. Uh
  116. 5:21you can either choose it to take it as
  117. 5:24letter or credit nonredit.
  118. 5:27So again all the lectures are recorded.
  119. 5:30We'll make sure to post the recordings
  120. 5:32at most two days after the lecture has
  121. 5:35happened. So feel free to watch it
  122. 5:39remotely if you want or attend the class
  123. 5:42uh in person. Actually we'd love to see
  124. 5:44in person. So uh feel free to choose
  125. 5:46either way. And this class
  126. 5:50has no homeworks
  127. 5:53but it has two exams. So one is the
  128. 5:57midterm and one is the final. So the
  129. 6:00midterm will be about the first four
  130. 6:04lectures and it will be one month from
  131. 6:07now I guess. Yeah, October 23rd and the
  132. 6:10final exam will be on the last five
  133. 6:13lectures. So there will be nine lectures
  134. 6:15in total
  135. 6:17and it will be accounting for 50% of the
  136. 6:20total.
  137. 6:22So given that it's not the first time
  138. 6:24that we're giving this class, we have
  139. 6:27already posted online what a midterm
  140. 6:30looks like, what a final looks like. So
  141. 6:32if you go on the website, you can
  142. 6:34actually see in the tab 2025
  143. 6:38what we would expect from this exam. So
  144. 6:39it's a multi multi-choice questions. We
  145. 6:42also have some free form questions. So
  146. 6:45this is the kind of question we would
  147. 6:46ask.
  148. 6:49Any questions on the logistics so far?
  149. 6:54Yep.
  150. 6:56So, uh I'm going to always repeat by the
  151. 6:58way questions just for uh people who are
  152. 7:01watching remotely. So, question is are
  153. 7:03there office hours? So, we don't have
  154. 7:05official office hours. However, Shervin
  155. 7:08and I will be staying after each class
  156. 7:10in case you want to ask any questions
  157. 7:12and uh we're going to see it actually
  158. 7:15here in case you have any uh so we're
  159. 7:19going to see it later if you have any
  160. 7:20questions there is also ED so platform
  161. 7:23where we can ask questions um so yeah
  162. 7:25love to answer there
  163. 7:29cool
  164. 7:31okay so in terms of the material
  165. 7:36so I was talking about the the midterms
  166. 7:38and and so on. So they're all uh so the
  167. 7:40ones from last year they're on the
  168. 7:42website. Um the website al also contains
  169. 7:45the syllabus
  170. 7:48and uh the recordings will be posted
  171. 7:50there. One thing that we're doing is
  172. 7:53that we're posting the slides one day
  173. 7:57before the lecture because last year
  174. 7:59some people came to us and said okay
  175. 8:01we'd love to be able to annotate on the
  176. 8:03slides. So now we took the habit of
  177. 8:07posting them one day before the lecture.
  178. 8:09So if you go on the website you can
  179. 8:11retrieve them.
  180. 8:13So in terms of the material we do have a
  181. 8:17textbook which is this one the super
  182. 8:20study guide transformers and LLMs. Uh I
  183. 8:23believe the library has a few copies so
  184. 8:25you can uh borrow from there. Uh you can
  185. 8:28also get it online. We got the website
  186. 8:31as well.
  187. 8:33And along with that, we also have a
  188. 8:35cheat sheet which aims at being the most
  189. 8:40upto-date. So Sharon and I actually
  190. 8:43updated it just uh a couple of weeks ago
  191. 8:47and that one aims at covering the whole
  192. 8:52content in a concise way. So maybe it's
  193. 8:55a good companion for studying right
  194. 8:58before each exam.
  195. 9:01And also I know a lot of us are
  196. 9:03international people. In case you don't
  197. 9:05see your language being translated, feel
  198. 9:08free to come to us. We'd love to partner
  199. 9:10with you. Uh so right now it's available
  200. 9:12in I believe 15 languages including
  201. 9:14English. So yeah, love to see more
  202. 9:17languages as well.
  203. 9:20Cool. Um, in terms of how we
  204. 9:22communicate, so we will post
  205. 9:24announcements on Canvas and you can also
  206. 9:29access ED through Canvas, but if you
  207. 9:32have any questions that you want to ask
  208. 9:34us in private, we can also um, you know,
  209. 9:37answer through the mailing list that is
  210. 9:39on the slides along with our Stanford
  211. 9:42emails.
  212. 9:45I think I'm done for the logistics. Is
  213. 9:47there any questions?
  214. 9:54Is it scary? Because we have we had only
  215. 9:56one question. Uh just wondering if
  216. 9:59there's any [snorts]
  217. 10:00that you may worry. Is everything clear?
  218. 10:02Super clear. Yeah. So the question is uh
  219. 10:06will we see how this ties back to what
  220. 10:09is practiced in the industry? The answer
  221. 10:11is yes. So one of the things we'll be
  222. 10:13seeing especially in the second part of
  223. 10:15this class is how we can apply those
  224. 10:17LLMs in different settings and so just
  225. 10:20as an anecdote uh so last year I
  226. 10:22remember there were some things that
  227. 10:23came up that were released as we were
  228. 10:26teaching the class and so we updated the
  229. 10:30content as we went so I'm sure we'll do
  230. 10:32the same thing this cycle as well. So
  231. 10:34yeah the answer is yes.
  232. 10:37Yeah. So the question is what is the
  233. 10:40recommendation for preparation given
  234. 10:41that there's no homework and it's 50/50
  235. 10:44midterm exam uh final. I would say
  236. 10:46depending on how you usually study I
  237. 10:49think just studying regularly I think
  238. 10:51works best. Um I would say just paying
  239. 10:54attention to things that we're covering
  240. 10:57in the class during the class I think is
  241. 10:59most important. So there may be topics
  242. 11:02that are in the textbook that we're not
  243. 11:04covering and I would say those are not
  244. 11:06expected in the in either exams. So
  245. 11:10roughly speaking anything we say can be
  246. 11:12in the exam.
  247. 11:15So question is do you have any practice
  248. 11:17problems? So yes. So last year we said
  249. 11:20no but now yes you have the 2025 ones.
  250. 11:22So yeah but the questions will be
  251. 11:26different. So yeah.
  252. 11:29Okay, great.
  253. 11:32So, one thing is we only have two hours
  254. 11:36or 1 hour and 50 minutes per week. So,
  255. 11:39we will have nowhere near the time to
  256. 11:41cover everything. So one thing that
  257. 11:43we'll be seeing in uh each of the slides
  258. 11:46that we'll be talking over is always I
  259. 11:50mean most of the time a source at the
  260. 11:53very bottom of the slides that is meant
  261. 11:55for you to check in case you're
  262. 11:57interested to learn more details. So
  263. 12:00feel free to refer to the slides in case
  264. 12:02you're interested in a topic that maybe
  265. 12:04we've covered for a few minutes but you
  266. 12:06want to learn more.
  267. 12:09Cool. Um, another thing, I mean,
  268. 12:12something that I personally have felt
  269. 12:13when I first started in the NLP field
  270. 12:17like a few years ago, there's so many
  271. 12:20abbreviations all over the place and it
  272. 12:23can be intimidating. So our hope is that
  273. 12:27in case you're feeling overwhelmed today
  274. 12:29by these abbreviations that by the end
  275. 12:31of this class you'll have a mental
  276. 12:34mapping of which abbreviation correspond
  277. 12:37to what concept. So that is our goal
  278. 12:42and with that we're going to start
  279. 12:46by asking ourselves how we got here.
  280. 12:51So 10 15 years ago in the 2010s
  281. 12:55so I remember uh the field was
  282. 12:59completely different. We didn't have one
  283. 13:02model that did everything. We had
  284. 13:04typically one model per use case. So the
  285. 13:07kind of model that was dominating the
  286. 13:10field was was RNN's recurrent neural
  287. 13:13networks which we'll briefly see in this
  288. 13:16lecture. And you had these mo use case
  289. 13:19specific models such as uh for sentiment
  290. 13:23extraction. So you asked yourself if a
  291. 13:26sentence a review is positive, negative
  292. 13:29or neutral. If you had a text you wanted
  293. 13:32to translate, you had a dedicated model
  294. 13:34for that. And if you had, I don't know,
  295. 13:36text you wanted to identify names,
  296. 13:39locations, and so on, you would also
  297. 13:41have a dedicated model for that.
  298. 13:44So this was the 2010s
  299. 13:46performance was okay
  300. 13:50but the thing that really
  301. 13:53made a true difference that was a
  302. 13:54turning point
  303. 13:56was 2017.
  304. 13:58So 2017 there's a paper that came out
  305. 14:02that we're going to talk about at length
  306. 14:04today that's called attention is all you
  307. 14:08need that introduced a new architecture
  308. 14:13that relied on a paradigm that proved to
  309. 14:16be very scalable
  310. 14:18by scalable I mean if you give your
  311. 14:22model more data more compute and more
  312. 14:26parameters you're actually able to see
  313. 14:29performance gains that are far greater
  314. 14:32compared to what you used to see before
  315. 14:35and it's something that we're going to
  316. 14:36see today. So this architecture is
  317. 14:38called the transformer
  318. 14:41and on the right you have an
  319. 14:43illustration of how it's uh illustrated
  320. 14:46in the original paper. We're going to
  321. 14:48see how it works.
  322. 14:50And from there people have taken this
  323. 14:54architecture and just scaled it from a
  324. 14:58model size perspective but also from the
  325. 15:01number of tokens it's been trained on.
  326. 15:04And this is how modern day LLMs have
  327. 15:08come into the picture. LLMs that
  328. 15:11actually know I mean that actually
  329. 15:14generate text pretty well that generate
  330. 15:16code pretty well. And in particular in
  331. 15:192022,
  332. 15:21chat GPT got released. So I remember in
  333. 15:24November I believe. Yeah.
  334. 15:28And again it was a turning point from
  335. 15:30more of a product perspective because
  336. 15:32before that date people were not really
  337. 15:34used to interacting with the chatbot. So
  338. 15:38I believe that release was pretty the
  339. 15:41first time that people got introduced to
  340. 15:43that aspect and I think even the person
  341. 15:47or the company who launched it probably
  342. 15:49didn't even realize how big it would
  343. 15:51get. I mean I'm assuming because in
  344. 15:53their tweets that released the the model
  345. 15:57I believe they had like a typo which uh
  346. 15:59I find funny because nowadays whenever
  347. 16:01there is a model release
  348. 16:04you know there's 10 times review of what
  349. 16:07the wording is so I'm assuming that this
  350. 16:10was not the case for for the
  351. 16:12announcement here but yeah so that is
  352. 16:15also another turning point
  353. 16:17and then here we are 2026
  354. 16:22I'm assuming a lot of you or all of you
  355. 16:26are interacting with coding agents
  356. 16:28almost on a daily basis. So we're going
  357. 16:30to see how we got to that stage. How we
  358. 16:33went from a conversational
  359. 16:36LLM conversational assistant to actually
  360. 16:40agentic behavior.
  361. 16:43So we're going to see that especially in
  362. 16:45the second part of this class.
  363. 16:51So far so good.
  364. 16:54Cool.
  365. 16:56So with that, we're going to start with
  366. 17:01one foundational concept which is
  367. 17:04tokenization.
  368. 17:06So what is tokenization?
  369. 17:09So when we talk about text,
  370. 17:12text is re not really something that
  371. 17:14models can understand. models understand
  372. 17:18numbers. They don't understand text.
  373. 17:22So the first goal is to find a way to
  374. 17:27represent that text in forms of
  375. 17:29something that models can understand. So
  376. 17:31in forms of numbers.
  377. 17:34So the way that we do that is we first
  378. 17:37try to divide the text into entities
  379. 17:42that we can then represent.
  380. 17:46And so the process of dividing the text
  381. 17:48into indivisible entities is what is
  382. 17:51called tokenization.
  383. 17:53So in this example we have a cute teddy
  384. 17:56bear is reading
  385. 17:58and one possible tokenization is to say
  386. 18:02that a is one indivisible unit, cute is
  387. 18:08another unit. Teddy bear can be another
  388. 18:10unit and so on and so forth.
  389. 18:15So each of these elements
  390. 18:18is called a token
  391. 18:21and our goal
  392. 18:23is to represent these tokens with
  393. 18:26mathematical representations that are
  394. 18:29meaningful.
  395. 18:30So in this case we want each token to be
  396. 18:33represented by a vector, a vector of
  397. 18:36numbers.
  398. 18:40So,
  399. 18:42in order for you to tokenize an input
  400. 18:45text, you need to know what are the
  401. 18:48tokens that are allowed for you to be
  402. 18:51using. And so, we have something that's
  403. 18:53called a vocabulary,
  404. 18:55which includes all possible tokens that
  405. 18:58you can use.
  406. 19:00And depending on the vocabulary that you
  407. 19:03choose,
  408. 19:04you may end up with different sequence
  409. 19:08length. So here by sequence lengths I
  410. 19:11mean the number of tokens by which you
  411. 19:14divided your your text. So for instance
  412. 19:15in this instance we have 1 2 3 4 5 six
  413. 19:19six tokens.
  414. 19:21We're going to see in a second that
  415. 19:23there's a tight relationship between
  416. 19:27vocabulary size and sequence length. And
  417. 19:29that's something that will inform which
  418. 19:32tokenizer we should be choosing.
  419. 19:38So far so good. So now you may be
  420. 19:41wondering well all of that is great but
  421. 19:43how do I know how I tokenize my text?
  422. 19:47Like this is just a theoretical uh
  423. 19:50concept but how do I do that? So one
  424. 19:53natural way is for you to say okay so
  425. 19:56I'll just tokenize the text with respect
  426. 20:00to words. So I'm going to consider space
  427. 20:03as being a delimiter between
  428. 20:06tokens. So here I would say a cute teddy
  429. 20:09bear is reading. So every word in that
  430. 20:11text would actually represent
  431. 20:13a token.
  432. 20:16So what are the pros and cons of this
  433. 20:18approach? So pros
  434. 20:20very simple especially for the English
  435. 20:22language. You map a token to its words.
  436. 20:26Very simple. It is also interpretable as
  437. 20:29in you know when you get a
  438. 20:31representation of a word that it
  439. 20:33corresponds or representation of a token
  440. 20:36that it corresponds to a given word.
  441. 20:40However
  442. 20:42at least in English
  443. 20:45you have many variation of words. So for
  444. 20:48instance
  445. 20:50a noun like you can have it is singular
  446. 20:54in plural you can have the masculine
  447. 20:56form the feminine form you can have many
  448. 20:59many variations so your vocabulary size
  449. 21:03may get very large as a result of that.
  450. 21:05So that's one con.
  451. 21:07The second con is we're going to see in
  452. 21:10a second that when we learn the
  453. 21:13representation of each token,
  454. 21:16there is nothing that guarantees us that
  455. 21:19two tokens that represent the same thing
  456. 21:22would get the same representation. So
  457. 21:25for instance, if you consider the word
  458. 21:28bear and the word bears,
  459. 21:32these are the singular and plural of the
  460. 21:34same animal which is a bear. And so you
  461. 21:38wouldn't want the representation of
  462. 21:39these two tokens to be too far from one
  463. 21:42another because they represent the same
  464. 21:44thing.
  465. 21:46Well, with this way of tokenizing your
  466. 21:48text, you would have a hard time first
  467. 21:53of all leveraging the knowledge that you
  468. 21:56have from the similar token and second
  469. 21:59just guaranteeing that these
  470. 22:01representations are similar.
  471. 22:04And then the third one is
  472. 22:07well given that you need to learn the
  473. 22:10representation of each of these words.
  474. 22:13So one word is one token. You may run
  475. 22:16into a case where if you train your
  476. 22:21tokenizer on a given corpus of text that
  477. 22:25you actually do not have a given word
  478. 22:28that you then encounter
  479. 22:31at inference time.
  480. 22:33So you may actually be missing
  481. 22:35representations that you could not have
  482. 22:38had the chance to learn just because you
  483. 22:40did not encounter that word at training
  484. 22:42time. And therefore you can run into the
  485. 22:46risk of
  486. 22:49out of vocabulary meaning that
  487. 22:52a token
  488. 22:54is actually not something that you have
  489. 22:55seen at training time and you don't have
  490. 22:57the representation for that one.
  491. 23:00So long story short, word level
  492. 23:03tokenization is simple but it comes with
  493. 23:06a few cons
  494. 23:08and one of the cons is really the fact
  495. 23:12that you are not able to leverage words
  496. 23:16of similar roots and this leads to
  497. 23:19vocabulary being large and risk of out
  498. 23:23of vocabulary.
  499. 23:27So the next question is okay can we do
  500. 23:30better? Is there another way of
  501. 23:31tokenizing the text that could make more
  502. 23:34sense? So a natural thought could be
  503. 23:39well you don't divide by words you
  504. 23:42divide by character.
  505. 23:45You have a fixed number of allowed
  506. 23:47characters at least in in English or in
  507. 23:49any languages. And so
  508. 23:53you are not running the risk of out of
  509. 23:56vocabulary anymore because you will
  510. 23:58encounter the all the letters in the
  511. 24:01alphabet in your training set or you can
  512. 24:03try to do that
  513. 24:05and by doing so you will also have a
  514. 24:07small vocabulary
  515. 24:10and you would also be robust to casing
  516. 24:15and misspellings that people usually
  517. 24:17make in when I mean I'm not sure if you
  518. 24:20recognize yourself. I do. So when I type
  519. 24:22uh I don't know on uh my computer, I
  520. 24:25sometimes misspell things and I wouldn't
  521. 24:27want the representation of a word I
  522. 24:31meant to write to be different from the
  523. 24:33actual word. And so here we would not be
  524. 24:37going into the case of
  525. 24:41not recognizing a word just because it
  526. 24:42is misspelled.
  527. 24:46But we will see that
  528. 24:49if you do that the sequence length is
  529. 24:54going to get much longer
  530. 24:58and model complexity is a function of
  531. 25:02sequence length. So if the sequence is
  532. 25:05very long then your model will take a
  533. 25:08long time to process the sequence. So it
  534. 25:10will make computations much slower
  535. 25:14and the embeddings themselves they're
  536. 25:18much less interpretable as in you know
  537. 25:20if we tell you the letter A has this
  538. 25:23representation it it's maybe much more
  539. 25:26abstract than talking about word
  540. 25:28representation
  541. 25:31and we will see that in a second.
  542. 25:36So far does that make sense?
  543. 25:39Yeah.
  544. 25:41So I hope
  545. 25:44I am motivating a trade-off enough that
  546. 25:47the next natural thought in your mind is
  547. 25:49to actually try something in between. So
  548. 25:51not word, not character, but in between.
  549. 25:54So subwords. So, how about we tokenize
  550. 25:58the text
  551. 26:00by leveraging
  552. 26:03knowledge that we have about words that
  553. 26:06we can learn from
  554. 26:08some training corpus and we divide
  555. 26:13common occurrences of letters and we
  556. 26:17represent them with a token. So for
  557. 26:18instance for
  558. 26:20reading we would represent read with a
  559. 26:23token and ink with another token.
  560. 26:26So how about we would do that. So the
  561. 26:29good thing here is that we would
  562. 26:30leverage the root of words. So in my
  563. 26:32previous example bear and bears would
  564. 26:36have the for instance bear token in
  565. 26:39common.
  566. 26:41And then the second thing is it would be
  567. 26:43actually learned from the data as in the
  568. 26:46way you tokenize text is informed by how
  569. 26:50words are actually written.
  570. 26:53But then the con is well you need to do
  571. 26:55that extra work. So in the word level
  572. 26:57case you just need to produce tokens by
  573. 27:01just divi dividing based on space. So
  574. 27:03here you do you need to do some extra
  575. 27:05work and then
  576. 27:09the way you obtain these tokens will be
  577. 27:11highly dependent on
  578. 27:14the type of data that you have when you
  579. 27:17do your tokenizer training. So that's
  580. 27:21another thing another con. So we need to
  581. 27:23make sure that the data that you use to
  582. 27:26learn how to tokenize things is actually
  583. 27:29aligned with your end goal.
  584. 27:35So um I just want to uh say something
  585. 27:39here. So I talked about three ways of
  586. 27:42tokenizing text. So word level,
  587. 27:45character level, subword level. Among
  588. 27:49the three, subword level is by far the
  589. 27:52most popular nowadays for all the
  590. 27:54reasons that I mentioned. And you'll
  591. 27:57hear the word or the acronym BPE a lot.
  592. 28:02So BPE is a type of subword tokenizer
  593. 28:06that stands for bite pair encoding. So
  594. 28:09the paper is linked at the bottom of
  595. 28:11this slide in case you're interested to
  596. 28:13learn more, but I'll give the just the
  597. 28:15gist of how it works. So, BPE
  598. 28:19learns what tokens should be in your
  599. 28:22vocabulary by starting from an initial
  600. 28:26set of tokens and
  601. 28:32identifying the most frequent pairs
  602. 28:35in your in your training data and by
  603. 28:38coming up with dedicated tokens for
  604. 28:43merge tokens of these pairs. So for
  605. 28:45instance, I'll give an example. Let's
  606. 28:47imagine your initial vocabulary is all
  607. 28:50the letters in the alphabet and you have
  608. 28:54I don't know the word
  609. 28:56un like an idea and
  610. 29:01an an amazing course. So un that occurs
  611. 29:04very frequently. So here it will say
  612. 29:07okay a and n appear very frequently
  613. 29:10together. So let's actually add a token
  614. 29:12that merges the two.
  615. 29:15it will add that new token in the
  616. 29:17vocabulary and then repeat the process
  617. 29:20until reaching
  618. 29:23a desired final vocabulary size and that
  619. 29:27will be your final vocabulary.
  620. 29:31So the nice thing is that these tokens
  621. 29:33are learned from the data. So things
  622. 29:35that appear together are actually
  623. 29:37identified and added to your vocabulary.
  624. 29:40So this will lead to your sequence
  625. 29:42length
  626. 29:44being shorter. So you will not have to
  627. 29:45decompose your text into that many
  628. 29:48tokens. So your model will not take
  629. 29:52that much time to process your text. And
  630. 29:55so that's where the efficiency come from
  631. 29:57comes from. So if you have a training
  632. 29:58corpus that has let's say a lot of the
  633. 30:02words that you encounter in practice
  634. 30:04then the sequence length of the tokens
  635. 30:07you will get from a piece of text that
  636. 30:11uses the same words as what you had in
  637. 30:13your training corpus will be much more
  638. 30:16much shorter.
  639. 30:19So in case you're doing multilingual
  640. 30:23work, then make sure that your tokenizer
  641. 30:25is trained on a corpus that's represents
  642. 30:29all the languages that you're interested
  643. 30:30in. That's one example.
  644. 30:35Okay, so that was a lot. So I'll just
  645. 30:38pause for a second. Is there any
  646. 30:39questions so far on
  647. 30:43this part?
  648. 30:46Yes.
  649. 30:47So uh the question is what is the the
  650. 30:51relationship between BP and engram? So
  651. 30:53engram is actually something separate
  652. 30:55and this one yes to your point it will
  653. 30:58learn the tokens from your corpus by
  654. 31:02merging the most frequent pairs in an
  655. 31:04iterative way until reaching a final
  656. 31:07desired vocabulary size.
  657. 31:10So next natural question is okay you
  658. 31:13have your tokens then now how do you
  659. 31:15know how to represent them? Maybe you're
  660. 31:17asking yourself this and we will see
  661. 31:19that actually in about five minutes. So,
  662. 31:22more on that in a bit. Actually, I'm
  663. 31:25looking at the time. I don't think I'm
  664. 31:27on time. So, I'll probably move on. But
  665. 31:30if you have any questions, please feel
  666. 31:31free to interrupt me.
  667. 31:34Tokenization is really the building
  668. 31:36block of everything we'll see from here.
  669. 31:39So, yeah.
  670. 31:42Okay. So, so far we've seen tokens that
  671. 31:46represent text that we want to tokenize.
  672. 31:49But the truth is we also have some
  673. 31:51special tokens. And these special tokens
  674. 31:54are meant to represent things that we
  675. 31:57want to express in a sequence. So one
  676. 32:00such token is whenever we encounter a
  677. 32:03term or a piece that is actually not
  678. 32:06something that is part of our
  679. 32:08vocabulary. So the convention is to have
  680. 32:11a dedicated token that represents this
  681. 32:14out of vocabulary piece of text and it's
  682. 32:18called an unknown token.
  683. 32:21That's one special token. So give you an
  684. 32:24example teddy bear. Imagine if I write
  685. 32:26it teddy d bear and in the training
  686. 32:30corpus we've never seen such a spelling.
  687. 32:35Then
  688. 32:37if your vocabulary is only composed of
  689. 32:39these four tokens, so teddy, cute, bear,
  690. 32:41and unknown, then teddy bear will be
  691. 32:44tokenized as unknown token and then
  692. 32:48bear.
  693. 32:50One example,
  694. 32:52another set of special tokens. So a lot
  695. 32:57of the times you need to indicate when
  696. 33:01the sequence is starting, when it is
  697. 33:02ending. And we'll see how we do that. So
  698. 33:06we have two set of special tokens. One
  699. 33:08is beginning of se sequence bos and then
  700. 33:12end of sequence EOS. Those are mostly
  701. 33:16used when we want to generate text. So
  702. 33:19for instance when when you want to start
  703. 33:22the generation the convention is to feed
  704. 33:25your model with the beginning of
  705. 33:27sequence token just to indicate to your
  706. 33:29token to your model that you you want to
  707. 33:31generate text and your model will then
  708. 33:35at the end of its generation just output
  709. 33:38the end of sequence token to just tell
  710. 33:40you that this generation is finished.
  711. 33:44So this is how it's used. So what a cute
  712. 33:47teddy bear would be beginning of
  713. 33:49sequence with a cute teddy bear and end
  714. 33:51of sequence as an example. And then the
  715. 33:53last one that you may encounter is the
  716. 33:56padding token and that one is meant to
  717. 34:00make your sequences be of a certain
  718. 34:04size.
  719. 34:05So this is sometimes used for efficiency
  720. 34:09perspectives
  721. 34:11if you want all your sequences to be of
  722. 34:13the same length because we will see that
  723. 34:15we can represent that with vectors,
  724. 34:17matrices, tensors and hardware loves
  725. 34:21things that have the same dimension then
  726. 34:25padding can also be used.
  727. 34:28But I want to say that this list is by
  728. 34:31no means exhaustive
  729. 34:34and that you also have a lot of
  730. 34:37different conventions that people take.
  731. 34:40So this way of writing BOS, EOS, this
  732. 34:44way of writing padding, it's not
  733. 34:46universal.
  734. 34:48So just don't don't be surprised if you
  735. 34:50encounter different variations. And
  736. 34:53nowadays you have things like
  737. 34:56assistance. So you have a user,
  738. 34:59assistant and those are other things
  739. 35:01that people represent with special
  740. 35:03tokens. So again this is not an
  741. 35:06exhaustive list but just know that such
  742. 35:09tokens exist and they are meant to
  743. 35:12convey something about the text that the
  744. 35:14model should understand.
  745. 35:22Cool.
  746. 35:24That that's it for tokenization. Any
  747. 35:28questions?
  748. 35:30Yes. The question is what is the order
  749. 35:32of magnitude of the vocabulary size for
  750. 35:34lens right now? So it's a great
  751. 35:36question. It is on the order of hundreds
  752. 35:40of thousands. So you will see something
  753. 35:42like hundreds of thousand 200,000
  754. 35:45something like this. And these are
  755. 35:47tokenizers that are able to handle both
  756. 35:50English but also other languages.
  757. 35:54And as I mentioned, the most common type
  758. 35:58of tokenizer nowadays is the BP one. So
  759. 36:00yeah, so these are the things that are
  760. 36:02good to have in mind. Yeah.
  761. 36:06So the question is having multiple
  762. 36:09languages be handled by your tokenizer.
  763. 36:11Does that make your tokenizer a bit less
  764. 36:13of an expert in a given language? I
  765. 36:15think it is hard to say. I would say
  766. 36:18because there may be some synergies
  767. 36:21between languages. So I would say it's
  768. 36:24hard to say in general, but that being
  769. 36:27said, the vocabulary size that you fix
  770. 36:31when you when you run your BP algorithm
  771. 36:34will be filled with tokens from
  772. 36:37different languages. So you may get a
  773. 36:42vocabulary that may lead you to longer
  774. 36:47sequence length if you're only
  775. 36:50interested in one particular language.
  776. 36:52So from an efficiency perspective maybe
  777. 36:55you'll you'll see something but then
  778. 36:57from a representation perspective it's
  779. 37:00not super clear. So one example is
  780. 37:03um acronyms of organizations that may be
  781. 37:07something that people talk about in a
  782. 37:08bunch of languages. So you may benefit
  783. 37:11from learning that representation from
  784. 37:16different text of different languages.
  785. 37:18So pros and cons.
  786. 37:24Great.
  787. 37:26Cool. So now what we know what we have
  788. 37:29learned is given an input text we're
  789. 37:33able to generate tokens or represent
  790. 37:37that text with tokens. So the next
  791. 37:39natural question is how to represent
  792. 37:42those tokens. So this is what we're
  793. 37:45going to see now.
  794. 37:47So the most naive way to do that is to
  795. 37:51say that each token is different.
  796. 37:55So it's extremely obvious but you can
  797. 37:57represent your tokens by what we call
  798. 38:00one hot encodings. So here uh let's say
  799. 38:03I have the the token soft I can say okay
  800. 38:06it's the one 0 0 vector
  801. 38:11and if you do that for all your tokens
  802. 38:14well the bad thing is they're all going
  803. 38:17to be orthogonal to each other if you
  804. 38:20take the dot products.
  805. 38:23So, is it a good thing?
  806. 38:28Right? No, it's not a good thing because
  807. 38:30it doesn't tell you anything about what
  808. 38:33these tokens are and how they're related
  809. 38:36to each other. So, it's not what you
  810. 38:37want.
  811. 38:39What you want is to represent these
  812. 38:42tokens in a way that reflect how similar
  813. 38:47they are to one another.
  814. 38:50That is what you want. So for instance,
  815. 38:52you want teddy bear to be similar to
  816. 38:56soft because teddy bears are soft, but
  817. 38:58maybe book to be maybe independent. This
  818. 39:02is what you want to learn. You want to
  819. 39:03learn meaningful representations.
  820. 39:06And by the way, why do you want to
  821. 39:09learn meaningful representations? Well,
  822. 39:11it's because you want to do something
  823. 39:12with your text. You need to have it as
  824. 39:14input into your model in order to do
  825. 39:16something as output. So for instance
  826. 39:19generating the next words
  827. 39:21predicting some class. So you need to
  828. 39:24understand what is in your text
  829. 39:27which is the reason why what you want is
  830. 39:31meaningful token representations.
  831. 39:35So this
  832. 39:38is what an earlier method called v word
  833. 39:43tovec
  834. 39:44try tried to achieve. So here the idea
  835. 39:49is
  836. 39:52to learn these representations
  837. 39:54through what we call a proxy task. So a
  838. 39:57proxy task is a task that you're trying
  839. 40:00to learn but it's not the task that
  840. 40:02you're trying to learn as an end goal.
  841. 40:05It is is a task that you try to learn in
  842. 40:07order to achieve something else.
  843. 40:10And here the proxy task is something
  844. 40:12like predicting the word that is in
  845. 40:16between some context words. So this is
  846. 40:19the continuous bag of words version of
  847. 40:21vorttovec
  848. 40:23or predicting words that are surrounding
  849. 40:27a given word that is the skip gram
  850. 40:29version. So we'll go through an example
  851. 40:32so that it becomes clear.
  852. 40:34So does everyone know what a neural
  853. 40:36network is?
  854. 40:38Yeah.
  855. 40:40Okay, so I represented a very basic
  856. 40:42neural network. So you can think of it
  857. 40:45as an input matrix multiplication to get
  858. 40:50a hidden representation of size D and
  859. 40:53then again matrix multiplication to go
  860. 40:55back to size V your vocabulary size. So
  861. 40:58let's assume
  862. 41:00that you have the the sentence a cute
  863. 41:03teddy bear is reading. And let's assume
  864. 41:06for the sake of simplicity that your
  865. 41:08goal is to predict cute from the word a.
  866. 41:16So let's imagine that your proxy task is
  867. 41:18to predict the next word.
  868. 41:22So here a
  869. 41:25your very naive representation of a
  870. 41:29is the one hot encoding. So let's assume
  871. 41:31that you have a vocabulary size of six
  872. 41:35and a is your first token. So you would
  873. 41:38represent a with 1 0 0 0.
  874. 41:43You pass it through your network. So
  875. 41:45think of it as matrix multiplication
  876. 41:48with this vector. you would have a
  877. 41:50hidden state of size two. Let's assume
  878. 41:53two numbers 02 and 0.9
  879. 41:57and then you pass it to your network. So
  880. 41:59again another matrix multiplication and
  881. 42:01then you have predictions that sum to
  882. 42:04one. So you can use something like a
  883. 42:06softmax to normalize them. And your goal
  884. 42:11is
  885. 42:14to
  886. 42:16have these probabilities be as close
  887. 42:20to the label that you have which is
  888. 42:22predicting the word cute. And so cute
  889. 42:25let's suppose that it's the second word
  890. 42:26of your vocabulary. So it is represented
  891. 42:28by 0 1 0 0.
  892. 42:32So your goal is like on the slide for
  893. 42:35the 0.4 to be as close as one as
  894. 42:38possible.
  895. 42:41So the idea is to have a loss function
  896. 42:45that penalizes
  897. 42:48the fact of having your probability of a
  898. 42:51given word being too far from the word
  899. 42:53that you're trying to predict. So in
  900. 42:55case you know the cross entropy loss
  901. 42:58and then updates the weights of your of
  902. 43:00your model in order to reflect what you
  903. 43:04want.
  904. 43:06So just so that we're clear I will just
  905. 43:09walk through all the quantities that we
  906. 43:11mentioned. So here the one hand encoding
  907. 43:14that represents the token is of size the
  908. 43:17vocabulary size.
  909. 43:19The hidden state or also called latent
  910. 43:22representation
  911. 43:24is of size D and D is actually a
  912. 43:28parameter that you can choose typically
  913. 43:30much smaller than the vocabulary size.
  914. 43:33And then the predicted word
  915. 43:34probabilities well you have a
  916. 43:36probability per token. So it needs to
  917. 43:38match the vocabulary size. So it's of
  918. 43:41size V. And that also matches the size
  919. 43:44of the onehood encoding. And this is
  920. 43:46where you're able to
  921. 43:50try to penalize for deviations from the
  922. 43:52word that you're trying to predict. So
  923. 43:55let's assume you do that
  924. 43:57for a trying to gen to predict cute. You
  925. 44:01repeat the same thing for cute for teddy
  926. 44:04bear. So you go cute, you represent it
  927. 44:07with the 100 encoding. You pass it
  928. 44:09through your network. You have a latent
  929. 44:10representation and again probabilities.
  930. 44:13You compare that with the actual label
  931. 44:16that is representing teddy bear. Compute
  932. 44:18the loss. Update the weights given how
  933. 44:21far you are from the from the predict
  934. 44:24from the label. And you repeat that
  935. 44:28through your whole corpus.
  936. 44:30Well, at the end of this,
  937. 44:33what the authors realize
  938. 44:36is that the latent representation that
  939. 44:39you learn in the middle of the network
  940. 44:42actually is
  941. 44:45making sense.
  942. 44:47As in,
  943. 44:50you can compute similarity measures
  944. 44:54between the learned representations. And
  945. 44:56you see that representations of similar
  946. 45:00tokens are actually similar.
  947. 45:05So on this example, so teddy bear is
  948. 45:07soft. What is Persian poetry to arts?
  949. 45:09Another example is Paris is to France,
  950. 45:12what Berlin is to Germany. So you have
  951. 45:14these nice associations
  952. 45:16that are actually something that the
  953. 45:18model learns.
  954. 45:20So that gives you meaningful
  955. 45:24word representations.
  956. 45:27So that's a method
  957. 45:30that appeared I believe in the early
  958. 45:322010s. I believe it was 2013 if I
  959. 45:35remember correctly. So who can tell me
  960. 45:37what is a a limitation of this approach?
  961. 45:45So here the representation of the words
  962. 45:47that we learn
  963. 45:51we saw that they end up being meaningful
  964. 45:54but is there
  965. 45:56is there a limitation to this approach?
  966. 45:59Yeah. So one answer is that you would
  967. 46:02have trouble if you actually are not
  968. 46:05encountering something that you have
  969. 46:06seen during um your training process. So
  970. 46:10yes, that is right and I think that's
  971. 46:12right in actually most cases beyond that
  972. 46:14case in particular. Um so that's one. Is
  973. 46:17there another yes another limitation?
  974. 46:20So the answer here is uh the dimension
  975. 46:24scales up when the the vocabulary size
  976. 46:27gets bigger. So actually this is a
  977. 46:29limitation of your tokenizer because the
  978. 46:32tokenizer is the one that determines
  979. 46:34your vocabulary size. And but you're
  980. 46:38right that um that this is a limitation
  981. 46:41but it's not specific to that approach
  982. 46:43as in you will always need to find a
  983. 46:46representation of
  984. 46:48each element in your vocabulary. So I
  985. 46:51mean it's a limitation but limitation in
  986. 46:54methods in general.
  987. 46:57Yes. Oh yes. So answer is words can have
  988. 47:00multiple meanings. So exactly. So um one
  989. 47:04limitation here is if the word let's say
  990. 47:08cute
  991. 47:10is in this sentence
  992. 47:13versus in another sentence they will
  993. 47:16both get the same representation. So
  994. 47:19if you say a cute teddy bear in a nice
  995. 47:21way versus someone who sarcastically
  996. 47:25says oh how cute.
  997. 47:28They may mean different things between
  998. 47:29the word behind the word cute. So I
  999. 47:32think a very
  1000. 47:36classic example is bank. So river bank
  1001. 47:39versus going to the bank. These are the
  1002. 47:41same words but different meaning. So the
  1003. 47:44problem with this approach is that
  1004. 47:47the representation of this word would
  1005. 47:50actually be the same regardless of the
  1006. 47:53sentence that it is in. So great point.
  1007. 47:56Another limitation here is that the word
  1008. 47:59order does not matter.
  1009. 48:02So let's assume we're saying the child
  1010. 48:05is hugging the teddy bear and the teddy
  1011. 48:08bear is hugging the child. These are the
  1012. 48:11exact same words, but they mean
  1013. 48:14different things. We would get the same
  1014. 48:16embeddings with this approach in both
  1015. 48:18cases.
  1016. 48:21So these are all limitations
  1017. 48:24which is the reason why this is
  1018. 48:27something that people have tried to
  1019. 48:30resolve through different means.
  1020. 48:33One such means is
  1021. 48:37RNN
  1022. 48:38which as we previously saw was the type
  1023. 48:42of model that was dominating
  1024. 48:45the models back in the 2010s.
  1025. 48:49And so here RNN's what they do is that
  1026. 48:54they actually have an extra quantity
  1027. 48:56that they compute which here is
  1028. 48:58represented with a
  1029. 49:01that is also called the hidden state
  1030. 49:05that tries to encapsulate
  1031. 49:07the meaning of the sentence seen so far.
  1032. 49:12So we're going to see that as an
  1033. 49:14example. So let's assume we go with the
  1034. 49:16same sentence. So a cute teddy bear is
  1035. 49:18reading. So here you would actually
  1036. 49:21put the word a into the RNN. It would
  1037. 49:25try to predict the word cute. But then
  1038. 49:28what it will do is keep
  1039. 49:32what we call the hidden state that
  1040. 49:34encodes the meaning of the sequence seen
  1041. 49:37so far.
  1042. 49:39That will be an input
  1043. 49:42to the next prediction. So we'll have
  1044. 49:45cute as an input and then these hidden
  1045. 49:49states as an input as well in order to
  1046. 49:52inform the next representation
  1047. 49:56and so on and so forth. So here what
  1048. 49:59you're doing is you're not just
  1049. 50:01considering embeddings of tokens on
  1050. 50:04their on their own. You're also
  1051. 50:07considering
  1052. 50:09the embedding of the sequence decoded so
  1053. 50:11far.
  1054. 50:13And that allows you to
  1055. 50:16take into consideration
  1056. 50:18the order of the words
  1057. 50:21in the sentence.
  1058. 50:24And RNN's are actually models that were
  1059. 50:26used in a bunch of tasks back in the
  1060. 50:28day. So for instance, for
  1061. 50:30classifications, what you would do is
  1062. 50:33process tokens one at a time and then
  1063. 50:35keep a selfmutating state that encodes
  1064. 50:38the meaning of the sequence seen so far
  1065. 50:41and it would try to predict let's say a
  1066. 50:44sentiment in the sentiment extraction
  1067. 50:46case.
  1068. 50:47In the multi-classification case, for
  1069. 50:50instance, if you wanted to determine if
  1070. 50:53a word was a noun or a verb, then you
  1071. 50:55would actually leverage the
  1072. 50:58representations corresponding to each
  1073. 51:00input, which again would take into
  1074. 51:03consideration the hidden states
  1075. 51:06or just generation.
  1076. 51:11But one
  1077. 51:13limitation of RNN's is that okay it was
  1078. 51:17great you would consider the order at
  1079. 51:20which the words would appear in a
  1080. 51:22sequence
  1081. 51:24but it would have trouble
  1082. 51:27remembering
  1083. 51:29words that happened far in the past
  1084. 51:33because what it used to do was to encode
  1085. 51:36the meaning of the sequence
  1086. 51:38in one single vector.
  1087. 51:41that kept on being modified.
  1088. 51:44So you had this issue of what we call
  1089. 51:47long range dependency
  1090. 51:50where if you end up two sentences after
  1091. 51:53something that you have talked about
  1092. 51:56prior to that, you would have trouble
  1093. 52:00teasing that out just using the hidden
  1094. 52:02state at that point.
  1095. 52:06And that can be problematic. For
  1096. 52:08instance, when you refer to something
  1097. 52:10that happened in the past. So for
  1098. 52:12instance, you can say, "Oh, my teddy
  1099. 52:15bear is so cute. Uh, it is
  1100. 52:193 ft tall." So it refers to something
  1101. 52:22that is in the past. So now let's assume
  1102. 52:24that the it is referring to something
  1103. 52:27that is far in the past.
  1104. 52:30then we have this problem of actually
  1105. 52:33having the right set of information in
  1106. 52:35the hidden state that we're considering.
  1107. 52:40So this is the reason why there were
  1108. 52:43some variations of RNN.
  1109. 52:46One such variation was called the LSTM
  1110. 52:50long short-term memory which tried to
  1111. 52:53address this problem by not only keeping
  1112. 52:57a hidden state but also another state
  1113. 53:00called the cell state that was meant to
  1114. 53:04carry information for longer.
  1115. 53:10But the truth is
  1116. 53:13even
  1117. 53:14such variations had their limitations
  1118. 53:18which again had the same issue.
  1119. 53:22So if we were to just recap the state of
  1120. 53:24the ways we could obtain our embedding
  1121. 53:28so far
  1122. 53:30we saw vortac which is a very simple
  1123. 53:33approach to compute
  1124. 53:36representations of words. But the
  1125. 53:39problem is that
  1126. 53:41if a word is let's say in a different
  1127. 53:44sequence then the representation is the
  1128. 53:47same. So that is a limitation and also
  1129. 53:50as mentioned previously
  1130. 53:53the same word can actually mean
  1131. 53:55different things and so that is also not
  1132. 53:58conveyed and in the case of RNN's we are
  1133. 54:03actually addressing the word order order
  1134. 54:06problem by having a hidden state that
  1135. 54:09encapsulate the sequence that is seen so
  1136. 54:12far.
  1137. 54:13But the problem is that we have this
  1138. 54:16long range dependency problem that is
  1139. 54:18actually coming from a deeper problem
  1140. 54:20come called the vanishing gradient
  1141. 54:22problem which is a a problem when you
  1142. 54:26want to back propagate
  1143. 54:28that just introduces some limitation
  1144. 54:31and another thing that we have not
  1145. 54:33mentioned but RNN's the problem is every
  1146. 54:37time you want to predict the next token
  1147. 54:40you need to have
  1148. 54:42the hidden state that encapsulates all
  1149. 54:44the things that you have seen so far. So
  1150. 54:47you always have to
  1151. 54:50just go through tokens one at a time in
  1152. 54:52order to make the next prediction. And
  1153. 54:54when it comes to training such a model,
  1154. 54:57it is just extremely slow
  1155. 55:01and
  1156. 55:03it had great results at the time but not
  1157. 55:07amazing either.
  1158. 55:10So for all these reasons in the 2010s
  1159. 55:14people tried different techniques
  1160. 55:17and there is one technique that really
  1161. 55:21stood out now from hindsight but that is
  1162. 55:25called attention
  1163. 55:27and the idea is as follows.
  1164. 55:31Instead of solely relying on the hidden
  1165. 55:34state to encapsulate the meaning of the
  1166. 55:37sequence that you have seen so far,
  1167. 55:40the idea is to let your model have
  1168. 55:45direct connections
  1169. 55:47from tokens that you have seen in the
  1170. 55:49past.
  1171. 55:51So in other words, we're not saying only
  1172. 55:54rely on the hidden state to know what
  1173. 55:56has happened in the past. We're saying
  1174. 55:58you can also have direct connections to
  1175. 56:02tokens that you have seen in the past in
  1176. 56:04order to predict the next token.
  1177. 56:08So in the translation example, so let's
  1178. 56:10assume you want to translate in French a
  1179. 56:13cute teddy bear is reading and let's
  1180. 56:15assume you say
  1181. 56:18and you want to predict the next words.
  1182. 56:21So intuitively in order to predict the
  1183. 56:24next words,
  1184. 56:26it would be amazing to know what the
  1185. 56:29word that you want to translate is.
  1186. 56:32So in the traditional RNN case, you
  1187. 56:35would not have access to that direct
  1188. 56:37access to that word. You would only have
  1189. 56:39access to it via the hidden state. So
  1190. 56:42here the idea is to have a direct
  1191. 56:44connection to previous tokens and let
  1192. 56:48the model learn which ones matter and
  1193. 56:52here for the prediction to rely on the
  1194. 56:54ones that matter in order to make the
  1195. 56:57prediction.
  1196. 57:00So this is the concept of attention.
  1197. 57:04The concept of attention is letting your
  1198. 57:06model draw direct connections from a
  1199. 57:09given token to some tokens in the past.
  1200. 57:16And
  1201. 57:18this concept is very important because
  1202. 57:21it is at a found at the foundation of
  1203. 57:23what we're going to see now.
  1204. 57:27So I mentioned previously that there was
  1205. 57:31this paper called attention is all you
  1206. 57:34need that came out in 2017 that was a
  1207. 57:37turning point because people saw that it
  1208. 57:40was it was very scalable. It was giving
  1209. 57:43you amazing results.
  1210. 57:45Well, this paper
  1211. 57:48relies on the concept of the self
  1212. 57:51attention, which is attention but on
  1213. 57:55steroids.
  1214. 57:57And we'll go through exactly what we
  1215. 58:00mean by that. So let's assume you have
  1216. 58:03the sequence a cute teddy bear is
  1217. 58:06reading.
  1218. 58:08So now the idea is to not say that we're
  1219. 58:10going to compute the representation of a
  1220. 58:12given word as a function of
  1221. 58:16the hidden state that encapsulates the
  1222. 58:19meaning of the sequence so far and the
  1223. 58:22word itself. We're not saying that now.
  1224. 58:24What we're saying is that in order to
  1225. 58:27compute the representation of a given
  1226. 58:28token, we we can actually do that by
  1227. 58:32expressing that representation as a
  1228. 58:34function of all the other tokens.
  1229. 58:37in that sequence.
  1230. 58:39Sorry. So I think you raised an
  1231. 58:42important point which is how do you know
  1232. 58:46the order of words if you just let
  1233. 58:48everyone interact to everyone in case
  1234. 58:50that was your question. Um so if you let
  1235. 58:54a token interact with all other tokens
  1236. 58:56you actually lose
  1237. 58:59the concept of word order and it is
  1238. 59:03actually something that is addressed
  1239. 59:04later on. So we're going to exactly see
  1240. 59:06that part. Uh but here you actually do
  1241. 59:09not know where tokens are are because
  1242. 59:12you have a direct connection in this
  1243. 59:14very vanilla representation. You don't
  1244. 59:16know where tokens are. So we're going to
  1245. 59:18see exactly how you fix that issue.
  1246. 59:22But does the idea make sense? The idea
  1247. 59:25that in order to compute a
  1248. 59:27representation of a token, you actually
  1249. 59:30want to express that as a function of
  1250. 59:32all the other tokens in the sequence.
  1251. 59:34Does this idea make sense
  1252. 59:40roughly?
  1253. 59:43Yeah, I'll take that as a guess. So,
  1254. 59:45we're going to go through examples and
  1255. 59:47actually Shervin has a detailed example
  1256. 59:49later on. So, hopefully that will make a
  1257. 59:51bit more sense.
  1258. 59:53There is a set of notations that people
  1259. 59:56use
  1260. 59:58that we're going to introduce now. So
  1261. 1:00:00these notations are queries,
  1262. 1:00:04keys and values Q, K and V.
  1263. 1:00:11So
  1264. 1:00:13the query
  1265. 1:00:14is the entity that is trying to
  1266. 1:00:17determine what a given token is about.
  1267. 1:00:22And the idea is
  1268. 1:00:25it wants to find tokens that are useful
  1269. 1:00:29in order to construct a meaningful
  1270. 1:00:31representation of the token that it is
  1271. 1:00:33responsible for. So the query for teddy
  1272. 1:00:35bear what it tries to do is to find
  1273. 1:00:39other tokens that is relevant in order
  1274. 1:00:41to compute a meaningful representation
  1275. 1:00:43of that token.
  1276. 1:00:45So what it will do is
  1277. 1:00:48see how similar that quantity is to keys
  1278. 1:00:54of the sequence that are associated with
  1279. 1:00:56each token in the sequence.
  1280. 1:01:00And once it determines the magnitude at
  1281. 1:01:03which it is similar to each token,
  1282. 1:01:06we will associate a value to each of
  1283. 1:01:10these tokens.
  1284. 1:01:12So in other words, we want to express
  1285. 1:01:15the representation of teddy bear as a
  1286. 1:01:17function of all the other tokens in the
  1287. 1:01:19sequence. So what we will do is first
  1288. 1:01:22determine the weights. So it's a
  1289. 1:01:24weighted average. We want the weights.
  1290. 1:01:25The weights are determined by how
  1291. 1:01:28similar the query for teddy bear is to
  1292. 1:01:30each key.
  1293. 1:01:33And then the actual value will be just
  1294. 1:01:36the value vector corresponding to each
  1295. 1:01:41each token. So it will be something like
  1296. 1:01:43if I were to write it. So it's like
  1297. 1:01:47the sum of something that is
  1298. 1:01:50representing the similarity. So Q Q and
  1299. 1:01:54KI
  1300. 1:01:58VI.
  1301. 1:01:59So this is your query. You're
  1302. 1:02:03trying to determine how similar your
  1303. 1:02:05query is to all the other keys with some
  1304. 1:02:08similarity operation. So here's the dot
  1305. 1:02:10product as an example. And you associate
  1306. 1:02:13that. So this is a scalar.
  1307. 1:02:15This is a scalar
  1308. 1:02:17and you associate that with vi which is
  1309. 1:02:21also a vector.
  1310. 1:02:25So
  1311. 1:02:27this may seem a little bit abstract. So
  1312. 1:02:29I'll give you an example. So let's
  1313. 1:02:30assume we want to know what best
  1314. 1:02:33describes the teddy bear. The query can
  1315. 1:02:35be asking itself, okay, what best
  1316. 1:02:37describes a teddy bear? And you look at
  1317. 1:02:40all the tokens, you're like, oh, cute
  1318. 1:02:44actually describes the teddy bear pretty
  1319. 1:02:45well. So maybe the dot product between Q
  1320. 1:02:50teddy bear and K cute is going to be
  1321. 1:02:54high.
  1322. 1:02:56So the representation that you compute
  1323. 1:02:58for teddy bear is actually something
  1324. 1:03:00that will depend heavily on cute let's
  1325. 1:03:03assume.
  1326. 1:03:06So these are the concepts of query key
  1327. 1:03:09value. Now the next question is how do
  1328. 1:03:11you obtain those? How do you obtain
  1329. 1:03:13queries key values?
  1330. 1:03:16So these are actually quantities
  1331. 1:03:19that you can learn with projection
  1332. 1:03:22matrices.
  1333. 1:03:25So you initially have some input token
  1334. 1:03:28that represents each
  1335. 1:03:31tokens token and what you do is you take
  1336. 1:03:35that representation
  1337. 1:03:37and you project it on the space of
  1338. 1:03:40queries of keys of values
  1339. 1:03:45through some projection matrices.
  1340. 1:03:49And then you use these quantities in
  1341. 1:03:52order to compute meaningful
  1342. 1:03:54representations
  1343. 1:03:57of tokens.
  1344. 1:04:00Yes.
  1345. 1:04:02Amazing question. So question is what is
  1346. 1:04:03the t? So t is actually just to be
  1347. 1:04:06mathematically rigorous. So t is
  1348. 1:04:08transpose. So it's just that uh this you
  1349. 1:04:11can also write it as
  1350. 1:04:15Q krpose
  1351. 1:04:25any other question
  1352. 1:04:28so we have a detailed example later so
  1353. 1:04:30in case that roughly makes sense I think
  1354. 1:04:33that's great
  1355. 1:04:36we we'll see that in a
  1356. 1:04:40So it just turns out that what I
  1357. 1:04:41described is something that is very
  1358. 1:04:45nicely something you can express in
  1359. 1:04:47mathematical terms
  1360. 1:04:50with matrices.
  1361. 1:04:52So in particular the operation I just
  1362. 1:04:55mentioned is something that can be
  1363. 1:04:56expressed as the soft max of the query
  1364. 1:05:00and the keys
  1365. 1:05:02and you scale that by some factor times
  1366. 1:05:05the values
  1367. 1:05:08and actually I maybe have enough time
  1368. 1:05:11for you to say why.
  1369. 1:05:14So let's assume you have [snorts]
  1370. 1:05:17so the softmax is just a way for you to
  1371. 1:05:19get the sum of the coefficients being
  1372. 1:05:23equal to one. So that's roughly what it
  1373. 1:05:25does. But the question is well if you
  1374. 1:05:28have query key transpose v I mean more
  1375. 1:05:35or less the softmax and the scaling.
  1376. 1:05:38Why does it give you the thing that we
  1377. 1:05:40saw above?
  1378. 1:05:42Well, let's assume that your query
  1379. 1:05:45matrix matrix has
  1380. 1:05:48like all your queries. So, q1
  1381. 1:05:52qn.
  1382. 1:05:54So, one is the first index of your
  1383. 1:05:57sequence. So, let's assume in the
  1384. 1:05:58previous slide that we say the first
  1385. 1:06:00index is a. Let's say a is one and then
  1386. 1:06:05the dot is n. Let's assume.
  1387. 1:06:08So we have
  1388. 1:06:10the query for A
  1389. 1:06:13up until the query for the dots
  1390. 1:06:16and you do the same for
  1391. 1:06:19K and V.
  1392. 1:06:22So if you multiply
  1393. 1:06:25the square matrix
  1394. 1:06:28times transpose
  1395. 1:06:30what you get is
  1396. 1:06:34K1 like this
  1397. 1:06:38KN.
  1398. 1:06:43And so this is where you're glad you
  1399. 1:06:46know some linear algebra.
  1400. 1:06:49So matrix multiplication. So you do this
  1401. 1:06:52times this
  1402. 1:06:54which is the dotproduct of Q1 K1
  1403. 1:07:00uh and then second element is Q1 K2.
  1404. 1:07:11So if you repeat this you will have the
  1405. 1:07:14matrix of the Qi
  1406. 1:07:17KJ
  1407. 1:07:20going to maybe write that up up there.
  1408. 1:07:32So I'm just going to write exactly
  1409. 1:07:34what's in what's what is above. So you
  1410. 1:07:38have
  1411. 1:07:47Q1 K1
  1412. 1:07:51up until Q1
  1413. 1:07:54KN.
  1414. 1:07:58And then you repeat that here. You put
  1415. 1:08:00that here. You repeat that here. Now if
  1416. 1:08:02you add a V in here
  1417. 1:08:07then
  1418. 1:08:12what you obtain is
  1419. 1:08:16V1
  1420. 1:08:19VN.
  1421. 1:08:22So again you do your matrix
  1422. 1:08:25multiplication and here what you get is
  1423. 1:08:29this times this plus this times this
  1424. 1:08:31plus this time this up until here. So
  1425. 1:08:34you have the sum
  1426. 1:08:37of Q1,
  1427. 1:08:42KI,
  1428. 1:08:45VI,
  1429. 1:08:48and the same up until the sum of QN,
  1430. 1:08:55KI,
  1431. 1:08:58VI.
  1432. 1:09:01So
  1433. 1:09:03long story short, I just wanted to say
  1434. 1:09:06that
  1435. 1:09:08the fact of expressing
  1436. 1:09:12something as a function of this
  1437. 1:09:16similarity operation and the values is
  1438. 1:09:18something that you can represent very
  1439. 1:09:20well with matrices
  1440. 1:09:24and you will see this formula quite
  1441. 1:09:25often. So I believe there was a question
  1442. 1:09:28on the midterm. So hint this formula can
  1443. 1:09:31be important.
  1444. 1:09:35And so now that we know how self
  1445. 1:09:38attention is defined, how self attention
  1446. 1:09:40works, now we're going to hopefully in
  1447. 1:09:43the next 17 minutes
  1448. 1:09:46see how self attention is used in the
  1449. 1:09:50transformer architecture which is a
  1450. 1:09:51trans which is the architecture that was
  1451. 1:09:53introduced in the attention is all you
  1452. 1:09:56need paper.
  1453. 1:09:58So what why is it called attention is
  1454. 1:10:01all you need?
  1455. 1:10:03Well the authors at the time most models
  1456. 1:10:09were recurrent. They were based on the
  1457. 1:10:11RNN. So they used to compute things in a
  1458. 1:10:14recurrent fashion.
  1459. 1:10:16But here what we're saying is actually
  1460. 1:10:18we don't care about keeping a hidden
  1461. 1:10:23states by recurring through tokens.
  1462. 1:10:27We're not doing that. What we're doing
  1463. 1:10:29instead is letting tokens interact with
  1464. 1:10:33all tokens
  1465. 1:10:35through direct connections
  1466. 1:10:38aka through self attention
  1467. 1:10:42which is why attention is all you need.
  1468. 1:10:46So this paper was released in the
  1469. 1:10:48context of machine translation.
  1470. 1:10:51So in this context, we're interested in
  1471. 1:10:53translating a source text, let's say in
  1472. 1:10:55English, over to another language, let's
  1473. 1:10:58say in French.
  1474. 1:11:00And what we do is we have two components
  1475. 1:11:03in the transformer.
  1476. 1:11:06On the left, we have what we call an
  1477. 1:11:08encoder.
  1478. 1:11:10And the role of the encoder is to
  1479. 1:11:13compute meaningful representations for
  1480. 1:11:16the source text that is fed as input.
  1481. 1:11:21And we have a second part of the
  1482. 1:11:23transformer which is called the decoder.
  1483. 1:11:26And the role of the decoder is to use
  1484. 1:11:29the meaningful representations from the
  1485. 1:11:32encoder along with some internal
  1486. 1:11:36embeddings that it is computing in order
  1487. 1:11:39to generate
  1488. 1:11:41the translation.
  1489. 1:11:45So that is the context in which the
  1490. 1:11:47transformer was released and it
  1491. 1:11:50performed great and it is at the
  1492. 1:11:53foundation of modern day LLMs which is
  1493. 1:11:56the reason why we're focusing on this.
  1494. 1:11:57So that that's the reason why we're
  1495. 1:11:59here. The reason why I I wrote these
  1496. 1:12:02formulas on the blackboard is because I
  1497. 1:12:05think this is probably the most
  1498. 1:12:07important formula when it comes to
  1499. 1:12:09transformers. So just visualizing this
  1500. 1:12:12in terms of matrix multiplies
  1501. 1:12:16is very important.
  1502. 1:12:19Okay. So what we will do now is walk
  1503. 1:12:22through each component of the
  1504. 1:12:24transformer and see how this all comes
  1505. 1:12:27together. And I'm looking at you with
  1506. 1:12:29respect to the position embeddings.
  1507. 1:12:31We're go we're going to talk about this
  1508. 1:12:33now. So
  1509. 1:12:36for machine translation
  1510. 1:12:39what you get as input is a text in a
  1511. 1:12:42source language
  1512. 1:12:44and your task is to translate that
  1513. 1:12:47source language that source that text in
  1514. 1:12:49the source language into a target
  1515. 1:12:51language.
  1516. 1:12:53So your first task is to understand what
  1517. 1:12:58your source text is about.
  1518. 1:13:00So here you have an input embedding that
  1519. 1:13:04is tasked with just converting this
  1520. 1:13:08input text into tokens and then
  1521. 1:13:10associated associating each of this
  1522. 1:13:13token with some embedding that you can
  1523. 1:13:15learn. This embedding is only
  1524. 1:13:18with respect to each token. It is not
  1525. 1:13:21context aware in any way.
  1526. 1:13:24And what you do is you add an embedding
  1527. 1:13:28that is associated with the position
  1528. 1:13:30that the token is in in the sequence.
  1529. 1:13:33And this is where we learn we know where
  1530. 1:13:36tokens are located.
  1531. 1:13:39So we add the token embedding
  1532. 1:13:41and the position embedding together.
  1533. 1:13:46And so the question you may have is well
  1534. 1:13:48how do you obtain the position
  1535. 1:13:49embedding? So you have different ways.
  1536. 1:13:52The ways people like the authors have
  1537. 1:13:56tried is actually two ways. One way is
  1538. 1:13:59to learn
  1539. 1:14:02the embedding. The second way is to
  1540. 1:14:04actually have something that is a
  1541. 1:14:06function of uh just different
  1542. 1:14:09frequencies. So there are some pros and
  1543. 1:14:12cons but I just want to so I think the
  1544. 1:14:15the learning way is very natural but a a
  1545. 1:14:19clear con is if you have an input text
  1546. 1:14:22that is longer than what you have
  1547. 1:14:24learned at training time. So if you have
  1548. 1:14:27let's say a thousand tokens as input but
  1549. 1:14:31you already you only have learned
  1550. 1:14:33positions like embeddings for positions
  1551. 1:14:35up to let's say 500 then you're out of
  1552. 1:14:38luck. You cannot represent positions
  1553. 1:14:40greater than that. Which is why the
  1554. 1:14:43arbitrary predefined representation can
  1555. 1:14:46be useful.
  1556. 1:14:48And I just want to illustrate why
  1557. 1:14:51choosing
  1558. 1:14:53different frequencies could be a good
  1559. 1:14:55way to represent something like the
  1560. 1:14:57position.
  1561. 1:14:59So you may have a watch and you may
  1562. 1:15:02notice that you represent the time with
  1563. 1:15:05let's say an hour
  1564. 1:15:08hour uh thingy with the minutes they all
  1565. 1:15:12turn at different frequencies.
  1566. 1:15:14So if you want to read the time so 449
  1567. 1:15:17it's four which is the the hour piece
  1568. 1:15:22and then you have the minutes and then
  1569. 1:15:23you have the seconds and each of them
  1570. 1:15:26they turn at different frequencies and
  1571. 1:15:28if you put them together you can exactly
  1572. 1:15:31know what time it is.
  1573. 1:15:34So this is the idea behind having a
  1574. 1:15:37vector of elements that vary with
  1575. 1:15:40different frequencies. So you can obtain
  1576. 1:15:42that with cosine and sine functions and
  1577. 1:15:46this is what people use here. So the
  1578. 1:15:49good thing with these representations is
  1579. 1:15:51that positions that are
  1580. 1:15:56close to one another
  1581. 1:15:58are very similar and the ones that are
  1582. 1:16:00far from one another are are dissimilar.
  1583. 1:16:02So this is one nice property.
  1584. 1:16:05So this is one way of representing the
  1585. 1:16:07positions.
  1586. 1:16:08Anyway, maybe I digress too much. We're
  1587. 1:16:10going to talk more about position next
  1588. 1:16:12time, but long story short, we can
  1589. 1:16:16represent tokens along with their
  1590. 1:16:18positions. So at this stage, what we did
  1591. 1:16:21was add the token embedding and the
  1592. 1:16:25position embedding.
  1593. 1:16:27And here we come into the encoder.
  1594. 1:16:30So the encoder is the component of the
  1595. 1:16:33transformer which is tasked with
  1596. 1:16:35computing meaningful representations of
  1597. 1:16:37the tokens.
  1598. 1:16:39So here we have one very important type
  1599. 1:16:43of layer called the attention layer.
  1600. 1:16:47It's actually called the self attention
  1601. 1:16:48layer. So self attention layer, what
  1602. 1:16:50does it do? What it does is compute
  1603. 1:16:55representations of tokens as a function
  1604. 1:16:58of all other tokens.
  1605. 1:17:01And this is where this query key value
  1606. 1:17:03thing happens.
  1607. 1:17:06So you're going to see that in the
  1608. 1:17:08example that Sherman will walk you
  1609. 1:17:09through. But the idea is to learn
  1610. 1:17:12projection matrices
  1611. 1:17:15that will allow you to project your
  1612. 1:17:18tokens into a space of queries, keys,
  1613. 1:17:22and values that will then allow them to
  1614. 1:17:25interact
  1615. 1:17:27through the formula that we saw. So this
  1616. 1:17:32so that allows you to represent your
  1617. 1:17:35tokens as a function of others.
  1618. 1:17:38And then you have another layer called
  1619. 1:17:42the feed for neural network which is a
  1620. 1:17:46way for your architecture
  1621. 1:17:48to project representations into spaces
  1622. 1:17:53of higher dimension
  1623. 1:17:56along with some activation function
  1624. 1:17:58which allows you to learn
  1625. 1:17:59nonlinearities.
  1626. 1:18:04So you go through the encoder at the end
  1627. 1:18:06of the at the tip of the encoder what
  1628. 1:18:08you get is a very meaningful
  1629. 1:18:10representation per token
  1630. 1:18:12that is a function of all of the tokens
  1631. 1:18:14in the sequence.
  1632. 1:18:18So what you do is now when you want to
  1633. 1:18:20translate the text
  1634. 1:18:23so you you take your special token that
  1635. 1:18:25we saw in the very beginning you know
  1636. 1:18:27end of sequence sorry beginning of
  1637. 1:18:29sequence. So you tell your model well
  1638. 1:18:31now I want to start the generation. So
  1639. 1:18:34you input begin sequence as an input to
  1640. 1:18:38the decoder. You add the position
  1641. 1:18:40encoding that is associated with that
  1642. 1:18:43token which is the first element in the
  1643. 1:18:45sequence and what you do is
  1644. 1:18:50you enter the decoder
  1645. 1:18:53which does two things.
  1646. 1:18:56The first thing is it also has an
  1647. 1:19:01attention self attention mechanism
  1648. 1:19:04with respect to the token itself and all
  1649. 1:19:07the tokens that was generated so far.
  1650. 1:19:12So it tries to express each token as a
  1651. 1:19:16function of itself and all the tokens
  1652. 1:19:18that were generated so far. So in the
  1653. 1:19:21beginning of sequence case it's the only
  1654. 1:19:23token that was generated so far. So that
  1655. 1:19:24that's it. And then you have a second
  1656. 1:19:30attention layer which is a different
  1657. 1:19:32kind
  1658. 1:19:34where you're actually letting the
  1659. 1:19:37representations
  1660. 1:19:38from tokens that were generated so far
  1661. 1:19:43and let them interact with tokens from
  1662. 1:19:46the source
  1663. 1:19:48from your input source from the source
  1664. 1:19:50language.
  1665. 1:19:52So I'm not sure if you can see in the in
  1666. 1:19:54the illustration you have one arrow
  1667. 1:19:57which is from what was generated so far
  1668. 1:19:59and then you have two arrows coming from
  1669. 1:20:01the encoder.
  1670. 1:20:03So the one error from the generated so
  1671. 1:20:06far is the query
  1672. 1:20:09and the key and the value are coming
  1673. 1:20:11from the encoder
  1674. 1:20:12because you're you're asking yourself
  1675. 1:20:15how can I express this token as a
  1676. 1:20:18function of all the tokens in the input
  1677. 1:20:21input text
  1678. 1:20:24by the way does that make sense? Yeah.
  1679. 1:20:27Okay. Great. And then you do that and
  1680. 1:20:29then you have another layer that's
  1681. 1:20:30called the fit for neural network that
  1682. 1:20:32again allows your model to learn
  1683. 1:20:36ways to project your data
  1684. 1:20:39and then at the end you get a very
  1685. 1:20:43meaningful representation of the word
  1686. 1:20:46that you the token that you passed as
  1687. 1:20:48input. So here in this case in the very
  1688. 1:20:50beginning you have beginning of sequence
  1689. 1:20:52and at the end of the decoder you have a
  1690. 1:20:56very meaningful representation of that
  1691. 1:20:58token.
  1692. 1:21:00So what you do is you then project that
  1693. 1:21:02representation on the space of
  1694. 1:21:04vocabularies
  1695. 1:21:07and you get probabilities
  1696. 1:21:10that correspond to what you think is the
  1697. 1:21:13next token.
  1698. 1:21:17And so here
  1699. 1:21:20translation is just figuring out what
  1700. 1:21:22the next token is. So you figure out
  1701. 1:21:24what the next token is and then you
  1702. 1:21:26choose what that next token is based on
  1703. 1:21:28the probabilities and then you repeat
  1704. 1:21:30that in an auto reggressive way. So you
  1705. 1:21:33put that new decoded token as input of
  1706. 1:21:36the dec decoder and you repeat exactly
  1707. 1:21:38what I mentioned.
  1708. 1:21:42So, we have five minutes. I have some
  1709. 1:21:47tricks to tell you, but I want to make
  1710. 1:21:49sure we're all on the same page. So, I'm
  1711. 1:21:51just going to open the floor in case
  1712. 1:21:52there is any questions so far. We we've
  1713. 1:21:55seen a lot of things, by the way, and
  1714. 1:21:58this first lecture is probably the one
  1715. 1:22:00of the most difficult in terms of number
  1716. 1:22:03of concepts we see. So, completely
  1717. 1:22:05normal if you feel like we've seen a
  1718. 1:22:07lot. Any questions on this?
  1719. 1:22:12Yep.
  1720. 1:22:13So the question is there are multiple
  1721. 1:22:15arrows merging into one. Uh so it's
  1722. 1:22:17because we have not seen it so far. So
  1723. 1:22:19this is a trick that actually we can see
  1724. 1:22:21now. So you may be referring to this
  1725. 1:22:24one, the residual connections. So this
  1726. 1:22:26is actually a trick to help your model
  1727. 1:22:30learn better. So these residual
  1728. 1:22:32connections, they're very useful in
  1729. 1:22:36architectures that are deep because they
  1730. 1:22:38allow your model to pass in features
  1731. 1:22:41directly instead of having them be
  1732. 1:22:46modified by some sub layer. So one way I
  1733. 1:22:49like to think about this is instead of
  1734. 1:22:52thinking about each layer as something
  1735. 1:22:55that modifies the whole
  1736. 1:22:58the whole input. So instead of saying
  1737. 1:23:02my layer is just changing the input. So
  1738. 1:23:05let's assume your input is
  1739. 1:23:09let's assume your input is x. Instead of
  1740. 1:23:14saying that the output of a layer is
  1741. 1:23:16some function of x.
  1742. 1:23:18What you're saying is the output of your
  1743. 1:23:22layer is
  1744. 1:23:24some function of x plus x.
  1745. 1:23:27And the way I like to think about it is
  1746. 1:23:29it's as if you were taking X and
  1747. 1:23:32modifying it as opposed to changing
  1748. 1:23:35completely X.
  1749. 1:23:38So in practice doing that
  1750. 1:23:43helps with back propagation
  1751. 1:23:47and allows your model to learn better.
  1752. 1:23:52So this is what this arrow is about.
  1753. 1:23:54Yeah. So speaking of the tricks, I have
  1754. 1:23:57some other tricks to tell you. So one
  1755. 1:23:58other is the fact of normalizing
  1756. 1:24:02the activations with what what we call
  1757. 1:24:04layer normalization.
  1758. 1:24:06So it also helps with convergence.
  1759. 1:24:10Um, you may have seen the word masked
  1760. 1:24:14self attention in the decoder. And the
  1761. 1:24:16reason why it's masked is because you
  1762. 1:24:18want your decoded tokens to only
  1763. 1:24:21interact with tokens you have decoded so
  1764. 1:24:24far
  1765. 1:24:26because you cannot interact with tokens
  1766. 1:24:28you have not decoded yet.
  1767. 1:24:32Uh, multi-head attention. So what I
  1768. 1:24:33described with QV, well, you can do it
  1769. 1:24:36with
  1770. 1:24:38in different ways. you can learn
  1771. 1:24:39different projections.
  1772. 1:24:42So for those of us who also are familiar
  1773. 1:24:44with vision related models, who knows
  1774. 1:24:47who who has a vision background here?
  1775. 1:24:51Okay. One. Okay. Two. Okay. So in case
  1776. 1:24:54you know uh when it comes to
  1777. 1:24:56convolutional neuronet networks
  1778. 1:24:59when you do the convolution operation
  1779. 1:25:02you can use several filters which are
  1780. 1:25:05different ways of convoluting on your
  1781. 1:25:07input. So having different attention
  1782. 1:25:10heads is also a way for your model to
  1783. 1:25:12learn to have different ways to learn
  1784. 1:25:15the same thing through through different
  1785. 1:25:17uh projection matrices. And so you
  1786. 1:25:19typically have h such
  1787. 1:25:22heads.
  1788. 1:25:25So another trick dropout. Who has who
  1789. 1:25:27has heard of dropout? Okay, great. Yeah,
  1790. 1:25:30this is a uh an idea that is not just
  1791. 1:25:35applied in the transformer but widely
  1792. 1:25:37used. So that one is a technique for
  1793. 1:25:40which at training time you intentionally
  1794. 1:25:42drop some units
  1795. 1:25:45with some probability in order for you
  1796. 1:25:49to have your model to not rely too much
  1797. 1:25:52on some features and that allows your
  1798. 1:25:56model to generalize better.
  1799. 1:26:00And then what do I have? Yeah, label
  1800. 1:26:02smoothing is another technique that was
  1801. 1:26:03used here. So the idea behind label
  1802. 1:26:05smoothing is when you tell your model to
  1803. 1:26:09predict the next words instead of saying
  1804. 1:26:15let's say what a nice day instead of
  1805. 1:26:17saying okay I want you to predict the
  1806. 1:26:19word day 100%.
  1807. 1:26:21Your model is saying you can predict the
  1808. 1:26:23word day actually not 100% you can have
  1809. 1:26:26also other words because in language you
  1810. 1:26:30can complete things in different ways
  1811. 1:26:32and still be valid. So you can say what
  1812. 1:26:34a nice day, what a nice class, what a
  1813. 1:26:38nice
  1814. 1:26:39evening. Anyways, so label smoozing
  1815. 1:26:43takes
  1816. 1:26:46these
  1817. 1:26:48labels and it softens it by saying okay
  1818. 1:26:52so instead of your model needing to
  1819. 1:26:55predict that label
  1820. 1:26:58as in you need to predict that model
  1821. 1:27:00100%. you say okay actually
  1822. 1:27:06the label that I want you to predict is
  1823. 1:27:08maybe I don't know 90%. And then the
  1824. 1:27:11remaining 10% is all the other words in
  1825. 1:27:13the vocabulary.
  1826. 1:27:16So it just allows your model to
  1827. 1:27:19generalize a bit better and authors have
  1828. 1:27:21found that this also improves metrics
  1829. 1:27:25when it comes to machine translation. So
  1830. 1:27:28uh for those of you who know blue is one
  1831. 1:27:30such metric
  1832. 1:27:34and with that I'll give it to Shervin.
  1833. 1:27:38Thank you Afin. So in this last part our
  1834. 1:27:42goal is going to piece all that Afin
  1835. 1:27:44talked about together in one single
  1836. 1:27:47example and see exactly how this
  1837. 1:27:49computation works in a precise example.
  1838. 1:27:53So as a mentioned the original
  1839. 1:27:56transformer is in the business of
  1840. 1:27:58machine translation. So what we're going
  1841. 1:28:00to take is a sentence in English and
  1842. 1:28:04we're going to try to translate it into
  1843. 1:28:06some other language. So in the example
  1844. 1:28:08of the original transformer paper they
  1845. 1:28:10took French and German. So let's take
  1846. 1:28:12that and let's start with our favorite
  1847. 1:28:16toy example. So a cute teddy bear is
  1848. 1:28:18reading. And as you recall, the first
  1849. 1:28:21step in all of this is tokenization.
  1850. 1:28:24And Afin mentioned that it's a way to
  1851. 1:28:28arbitrarily split these words into
  1852. 1:28:31atomic entities. So Afin mentioned
  1853. 1:28:34subword is an optimal way to do it. But
  1854. 1:28:38for the sake of this example, I'm going
  1855. 1:28:39to take another split just to prove that
  1856. 1:28:42it's arbitrary. So let's say we split it
  1857. 1:28:45like this. As a mentioned, we have also
  1858. 1:28:48special tokens. So, beginning of
  1859. 1:28:50sentence and end of sentence sequence
  1860. 1:28:54that you put to characterize where your
  1861. 1:28:56sequence starts and ends.
  1862. 1:29:00Now, let's look at how we encode them.
  1863. 1:29:03So,
  1864. 1:29:05we have in this architecture a lookup
  1865. 1:29:09table that is made of learnable weights.
  1866. 1:29:12So this is what we call embeddings and
  1867. 1:29:15these will be learned as part of the
  1868. 1:29:17learning process
  1869. 1:29:19and as someone mentioned it here if you
  1870. 1:29:23want to perform attention in [music] a
  1871. 1:29:24way that's context aware and that you
  1872. 1:29:26know where other tokens are positioned
  1873. 1:29:29you need that position information and
  1874. 1:29:31the original transformer paper puts this
  1875. 1:29:35position information at the beginning of
  1876. 1:29:38of the input. So you add it additively.
  1877. 1:29:42So let's say you call your embedding of
  1878. 1:29:45size D model. Then your position
  1879. 1:29:48embedding that I've been described by a
  1880. 1:29:50series of signs and cosiness of
  1881. 1:29:52different frequencies will be a vector
  1882. 1:29:55of the same length and it's additive
  1883. 1:29:57operation.
  1884. 1:30:00So at this stage you end up with an
  1885. 1:30:02embedding that's at least half
  1886. 1:30:06learnable. So the lookup table that I
  1887. 1:30:08mentioned to you is at least learnable.
  1888. 1:30:10Maybe the positions as well depends on
  1889. 1:30:12your design choice and this is what you
  1890. 1:30:15will put as an input to your encoder.
  1891. 1:30:19So what happens next? Every token has
  1892. 1:30:23this representation and you can
  1893. 1:30:25represent it in a nice matrix form.
  1894. 1:30:28Okay, let's go with it. And you're going
  1895. 1:30:31to go into the encoder and as we have
  1896. 1:30:34seen the first component of the encoder
  1897. 1:30:36is going to be that self attention
  1898. 1:30:38layer.
  1899. 1:30:41So
  1900. 1:30:42you project
  1901. 1:30:44this input into the space of queries. So
  1902. 1:30:47for that you have this WQ projection
  1903. 1:30:51matrix. You get queries with the same
  1904. 1:30:54initial embeddings. You project it on
  1905. 1:30:57keys. So you have a WQ W K projection
  1906. 1:31:02matrix that you will learn to project it
  1907. 1:31:04into keys K and you do the same with
  1908. 1:31:08values V.
  1909. 1:31:12Okay, great. And then based on that you
  1910. 1:31:16apply the formula that we mentioned that
  1911. 1:31:18is so important that softmax formula and
  1912. 1:31:22we do this matrix product and then we
  1913. 1:31:25obtain uh another matrix that is of same
  1914. 1:31:29dimension as the matrix V.
  1915. 1:31:34So before we dive deeper into more
  1916. 1:31:37specifics, I just want for us to get on
  1917. 1:31:40the same page of on dimensions because
  1918. 1:31:44we talked about a lot of embeddings
  1919. 1:31:45here. We project things and I just want
  1920. 1:31:48to make sure that we speak the same
  1921. 1:31:49language as to what size are these
  1922. 1:31:53objects.
  1923. 1:31:55So your input sequence, so we mentioned
  1924. 1:31:59it's of length n. And one notation that
  1925. 1:32:03people use to characterize these
  1926. 1:32:05embedding size is D model.
  1927. 1:32:09And then what the projection matrices of
  1928. 1:32:12Q, K and V do is respectively you start
  1929. 1:32:16from the Dodel world and you turn it
  1930. 1:32:20into the query world and then key world
  1931. 1:32:24and then value world. So this is why
  1932. 1:32:26it's of size D model and DQ and
  1933. 1:32:30similarly D model DK D model DV for each
  1934. 1:32:35projection matrix
  1935. 1:32:37and you obtain these queries keys and
  1936. 1:32:40values that are of size n rows but that
  1937. 1:32:44are this time into this query key and
  1938. 1:32:47value space. So the number of columns is
  1939. 1:32:50DQ, DK and DV.
  1940. 1:32:54And since you do this matrix multiply,
  1941. 1:32:57you need this constraint that DQ is
  1942. 1:33:00equal to DK. So here I put DQ and DK
  1943. 1:33:04just for the sake of properly naming
  1944. 1:33:06things. But DQ should be equal to DK by
  1945. 1:33:09construction.
  1946. 1:33:12And this is what you get.
  1947. 1:33:15All good so far.
  1948. 1:33:18Okay, great. So now let's pause a second
  1949. 1:33:22and then go back to this example and see
  1950. 1:33:26how the matrix matrix computation work.
  1951. 1:33:29So as Ain was mentioning earlier each
  1952. 1:33:33token can be represented as a row
  1953. 1:33:37embedding
  1954. 1:33:39and you have that for Q if you consider
  1955. 1:33:42K transpose each column is going to be
  1956. 1:33:46the embedding of a given vector. So when
  1957. 1:33:49you do the matrix multiply, you're going
  1958. 1:33:52to end up with a matrix of size n by n
  1959. 1:33:57where each cell is going to be some
  1960. 1:34:01similarity like here the exact dot
  1961. 1:34:03product between a given query and a
  1962. 1:34:08given key.
  1963. 1:34:11And let's suppose here you multiply this
  1964. 1:34:14by v. What you're going to end up with
  1965. 1:34:17is for each row you have a given query.
  1966. 1:34:21You project it on the space of keys that
  1967. 1:34:24you have in your sentence. So you get
  1968. 1:34:27some so you want to get some probability
  1969. 1:34:29distribution over keys and then you're
  1970. 1:34:32going to use these weights
  1971. 1:34:35to
  1972. 1:34:37to to weight the values and then you're
  1973. 1:34:40going to do a sum of all of this. Now
  1974. 1:34:42you're going to say okay Shvin and Ashin
  1975. 1:34:44you talk about qkranspose v qkranspose v
  1976. 1:34:48this is not what the formula is and then
  1977. 1:34:49you are right the formula is
  1978. 1:34:52approximately this we take the soft max
  1979. 1:34:54in order to get a probability
  1980. 1:34:56distribution that sums to one and has
  1981. 1:34:59nice properties and one thing we haven't
  1982. 1:35:02mentioned but that the authors chose is
  1983. 1:35:05that you will normalize by some factor
  1984. 1:35:08because the dimension dk K will
  1985. 1:35:12influence the variance that you might
  1986. 1:35:14get as part of the sum. So if you want
  1987. 1:35:16everything to be properly normalized,
  1988. 1:35:19you can divide by the standard
  1989. 1:35:21deviation. And this is what happens
  1990. 1:35:24here.
  1991. 1:35:26And so as we mentioned this is a
  1992. 1:35:30multi-headed process. So you do not do
  1993. 1:35:32this process once, you do it eight
  1994. 1:35:34times. So this process of learning
  1995. 1:35:39queries, keys and values is done in
  1996. 1:35:41parallel and then at the end you
  1997. 1:35:43concatenate all these softmax of KQ uh Q
  1998. 1:35:48krpose over square root of DK * V
  1999. 1:35:52together and then you have a last
  2000. 1:35:55projection matrix that we call WO that
  2001. 1:35:58will turn these embeddings in a space H
  2002. 1:36:02DV back into the model.
  2003. 1:36:07So you have this nice property by the
  2004. 1:36:09way in the transformer where a lot of
  2005. 1:36:11the operations make the original
  2006. 1:36:13dimension of embeddings invariant. So
  2007. 1:36:16you start with D model, you do a bunch
  2008. 1:36:18of attention calculations, you end up
  2009. 1:36:22with D model and then you go into the
  2010. 1:36:24next layer which is a fitforward neural
  2011. 1:36:26network that is a one hidden layer
  2012. 1:36:30network that projects this D model
  2013. 1:36:33representation into a DFF1 and then
  2014. 1:36:36typically you would have this dimension
  2015. 1:36:38that is bigger than the model in order
  2016. 1:36:41to allow for learning complex
  2017. 1:36:43representations.
  2018. 1:36:46And you do all of that big end time. So
  2019. 1:36:50in the original transformer paper, big N
  2020. 1:36:53is equal to six. So you do that a bunch
  2021. 1:36:55of time. And then at the end
  2022. 1:36:58of the encoder, you have for each token
  2023. 1:37:01a representation that represents that
  2024. 1:37:04token in a context aware and learned
  2025. 1:37:07way.
  2026. 1:37:10Is everything good so far?
  2027. 1:37:14Okay, awesome. So, I'm asking because
  2028. 1:37:16we're going to switch to the decoder.
  2029. 1:37:18So, I just want to make sure all makes
  2030. 1:37:19sense.
  2031. 1:37:22So, now that we have that,
  2032. 1:37:26as we mentioned, the original
  2033. 1:37:28transformer is in the business of
  2034. 1:37:30machine translation. So, you need to
  2035. 1:37:31start the beginning of your translated
  2036. 1:37:34sentence. And one way to force the start
  2037. 1:37:37of it is to have this placeholder token.
  2038. 1:37:41So you add this POS token, look at the
  2039. 1:37:44lookup table of your embeddings, you
  2040. 1:37:46have an initial embedding, you add your
  2041. 1:37:49position embedding to it, and then you
  2042. 1:37:51pass it to the decoder.
  2043. 1:37:53And you have this self attention layer
  2044. 1:37:57that Ashin mentioned is a masked self
  2045. 1:37:59attention layer because what happens
  2046. 1:38:01here is that it's causal. Every token
  2047. 1:38:04looks at itself and the tokens that
  2048. 1:38:07precede it.
  2049. 1:38:10And
  2050. 1:38:12once that happens, you have another
  2051. 1:38:14attention layer that's called cross
  2052. 1:38:16attention where the query is the decoded
  2053. 1:38:21token and then the keys and the values
  2054. 1:38:25are the tokens that come from the
  2055. 1:38:27encoder. So you look at the stack of
  2056. 1:38:29encoders, you look at the output
  2057. 1:38:31embedding and then every layer of
  2058. 1:38:34decoder like every decoder block will
  2059. 1:38:38get that last embedding as keys and
  2060. 1:38:40values.
  2061. 1:38:42Okay, so you do that and then you have
  2062. 1:38:44just like in the encoder a layer of fit
  2063. 1:38:47forward neural network that allows for
  2064. 1:38:49complex feature learning
  2065. 1:38:52and all of that goes and then you have
  2066. 1:38:54some linear layer and then a softmax
  2067. 1:38:58layer that will turn these
  2068. 1:39:00representations into a probability
  2069. 1:39:03distribution over the space of your
  2070. 1:39:05words of your of your tokens over the
  2071. 1:39:07vocabulary space to predict the next
  2072. 1:39:10word.
  2073. 1:39:11And then what happens here is that we
  2074. 1:39:13will see in the next lectures what could
  2075. 1:39:16be heruristics to pick the next word.
  2076. 1:39:18But let's say here we pick like the max.
  2077. 1:39:21So you pick the max, you know what word
  2078. 1:39:23we have predicted and then you put it
  2079. 1:39:25back as an input to the decoder and you
  2080. 1:39:28do the exact same process again. So here
  2081. 1:39:33we put beginning of sequence, you get
  2082. 1:39:36and then you you get the next token
  2083. 1:39:40which is the equivalent of teddy bear
  2084. 1:39:42[snorts] and so on
  2085. 1:39:44and then you get at the end your
  2086. 1:39:48your your sequence in the target
  2087. 1:39:50language and then you do that until you
  2088. 1:39:53hit an end of sequence token. This is
  2089. 1:39:57where you know that you should stop the
  2090. 1:39:58translation process.
  2091. 1:40:01Okay, so this is how we start from a
  2092. 1:40:05from a sentence in a given language and
  2093. 1:40:06we end up in one in the target language.
  2094. 1:40:10So
  2095. 1:40:12any questions on this so far?
  2096. 1:40:18Yep.
  2097. 1:40:20The comment here is it look it all looks
  2098. 1:40:22complicated. If you were to boil down
  2099. 1:40:24exactly what makes it work, what would
  2100. 1:40:26it be? So attention is all you need. The
  2101. 1:40:29title of the paper translates a bit the
  2102. 1:40:32secret sauce. So the attention layer
  2103. 1:40:36here is key. You we're going to see in
  2104. 1:40:38the next lectures that actually a lot of
  2105. 1:40:40these things are dropped and we rely on
  2106. 1:40:43a subset of these components that we
  2107. 1:40:47repeat again and again. So uh this
  2108. 1:40:49attention layer is is the key. And then
  2109. 1:40:51the second thing is this feed forward
  2110. 1:40:53neural network where most of the
  2111. 1:40:55parameters of the network resides. So if
  2112. 1:40:57you were to calculate exactly the
  2113. 1:40:59parameters of your model, you realize
  2114. 1:41:01that these contain most of the capacity
  2115. 1:41:04and this is where the learning happens.
  2116. 1:41:06So if you were to ask me these two and
  2117. 1:41:08then the rest are just tricks to better
  2118. 1:41:12learn to yeah improve it and then of
  2119. 1:41:15course the quality of the data which is
  2120. 1:41:17another layer of complexity.
  2121. 1:41:20Yep.
  2122. 1:41:22Yeah. So uh the question is can you talk
  2123. 1:41:24more about the masked part? So it's a
  2124. 1:41:29computational trick where you have a
  2125. 1:41:31triangular matrix that will mask some
  2126. 1:41:34connections of your self attention layer
  2127. 1:41:38and at training time it prevents
  2128. 1:41:40connections that you would you shouldn't
  2129. 1:41:43know to be made. So yeah that that's the
  2130. 1:41:47that's the gist of it.
  2131. 1:41:49Yeah exactly. So yeah, how the question
  2132. 1:41:51is how it relates to soft max. So you
  2133. 1:41:53have minus infinities and then this will
  2134. 1:41:54be zero. Like soft max of minus infinity
  2135. 1:41:57would be zero. This is how it relates.
  2136. 1:42:00Yeah.
  2137. 1:42:01Yeah. But these are more computational
  2138. 1:42:04tricks. I think the main thing to have
  2139. 1:42:07in mind is to forget about all
  2140. 1:42:10connections from a given token and all
  2141. 1:42:12the ones that succeeded.
  2142. 1:42:14I think that's uh you know good enough
  2143. 1:42:16as a mental model.
  2144. 1:42:19Yeah.
  2145. 1:42:20Okay. Awesome. Yeah. The question here
  2146. 1:42:23is on various uses of softmax. So the
  2147. 1:42:27ones that are used in the the self
  2148. 1:42:30attention layers and the cross attention
  2149. 1:42:32layers have a different function than
  2150. 1:42:34the one at the last layer. You should
  2151. 1:42:37see the ones in the attention layer as a
  2152. 1:42:39projection of the query over the space
  2153. 1:42:41of keys. So what we do is projecting the
  2154. 1:42:45representation of a given token across
  2155. 1:42:48tokens whereas the last softmax layer
  2156. 1:42:51has a different function. It's one that
  2157. 1:42:53tries for you to predict the next token.
  2158. 1:42:57So in some sense uh yeah so I I do get
  2159. 1:43:00the I think it's a great point that
  2160. 1:43:03we're using like several times this
  2161. 1:43:05function but it's for different things.
  2162. 1:43:09I think that was Yep. So the question is
  2163. 1:43:12why is the transition not having
  2164. 1:43:14beginning of sequence? It does. Yeah,
  2165. 1:43:16it's the first token here. Oh yeah. So
  2166. 1:43:19the first token here is a placeholder
  2167. 1:43:22for you to predict the next token that
  2168. 1:43:24comes after it. So it doesn't come at
  2169. 1:43:26the output of the decoder. It's just the
  2170. 1:43:28input of the decoder. And then what you
  2171. 1:43:30get as the output of the decoder that
  2172. 1:43:32you should watch out is end of sequence
  2173. 1:43:35because this is where you should stop.
  2174. 1:43:38Yeah.
  2175. 1:43:40Okay. Awesome. And then with all that, I
  2176. 1:43:43want to tell you that
  2177. 1:43:46what we presented today is just the
  2178. 1:43:48beginning. We're just in 2017 at this
  2179. 1:43:51point and there has been, as I'm sure
  2180. 1:43:54you know, many uses of this technology
  2181. 1:43:57that now powers all these chatbots that
  2182. 1:44:00we use. So we're going to cover how we
  2183. 1:44:02train such models in the next few
  2184. 1:44:05lectures. And then in the second part of
  2185. 1:44:07the class, we will tackle how these can
  2186. 1:44:11power the agents that we interact and
  2187. 1:44:13use today and how it can be used in
  2188. 1:44:16several systems. And with that, thank
  2189. 1:44:19you for your attention and I hope you
  2190. 1:44:21have a great weekend.

About this transcript

This page contains the full transcript of YouTube transcript (114i2Kz-LZA) , generated from the public captions YouTube serves with the video. The transcript has 13,846 words across 2,190 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.