YouTube2Text

Transformer Arch Decoder Inference [with Paper & Pen] -How Transformers ACTUALLY Generate Text Part3 — Transcript

by yogesh murumkar · 9,388 words · 1,766 segments · language en · Watch on YouTube

Full transcript

  1. 0:01Hello everyone. This is Yogesh Murumkar.
  2. 0:04In this video, we'll discuss the
  3. 0:05Transformer architecture during
  4. 0:07inference or prediction phase.
  5. 0:10Before this, in the last two videos, we
  6. 0:13have already discussed about encoder and
  7. 0:15decoder architecture during training
  8. 0:17phase.
  9. 0:18And for your reference, the links for
  10. 0:20those videos are given in description.
  11. 0:24And to explain decoder architecture
  12. 0:26during inference phase,
  13. 0:28I'll use all these diagrams. You can
  14. 0:32have a look at all these diagrams
  15. 0:35one by one.
  16. 0:37Which will make the things uh
  17. 0:39easy and simple for understanding.
  18. 0:44So, you see everyone, these are the
  19. 0:45detailed diagrams which I'll be using.
  20. 0:48And the link for downloading all these
  21. 0:51diagrams is also given in the
  22. 0:54description.
  23. 0:56So, you can see,
  24. 0:57this is what I'll be
  25. 1:00using to explain you all the concepts.
  26. 1:05Fine?
  27. 1:08So,
  28. 1:10to start with everyone,
  29. 1:13this is our Transformer architecture
  30. 1:14diagram.
  31. 1:16Okay?
  32. 1:17Before starting with the explanation of
  33. 1:18Transformer decoder during inference
  34. 1:20phase,
  35. 1:21I'll recommend you,
  36. 1:23please refer previous two videos on
  37. 1:26Transformer encoder and Transformer
  38. 1:28decoder architecture, where you can get
  39. 1:30the complete understanding of how
  40. 1:32encoder
  41. 1:33this particular part and how decoder
  42. 1:35this particular part works during
  43. 1:38training. The link for both the videos
  44. 1:40is given in description.
  45. 1:43Now,
  46. 1:45we have not
  47. 1:47yet discussed how does the Transformer
  48. 1:50architecture behave during inference
  49. 1:53time.
  50. 1:56Or during prediction time. Inference
  51. 1:58means prediction. So, the topic of
  52. 2:01today's video is exactly this.
  53. 2:04Since we have read the entire
  54. 2:06architecture and got the idea of all the
  55. 2:08components, in this video, we will
  56. 2:10discuss that once your Transformer model
  57. 2:13is trained and after that, when you do
  58. 2:16prediction through it, how does the
  59. 2:18Transformer architecture behave during
  60. 2:20that prediction time?
  61. 2:22So, the topic of today's video is
  62. 2:25Transformer
  63. 2:27during inference.
  64. 2:29Okay? I really hope you understand the
  65. 2:31plan.
  66. 2:32Now, I'll click quickly tell you
  67. 2:35setup of this video. The setup is very
  68. 2:37simple.
  69. 2:38You can assume that
  70. 2:40uh let's say
  71. 2:41you had to solve a machine translation
  72. 2:43task.
  73. 2:44And the translation task is very simple,
  74. 2:46which is English to
  75. 2:48Hindi translation.
  76. 2:50So, for example,
  77. 2:52you have data set given.
  78. 2:55Okay? So, we have a machine translation
  79. 2:57task, which will be
  80. 2:59converting English sentence to Hindi
  81. 3:01sentence.
  82. 3:02Okay? So, you have the data set that
  83. 3:04looks something like this.
  84. 3:08Fine. You have English sentence in your
  85. 3:10input and Hindi sentence in your
  86. 3:13output.
  87. 3:15And you have many such rows.
  88. 3:19As you can see, let's say here the first
  89. 3:21English sentence is how are you? The
  90. 3:23corresponding Hindi sentence is aap
  91. 3:25kaise ho? Then thank you, dhanyawad.
  92. 3:28And so on.
  93. 3:30Okay? Like this,
  94. 3:32you have a lot of rows.
  95. 3:34Fine.
  96. 3:36Now,
  97. 3:37for now, I have shown only three rows,
  98. 3:40but you can assume let's say you have uh
  99. 3:4210,000 rows.
  100. 3:45Okay? Let's say you have 10,000 rows.
  101. 3:49And you have a Transformer architecture.
  102. 3:52Right? This particular transformer
  103. 3:54architecture. So,
  104. 3:56what have you done with this particular
  105. 3:59data?
  106. 4:00This particular data, you have trained
  107. 4:02this transformer architecture
  108. 4:05this particular transformer architecture
  109. 4:07on this data.
  110. 4:09Which is having 10,000 rows.
  111. 4:12Okay? Meaning, you have completed
  112. 4:15the entire training part.
  113. 4:18Okay? And all the weights and bias
  114. 4:21values have been obtained. So, your
  115. 4:23transformer architecture is ready to do
  116. 4:26predictions.
  117. 4:29Fine?
  118. 4:30And now, let's say you have asked it a
  119. 4:33question.
  120. 4:35Let's say I asked this English sentence.
  121. 4:38This one.
  122. 4:40After the training on this entire data
  123. 4:42input and the output that is English to
  124. 4:43Hindi sentence, let's say I ask it
  125. 4:46a question.
  126. 4:48Okay? I have I have this English
  127. 4:50sentence.
  128. 4:51We are ready.
  129. 4:53So, tell me tell me
  130. 4:56what will be its Hindi translation?
  131. 4:58We are ready. What will be its
  132. 5:00What will be its Hindi translation? This
  133. 5:02is what let's say I have asked.
  134. 5:04And now, we will discuss step by step
  135. 5:07what happens when you put this sentence
  136. 5:12in this particular transformer
  137. 5:14architecture.
  138. 5:16But during prediction time.
  139. 5:18Okay? So, this is the setup that we are
  140. 5:20going to start with this video.
  141. 5:24Fine?
  142. 5:26And uh
  143. 5:27although
  144. 5:30I have made a detailed diagram of how
  145. 5:32the transformer architecture behaves
  146. 5:35during inference.
  147. 5:37As you can see here, everyone.
  148. 5:39This is the detailed diagram to show you
  149. 5:41how transformer architecture behave
  150. 5:42during
  151. 5:43inference.
  152. 5:46Okay? That is nothing but uh
  153. 5:48prediction time.
  154. 5:50But before I deep dive a deep dive into
  155. 5:52this particular diagram,
  156. 5:54I want to simplify some things for you
  157. 5:57because
  158. 5:58if I do that, then when we discuss this
  159. 6:01particular diagram, you will have an
  160. 6:04easier understanding
  161. 6:06of all these concepts.
  162. 6:08Right? This is This is the diagram here
  163. 6:09you can see which we'll be using now.
  164. 6:12So,
  165. 6:13in simple terms, the Transformer
  166. 6:15architecture is divided into two parts
  167. 6:18as we are already aware about even,
  168. 6:20right?
  169. 6:21Encoder
  170. 6:22and decoder.
  171. 6:24Now, if you talk about training time and
  172. 6:26inference time,
  173. 6:28okay? So, if you talk about this
  174. 6:30training time and inference time,
  175. 6:33>> [clears throat]
  176. 6:35>> your encoder
  177. 6:37See this? Your encoder
  178. 6:42it behaves
  179. 6:43same.
  180. 6:45Okay? Your encoder behaves exactly the
  181. 6:48same way
  182. 6:49in both the stages, whether it is
  183. 6:51training or inference.
  184. 6:56Fine? The behavior of the encoder
  185. 6:59is what
  186. 7:00uh it is during
  187. 7:03training. It's exactly same during
  188. 7:05inference as well. That's why I have
  189. 7:06written same same for encoder.
  190. 7:09So, since the encoder's behavior is same
  191. 7:12in both the stages, that is training and
  192. 7:14inference, we do not need to discuss the
  193. 7:16encoder in today's video.
  194. 7:19Okay? And anyway, we have already
  195. 7:21discussed it in the previous videos.
  196. 7:23But the main difference comes
  197. 7:26on the decoder side.
  198. 7:28The decoder behaves differently during
  199. 7:30training
  200. 7:31and inference time.
  201. 7:34During training time,
  202. 7:36I have the output sentence.
  203. 7:38Okay? During this, we have output
  204. 7:40sentence, that is in our case Hindi
  205. 7:41sentence, All the words of which I
  206. 7:43already know beforehand.
  207. 7:45I can send all of them
  208. 7:47together to the decoder at once. So, our
  209. 7:50decoder behaves in a non
  210. 7:52auto-regressive manner.
  211. 7:55During training
  212. 7:57during training, decoder behaves in non
  213. 8:00auto-regressive manner.
  214. 8:03Okay? We discussed this in the masked
  215. 8:06self-attention during last video of
  216. 8:08decoder.
  217. 8:09Fine? Whereas
  218. 8:12during prediction time, that is
  219. 8:14inference time, we do not have the
  220. 8:16output sentence. We have to predict it,
  221. 8:18right? So, here we do
  222. 8:22one by one prediction in multiple time
  223. 8:24steps. So, here your decoder behaves in
  224. 8:27auto-regressive manner. This is the main
  225. 8:30summary that uh you should already know.
  226. 8:35Fine? So, to summarize, we can say the
  227. 8:38encoder behaves exactly the same way
  228. 8:41during training and inference time.
  229. 8:47Okay? There is nothing new
  230. 8:49to learn here.
  231. 8:51But, the decoder behaves in a non
  232. 8:53auto-regressive manner during training
  233. 8:55time, but behaves in an auto-regressive
  234. 8:58manner during inference time.
  235. 9:01Which means going forward, our focus
  236. 9:03will be more on decoder's working.
  237. 9:07Okay?
  238. 9:08Now, coming to this particular diagram
  239. 9:09again,
  240. 9:12as I've told you, this is a detailed
  241. 9:13diagram and which which will be
  242. 9:14following everyone.
  243. 9:16So, let us start with our example.
  244. 9:18So,
  245. 9:20as I already shown you, what was our
  246. 9:21example? Our example was
  247. 9:24"We are ready." Now, let's say we asked
  248. 9:27it, "What will be the Hindi translation
  249. 9:29of this English sentence?" So, let us
  250. 9:31start with our
  251. 9:33simple example, "We are ready." Please
  252. 9:35understand, okay? Training is already
  253. 9:37done on this data. Let's say we assume
  254. 9:39that there were 10,000 rows, English to
  255. 9:41Hindi. Now you are asking, "What will be
  256. 9:43the Hindi translation of we are ready?"
  257. 9:47Fine. So, let us start with our example.
  258. 9:49As you can see here, I use the same
  259. 9:51example, we are ready.
  260. 9:55Okay. So, we have this query sentence in
  261. 9:58English, we are ready, and
  262. 10:01we are being told that
  263. 10:04you have trained the transform
  264. 10:05architecture on a lot of data. So, using
  265. 10:08that, generate the Hindi translation of
  266. 10:11this English sentence.
  267. 10:14First, you send this sentence to the
  268. 10:17encoder. The encoder will behave exactly
  269. 10:19the way it did during training.
  270. 10:23And input embedding, as you can see.
  271. 10:28Okay. So, I think you know
  272. 10:30how how the encoder basically works. It
  273. 10:32will behave exactly the same way it did
  274. 10:34during training. So, what we can say is
  275. 10:37you tokenize this we are ready sentence.
  276. 10:40You tokenize this
  277. 10:42into
  278. 10:43separate separate tokens. Like, we will
  279. 10:45be separate token, are will be separate
  280. 10:47token, and ready will be separate token.
  281. 10:51And then you calculate the embeddings of
  282. 10:53all three tokens.
  283. 10:55So, see everyone, something like this.
  284. 11:00Okay. Tokenization
  285. 11:02uh
  286. 11:04as even we have already discussed. So,
  287. 11:06after that, we will be talking about uh
  288. 11:10all these steps. So, something like this
  289. 11:12we'll have to do.
  290. 11:13Right? After doing uh
  291. 11:15tokenization, right? Embedding, right?
  292. 11:18So, we'll we will have to check out this
  293. 11:21particular diagram, also.
  294. 11:23So,
  295. 11:24we will be separate token, are will be
  296. 11:26separate token, and ready will be
  297. 11:27separate token.
  298. 11:28And then what you do? Then you calculate
  299. 11:30the embeddings of all three tokens. So,
  300. 11:32you see through through
  301. 11:34input embedding
  302. 11:37the embeddings of all these separate
  303. 11:39tokens will be calculated. So, obviously
  304. 11:40you know before embedding tokenization
  305. 11:43will happen. And I think
  306. 11:46And I think everyone you know
  307. 11:50how these [clears throat] things are
  308. 11:51basically done. We already discussed
  309. 11:52this in the previous videos.
  310. 11:56Then you add positional encoding to
  311. 11:59these embeddings.
  312. 12:01Then you send it to
  313. 12:03multi-head attention
  314. 12:05to extract the context.
  315. 12:07Then you send it to feed forward neural
  316. 12:10network
  317. 12:12just to introduce non-linearity. And in
  318. 12:14between all this
  319. 12:16what we do is we do
  320. 12:18add and normalize here as you can see.
  321. 12:21Okay, encoder part.
  322. 12:22And how many times you do all this work?
  323. 12:26Six times because we know everyone the
  324. 12:28the value of this n is six.
  325. 12:32Right? Because we have
  326. 12:33six encoder blocks like this. And
  327. 12:35finally the output from the sixth
  328. 12:37encoder is what you get here.
  329. 12:44Okay? Or I can say this is the output
  330. 12:46this is the output driven from the sixth
  331. 12:48encoder block.
  332. 12:50So, contextual embedding for we
  333. 12:52for are and for ready. Like these will
  334. 12:55be vectors given, okay? These will be
  335. 12:56vectors. Just for understanding purpose
  336. 12:57I have written like this we are ready.
  337. 13:00See, all these steps in encoder we have
  338. 13:02already discussed in previous video. And
  339. 13:04the link for it is given in the
  340. 13:05description. If you want
  341. 13:07you can refer it for revision.
  342. 13:11Moving forward
  343. 13:13So, for every token that you have that
  344. 13:16is we are ready
  345. 13:18you get a corresponding context vector.
  346. 13:21For we you get a context vector, for are
  347. 13:24you get a context vector, and for ready
  348. 13:26you get a context vector.
  349. 13:28So, we have reached a stage where our
  350. 13:30transformer has understood our English
  351. 13:32sentence. Now, from here, the work of
  352. 13:35the decoder begins.
  353. 13:37Which has to print the output that is
  354. 13:41which has to print out the Hindi
  355. 13:42sentence one by one.
  356. 13:45So, now that encoder's work is done, we
  357. 13:49will talk about decoder. The behavior of
  358. 13:51the decoder during
  359. 13:54training stage, during inference stage,
  360. 13:57it is different.
  361. 14:00Okay? So, at this point,
  362. 14:02we have processed the output from the
  363. 14:03encoder.
  364. 14:05We have our context vectors.
  365. 14:08And now the decoder will start its
  366. 14:10processing. You will notice
  367. 14:13here that although
  368. 14:15we have drawn only one encoder,
  369. 14:19but here you may see multiple
  370. 14:21decoders. 1 2 3 4. One encoder, but
  371. 14:24multiple decoders.
  372. 14:27Okay?
  373. 14:28This is because the processing in the
  374. 14:30decoder during inference happens step by
  375. 14:33step. First step, second step, third
  376. 14:35step, fourth step.
  377. 14:37And at every step, you get one word
  378. 14:39output like this.
  379. 14:41Like hum tayar hai.
  380. 14:43And then this is
  381. 14:45end of sentence.
  382. 14:48Okay? At every step, you get
  383. 14:50one word
  384. 14:51as output.
  385. 14:53So, the first decoder you will see give
  386. 14:55you the first word.
  387. 14:57The second will give you the second and
  388. 14:58so on.
  389. 14:59So, let us now deep down deep dive into
  390. 15:02how the decoder is processing the
  391. 15:04output. To start the decoder processing,
  392. 15:07you send a special token into the
  393. 15:10decoder.
  394. 15:12So, you see, this SOS is what I'm
  395. 15:14talking about. SOS is a special token,
  396. 15:17start of sentence.
  397. 15:22Okay?
  398. 15:22>> [clears throat]
  399. 15:23>> This special token you call SOS, start
  400. 15:26of sentence, or simply start.
  401. 15:29As soon as the decoder receives this,
  402. 15:30the decoder understands that it now has
  403. 15:33to start its work.
  404. 15:36Fine?
  405. 15:37Now, to explain the process in detail,
  406. 15:39what I will do is I will use this
  407. 15:40particular diagram.
  408. 15:44Fine?
  409. 15:45I hope so it is clearly visible.
  410. 15:47So, here
  411. 15:50in our SOS token,
  412. 15:53okay, start of sentence or start,
  413. 15:56right? This is our SOS token. Since this
  414. 15:59is currently an English word, our
  415. 16:00machine cannot understand it. So, the
  416. 16:02first thing you do is vectorization.
  417. 16:06Or vectorize this word. Convert it to
  418. 16:08numbers.
  419. 16:10And this work,
  420. 16:11as you know, will be done by embedding
  421. 16:14layer.
  422. 16:15Okay? This will be done by embedding
  423. 16:17layer. As soon as this word goes into
  424. 16:19the embedding layer, you get a 512
  425. 16:22dimension vector.
  426. 16:25Okay? This is
  427. 16:26Basically, this is 512 dimension. This
  428. 16:28will give you 512 dimensional vector.
  429. 16:32Okay?
  430. 16:33>> [clears throat]
  431. 16:34>> Right after that comes the positional
  432. 16:36encoding layer.
  433. 16:37You see? This positional encoding layer.
  434. 16:39So, we got this vector, 512 dimension
  435. 16:41vector, and then after that, we apply
  436. 16:44positional encoding, or positional
  437. 16:46encoding is applied.
  438. 16:51Now, the job of positional encoding is
  439. 16:53to encode positions in the embeddings.
  440. 16:56Right?
  441. 16:57Encode the positions in your
  442. 17:00embeddings. Although, here it is not
  443. 17:02necessary because we have only one
  444. 17:04token, but since we already we always
  445. 17:06apply positional encoding, we will do it
  446. 17:08here, too.
  447. 17:10So, we add the positional encoding
  448. 17:13vector to this embedding vector.
  449. 17:15As a result, we finally get our input
  450. 17:17vector, which we call X1.
  451. 17:19And this X1 is finally
  452. 17:21what goes into the
  453. 17:23decoder.
  454. 17:26Okay? So,
  455. 17:29it means everyone, I want I want to say
  456. 17:31see this
  457. 17:33SOS we we have passed, embedding is
  458. 17:35done, positional encoding is applied,
  459. 17:37and then now we are here.
  460. 17:39Okay? We are here.
  461. 17:41In the first decoder.
  462. 17:43Now, as per the discussion in the video
  463. 17:45of second part of transformer decoder
  464. 17:47architecture, if you remember, the
  465. 17:49decoder has mainly three blocks.
  466. 17:53Which are those anyone? The first block,
  467. 17:55as you can see,
  468. 17:57is the masked attention block, this one.
  469. 18:00Second is the cross attention,
  470. 18:03this one, and third is the feed forward
  471. 18:06neural network, this one.
  472. 18:09Okay? We have already discussed about
  473. 18:11this one as well in the last video.
  474. 18:13And if you see in between, there are
  475. 18:16add and norm.
  476. 18:18Right?
  477. 18:19Add and normalization layer. So, first
  478. 18:21we are going to send our input X1.
  479. 18:24We were here, right? So, we are going to
  480. 18:25send our input X1 to the masked self
  481. 18:29attention block.
  482. 18:31Okay? That is this one.
  483. 18:35Now, [clears throat]
  484. 18:36inside this
  485. 18:38self attention block, okay? This is our
  486. 18:40X1 input. Now, we are going to send it
  487. 18:42to the masked self attention block.
  488. 18:46Okay? Inside the attention block, there
  489. 18:48are three matrices,
  490. 18:50WQ, WK, WV.
  491. 18:55You do dot product of X1
  492. 18:59with WQ to get a query vector Q.
  493. 19:03Then dot product of X1 with WK to get
  494. 19:07key vector,
  495. 19:09this one. And similarly, dot product of
  496. 19:11X1 with WV to get value vector, that is
  497. 19:14V.
  498. 19:16Then, you do a dot product between your
  499. 19:19query and key vector.
  500. 19:22Okay? So, dot product between this query
  501. 19:26and
  502. 19:27key vector.
  503. 19:30Which gives you a scalar.
  504. 19:33You do scaling on that particular scalar
  505. 19:36and then apply soft max, which which
  506. 19:38basically gives you attention score.
  507. 19:40Let's say this is 0.9.
  508. 19:42Okay? As you can see, let's say it is
  509. 19:440.9. So, this attention score represents
  510. 19:47how similar your start of sentence token
  511. 19:50is with itself. Since we have only one
  512. 19:52token, we are extracting the similarity
  513. 19:54of the token with itself.
  514. 19:58And then,
  515. 19:59we multiply that similarity with the
  516. 20:01value vector. You see this
  517. 20:03multiplication operation? We multiply
  518. 20:04that similarity with the
  519. 20:08uh value vector.
  520. 20:11Okay? Which gives you
  521. 20:14uh
  522. 20:16let's say uh
  523. 20:18another vector, but how similar?
  524. 20:23As I've told you this attention score
  525. 20:25represents how similar your start of
  526. 20:26sentence token is with itself.
  527. 20:29Right? Because we have only one token,
  528. 20:31we are extracting the similarity of the
  529. 20:32token with itself.
  530. 20:34Whatever the similarity we have got,
  531. 20:37right?
  532. 20:39We multiply that similarity with the
  533. 20:41value vector, that is this one.
  534. 20:43See, all vectors you see are of 512
  535. 20:47dimensions.
  536. 20:50When you multiply a scalar with a
  537. 20:52vector,
  538. 20:53you get back a vector.
  539. 20:56And we are calling this as a Z1. So, we
  540. 20:58we have done this multiplication and we
  541. 21:00got this particular vector Z1, which is
  542. 21:02also
  543. 21:03a 512 dimension vector.
  544. 21:06So, at this point we have completed the
  545. 21:08masked self-attention processing.
  546. 21:12Okay?
  547. 21:13That is nothing but this one given.
  548. 21:16This is done and now we are here.
  549. 21:19Next
  550. 21:20Next is the
  551. 21:22add and norm layer.
  552. 21:24Okay? So, what you do is
  553. 21:27you take this Z1, this is Z1, you take
  554. 21:29this Z1 and add it back with X1 through
  555. 21:32a residual connection. You see this
  556. 21:34residual connection?
  557. 21:35Right? This residual connection. And And
  558. 21:38why are we adding it again because you
  559. 21:39see
  560. 21:40because you see
  561. 21:41this residual connection. Right? This
  562. 21:44one is going here. So, exactly same
  563. 21:46thing I'm showing you with the help of
  564. 21:48this particular diagram.
  565. 21:50Okay?
  566. 21:51Through this residual connection we have
  567. 21:54X1 here.
  568. 21:56So, you take this Z1
  569. 21:59and add it back with X1
  570. 22:01through through residual connection.
  571. 22:04By adding both
  572. 22:05X1
  573. 22:07and Z1 we get Z1'.
  574. 22:10All these vectors are again of 512
  575. 22:14dimensions.
  576. 22:16Okay? Finally, you send this vector to
  577. 22:18layer normalization because there was
  578. 22:20add a norm, so we send this to layer
  579. 22:22normalization.
  580. 22:25And finally, you get Z1 norm or Z1
  581. 22:28normalized.
  582. 22:31So, everyone
  583. 22:32we are at this particular point now. So,
  584. 22:36we have done this and we are at this
  585. 22:37point now.
  586. 22:38Okay? We are at this point.
  587. 22:41Next, we will go to our cross-attention,
  588. 22:44that is this one. Cross-attention block.
  589. 22:46Okay? Cross-attention is a very
  590. 22:48important aspect of this architecture
  591. 22:50because its job is to calculate
  592. 22:51attention scores between two given
  593. 22:53sequences.
  594. 22:56Here we take sequence from the decoder
  595. 22:59which has only one token. You see this
  596. 23:01one.
  597. 23:03Right? Which has only one token.
  598. 23:05That is SOS.
  599. 23:07And
  600. 23:08we also take encoder sequence.
  601. 23:13You see this this arrow? This is coming
  602. 23:15from here. We also take encoder sequence
  603. 23:18even.
  604. 23:20Which is we are ready.
  605. 23:23Whose contextual vectors we have. We
  606. 23:25calculate the attention scores between
  607. 23:27these two sequences.
  608. 23:29One coming from here and one coming from
  609. 23:30the
  610. 23:31decoder part. In a way, we want to find
  611. 23:34out how our SOS is similar to we, how
  612. 23:38much to are, and how much to ready.
  613. 23:41We want to find out the similarity of
  614. 23:42SOS with all of them.
  615. 23:47This entire calculation happens inside
  616. 23:50the cross attention block. This one.
  617. 23:54Okay?
  618. 23:55Two points are coming.
  619. 23:57One and two.
  620. 23:59One from the Like two points means I
  621. 24:00mean to say, one is coming from here,
  622. 24:02one is coming from here, and one
  623. 24:04basically coming from the
  624. 24:06left side, that is this encoder. You see
  625. 24:08this this arrow? Right? Encoder.
  626. 24:10So, one and two. These two things are
  627. 24:13basically coming.
  628. 24:16Moving forward,
  629. 24:20let me explain you with the help of this
  630. 24:22particular diagram also.
  631. 24:24So,
  632. 24:25at this point,
  633. 24:27as I've told you earlier, you know, we
  634. 24:29got this Z1 normalized.
  635. 24:31Right? We got this particular
  636. 24:33uh
  637. 24:34Z1 norm from the decoder.
  638. 24:36The cross attention block is attention
  639. 24:38block. So, inside it, there are
  640. 24:41three matrices again. So, I will write
  641. 24:43down this Z1 norm here. Okay? This Z1
  642. 24:44norm is written here, as you can see.
  643. 24:49Okay? And inside this particular
  644. 24:51attention cross attention even, as it's
  645. 24:54attention block, so inside this, there
  646. 24:56are three matrices.
  647. 24:58W
  648. 24:59Q W K and WV.
  649. 25:02The query vector is extracted from the
  650. 25:06decoder sequence. This query vector is
  651. 25:07extracted from decoder sequence, that is
  652. 25:09Z1 now.
  653. 25:12And the keys and the values vectors are
  654. 25:13extracted from the encoder sequence.
  655. 25:15This is This is basically coming from
  656. 25:17encoder view, okay?
  657. 25:18This is coming from where? This is
  658. 25:20coming from encoder.
  659. 25:25So, remember this.
  660. 25:29Keys and values vector are extracted
  661. 25:31from the encoder sequence. The query
  662. 25:33vector is extracted from decoder
  663. 25:35sequence.
  664. 25:36So, we take the vector Z1 now
  665. 25:40and dot product with WQ
  666. 25:43to get a query vector of SOS. This is
  667. 25:45the query vector of SOS given Q.
  668. 25:48Then these
  669. 25:50>> [clears throat]
  670. 25:50>> three vectors, we are ready.
  671. 25:54This also go into the cross attention
  672. 25:56block, that is this one. This is cross
  673. 25:57attention block. See, I have shown you
  674. 25:58already.
  675. 26:00These three also go inside cross
  676. 26:01attention block. Each does dot product
  677. 26:04with WK and WV.
  678. 26:07When V goes
  679. 26:10when V goes
  680. 26:13Okay? All the vector of contextual
  681. 26:15vector of V goes
  682. 26:17it takes dot product with WK
  683. 26:21and WV
  684. 26:23giving us
  685. 26:24the
  686. 26:26key and value. This K and V means key
  687. 26:29and value vectors for V.
  688. 26:33Similarly, everyone
  689. 26:36R will go and there will be a dot
  690. 26:38product with
  691. 26:40WK and WV and similarly for ready, also
  692. 26:42will go and there will be dot product
  693. 26:44with WK and WV. So, we'll get
  694. 26:47key and value vectors for R and key and
  695. 26:48value vectors for
  696. 26:50ready as well.
  697. 26:52Okay?
  698. 26:53So, once you see here we have the key
  699. 26:57value vectors for
  700. 26:58we are ready. And we have query vector
  701. 27:01for start of sentence.
  702. 27:04Now, what you do is
  703. 27:07you do dot product between the query
  704. 27:09vector
  705. 27:10and all the key vectors. Key vectors of
  706. 27:14we are ready.
  707. 27:15So, you have one query vector, but three
  708. 27:18key vectors. So, we get three scalars,
  709. 27:21w1, w2, w3.
  710. 27:24We scale this by square root of d, then
  711. 27:27apply softmax, and finally
  712. 27:29what we do is we multiply w1
  713. 27:33as you can see, we multiply w1 with the
  714. 27:36value vector of v.
  715. 27:38So, this is value vector of this what I
  716. 27:39showed, w1 with value vector of v, plus
  717. 27:42w2 with value vector of r, and w3 with
  718. 27:45value vector of
  719. 27:46ready.
  720. 27:49Okay?
  721. 27:51From this, we get cross attention output
  722. 27:54vector, and let's say it is represented
  723. 27:57as zc1. C for cross attention.
  724. 28:02So,
  725. 28:04till now,
  726. 28:06you can say we have
  727. 28:10reached here. Okay? We have reached here
  728. 28:13again.
  729. 28:15Here.
  730. 28:18Now, after this, there is also add a
  731. 28:21norm, as you can see in this diagram.
  732. 28:24So, what we will do is we will add the
  733. 28:27zc1
  734. 28:30with z1 norm. And z1 norm is coming
  735. 28:34through a residual connection.
  736. 28:36As you can see, clearly see here, right?
  737. 28:39And which was there in the original
  738. 28:40transformer architecture, also.
  739. 28:42So, then we normalize through
  740. 28:45So, so after adding these two, z1 norm
  741. 28:47and ZC1, we got ZC1 dash. Okay, which is
  742. 28:50also 512 dimension vector.
  743. 28:52And then we normalize through layer
  744. 28:54normalization. And finally, everyone, we
  745. 28:56got ZC1 norm.
  746. 28:59Okay? So, now
  747. 29:02in the in our diagram, we are actually
  748. 29:06at this particular point. So,
  749. 29:09this add a norm is done, right? So, we
  750. 29:11are here.
  751. 29:13So, we are here, then.
  752. 29:14Okay? We are here.
  753. 29:17At this point.
  754. 29:18So, at this point, the next block is
  755. 29:20what? Feed forward neural network block.
  756. 29:23This is the feed forward neural network
  757. 29:25block that has neural network inside it.
  758. 29:28So, what we do is we send the vector to
  759. 29:30the feed forward neural network. It does
  760. 29:32a non-linear transformation, and then we
  761. 29:35apply add a norm layer again.
  762. 29:38Let me show you that.
  763. 29:41Okay, so we got ZC1 norm here.
  764. 29:43And after this feed forward neural
  765. 29:45network is what I will be showing you.
  766. 29:47So, you see, everyone, ZC1 norm is here.
  767. 29:50And as I've told you that we send the
  768. 29:52vector to the feed forward neural
  769. 29:53network block. It does a non-linear
  770. 29:56transformation, and then we apply add a
  771. 29:58norm layer again. So, this is our feed
  772. 30:01forward neural network architecture, you
  773. 30:03can say. Here you can see we have two
  774. 30:04layers, one and two.
  775. 30:06So, this particular layer is having 2048
  776. 30:09neurons.
  777. 30:10This particular layer is having 512
  778. 30:12neurons.
  779. 30:13Here we are we have a rectified linear
  780. 30:16unit activation function, and here we
  781. 30:18have linear activation function.
  782. 30:20So,
  783. 30:23we do matrix multiplications, and from
  784. 30:25this we get our output vectors.
  785. 30:29Then we add and normalize. We send the
  786. 30:32vectors, uh do addition, and apply layer
  787. 30:35normalization.
  788. 30:37Fine? So, I think uh you know, everyone,
  789. 30:38how basically this works. So, this can
  790. 30:41take 512 dimension vector,
  791. 30:43right so let's see if I have Z Z 7 norm
  792. 30:45so what will happen is it will go 1 1
  793. 30:48cross 512 dimension vector I will have
  794. 30:50and these weights will be what 512 cross
  795. 30:532048 so
  796. 30:56512 cross 2048
  797. 30:59that means what 512 512 will match you
  798. 31:01will get 1 cross 2048 right and these
  799. 31:04weights will be what these weights will
  800. 31:06be like 2048 512 so 2048 cross 512
  801. 31:10right so here we have got 1 cross 2048
  802. 31:142048 cross 512 weights are there this
  803. 31:16this will match and finally everyone
  804. 31:18will will get a vector of size 1 cross
  805. 31:20512 that means one vector of size 512
  806. 31:23dimension
  807. 31:25this is how it is going to happen which
  808. 31:26we have even already discussed
  809. 31:28okay so we completed one decoder block
  810. 31:31and you can say that we have reached
  811. 31:34this particular point again so after
  812. 31:36feed forward neural network after add
  813. 31:38and norm I can say that we have reached
  814. 31:41here
  815. 31:43okay
  816. 31:47now
  817. 31:48this was the work of single decoder
  818. 31:50block but we have six such blocks
  819. 31:53right
  820. 31:54we have six such blocks we already know
  821. 31:56everyone
  822. 31:57the value of n is 6 this is same process
  823. 31:59we will repeat five more times with the
  824. 32:01same architecture but with different
  825. 32:03different parameters and that is what
  826. 32:05everyone I showed you see
  827. 32:07uh
  828. 32:08we applied this we got Y1 right we we
  829. 32:11had an add and norm operation and then
  830. 32:13we got Y1 norm and now as I have told
  831. 32:16you we need to repeat the same process
  832. 32:18five more times
  833. 32:21right
  834. 32:22with the same architecture but with
  835. 32:23different different parameters so we
  836. 32:25will finally get our final vector after
  837. 32:29going through all the six
  838. 32:31blocks
  839. 32:33after all six blocks
  840. 32:35you get an output vector
  841. 32:37like this.
  842. 32:40Okay, this output vector again is of 512
  843. 32:43dimension.
  844. 32:45You can see here.
  845. 32:47And it is passed through a linear layer.
  846. 32:50This particular linear layer here.
  847. 32:52Right? As as you can see in our diagram
  848. 32:54as well. See, this whatever we have got
  849. 32:56here, we are going to pass it through
  850. 32:59linear layer.
  851. 33:00So, this particular linear layer, if I
  852. 33:03want to talk about even this linear
  853. 33:04layer is uh
  854. 33:06going to take again 512
  855. 33:09dimension vector as an input.
  856. 33:11And it is basically this weight having a
  857. 33:16size of 512 cross V dimensions. Here V
  858. 33:19is a vocabulary size all of you. V is
  859. 33:22the vocabulary size. That means the
  860. 33:24count of all unique Hindi words in all
  861. 33:27the sentences of your data.
  862. 33:30This V is nothing but what? Count of all
  863. 33:31unique Hindi words in all the sentences
  864. 33:34of your data. And there is
  865. 33:36one neuron
  866. 33:38corresponding to each unique Hindi word,
  867. 33:41which we call it as logit. So, one logit
  868. 33:43means
  869. 33:44it represents one unique Hindi word. So,
  870. 33:46as soon as the operation is done, each
  871. 33:49neuron throws an output. This neuron
  872. 33:51will throw output. This neuron will
  873. 33:52throw output. And so on.
  874. 33:55But the problem is that this output is
  875. 33:57unnormalized. And that's why softmax is
  876. 34:01applied to make them normalized. To make
  877. 34:05those numbers normalized. And an output
  878. 34:08number should take the form of
  879. 34:11probability distribution. And softmax
  880. 34:13gives you probability for each word in
  881. 34:16your vocabulary. For example, let's say
  882. 34:19for hum, we got the probability as 0.3.
  883. 34:23Okay? Then for let's say
  884. 34:26tayyar,
  885. 34:27we got the probability as 0.03.
  886. 34:30And for let's say hai, we got the
  887. 34:33probability as 0.2.
  888. 34:35So, in this way our our time step one,
  889. 34:39which is our first step from the
  890. 34:40decoder,
  891. 34:42that gets complete.
  892. 34:44Okay? And from this step, the output we
  893. 34:46got is let's say hum because the
  894. 34:47probability is highest.
  895. 34:50Okay? So, this one here. You see, we got
  896. 34:52hum.
  897. 34:53In the time step one, we got hum.
  898. 34:57Hum is our first word
  899. 34:59from our auto regressive decoder. And
  900. 35:02finally, we pick such a word for for
  901. 35:05which we get highest probability. Let's
  902. 35:06say in our case that word is hum. So,
  903. 35:08like this step one, decoder is complete
  904. 35:11and we got hum corresponding to this
  905. 35:13SOS. So, corresponding to SOS given, we
  906. 35:15got hum here.
  907. 35:18Now,
  908. 35:19we will move to second time step.
  909. 35:21So, I have already told you that decoder
  910. 35:24will work in an auto regressive manner,
  911. 35:26which means it will step by step do
  912. 35:29output generation. In the first time
  913. 35:31step, it extracted hum word as output.
  914. 35:35Now, we will move to the second time
  915. 35:37step. So, what will be the input for the
  916. 35:39decoder at the second time step?
  917. 35:43So, look here.
  918. 35:44Now, what your input will be is whatever
  919. 35:48tokens you have so far.
  920. 35:50The SOS token you had beforehand and hum
  921. 35:53token now
  922. 35:55also come to you now, right?
  923. 35:57Hum token is also there.
  924. 36:00So, now what input you will send
  925. 36:04is these two tokens, even SOS and hum.
  926. 36:09You will send SOS as well as hum.
  927. 36:12And now, this
  928. 36:15entire thing will repeat again. The only
  929. 36:18difference is that
  930. 36:19where the last time only one token was
  931. 36:22there, this time we will go forward with
  932. 36:25these two tokens, SOS and hum.
  933. 36:29Okay? So, again, I have made a detailed
  934. 36:31diagram.
  935. 36:32I'll
  936. 36:34use that particular diagram to explain
  937. 36:37you these concepts. So, see here. This
  938. 36:40is another diagram, but now with two
  939. 36:42tokens.
  940. 36:43So, look here.
  941. 36:46We have started from uh here.
  942. 36:50SOS
  943. 36:52and hum.
  944. 36:53Instead of only one token now, we have
  945. 36:54two.
  946. 36:56So, we have sent it to the decoder.
  947. 37:01First, we got embedding.
  948. 37:03The embedding layer, so what will be the
  949. 37:05embedding layer What will embedding
  950. 37:07layer do? It will have the embedding of
  951. 37:09SOS already.
  952. 37:11It will calculate the embedding of hum.
  953. 37:13So, this embedding it was already
  954. 37:14having, it will calculate the embedding
  955. 37:16of hum, that is this one.
  956. 37:18Right? This is the embedding of
  957. 37:20uh this is the embedding of hum. And
  958. 37:22this SOS embedding, it already got
  959. 37:25earlier.
  960. 37:28So, from this, I get two embedding
  961. 37:30vectors.
  962. 37:32Okay? And
  963. 37:34this is the embedding of SOS, and this
  964. 37:37is your embedding of hum.
  965. 37:39Now, in these two, I will add positional
  966. 37:42encodings for position zero and position
  967. 37:45one.
  968. 37:46As you can see, right? This is This is
  969. 37:47basically positional encoding.
  970. 37:52And by adding both, now finally I get my
  971. 37:55two input vectors. One is X1,
  972. 37:58which represents SOS, and another one is
  973. 38:00X2, which represents the vector of 512
  974. 38:04dimension vector for
  975. 38:06hum.
  976. 38:08Okay? One is X1, and another one is X2.
  977. 38:12In the step we just did the last time,
  978. 38:15it had only one vector, if you remember
  979. 38:18it. That was X1. You see, this last
  980. 38:20diagram is also there.
  981. 38:23Okay, you see it was only X1 but this
  982. 38:26time again you see we have X1 and X2
  983. 38:29both.
  984. 38:32Right, this X1 was corresponding to SOS
  985. 38:35but since now we have two tokens X1 and
  986. 38:38X2 came here.
  987. 38:42Okay, now we will send this X1 and X2 to
  988. 38:45our first block. Our first block is
  989. 38:47masked multi-head attention. That means
  990. 38:50if I go to our previous diagram again,
  991. 38:52now I am at time step two, okay, so I'll
  992. 38:54use this particular decoder.
  993. 38:57So, what we will do is we will send this
  994. 38:59X1 and X2 so so we are here now. We are
  995. 39:01here now, you can say.
  996. 39:03And now we are going to send that X1 and
  997. 39:05X2
  998. 39:07right? to masked
  999. 39:10multi-head attention.
  1000. 39:13Okay, our first block is what? Masked
  1001. 39:15multi-head attention. So, this is our
  1002. 39:17masked multi-head attention block and
  1003. 39:19since this is an attention block inside
  1004. 39:21uh this there are three matrices
  1005. 39:24WQ WK and WV. So, this this this is our
  1006. 39:28masked multi-head attention block, okay?
  1007. 39:31Masked multi-head
  1008. 39:35masked multi-head attention block.
  1009. 39:38Fine. So, inside this we have WQ, WK and
  1010. 39:41WV.
  1011. 39:43So, we will calculate three vectors for
  1012. 39:46each token. We will calculate query, key
  1013. 39:49and value vector for X1.
  1014. 39:52And we'll also calculate query, key and
  1015. 39:54value vector for X2.
  1016. 39:57So, at this point I have both of my
  1017. 40:00tokens
  1018. 40:01with their corresponding
  1019. 40:03with with their corresponding query.
  1020. 40:06See.
  1021. 40:10Not only query, we have query, key and
  1022. 40:12value, okay?
  1023. 40:14These three vectors.
  1024. 40:16So, now you know how the work happens.
  1025. 40:19What will you do? You will take the
  1026. 40:21first tokens query.
  1027. 40:24Okay?
  1028. 40:25Whatever we have.
  1029. 40:27See this.
  1030. 40:29Query, key, and value vectors, right?
  1031. 40:32So,
  1032. 40:34with the help of this X1
  1033. 40:37and WQ, let's say we got Q1.
  1034. 40:41After doing dot product, X2 and WQ, we
  1035. 40:43got Q2.
  1036. 40:45Fine? This query vectors we got.
  1037. 40:48Now,
  1038. 40:51you will take the first tokens query,
  1039. 40:53that is Q1.
  1040. 40:56This Q1 vector and multiply it with the
  1041. 40:58first
  1042. 41:01key vector.
  1043. 41:02Okay? So, you will take Q1 and multiply
  1044. 41:05it with K1. You see this arrow?
  1045. 41:09Or do a dot product, I can say. And then
  1046. 41:11from that, you will get
  1047. 41:13a number. Let's say this is 0.2.
  1048. 41:17So, Q1 into K1,
  1049. 41:19let's say you got
  1050. 41:210.2.
  1051. 41:22After that, you will take Q1 dot product
  1052. 41:26with K2.
  1053. 41:28And from that, you get a second number,
  1054. 41:30let's say zero.
  1055. 41:31Then, you will take Q2
  1056. 41:34do a dot product with K1, let's say you
  1057. 41:36got 0.1, and Q2 with K2, let's say you
  1058. 41:38got 0.6.
  1059. 41:40That is the fourth number. So,
  1060. 41:41basically, you are calculating this
  1061. 41:43particular matrix anyway.
  1062. 41:45Okay?
  1063. 41:48So, see,
  1064. 41:51actually, you are you are calculating
  1065. 41:54something like this one. So, I'll show
  1066. 41:58you.
  1067. 41:59I'll show you here on this particular
  1068. 42:01page, something like this one here. You
  1069. 42:02see, we have SOS token
  1070. 42:05and we have hum token.
  1071. 42:07So,
  1072. 42:09we have SOS token and we have hum token,
  1073. 42:12right? So, you are actually calculating
  1074. 42:14a matrix like this.
  1075. 42:16SOS hum SOS hum. So, you will calculate
  1076. 42:20SOS with SOS, SOS with hum, hum with
  1077. 42:23SOS, and hum with hum.
  1078. 42:25So, you actually got these values.
  1079. 42:28Now, as soon as you get these numbers,
  1080. 42:30you will divide them, scale them by
  1081. 42:33square root of D, and after that, you
  1082. 42:35will apply softmax. But, before applying
  1083. 42:37softmax, everyone, what will you have to
  1084. 42:40What will you have to do? You will have
  1085. 42:42to do masking.
  1086. 42:44What you will have to do is masking.
  1087. 42:47Which is very important.
  1088. 42:48So, what is masking basically during
  1089. 42:51inference?
  1090. 42:52So, what will you do? You will make sure
  1091. 42:55that this SOS token,
  1092. 42:58right? This SOS token, this does not see
  1093. 43:01its future token.
  1094. 43:03That means hum token.
  1095. 43:06Right? As in, hum should not be visible
  1096. 43:08to SOS. Whereas, hum can see both,
  1097. 43:12itself and SOS.
  1098. 43:14This is how it was working so far in
  1099. 43:17training.
  1100. 43:19So, you will do masking in this way.
  1101. 43:21Okay?
  1102. 43:23That is why see again.
  1103. 43:25Something like this.
  1104. 43:290.2 That's why we got these numbers.
  1105. 43:32Right? So,
  1106. 43:35this number, 0.2,
  1107. 43:390, 0.1 and 0.6. This is what we'll be
  1108. 43:42using here.
  1109. 43:45So, as we want to do masking, so as I
  1110. 43:47have told you, this is SOS hum SOS hum,
  1111. 43:50right? Now, SOS should not be able to
  1112. 43:52see the next token, that is hum.
  1113. 43:55So, everyone, this will become zero. The
  1114. 43:56upper triangular matrix will become zero
  1115. 43:59here.
  1116. 44:01Now, what will be the effect of masking
  1117. 44:02on calculation? So, see now.
  1118. 44:05What will happen is that when you
  1119. 44:06calculate the vector for SOS
  1120. 44:09then this 0.2 will be multiplied with
  1121. 44:12V1.
  1122. 44:14And this zero will be multiplied with
  1123. 44:15V2.
  1124. 44:16Which means in SOS calculation
  1125. 44:20hum component will not come. This is SOS
  1126. 44:23hum. SOS hum. So in SOS calculation
  1127. 44:26everyone, hum component will not come
  1128. 44:28and that is what we wanted. Whereas when
  1129. 44:30you when you will calculate the vector
  1130. 44:33for hum
  1131. 44:36then this 0.1 will be multiplied with V1
  1132. 44:40and 0.6 with V2.
  1133. 44:44So in hum SOS component is coming and
  1134. 44:47hum component is also coming.
  1135. 44:50So this masking you have to do even
  1136. 44:53during inference time. Some people get
  1137. 44:56the doubt that masking does not happen
  1138. 44:58during inference time. But that is not
  1139. 45:00the case. In transformer architecture
  1140. 45:03masking happens even during inference
  1141. 45:05time.
  1142. 45:06So why I'm masking during inference by
  1143. 45:08the way? See, ideally you can argue like
  1144. 45:11what is the need of for masking? I have
  1145. 45:13both the tokens.
  1146. 45:15SOS and hum.
  1147. 45:17Both these tokens. SOS beforehand and
  1148. 45:20hum
  1149. 45:21hum basically is predicted.
  1150. 45:23Right? Hum is predicted here.
  1151. 45:26As you can see.
  1152. 45:27Hum is predicted.
  1153. 45:30Then why masking is needed?
  1154. 45:35Right? So see
  1155. 45:37even though we have hum predicted, we
  1156. 45:40have this SOS as well.
  1157. 45:42So
  1158. 45:44I can show
  1159. 45:47hum to SOS, right?
  1160. 45:49But you don't do that. You won't do it
  1161. 45:52because during your training process
  1162. 45:55you have used masking. Now if you do not
  1163. 45:58use masking during prediction or
  1164. 46:00inference time, then in a way a shift
  1165. 46:02will come in the data. And because of
  1166. 46:05that shift coming, the quality of your
  1167. 46:07prediction will not be good. And this is
  1168. 46:10why I'm masking is used during
  1169. 46:11inference. So, in simple words, across
  1170. 46:13all machine learning, this is
  1171. 46:14applicable. Whatever work you do on
  1172. 46:16training data, you also do the same work
  1173. 46:19on query data during prediction time as
  1174. 46:22well.
  1175. 46:24Fine?
  1176. 46:25Okay.
  1177. 46:26Later, let's say if a third word comes.
  1178. 46:31Let's say for example, something like
  1179. 46:33this one.
  1180. 46:34Let's Let's assume that even third word
  1181. 46:36also comes into picture.
  1182. 46:40Let's say there is uh
  1183. 46:43SOS.
  1184. 46:45There is hum,
  1185. 46:46and then third word is let's say tayar.
  1186. 46:51Here also,
  1187. 46:52SOS.
  1188. 46:53And then hum, and then let's say tayar.
  1189. 46:57Okay? So, tayar is let's say third word.
  1190. 47:03Then there'll be some numbers here also.
  1191. 47:07There'll be some number.
  1192. 47:10SOS SOS, there'll be some number here.
  1193. 47:14This will become zero, this will become
  1194. 47:15zero.
  1195. 47:17SOS does not see
  1196. 47:19hum
  1197. 47:20and tayar.
  1198. 47:22Now, in the hum one, this one,
  1199. 47:24there's a number here, and there's a
  1200. 47:26number here.
  1201. 47:27But this will become zero.
  1202. 47:31Right?
  1203. 47:33So,
  1204. 47:36here in case of hum,
  1205. 47:39there is There's a number and there's a
  1206. 47:41number here, right?
  1207. 47:44Hum like SOS
  1208. 47:46is shown to hum.
  1209. 47:48Fine? And hum can see hum itself.
  1210. 47:52But don't show tayar.
  1211. 47:56Right? Because these are This is future
  1212. 47:57token. And in case of the other way
  1213. 47:59around
  1214. 48:00these three numbers
  1215. 48:03are going to be there.
  1216. 48:07Because the other word came at last. So,
  1217. 48:09the masking concept will be valid
  1218. 48:12while inferencing as well.
  1219. 48:14This is very important.
  1220. 48:16Okay?
  1221. 48:18Now,
  1222. 48:19let's talk about the output from the
  1223. 48:21mask attention and add and norm.
  1224. 48:25So, whatever happens from these two
  1225. 48:27calculations
  1226. 48:28whatever we are discussing here
  1227. 48:31whatever happens from these two
  1228. 48:33calculations even
  1229. 48:35I've told you, right?
  1230. 48:37This multiplication and then this
  1231. 48:39addition.
  1232. 48:41You'll get two matrices again. Let's say
  1233. 48:44one is uh
  1234. 48:46So, here, right? Yeah, here here. Here
  1235. 48:49here, actually. So, whatever happens
  1236. 48:51with this this particular calculation
  1237. 48:53even, we get two matrices. That is
  1238. 48:54nothing but what? One is Z1 and another
  1239. 48:57one is Z2. I hope you understood this. I
  1240. 48:58already told you what happens here.
  1241. 49:01Okay?
  1242. 49:03Now, this is your output from the mask
  1243. 49:06attention block.
  1244. 49:08As you can see here.
  1245. 49:12Okay?
  1246. 49:13Mask attention block.
  1247. 49:16Okay, this one.
  1248. 49:19Right? It means uh
  1249. 49:21we have reached this place in our
  1250. 49:22diagram.
  1251. 49:23Now, again, we will do add and norm
  1252. 49:26as it is mentioned.
  1253. 49:28As you can see here.
  1254. 49:31But, listen carefully. This is my
  1255. 49:35This is basically my X1 and this is X2.
  1256. 49:40Right? These two.
  1257. 49:41X1 and X2. We send to the block
  1258. 49:44through residual connection.
  1259. 49:46We look it from here through residual
  1260. 49:48connection and we added it back to Z1
  1261. 49:51and Z2.
  1262. 49:52So, now our output is
  1263. 49:55Z1' and Z2'. Basically, this is the
  1264. 49:59output after addition, I can say. You
  1265. 50:00see addition.
  1266. 50:02Why addition? Because because
  1267. 50:04because we were here and this add
  1268. 50:07operation is here, that's why.
  1269. 50:09So, now our new output is Z1' Z2'
  1270. 50:13and now these both went to layer
  1271. 50:16normalization.
  1272. 50:17Right? As I showed you in the original
  1273. 50:20diagram. So, layer normalization will
  1274. 50:21happen.
  1275. 50:23And from these, we got the normalized
  1276. 50:25output Z1 norm, Z2 norm.
  1277. 50:29As you can see in this particular
  1278. 50:30diagram. So, at this point, we are
  1279. 50:33basically at this place. After doing so,
  1280. 50:37we are at this place.
  1281. 50:41Now, the next thing is cross-attention.
  1282. 50:43Now, the cross-attention
  1283. 50:45layer
  1284. 50:47this cross-attention layer or block
  1285. 50:50uh
  1286. 50:51we have
  1287. 50:52like in it again, we will calculate the
  1288. 50:54attention scores between two different
  1289. 50:56sequences. As you can see, this is one
  1290. 50:58sequence coming from the decoder part
  1291. 51:00and this is another sequence, you see
  1292. 51:01you see. This is basically coming coming
  1293. 51:03from the encoder. I showed it like this,
  1294. 51:05okay? This particular arrow. I hope so
  1295. 51:07you are able to see that.
  1296. 51:12Fine. Now,
  1297. 51:13>> [clears throat]
  1298. 51:15>> this as I've told you like what will
  1299. 51:17happen what will happen again here in
  1300. 51:19the
  1301. 51:19encoder output
  1302. 51:21this this encoder output
  1303. 51:24this will be sent
  1304. 51:26as you can see here.
  1305. 51:30This is being sent this way. And from
  1306. 51:32below, our
  1307. 51:34two vectors are coming.
  1308. 51:36Why I say two vectors? Because you see
  1309. 51:38Z1 norm and Z Z2 norm I'm talking about.
  1310. 51:42Fine?
  1311. 51:43So, you can see this is being sent this
  1312. 51:45way.
  1313. 51:48And we have to calculate cross attention
  1314. 51:50between these two sets of vectors.
  1315. 51:53Basically, this is our cross attention
  1316. 51:55block.
  1317. 51:57Okay, cross attention.
  1318. 51:59This is also similar to what we
  1319. 52:00discussed earlier, but the only thing is
  1320. 52:01that now we have we are actually getting
  1321. 52:03out these two two SOS and hum. That's
  1322. 52:06why we have got two vectors here.
  1323. 52:08So, let me show you how this entire
  1324. 52:10thing will happen.
  1325. 52:13I meant to say setting up the cross
  1326. 52:15attention input. So, look here. Here Z1
  1327. 52:17norm, here Z Z2 norm we have, and
  1328. 52:21uh this is our encoder output given,
  1329. 52:24okay? Whatever you are able to see,
  1330. 52:25whatever you are able to see this one,
  1331. 52:27this is Z1 norm, Z2 norm, and this is
  1332. 52:29our encoder output.
  1333. 52:31Okay, I hope so it is it is visible now.
  1334. 52:34Okay, this is our encoder output.
  1335. 52:37So, what will happen again is that with
  1336. 52:39the help of your encoder vectors, we
  1337. 52:41will extract keys and values, and from
  1338. 52:44the decoder
  1339. 52:46and from the decoder, these two vectors
  1340. 52:48we will get.
  1341. 52:49Okay, these two vectors are that are
  1342. 52:51coming from these uh
  1343. 52:53uh
  1344. 52:54from these two vectors basically, we'll
  1345. 52:55calculate the queries, I meant to say.
  1346. 52:57So, since
  1347. 52:59here two vectors are coming, we will get
  1348. 53:01two query vectors. As these two vectors
  1349. 53:03are coming, so we'll be getting two
  1350. 53:04query vectors.
  1351. 53:07So, what will happen? This Z1 normalized
  1352. 53:09will take dot product with uh WQ.
  1353. 53:14And from that, we will get the query
  1354. 53:15vector.
  1355. 53:17Let's say this one, query vector for
  1356. 53:19SOS.
  1357. 53:22Okay, query of SOS. And then we will
  1358. 53:24take dot product
  1359. 53:26of this vector with the WQ. And then we
  1360. 53:29will get the query vector of hum.
  1361. 53:32Then we send
  1362. 53:34V.
  1363. 53:37Right?
  1364. 53:38Its dot product will happen with
  1365. 53:40WK.
  1366. 53:43And uh we will get a vector of
  1367. 53:46key of W
  1368. 53:48key of V basically. We'll get this one.
  1369. 53:51We take dot product with WV as well and
  1370. 53:53we will get the value vector of
  1371. 53:55V. Similarly,
  1372. 53:58when R
  1373. 54:00and this ready is also sent to you and
  1374. 54:03same thing will happen. So, you see
  1375. 54:05we'll get get the key value vector for
  1376. 54:07ready and R.
  1377. 54:09So, like this we'll get the key
  1378. 54:10respective key value vectors for V, R,
  1379. 54:13ready.
  1380. 54:15Fine?
  1381. 54:17Now, to compute the attention weights.
  1382. 54:20So, now what do we have to do? We have
  1383. 54:24as many query vectors as we have which
  1384. 54:27is basically two. We have two query
  1385. 54:28vectors.
  1386. 54:30And we have
  1387. 54:32these
  1388. 54:33key and value vectors.
  1389. 54:35Right? We actually have three key
  1390. 54:37vectors.
  1391. 54:40Two query vectors,
  1392. 54:41three key vectors. So, we have to do
  1393. 54:43multiplication between them.
  1394. 54:45As as it is shown with the help of these
  1395. 54:47arrows as well.
  1396. 54:48So, we will do hums dot product that is
  1397. 54:52this one
  1398. 54:53with
  1399. 54:55V's key,
  1400. 54:56hums dot product with V's key,
  1401. 55:00and with ready's key, ready's key, and
  1402. 55:03with R's key.
  1403. 55:06So, we will get what? We will get W11,
  1404. 55:09W12, and W13.
  1405. 55:14Okay, so in this matrix, as you can see
  1406. 55:16we get W11, W12, W13.
  1407. 55:21Right? These three vectors, if you pay
  1408. 55:22attention everyone, these three vectors
  1409. 55:24is what I'm talking about. This is what
  1410. 55:26we will get after doing dot product of
  1411. 55:27this query vector with key vectors of V,
  1412. 55:30R, ready.
  1413. 55:33Okay? And then we do the the thing for
  1414. 55:36query vector of SOS. And here again
  1415. 55:39we'll get W21, W22, W23. So, you see
  1416. 55:42W21, W22, W23.
  1417. 55:47Right?
  1418. 55:49You can understand it this way. Here is
  1419. 55:53we right? Like we have
  1420. 55:57V R ready value vectors and V R ready
  1421. 56:01key vectors.
  1422. 56:04So,
  1423. 56:06here is V, here is R, and here is ready.
  1424. 56:09Or or or this matrix also you can
  1425. 56:11understand. Here is V, here is R, here
  1426. 56:13is ready, and here is SOS, and here is
  1427. 56:14hum.
  1428. 56:16So, you can easily understand. V SOS
  1429. 56:18with V, SOS with R, SOS with ready.
  1430. 56:21Hum with V, hum with R, hum with ready.
  1431. 56:23Uh notations you can use anything.
  1432. 56:27Okay?
  1433. 56:28So, these are our similarity scores.
  1434. 56:30Obviously, you will scale them and apply
  1435. 56:32softmax on them, which will finally give
  1436. 56:34your weights.
  1437. 56:36Which will finally give your weights.
  1438. 56:39And now what will you do? You will
  1439. 56:41calculate these two vectors. You you
  1440. 56:43will multiply W11
  1441. 56:47with the value of value vector of V.
  1442. 56:50You'll multiply W12 with the value
  1443. 56:52vector of R, and W13 with the value
  1444. 56:54vector of
  1445. 56:55ready.
  1446. 56:56So, from this we'll get a vector which
  1447. 56:58is
  1448. 56:59vector ZC1.
  1449. 57:04Right? You can see ZC1. And then we will
  1450. 57:07uh multiply this uh bottom row also,
  1451. 57:11as you can see,
  1452. 57:12with all the three value vectors. And
  1453. 57:14from this
  1454. 57:15uh let's say we will get a second
  1455. 57:16vector, and that is named as ZC2.
  1456. 57:20So, at this point
  1457. 57:22in our original diagram video, earlier
  1458. 57:24diagram,
  1459. 57:26you [clears throat] can say that
  1460. 57:29we have we are here.
  1461. 57:31Okay? we are here.
  1462. 57:34Now, we will do add a norm again as
  1463. 57:37shown here. If you notice from here, I
  1464. 57:39have sent a residual connection. You
  1465. 57:40see, this residual connection is here.
  1466. 57:45Which came here and we added
  1467. 57:47like this. See?
  1468. 57:49I'm talking about this one here. See?
  1469. 57:51This is a residual connection, Z1 norm,
  1470. 57:52Z2 norm. It is basically coming here.
  1471. 57:54So, Z1 norm, Z2 norm is coming here and
  1472. 57:57with these two things will be added to
  1473. 57:59ZC1 and ZC2. And we will get a
  1474. 58:03normalized
  1475. 58:05So, addition addition basically ZC1' and
  1476. 58:08ZC2'.
  1477. 58:11We basically got ZC1', ZC2', ZC2'
  1478. 58:15which we will send again to layer
  1479. 58:17normalization.
  1480. 58:19And we will get normalized ZC1,
  1481. 58:21ZC1 norm, and normalized ZC2, that is a
  1482. 58:24ZC2 norm.
  1483. 58:26And now we are at this particular place.
  1484. 58:30We are at this particular place.
  1485. 58:34Okay? And now the next block is what?
  1486. 58:36Feed forward neural network block. So,
  1487. 58:39let's talk about that or let's try to
  1488. 58:41understand feed forward neural network.
  1489. 58:43Let's quickly see what happens in the
  1490. 58:45feed forward neural network block. For
  1491. 58:47that even
  1492. 58:49I show you
  1493. 58:51with the help of this particular
  1494. 58:52diagram. See this?
  1495. 58:54So, as I've told you
  1496. 58:55we have ZC1 norm, ZC2 norm.
  1497. 58:58Okay? After this this is how our feed
  1498. 59:01forward neural network block looks like.
  1499. 59:03Okay? There are two layers again.
  1500. 59:072048 neurons, 512 neurons. This will
  1501. 59:10take input of size 512. Right? Here you
  1502. 59:13have ReLU,
  1503. 59:14rectified linear unit. Here you have
  1504. 59:16linear activation function. You already
  1505. 59:18know this.
  1506. 59:20So, it's exactly the same way matrix
  1507. 59:21multiplication will happen from this and
  1508. 59:24we will get two vectors,
  1509. 59:26Y1, Y2.
  1510. 59:29So,
  1511. 59:31>> [clears throat]
  1512. 59:31>> we have reached here.
  1513. 59:34We have reached here.
  1514. 59:38Now, again, you will do add a norm, as
  1515. 59:40you can see, add a norm is there.
  1516. 59:43Okay? Again, you will do add a norm. You
  1517. 59:45can see, we send this
  1518. 59:49uh
  1519. 59:50this uh
  1520. 59:52as we are going to do add a norm, so you
  1521. 59:55can see, we send these ZC1 norm, ZC2
  1522. 59:59norm
  1523. 1:00:00here. Okay? Through the residual
  1524. 1:00:02connection. We have sent it here. So, Y1
  1525. 1:00:04we have got, Y2 we have got.
  1526. 1:00:06And this ZC1 norm, ZC2 norm, also we
  1527. 1:00:09have got here with through residual
  1528. 1:00:10connection.
  1529. 1:00:13And then again, perform the addition.
  1530. 1:00:15This addition again, as you can see.
  1531. 1:00:18And that addition uh we send inside
  1532. 1:00:22layer norm or layer normalization. And
  1533. 1:00:24from layer norm, we got normalized
  1534. 1:00:27vectors.
  1535. 1:00:28Y1 normalized, Y2 normalized.
  1536. 1:00:31Two vectors have come to
  1537. 1:00:34this place.
  1538. 1:00:35And at this point, we are at this place
  1539. 1:00:39in our diagram. After doing this, so we
  1540. 1:00:41are at this place again.
  1541. 1:00:44Okay?
  1542. 1:00:45So, this was the work of a single
  1543. 1:00:47decoder block. But we have six such
  1544. 1:00:49blocks, which means the same process we
  1545. 1:00:53will repeat five more times. And that is
  1546. 1:00:55why five more decoder blocks it will go
  1547. 1:00:57through.
  1548. 1:00:59With the same architecture, but again
  1549. 1:01:00with different different parameters. So,
  1550. 1:01:02finally, we will get two vectors.
  1551. 1:01:07YF1 normalized
  1552. 1:01:09and YF2 normalized.
  1553. 1:01:11F, let's say, for final.
  1554. 1:01:13And now, on this entire journey, we have
  1555. 1:01:17reached this place.
  1556. 1:01:21So, after doing this,
  1557. 1:01:23uh after doing this add and norm every
  1558. 1:01:25time.
  1559. 1:01:25Okay?
  1560. 1:01:27As I've told you,
  1561. 1:01:29sorry, this this normalization was
  1562. 1:01:30actually done. So, we are actually here
  1563. 1:01:32now. We are now because after addition
  1564. 1:01:34this normalization should be done and
  1565. 1:01:36now we are here.
  1566. 1:01:38Okay? Now, we just have to print the
  1567. 1:01:40output.
  1568. 1:01:43So,
  1569. 1:01:44what we will do is
  1570. 1:01:46we use a linear
  1571. 1:01:48plus
  1572. 1:01:50softmax thing here. Okay? Softmax
  1573. 1:01:52function.
  1574. 1:01:54So, we use a combination of both to
  1575. 1:01:56print the output. Now, there is an
  1576. 1:01:58interesting thing here. Always at every
  1577. 1:02:00time step of the decoder you need only
  1578. 1:02:03one single token's output, but you are
  1579. 1:02:05constantly carrying two vectors. So,
  1580. 1:02:07like here we have YF1 norm, here we have
  1581. 1:02:11YF2 norm. We are constantly carrying two
  1582. 1:02:13vectors, but finally we need only one.
  1583. 1:02:17So, now if you send both these vectors
  1584. 1:02:19here,
  1585. 1:02:22then two tokens will be printed, but we
  1586. 1:02:25need only one token. The auto regressive
  1587. 1:02:28property tells us this. Always at every
  1588. 1:02:30time step one token output should
  1589. 1:02:33happen.
  1590. 1:02:33So, at this time step, what do you do?
  1591. 1:02:36This vector that you have
  1592. 1:02:39This vector is corresponding to SOS and
  1593. 1:02:41this vector is corresponding to hum. So,
  1594. 1:02:43now you won't use this thing.
  1595. 1:02:48Again, you will not use this.
  1596. 1:02:50You will only send this particular
  1597. 1:02:53vector.
  1598. 1:02:55Which corresponds to hum.
  1599. 1:02:57You will only send this particular
  1600. 1:02:58vector to this network.
  1601. 1:03:01You won't send this one.
  1602. 1:03:04Auto regressive property.
  1603. 1:03:06And then this network that you have, it
  1604. 1:03:09will work exactly the same way. A number
  1605. 1:03:11will come out from every logit.
  1606. 1:03:14This is a logit. A number will come out
  1607. 1:03:15out of every logic, every neuron area.
  1608. 1:03:18Right? We already discussed something
  1609. 1:03:20like this before also.
  1610. 1:03:24Which will be unnormalized. These
  1611. 1:03:27numbers which will be coming everyone,
  1612. 1:03:28they will be
  1613. 1:03:30unnormalized.
  1614. 1:03:32And now
  1615. 1:03:34you will take those that logic whose
  1616. 1:03:37probability is the
  1617. 1:03:39And before that, before that, what you
  1618. 1:03:41will do is you will send it to the
  1619. 1:03:42softmax.
  1620. 1:03:44As they are not normalized, so whatever
  1621. 1:03:47the numbers which will be coming
  1622. 1:03:48everyone, they will be sent to the
  1623. 1:03:50softmax, which will normalize it and
  1624. 1:03:52convert it to a probability
  1625. 1:03:53distribution. And now you will take that
  1626. 1:03:55logic whose probability is the highest
  1627. 1:03:57from the probability distribution. And
  1628. 1:03:59let's assume that
  1629. 1:04:01the word that comes out with the highest
  1630. 1:04:03probability is tayyar.
  1631. 1:04:06So tayyar will be the output of time
  1632. 1:04:09step two.
  1633. 1:04:12So here, please don't get confused.
  1634. 1:04:15This step is very crucial.
  1635. 1:04:17Okay? This particular step is very
  1636. 1:04:19crucial.
  1637. 1:04:20All the way to the end you are carrying
  1638. 1:04:22all the vectors with you.
  1639. 1:04:24But at the very end moment, you send
  1640. 1:04:26only the last one forward.
  1641. 1:04:29You forget this one.
  1642. 1:04:32And in this way, you got your second
  1643. 1:04:34word that is nothing but tayyar.
  1644. 1:04:37So as you can see here everyone, this is
  1645. 1:04:39our second word, tayyar.
  1646. 1:04:44Now think about what will happen in the
  1647. 1:04:45next time step. In the next time step,
  1648. 1:04:48you will send
  1649. 1:04:50three tokens in the input.
  1650. 1:04:52Like this one everyone.
  1651. 1:04:55SOS hum
  1652. 1:04:57and tayyar.
  1653. 1:05:00Okay? Which means this whole process
  1654. 1:05:03will repeat. But instead of two tokens,
  1655. 1:05:06there will be three tokens. All three
  1656. 1:05:08vectors everywhere. As tayyar is added
  1657. 1:05:11here,
  1658. 1:05:13as they are is added here, so I can show
  1659. 1:05:15you
  1660. 1:05:18>> [snorts]
  1661. 1:05:18>> what will happen.
  1662. 1:05:21See, as they are is added here, so there
  1663. 1:05:23will be they are
  1664. 1:05:25word.
  1665. 1:05:28One more vector will be added here,
  1666. 1:05:30everyone.
  1667. 1:05:32One more vector will also be added here.
  1668. 1:05:37Right?
  1669. 1:05:38One more set of query key and value
  1670. 1:05:41query
  1671. 1:05:43key and value, whatever we have, so we
  1672. 1:05:44will get one more set of query key and
  1673. 1:05:46value here.
  1674. 1:05:49One more vector here, one more vector
  1675. 1:05:51here, one more vector here as well.
  1676. 1:05:55And this entire calculation will adjust
  1677. 1:05:58in that way. And everywhere we will get
  1678. 1:06:00three vectors. Everywhere you'll get
  1679. 1:06:01three vectors. Here also you'll get
  1680. 1:06:03three vectors. Okay?
  1681. 1:06:05One more query key value pair will be
  1682. 1:06:07added. Here also one more query uh
  1683. 1:06:10vector here also one more vector you
  1684. 1:06:12will get. Here also one more vector you
  1685. 1:06:14will get. And finally here as well.
  1686. 1:06:19So, like this if you go,
  1687. 1:06:23same thing will happen. One more vector
  1688. 1:06:25here,
  1689. 1:06:26one more vector here, one more vector
  1690. 1:06:28here.
  1691. 1:06:29And finally we will have here also. And
  1692. 1:06:33this Y F3 norm also will be there.
  1693. 1:06:38Exactly same, following same process.
  1694. 1:06:41So, we will have Y F3 norm as well.
  1695. 1:06:45And here we will have uh
  1696. 1:06:48as as we have this third vector, which
  1697. 1:06:50will be corresponding to they are,
  1698. 1:06:51right? This this basically corresponds
  1699. 1:06:53to they are.
  1700. 1:06:55But now, what will you do? You won't uh
  1701. 1:06:58you won't basically send this one.
  1702. 1:07:02You won't send this one as well.
  1703. 1:07:06Right? You'll only send
  1704. 1:07:08this one.
  1705. 1:07:11Right? Because you want only one output.
  1706. 1:07:13Now, on the on this entire journey
  1707. 1:07:17on this entire journey, everyone, here I
  1708. 1:07:19will come.
  1709. 1:07:23Here one more vector will come. Right?
  1710. 1:07:25Like the output will be here. Now, once
  1711. 1:07:27this is there, everyone,
  1712. 1:07:31as I want to show you, see, this this
  1713. 1:07:33hey we have got as a corresponding token
  1714. 1:07:35of the year.
  1715. 1:07:37And now, in the next step, what will
  1716. 1:07:39happen is
  1717. 1:07:41there'll be SOS as an input. SOS the
  1718. 1:07:43year hey will be input.
  1719. 1:07:46So, hey is also coming here. That means
  1720. 1:07:49That means on this entire journey, I
  1721. 1:07:51will get hey as well here. So, here you
  1722. 1:07:53you will get four vectors, one more
  1723. 1:07:55query key and value pair, one more
  1724. 1:07:57vector here here here, and so on. Like
  1725. 1:08:00this, everyone, finally you will get one
  1726. 1:08:03more vector here.
  1727. 1:08:07Okay? And like this, you will reach up
  1728. 1:08:09again.
  1729. 1:08:10And here, let's say I have YF4
  1730. 1:08:14norm.
  1731. 1:08:15YF4 normalize. And then again,
  1732. 1:08:18you will ignore this one, you will
  1733. 1:08:20ignore this one, you will ignore this
  1734. 1:08:21one.
  1735. 1:08:24You will only send this one.
  1736. 1:08:28And hopefully from this, you will get
  1737. 1:08:30end of sentence. That is nothing but
  1738. 1:08:32EOS, end of sentence token.
  1739. 1:08:36And as soon as you get end of sentence,
  1740. 1:08:39you will understand that you have to
  1741. 1:08:41stop your inference process.
  1742. 1:08:43You stop it. And your output will be
  1743. 1:08:45what? Your output will be hum the year
  1744. 1:08:50hey. Okay? It will be like hum the year
  1745. 1:08:52hey, like this area. Your output will be
  1746. 1:08:54what? Hum the year hey. And finally, we
  1747. 1:08:57got end of sentence.
  1748. 1:08:59And this is is transformer inference
  1749. 1:09:02works.
  1750. 1:09:04So, I have tried to explain this entire
  1751. 1:09:06process through a detailed diagram. The
  1752. 1:09:08main difference is the encoder works
  1753. 1:09:10absolutely in the same way, but the main
  1754. 1:09:13difference comes in the decoder. The
  1755. 1:09:14decoder behaves in a non-autoregressive
  1756. 1:09:17manner during training time. It takes
  1757. 1:09:19all tokens together, generates all
  1758. 1:09:21outputs together. Whereas during
  1759. 1:09:23inference time, it behaves in an
  1760. 1:09:25autoregressive manner. It takes
  1761. 1:09:28tokens one by one and gives only one
  1762. 1:09:30token output at every time step.
  1763. 1:09:33So, that's it
  1764. 1:09:34about the decoder architecture during
  1765. 1:09:36inference time.
  1766. 1:09:38Thank you, everyone.

About this transcript

This page contains the full transcript of Transformer Arch Decoder Inference [with Paper & Pen] -How Transformers ACTUALLY Generate Text Part3 by yogesh murumkar, generated from the public captions YouTube serves with the video. The transcript has 9,388 words across 1,766 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 translate the transcript into 100+ languages.

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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.