YouTube2Text

Transformer Decoder Arch During Training Time - Pen & Paper Explaination | Transformer Series Part2 — Transcript

by yogesh murumkar · 11,315 words · 1,895 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hello everyone, this is Yogesh Muramar.
  2. 0:03In this video, we are going to
  3. 0:05understand decoder part of transformer
  4. 0:07architecture in very much detail. I'll
  5. 0:10be using all these handwritten diagrams
  6. 0:13to make the understanding very simple
  7. 0:17and easy. You can have a look at all
  8. 0:20these diagrams one by one. So that at
  9. 0:23least it will give an idea about the
  10. 0:25flow which we are going to follow to
  11. 0:28understand the entire decoder
  12. 0:30architecture.
  13. 0:33Fine. And uh one more thing everyone uh
  14. 0:36you can download all these diagrams. I
  15. 0:38have already created a PDF file and the
  16. 0:40link for the same is given in the
  17. 0:42description. So if you just go if you
  18. 0:45just try to download that PDF file and
  19. 0:48then follow this uh explanation I think
  20. 0:52uh it will be good for you to understand
  21. 0:55the things in uh less time okay and that
  22. 0:58too uh properly you will understand the
  23. 1:01architecture you'll be able to follow it
  24. 1:03properly that's what I want to say fine
  25. 1:06so yes these are all the diagrams even
  26. 1:08which I'll be using I just try to show
  27. 1:10it to you uh so that at least you'll get
  28. 1:14an idea what kind of a material we'll be
  29. 1:16making use of here to understand this
  30. 1:18particular architecture.
  31. 1:21One very important thing is that in this
  32. 1:24video the decoder architecture
  33. 1:27we will study is from the training
  34. 1:29perspective. You can see I underline
  35. 1:31this particular word training that means
  36. 1:34how the decoder architecture behaves
  37. 1:36when training is running. We will
  38. 1:38discuss decoder architecture working
  39. 1:41during inference or prediction in the
  40. 1:43next video. Fine.
  41. 1:46So until now we have thoroughly studied
  42. 1:50the decoder uh the encoder part of the
  43. 1:52transformer architecture in previous
  44. 1:54video and the link for the same is also
  45. 1:56given in the description. Even if
  46. 1:59someone has not watched the encoder part
  47. 2:02anyway I'll just revise it in short at
  48. 2:05the start of this video.
  49. 2:07But I recommend if you want to
  50. 2:09understand the things about encoder in
  51. 2:11detail then please refer previous
  52. 2:12[clears throat] video of encoder part
  53. 2:18and another uh other than this if you
  54. 2:21want to understand the concepts like
  55. 2:23tokenization embedding positional
  56. 2:25encoding self attention multi-air
  57. 2:26attention mask self attention cross
  58. 2:29attention layer normalization and uh
  59. 2:32feed forward neural network then these
  60. 2:34things are also explained in the
  61. 2:36for which link is given in the
  62. 2:38description.
  63. 2:40Okay. Now we are actually ready to study
  64. 2:42the architecture of decoder.
  65. 2:47Always remember that the decoder behaves
  66. 2:50differently during training and
  67. 2:53inference. Whenever I say inference I
  68. 2:55mean to say during prediction. Okay.
  69. 2:58Although the architecture is same
  70. 3:01during inference it becomes auto
  71. 3:03reggressive.
  72. 3:05Okay. Remember this what I want to say
  73. 3:07everyone is the decoder architecture
  74. 3:09which we are going to discuss.
  75. 3:12So during inference
  76. 3:15or prediction it becomes what it becomes
  77. 3:19auto reggressive
  78. 3:22and during training
  79. 3:25during training it becomes
  80. 3:29nonauto reggressive.
  81. 3:33Okay, please remember this non-ordering.
  82. 3:38Now see as I've told you that the
  83. 3:43decoder behaves differently during
  84. 3:45training and inference although the
  85. 3:46architecture is same but during
  86. 3:50inference it becomes auto reggressive
  87. 3:54and during training it works in nonauto
  88. 3:57reggressive manner. Now what is the
  89. 3:59meaning of this one? What is the meaning
  90. 4:02of let's say this auto reggressive see
  91. 4:05auto means what? Self
  92. 4:07and regressive means what? Regressive
  93. 4:10means predicting based on previous
  94. 4:13values.
  95. 4:15Okay. Predicting based on previous
  96. 4:18values.
  97. 4:20So auto reggressive means what? What is
  98. 4:21the meaning of auto reggressive?
  99. 4:23Auto reggressive it means predicting the
  100. 4:26next thing using all the previous things
  101. 4:29uh you already generated.
  102. 4:33Think of it like completing a sentence
  103. 4:35word by word. For example, even see
  104. 4:38let's say if the input is something like
  105. 4:40this. The cat
  106. 4:44sat on dash.
  107. 4:48So step one will be what?
  108. 4:52Step one will be to predict
  109. 4:56predict the next word. So let's say the
  110. 4:58next word is matt.
  111. 5:01Okay. Then again the input will become
  112. 5:03what?
  113. 5:04The cat
  114. 5:06sat on mat
  115. 5:10and then again next word. So step two
  116. 5:13will be what? Step two will be what?
  117. 5:15Step two will be predict the next word.
  118. 5:17Let's say next word is
  119. 5:20this. predict the next word and the next
  120. 5:22word is let's say and okay then
  121. 5:27input will be what the input will become
  122. 5:30like this the cat sat on match and
  123. 5:39and then step three will be what step
  124. 5:43three will be to predict
  125. 5:48let's say the next word next word is
  126. 5:49let's say this
  127. 5:51and so on. Okay, so each new word
  128. 5:55depends on all previously generated
  129. 5:57words. Each new word depends on all
  130. 6:02previously generated words. That's auto
  131. 6:06reggressive everyone.
  132. 6:08You feed your own output back as input
  133. 6:11for the next step. Okay, this is in
  134. 6:13short auto reggressive.
  135. 6:16What is non-auto?
  136. 6:19Always remember as I've told you decoder
  137. 6:23behaves nonauto regggressive in in
  138. 6:25non-auto regggressive manner during
  139. 6:27training time. This is also called as
  140. 6:29non-auto regggressive is also called as
  141. 6:31what?
  142. 6:34Teacher forcing. Remember this word
  143. 6:36later on you will need this. Okay. Nona
  144. 6:39autogressive means what? Teacher
  145. 6:41forcing.
  146. 6:43It means don't use your predictions. Use
  147. 6:47the correct answers all at once. I'll
  148. 6:50repeat, don't use your own predictions,
  149. 6:54use the correct answer all at once.
  150. 6:59So it means instead of instead of
  151. 7:03waiting for its own output, the model
  152. 7:05receives the entire correct sentence in
  153. 7:07one shot
  154. 7:10but with a mask blocking future word. So
  155. 7:14it cannot cheat.
  156. 7:17For example, even
  157. 7:20position one
  158. 7:22position let's say there are sentences
  159. 7:24like there are words in the sentence
  160. 7:26right like this one this one this one so
  161. 7:27this is position one this is position
  162. 7:29two this is position three and so on so
  163. 7:32position one can see
  164. 7:35start token there's something called a
  165. 7:36start token we'll talk about it start
  166. 7:38means this is something which will tell
  167. 7:40the
  168. 7:42machine that okay you can start the work
  169. 7:43so position one can see start token
  170. 7:47position two
  171. 7:50can see the start token and itself see
  172. 7:56before this before this the cats had
  173. 7:59let's say there's a start token so
  174. 8:01position one can see only start position
  175. 8:03two can see start and the
  176. 8:06position three can see start
  177. 8:11the
  178. 8:12and cat
  179. 8:15Okay, all positions computed
  180. 8:17simultaneously parallel and fast. This
  181. 8:21is non-auto ree regressive. Fine. But
  182. 8:24please don't worry
  183. 8:27everyone. Uh you will understand these
  184. 8:28concepts once you go through the entire
  185. 8:30process shown in this video. Okay. So I
  186. 8:33I just tried to explain you in very much
  187. 8:36short way the meaning of uh auto
  188. 8:40reggressive and non-regressive. But
  189. 8:42remember during training decoder behaves
  190. 8:45in non-auto regggressive manner and
  191. 8:48during inference or prediction it
  192. 8:49behaves in auto reggressive manner. If
  193. 8:51these things are not clear later on it
  194. 8:53will be more clear. Fine. So in this
  195. 8:56video we'll focus on
  196. 8:59training process of decoder. In the next
  197. 9:03video I will tell you how the decoder
  198. 9:05works during inference time. Fine.
  199. 9:10So let's see decoder architecture from
  200. 9:12the training perspective. Now to explain
  201. 9:15the decoder architecture, I will show
  202. 9:17you two representations of the decoder
  203. 9:21which will give you an overview of how
  204. 9:23the decoder architecture is built.
  205. 9:28Once you get that particular overview
  206. 9:30then we will do a deep dive and try to
  207. 9:33understand how the how all the
  208. 9:35components are interconnected with each
  209. 9:36other through some simple example. Okay.
  210. 9:41So first simplified overview and then a
  211. 9:44deep dive
  212. 9:46and all of this will start with the main
  213. 9:49transformer architecture diagram and
  214. 9:52that is nothing but this one which you
  215. 9:54are able to see here.
  216. 9:56Fine. I think this particular diagram is
  217. 9:58now familiar to everyone.
  218. 10:02So remember this part, this encoder part
  219. 10:04we have already discussed in detail in
  220. 10:06previous video. Now we are going to
  221. 10:08focus on the decoder part and that too
  222. 10:10during training. Fine.
  223. 10:13Next the most simplified representation
  224. 10:16of this particular diagram would be
  225. 10:20something like this. You see
  226. 10:24transformer architecture in a very
  227. 10:25simplified manner I can show it like
  228. 10:27this encoder and decoder point. So
  229. 10:30transformer is nothing but what
  230. 10:32transformer is nothing but a box. In a
  231. 10:35very simple way I can say it's a box.
  232. 10:37You can think of transformer as a single
  233. 10:39box. And inside that single box there
  234. 10:42are two more boxes. This one and this
  235. 10:45one. The first box is called the encoder
  236. 10:47whose job is to encode the input. And
  237. 10:49the second box is called the decoder
  238. 10:51whose job is to decode the encoded
  239. 10:53sentence or encoded input and print the
  240. 10:57output.
  241. 10:59Now we understand at the simplest level
  242. 11:02that transformer is a box
  243. 11:05with two more boxes inside it. Now let
  244. 11:08us add a bit more complexity.
  245. 11:14You can see this diagram.
  246. 11:16Okay, you can see this particular
  247. 11:18diagram here.
  248. 11:20Encoder is made up of six boxes.
  249. 11:25Okay, the good news is that the encoder
  250. 11:28box is not a single box. It is made up
  251. 11:31of six boxes. So what I mean is that the
  252. 11:34transformers encoder is actually made up
  253. 11:37of six encoder blocks. 1 2 3 4 5 six.
  254. 11:41So here are those six blocks.
  255. 11:46Okay. And the same thing is true for
  256. 11:49decoder also. The transformers decoder
  257. 11:51is also not a single box but it is made
  258. 11:54up of six blocks. 1 2 3 4 5 6. So here
  259. 12:01here you can see six block six boxes for
  260. 12:05uh six blocks for encoder and six blocks
  261. 12:07for decoder.
  262. 12:09Okay. Now the obvious curiosity comes
  263. 12:12what goes on uh inside one single
  264. 12:16encoder block. I already discussed this
  265. 12:18in the previous video of transformer
  266. 12:20encoder architecture but just for
  267. 12:22revision let's discuss uh one once more
  268. 12:27what goes on inside one single encoder
  269. 12:29block.
  270. 12:31Okay
  271. 12:34you see one single encoder block looks
  272. 12:37like this.
  273. 12:40It has two more blocks inside it. One,
  274. 12:44two.
  275. 12:47One is the self attention block
  276. 12:50and other is the feed forward neural
  277. 12:53network block.
  278. 12:55These two together make up one single
  279. 12:58encoder block like this.
  280. 13:02But if you don't know self attention
  281. 13:04feed forward neural network, no problem.
  282. 13:06I'll explain it uh as and when required.
  283. 13:10So it will not stop you from
  284. 13:12understanding decoder architecture.
  285. 13:14Fine. Now next everyone
  286. 13:19this one this one as you can see this is
  287. 13:24the cutout of encoder from the original
  288. 13:26transformer architecture. As you can see
  289. 13:29here
  290. 13:31in the original transform architecture
  291. 13:33as you can see multi retention add and
  292. 13:36nom feed forward add a norm. So whatever
  293. 13:39I'm showing you here everyone whatever
  294. 13:41I'm showing you here this one
  295. 13:44is the cut out of encoder from the
  296. 13:47original transformer architecture you
  297. 13:49see multi- redempion addenom feed
  298. 13:50forward addenom
  299. 13:53okay and as we know there are six
  300. 13:56encoder blocks
  301. 13:59as we know that there are six encoder
  302. 14:01blocks
  303. 14:03this is how the encoder architecture
  304. 14:06looks like you see first encoder block
  305. 14:09multi- retention add anom feed forward
  306. 14:11addon and then even you can imagine it
  307. 14:13like this this exactly same encoder
  308. 14:15block will be here second encoder third
  309. 14:18encoder fourth encoder fifth encoder
  310. 14:20they will be exactly same and finally
  311. 14:21sixth encoder
  312. 14:24okay so this is how the encoder
  313. 14:26architecture looks like and one more
  314. 14:29thing all the encoder blocks are
  315. 14:31identical as I already told you and we
  316. 14:33already seen this in the previous
  317. 14:35discussion of encoder architecture of
  318. 14:37transformer
  319. 14:39All the encoder blocks are identical
  320. 14:41meaning their architecture is exactly
  321. 14:44copy paste. This encoder block first
  322. 14:45encoder block is uh similar to second,
  323. 14:48third, fourth, fifth and sixth. Okay,
  324. 14:52their architecture is exactly copy
  325. 14:53paste. Same the parameters are
  326. 14:56different. The weights and the biases
  327. 14:57inside will be different. Their values
  328. 14:59will be different. But from the
  329. 15:01architecture point of view, it is
  330. 15:03exactly same. Whether you talk about
  331. 15:05first, second, third, fourth or sixth
  332. 15:07encoder clock.
  333. 15:10Fine. Think of it this way. For example,
  334. 15:14a very common example is given. Let's
  335. 15:16say if you take some company's phone,
  336. 15:19say an iPhone 15, then all iPhone 15s
  337. 15:22are designed in exactly the same way.
  338. 15:24But which apps are installed inside that
  339. 15:27phone varies from user to user.
  340. 15:29Similarly, encoders architecture is same
  341. 15:31for all blocks. But parameter values
  342. 15:34inside are different. Okay. I think it
  343. 15:37makes you understand the
  344. 15:40meaning of whatever I'm saying. Fine.
  345. 15:44Now
  346. 15:45[clears throat]
  347. 15:48as I've told you this this decoder
  348. 15:50everyone also has six six box right six
  349. 15:55boxes inside it or it is basically six
  350. 15:58decoders we have like this right just
  351. 16:01like the encoder the decoder is also
  352. 16:04made up of six blocks
  353. 16:07the obvious curiosity comes what goes
  354. 16:09inside one single decoder log.
  355. 16:14So the simplified representation
  356. 16:17if I want to show you here everyone
  357. 16:21for uh this one decoder block will be
  358. 16:25like this. You see
  359. 16:30okay you can see here
  360. 16:35a single decoder block consist of three
  361. 16:38blocks.
  362. 16:40First block is
  363. 16:43masked self attention.
  364. 16:46Second is cross attention which is also
  365. 16:49called encoder decoder attention.
  366. 16:53Third is feed forward neural network.
  367. 16:57As you can see in this particular
  368. 16:58diagram right this is one single block
  369. 17:02of decoder. These three blocks together
  370. 17:06make up a single decoder block. Now if
  371. 17:08the curiosity is coming that how are
  372. 17:10these blocks interconnected with each
  373. 17:13other then the answer will come from a
  374. 17:15diagram which is an exact cutout from
  375. 17:17the main diagram something like this one
  376. 17:20even
  377. 17:21this is the cutout of one decoder block.
  378. 17:25So at the start as I've already shown
  379. 17:27you this main transformer architecture
  380. 17:31diagram if you look at this part here
  381. 17:33you see this one masked multi- retention
  382. 17:37adder nom multi- retention add nom feed
  383. 17:40forward addon norm
  384. 17:42okay so
  385. 17:47as you can see this particular diagram
  386. 17:50is an exact cutout from the main diagram
  387. 17:52you see masked multiate attention
  388. 17:55add a normal retention adder norm feed
  389. 17:58forward adder norm.
  390. 18:01Okay, this this cutout is basically
  391. 18:03taken from the main diagram only. So you
  392. 18:05can see how much data is
  393. 18:07data flow is happening and how are all
  394. 18:10these blocks interconnected with each
  395. 18:12other and this is exactly what we need
  396. 18:15to understand in this video. I think you
  397. 18:16know everyone right this these
  398. 18:18connections right this one this one
  399. 18:21right these connections are called as
  400. 18:23what residual connections
  401. 18:26or sche connections
  402. 18:28we already have discussed about these
  403. 18:30things in detail in the
  404. 18:33transformer encoder architecture part
  405. 18:37okay so this is the exact cutout of one
  406. 18:40decoder block I can say
  407. 18:44fine Now [clears throat]
  408. 18:46as I've told you you can see how much
  409. 18:49data flow is happening and how are all
  410. 18:51these blocks interconnected with each
  411. 18:53other. You can see or you can have a
  412. 18:55look at this particular diagram format
  413. 18:57and this is exactly what we need to
  414. 18:59understand in this video. Now the fun
  415. 19:02thing is again that we do not have just
  416. 19:06one decoder block as we discussed
  417. 19:07already. We have got six decoder blocks
  418. 19:10which means our decoder
  419. 19:13looks something like this.
  420. 19:17See everyone a decoder looks something
  421. 19:20like this. Okay, don't worry about this
  422. 19:23particular part at least for now. But
  423. 19:25you see our decoder looks something like
  424. 19:27this. This is the first decoder block.
  425. 19:30You can see this is the exact cutout
  426. 19:32which I shown you in the previous
  427. 19:33diagram.
  428. 19:36Right?
  429. 19:38And from this is first decoder block.
  430. 19:39From this from here the input goes to
  431. 19:44the second decoder block.
  432. 19:46Right? As I've told you we have got six
  433. 19:48decoder blocks which means our decoder
  434. 19:51looks entire decoder looks something
  435. 19:53like this one.
  436. 19:57From here the input goes to
  437. 20:01this one. This first decoder block.
  438. 20:02Okay. From here as as you can see I'm
  439. 20:04highlighting it. From here the input
  440. 20:06goes to first decoder block. Okay, this
  441. 20:09is our first decoder block. And this
  442. 20:12first decoder block as you can see
  443. 20:14everyone
  444. 20:16it is having three blocks inside it.
  445. 20:21Masked multi head attention you can say.
  446. 20:23Then this is called as cross attention.
  447. 20:26Okay. And then feed forward neural
  448. 20:28network.
  449. 20:31Okay. This first decoder blocks output
  450. 20:35goes to second decoder block
  451. 20:39which which also has its three blocks
  452. 20:42inside it like this
  453. 20:45and second decoder blocks output goes to
  454. 20:47the third and then fourth and so on.
  455. 20:51like this you reach the sixth decoder
  456. 20:53block
  457. 20:55and the output from the sixth decoder
  458. 20:57block goes to an output block.
  459. 21:01So everyone this is our output block.
  460. 21:05This is our output block I can say.
  461. 21:12Okay.
  462. 21:14And here you get your final output after
  463. 21:16this. So
  464. 21:19uh don't worry. I know it looks uh like
  465. 21:22a lot of information flow is happening.
  466. 21:23All these blocks are interconnected in
  467. 21:25some way. And uh yes, this is exactly
  468. 21:30what we need to understand in this
  469. 21:31video. So don't worry about this. I'll
  470. 21:33explain you each and everything. Okay,
  471. 21:34this is how our decoder looks like. I'll
  472. 21:38be coming to this particular diagram
  473. 21:39again and again as and when required.
  474. 21:42Now what we are going to do is we are
  475. 21:45going to take this entire diagram and
  476. 21:49feed an example sentence into this as a
  477. 21:52input
  478. 21:54and through that sentence a journey we
  479. 21:56will try to learn how this entire
  480. 21:58architecture works. So don't worry it
  481. 22:01would be very very interesting and by
  482. 22:03the end of this video you will
  483. 22:04understand each and everything.
  484. 22:08Fine. Next,
  485. 22:10I have divided this entire explanation
  486. 22:13into three parts.
  487. 22:16In the first part, we will try to
  488. 22:18understand a section where we take a
  489. 22:20decoder input and prepare it. That means
  490. 22:23even this part.
  491. 22:26Okay, this is let's say input part.
  492. 22:30Okay, just to make the expression easy,
  493. 22:32I'll name it as input part.
  494. 22:35There are two to three kinds of work you
  495. 22:37do here and we will discuss those. So
  496. 22:40this is the first part of the
  497. 22:42explanation. Okay.
  498. 22:45In the second part of the explanation, I
  499. 22:47will exactly explain what is happening
  500. 22:49inside a single decoder block. This will
  501. 22:52be the largest part of the explanation.
  502. 22:56Here we will spend
  503. 22:58some time but here we will understand
  504. 23:01everything properly.
  505. 23:03Okay. So I'm talking about I'm talking
  506. 23:06about this second part even okay second
  507. 23:11part
  508. 23:16and the good thing is that since all
  509. 23:18decoder blocks are identical
  510. 23:21if you understood what is happening
  511. 23:23inside this one block first decoder
  512. 23:26block you'll automatically understand
  513. 23:27the next five blocks second third fourth
  514. 23:30fifth and sixth
  515. 23:32okay and then everyone In the third part
  516. 23:35of the explanation,
  517. 23:38third part of the explanation that is
  518. 23:40this output block, I'll explain what is
  519. 23:43happening inside this output block.
  520. 23:46Okay, once we are done with first,
  521. 23:48second and then we will go with the
  522. 23:49third and that is nothing but the output
  523. 23:53block. So the entire deep dive can be
  524. 23:56divided into three parts.
  525. 23:59Input block processing I can say. Okay.
  526. 24:03input block processing
  527. 24:09the entire portion inside decoder.
  528. 24:14Okay, this entire portion inside decoder
  529. 24:17and then the output block.
  530. 24:21This is how we are going to proceed and
  531. 24:23to carry out this entire discussion
  532. 24:26we will use an example and that example
  533. 24:28is a machine translation task.
  534. 24:32Okay. So for example, let's say I have a
  535. 24:37English sentence.
  536. 24:41Okay. English sentence is let's say we
  537. 24:45are ready.
  538. 24:49Fine. So as it's a machine translation
  539. 24:51task, let's say I want to translate this
  540. 24:53into Hindi. So Hindi translation is
  541. 24:56what? H
  542. 24:59or you can take any example anyone.
  543. 25:01Okay. R
  544. 25:03so English to Hindi. Okay, so to carry
  545. 25:06out this entire discussion even we will
  546. 25:08use this example and it's a machine
  547. 25:10translation task.
  548. 25:12Okay,
  549. 25:13it's a machine
  550. 25:16translation task.
  551. 25:21Fine. So we'll be taking English to
  552. 25:24Hindi translation as an example. And
  553. 25:25remember here we are talking about
  554. 25:28training.
  555. 25:30So at this point you can assume that we
  556. 25:32have a training data set of English to
  557. 25:35Hindi sentences.
  558. 25:38For now you can assume you have just one
  559. 25:40row of data where the English sentence
  560. 25:42is we are ready and it's Hindi
  561. 25:45translation is
  562. 25:49apart from this you do not have any
  563. 25:50other English to Hindi sentence pairs.
  564. 25:53Okay just to make the things easy
  565. 25:55everyone we'll take a very simple
  566. 25:56example. So we are going to send this
  567. 25:59data to our decoder.
  568. 26:02Right? As I've told you
  569. 26:05whenever I say decoder.
  570. 26:07So in a decoder everyone we have as we
  571. 26:11already seen there are six decoder
  572. 26:14blocks. First, second, third, fourth,
  573. 26:15fifth, sixth. Right? So we are going to
  574. 26:18send this particular data this data to
  575. 26:22our decoder. But before that one thing I
  576. 26:24want to clarify the English sentence
  577. 26:26will go inside encoder. Everyone the
  578. 26:30English sentence will go inside encoder
  579. 26:35and the encoder will generate contextual
  580. 26:37embeddings or encoded embeddings from
  581. 26:39it. The output of the encoder will be
  582. 26:42what? Contextual embeddings
  583. 26:47or encoded embeddings which will go to
  584. 26:50the decoder. So how how exactly this
  585. 26:52thing will be used we'll talk about it.
  586. 26:57Okay. So in short before decoder starts
  587. 27:00its work before this decoder starts
  588. 27:02starts its work the encoder will have
  589. 27:05already done its work.
  590. 27:08It will have already processed
  591. 27:11this English sentence.
  592. 27:15Understand? Okay. encoder will have
  593. 27:19already processed this English sentence
  594. 27:21and for every token of it for every
  595. 27:24token of it,
  596. 27:26it will have generated contextual or
  597. 27:29encoded embeddings which will be
  598. 27:32available with us.
  599. 27:34Fine. And then the decoder will start
  600. 27:38its work with Hindi sentence.
  601. 27:42Okay? Like in this case, this is our
  602. 27:44Hindi sentence corresponding to this
  603. 27:46English English sentence. Now I really
  604. 27:49hope that this setup is completely clear
  605. 27:51to you.
  606. 27:54Fine.
  607. 27:55Okay. Now we will start our explanation
  608. 27:59on decoder architecture. And the first
  609. 28:02thing we will discuss is this input
  610. 28:05part.
  611. 28:08The input portion has four operations.
  612. 28:10The names of all four operations are
  613. 28:13like this also we have discussed during
  614. 28:15uh encoder everyone. But see which four
  615. 28:19operations as you can see here shifted
  616. 28:21right. Okay. So shifted right or we call
  617. 28:24it as shift right.
  618. 28:27This is the first operation
  619. 28:30in the input part input block
  620. 28:32processing. Second operation everyone is
  621. 28:35tokenization.
  622. 28:38I hope you understand the meaning of
  623. 28:40tokenization. Then third aran is nothing
  624. 28:42but what? Embedding
  625. 28:45and fourth is nothing but positional
  626. 28:49encoding.
  627. 28:51Positional encoding.
  628. 28:55So the input portion has four
  629. 28:57operations.
  630. 29:00Right shift tokenization embedding
  631. 29:03positional encoding. The entire input
  632. 29:06block is very simple in its work. It
  633. 29:08takes your output sentence.
  634. 29:11In our case, the output sentence is
  635. 29:15Hindi sentence H.
  636. 29:19And after processing it, it brings it
  637. 29:23into such a form that you can send it to
  638. 29:26this decoder block. Okay? you can send
  639. 29:30it to the
  640. 29:33decoder's first block I can say or first
  641. 29:36decoder block. Okay, this input block
  642. 29:39processing or this input part it will do
  643. 29:42all these things and it will process
  644. 29:44this Hindi sentence your output sentence
  645. 29:46in such a way that it can be easily
  646. 29:48passed to the uh input it it can be
  647. 29:52easily passed as a input to the first
  648. 29:54decoder block. This is just overview.
  649. 29:57Now let's see what's happening in input
  650. 30:00part in detail. So for this everyone we
  651. 30:04will use
  652. 30:07this particular diagram for the detailed
  653. 30:09explanation. Okay. I hope so you are
  654. 30:11able to see this clearly.
  655. 30:15Okay you can have a look at this. This
  656. 30:17is very important diagram everyone which
  657. 30:18will make the things very easier and
  658. 30:20simple for you to understand.
  659. 30:23Fine.
  660. 30:26Now [clears throat]
  661. 30:29as I've told you this diagram we will
  662. 30:31use for the
  663. 30:33detailed explanation. Okay. So in our
  664. 30:35case what was the English sentence?
  665. 30:39English sentence is we are ready.
  666. 30:42Okay. And Hindi sentence is
  667. 30:45remember this. So as I've told you our
  668. 30:48encoder is ready
  669. 30:50with the processed English sentence. And
  670. 30:53now we will take the Hindi sentence. The
  671. 30:55first operation we will apply on the
  672. 30:57entire Hindi sentence is what is right
  673. 31:01shifting. This first operation given
  674. 31:04shift right or right shifting as as even
  675. 31:06it is mentioned in the diagram here as
  676. 31:09well. Shifted right or if you go to the
  677. 31:12if you go to the original uh transformer
  678. 31:15architecture you see the first operation
  679. 31:17shifted right. Okay same thing I'm
  680. 31:19talking about.
  681. 31:22So our encoder is ready with the process
  682. 31:23English sentence and we will take the
  683. 31:25Hindi sentence. The first operation we
  684. 31:27will apply on this entire Hindi sentence
  685. 31:29is right shifting in this operation.
  686. 31:34Okay, as you can see
  687. 31:37I passed this as a input to right shift
  688. 31:40first operation.
  689. 31:42Okay.
  690. 31:44So
  691. 31:46in this operation you add a kind of a
  692. 31:50token at the front of the sentence which
  693. 31:53is basically start token. You see right
  694. 31:56shift what happens here? We add a
  695. 31:59special token called as start token at
  696. 32:01the start of the sentence
  697. 32:05or or you can say at the front of the
  698. 32:07sentence. So we add start token
  699. 32:11at the front of.
  700. 32:14So this token is like a flag that starts
  701. 32:17the training process. It means our
  702. 32:19training process is starting from here.
  703. 32:23Okay.
  704. 32:24So now our transformed input is what?
  705. 32:27Start token then h then t then.
  706. 32:32The second operation is tokenization.
  707. 32:37You already know what tokenization is.
  708. 32:39Tokenization means you break down a
  709. 32:41sentence into tokens.
  710. 32:46Those tokens could be words, bgrams,
  711. 32:48engrams. It depends on you. We are using
  712. 32:52a simple tokenization technique. We are
  713. 32:54basically converting every word into a
  714. 32:58token. So as soon as we pass our entire
  715. 33:01sentence through this to tokenizer this
  716. 33:03entire sentence through this tokenizer
  717. 33:08we get four tokens
  718. 33:10start token
  719. 33:12H token tar token head token these are
  720. 33:16four separate tokens
  721. 33:19fine
  722. 33:20the third operation is embedding layer
  723. 33:23okay so you see we are done with right
  724. 33:26shift we are done with tokenization and
  725. 33:27then embedding Okay. So the third
  726. 33:29operation is emitting layer. The job of
  727. 33:32this layer is you have English words or
  728. 33:35Hindi words
  729. 33:37return right. Let's say from in our case
  730. 33:39Hindi words. So what is the job of this
  731. 33:42embedding layer?
  732. 33:46See this embedding layer takes every
  733. 33:49token generated
  734. 33:53in the previous step or I can say the
  735. 33:56job of this layer is let's say if you
  736. 33:58have English or Hindi words written out
  737. 34:00but your machine cannot understand words
  738. 34:02right so there has to be some way where
  739. 34:04you can convert your words into numbers
  740. 34:08so the embedding layer this layer takes
  741. 34:11every token and generates vectors from
  742. 34:16It it generates vectors from it. In the
  743. 34:19original transformer paper, every vector
  744. 34:21you see is 512 dimension vector. So this
  745. 34:25will be 512 dimension. This will be 512
  746. 34:27dimension. 512 dimension vector. And
  747. 34:29this also will be 512 dimension vector.
  748. 34:33Okay.
  749. 34:35And with the help of this 512 dimension
  750. 34:38numbers or vectors, we form a vector or
  751. 34:41or with the help of this 512 numbers, we
  752. 34:42form a vector. So start token gets
  753. 34:48this even corresponding vector for start
  754. 34:50token we got even corresponding vector
  755. 34:52you can say okay which is also 512
  756. 34:56dimensions which is also a 512
  757. 34:58dimensions token gets E2 which is again
  758. 35:03512 dimension vector
  759. 35:07gets E3 and similarly this high gets E4
  760. 35:13512 dimensional vector. So at this point
  761. 35:17we have achieved that for every token we
  762. 35:20have vectors which the machine can
  763. 35:22process. It can understand and it can
  764. 35:24process. But there is a problem. We have
  765. 35:27not informed our system in any way which
  766. 35:31word came first and which came later.
  767. 35:35And you know that in NLP related task
  768. 35:38this information of when which word is
  769. 35:41used in the sentence is very crucial. So
  770. 35:43to bring this information we use a
  771. 35:45technique which we call positional
  772. 35:48encoding. That means after embedding
  773. 35:50everyone we are going to discuss about
  774. 35:52positional encoding.
  775. 35:55Okay. So positional encoding. Okay. This
  776. 35:58this is basically uh you can see this
  777. 36:02this is positional encoding. Okay.
  778. 36:04positional encoding.
  779. 36:08So positional encoding generates a
  780. 36:11vector for every unique position.
  781. 36:14Like for position one, it will generate
  782. 36:16a vector. For position two, it will
  783. 36:18generate a vector. For position three
  784. 36:19and for position four, it will generate
  785. 36:22one one vector.
  786. 36:25And here too we make sure that every
  787. 36:29vector is gen uh every vector that is
  788. 36:31generated is of 512 dimensions.
  789. 36:35This one, this one, this one, this one.
  790. 36:38Okay. So at this point I have two sets
  791. 36:40of vectors. First set of vectors are my
  792. 36:44embeddings that is this one E1, E2, E3,
  793. 36:47E4.
  794. 36:50Okay.
  795. 36:52and second set of vectors are my
  796. 36:54positional embedding vectors that is P1,
  797. 36:57P2, P3, P4.
  798. 37:01Now what we have to do is add these two.
  799. 37:05So you see here addition addition
  800. 37:06addition addition here. Okay? Or I can
  801. 37:09show you in this diagram also. You see
  802. 37:13embedding vectors position encoding and
  803. 37:16you see this addition operation. Okay,
  804. 37:19that is why I added this addition
  805. 37:22operation here.
  806. 37:26Fine.
  807. 37:28So what we have to do is add these two.
  808. 37:32Okay, add these two. So we will add
  809. 37:35start tokens embedding vector.
  810. 37:38Start tokens embedding vector is even.
  811. 37:41So
  812. 37:43we will add start tokens embedding
  813. 37:45vector with the first position's
  814. 37:47embedding vector. We will add hum tokens
  815. 37:50embedding vector with the second
  816. 37:51position embedding vector and so on.
  817. 37:54That means E1 plus P1, E2 plus P2, E3
  818. 37:56plus P3 and E4 + P4 respectively.
  819. 38:00Okay, since both these sets are 512
  820. 38:04dimension vectors, this addition will
  821. 38:05happen and finally we will get our input
  822. 38:07vectors
  823. 38:09X1, X2, X3, X4. This one is basically as
  824. 38:14many tokens as you have in the sentence
  825. 38:17you will have that many vectors. So we
  826. 38:19have 1 2 3 four tokens. So we will get 1
  827. 38:232 3 four. Okay, we will get four vectors
  828. 38:26here. And this final set of vectors is
  829. 38:31what goes into the decoder.
  830. 38:36So this x1, x2, x3, x4 they are very
  831. 38:41important vectors because they are the
  832. 38:42vectors that will uh that we will send
  833. 38:46to the first block of decoder
  834. 38:49and that is nothing but even we are
  835. 38:51here. Now we are here. Okay, first block
  836. 38:54of decoder that means we are here.
  837. 38:58I really hope the working of the entire
  838. 39:00input block has been understood by you.
  839. 39:02Okay, this input part has been
  840. 39:04understood by you.
  841. 39:07Now we move to the main part which is
  842. 39:10the first decoder block that is nothing
  843. 39:13but this one. Okay, this one everyone
  844. 39:15will see now.
  845. 39:19Our first decoder block has three main
  846. 39:21operations. First is the operation where
  847. 39:23we apply mask multi-air attention that
  848. 39:26is this one.
  849. 39:28Second is the operation where we apply
  850. 39:30cross attention that is this one.
  851. 39:34And third is where we apply feed forward
  852. 39:37neural network. So let us see these
  853. 39:39three one by one how each one is
  854. 39:42executed.
  855. 39:44Okay.
  856. 39:47So for that let's once again come to
  857. 39:48this diagram. We have four input vectors
  858. 39:53as you can see x1 x2 x3 x4. Right? This
  859. 39:56was the last point in this diagram we
  860. 39:59discussed.
  861. 40:01And now we are sending these four input
  862. 40:04vectors to our decoder block where first
  863. 40:07they will they'll be received by multi
  864. 40:10mask multi attention block. As you can
  865. 40:12see easily here
  866. 40:14inside the decoder first decoder what is
  867. 40:17the first thing? Mask multi head
  868. 40:19attention.
  869. 40:21So if you have watched my earlier video
  870. 40:23then perhaps you remember that this
  871. 40:25masked multi-headed attention block
  872. 40:28works exactly
  873. 40:31like a normal attention uh normal multi-
  874. 40:34attention block. Okay, this one this one
  875. 40:36I'm talking about
  876. 40:38there is only one big difference here in
  877. 40:41this case masking is implemented.
  878. 40:44So what will happen here is that for
  879. 40:47every input vector corresponding
  880. 40:49contextual
  881. 40:51embedding vector will be generated like
  882. 40:54for X1
  883. 40:57here you can see like for X1 here we
  884. 41:01will get something like Z1
  885. 41:05okay
  886. 41:07for X2 we'll get for X2 we'll get Z2
  887. 41:12and same for X3 and X4 4 that is Z3 and
  888. 41:15Zed4 respectively. But there is one big
  889. 41:19difference in the process of generating
  890. 41:22Z1. Okay, this is Zed 1. In the process
  891. 41:25of generating Z1 that is this one,
  892. 41:30we will only consider start token.
  893. 41:34Please try to understand that in the
  894. 41:35process of considering uh in the process
  895. 41:37of generating Z1, we will only consider
  896. 41:42star token. We will not consider
  897. 41:46h
  898. 41:48token t token high token.
  899. 41:52Okay remember.
  900. 41:54So it is something like this one to
  901. 41:56generate the zed 1 we will only consider
  902. 42:00start token. to generate
  903. 42:03Z2. When we generate Z2, we will only
  904. 42:06consider
  905. 42:08this star token
  906. 42:11and H token.
  907. 42:14We will not consider TAR and H token
  908. 42:19when we generate Z3 that is this one. So
  909. 42:23I think you are getting my point. We
  910. 42:26will consider
  911. 42:29star token, h token and we will consider
  912. 42:33tar token. We will not consider high
  913. 42:36token. And when we generate Z4,
  914. 42:39we will consider all four that is start
  915. 42:44and then hum and then tar and then head
  916. 42:47token.
  917. 42:49So that's the only difference between a
  918. 42:51normal multi-head attention and masked
  919. 42:54multi head attention. That means even
  920. 42:56here we are trying to do masking.
  921. 43:00Okay, I really hope you understand what
  922. 43:01is happening here. If you want the
  923. 43:03detailed understanding, go back to video
  924. 43:06mentioned in the description where I
  925. 43:08explain the [clears throat] entire
  926. 43:09process of how how you do masking and
  927. 43:12how this output comes out. But whatever
  928. 43:16I have told you exactly same thing
  929. 43:17happens everyone. This is how masking
  930. 43:19will be taken care.
  931. 43:21Okay. I think you are getting my point.
  932. 43:26See once again like as I've told you
  933. 43:30when we generate Z1 we will consider
  934. 43:32only start token. To generate Z1 we will
  935. 43:34consider only start token. To generate
  936. 43:37Z2 we will consider start and H. To
  937. 43:39generate Z3 we will consider start H and
  938. 43:41T. And to generate Z4 we will consider
  939. 43:43all start and then H and then P and then
  940. 43:46H.
  941. 43:48Okay.
  942. 43:49So I really hope you understand what is
  943. 43:51happening here. If you want detail
  944. 43:52explanation as I've told you please go
  945. 43:54and please check the video in the
  946. 43:55description. Fine. So at this point we
  947. 44:00have our masked multi head attention
  948. 44:03output. See here
  949. 44:06that means now we are here.
  950. 44:09Okay. Now we are here
  951. 44:12we have our mass to multi-year retention
  952. 44:14output. Now what comes next
  953. 44:17just ahead is add and non block. You see
  954. 44:20add and n. So here we have to perform an
  955. 44:22addition first and then perform
  956. 44:23normalization on whatever the result
  957. 44:25comes. The question is what do we do to
  958. 44:28add? The answer is very simple. We have
  959. 44:31to add the result of this masked
  960. 44:34multi-year redention and that is nothing
  961. 44:37but the result is
  962. 44:40zed 1 zed2 zed3 zed4. We need to add
  963. 44:44this result
  964. 44:47with the original input vectors and that
  965. 44:49is nothing but x1 x2 x3 x4 and that is
  966. 44:52because here in this diagram and even as
  967. 44:56you see there is a residual connection.
  968. 44:59You see this one residual connection.
  969. 45:01You see
  970. 45:02we will have to add this result with
  971. 45:05this
  972. 45:07uh with this particular thing
  973. 45:10right. These are the original input
  974. 45:13vectors. From here we will get original
  975. 45:16input vectors or in the in the uh
  976. 45:18original transformer architecture
  977. 45:20diagram as well you see here this as
  978. 45:22I've told you right this is nothing but
  979. 45:23what this is residual or skip
  980. 45:26connection. Okay, residual or skip
  981. 45:30connection which we even also discussed
  982. 45:32in encoder architecture. Fine. So as
  983. 45:36there's a residual connection here,
  984. 45:38this is uh residual connection as I've
  985. 45:41told you or a skip connection. So see
  986. 45:46everyone what's going to happen. So that
  987. 45:48residual connection you see here like
  988. 45:50this I shown.
  989. 45:52Okay. So from here we will send this x1
  990. 45:56x2 x3 x4
  991. 45:59we will send this ahead and we will add
  992. 46:02it with z1 zed2 zed3 zed4.
  993. 46:07So you see this addition operation
  994. 46:10everyone I hope you are able to see
  995. 46:12addition operation and this is basically
  996. 46:14skip connection or residual connection.
  997. 46:17All these vectors are still 512
  998. 46:20dimensional vectors.
  999. 46:22All of them. Okay. All of this addition
  1000. 46:26even this addition like here I shown you
  1001. 46:28this Z1 + X1 Z2 + X2 Z3 + X3 Z4 + X4.
  1002. 46:33This will happen. And let's suppose even
  1003. 46:35we got this one.
  1004. 46:38Okay, these are all 512 dimension
  1005. 46:41vectors.
  1006. 46:43All these vectors are still 512
  1007. 46:45dimensional vectors. So you can perform
  1008. 46:47addition between
  1009. 46:49these
  1010. 46:52right you can perform addition between
  1011. 46:53them because they are of same dimension
  1012. 46:55by addition by adding them you get let's
  1013. 46:58say these new vectors which we call zed
  1014. 47:011 dash zed 2 dash zed3 dash and zed 4
  1015. 47:05dash
  1016. 47:06okay after this comes the normalization
  1017. 47:10step as you can see in the first decoder
  1018. 47:14block as well so what we have done is we
  1019. 47:16are here now.
  1020. 47:19Sorry. Uh we got this one right? We we
  1021. 47:22we already have done
  1022. 47:24mass multi uh mask multi addition and
  1023. 47:27then we added and after this you see
  1024. 47:28normalization. So this addition is done
  1025. 47:31and now we are going to go with
  1026. 47:32normalization. So after this uh comes a
  1027. 47:35normalization step and in normalization
  1028. 47:37step which normalization which
  1029. 47:38normalization layer have we will be
  1030. 47:41using layer normalization here. Right?
  1031. 47:44You can see here layer normalization.
  1032. 47:47So what we do is we send all these
  1033. 47:49vectors to the layer norm layer. Z1
  1034. 47:53dash, zed 2 dash, zed3 dash, zed4 dash.
  1035. 47:56We will send it to the
  1036. 47:59layer norm. Okay. And the layer norm
  1037. 48:02layer calculates
  1038. 48:04mean. It calculates the sigma or the
  1039. 48:08standard deviation
  1040. 48:10for every vector.
  1041. 48:12Okay, for every vector and performs
  1042. 48:15normalization. I think in machine
  1043. 48:17learning definitely you must have come
  1044. 48:18across what exactly is normalization.
  1045. 48:20Okay, so for every vector here you will
  1046. 48:23get a normalized vector. For every
  1047. 48:24vector here everyone you will get
  1048. 48:26normalized vector
  1049. 48:29and we do this particular step because
  1050. 48:32you want to make your training somewhat
  1051. 48:34stable. You always you would always want
  1052. 48:38that whatever numbers
  1053. 48:41are in these vectors
  1054. 48:43they are in small given range
  1055. 48:47so that the training process will be
  1056. 48:50stable. Okay. So at this point I can say
  1057. 48:55now everyone we have reached here.
  1058. 48:59Okay. We have reached here from addon
  1059. 49:03norm. We got our output from add nom. We
  1060. 49:05got our output. Now we will send it to
  1061. 49:08the next block which is our cross
  1062. 49:11attention. Okay. This one area which is
  1063. 49:14our cross attention.
  1064. 49:21This is cross attention block. Fine. Now
  1065. 49:26cross attention block is the most
  1066. 49:28interesting portion of this entire
  1067. 49:30decoder architecture. Basically this is
  1068. 49:33the first decoder block. Okay. Why I
  1069. 49:36said that this is the most interesting
  1070. 49:38portion of this entire decode
  1071. 49:40architecture? Because here a very
  1072. 49:43important work happens.
  1073. 49:48You make your input sequence which is an
  1074. 49:51uh English sentence.
  1075. 49:54You make your input sentence which is
  1076. 49:57English sentence and your output
  1077. 49:59sequence which is a Hindi sentence you
  1078. 50:02make them talk to each other.
  1079. 50:05So basically every token that is present
  1080. 50:08in your English sentence you find out a
  1081. 50:12similarity score with every token that
  1082. 50:14is present in your Hindi sentence. And
  1083. 50:17this work is happening in cross
  1084. 50:19attention block.
  1085. 50:21Okay.
  1086. 50:23And that is why you will notice that in
  1087. 50:26this block diagram input is coming from
  1088. 50:29two places. One input is coming from
  1089. 50:32here. You see this one, this arrow.
  1090. 50:37Okay?
  1091. 50:39One input is coming from here from the
  1092. 50:41previous masked attention block. And one
  1093. 50:44is coming from here. You see this? This
  1094. 50:47one is here.
  1095. 50:50Okay.
  1096. 50:51And that input is actually coming from
  1097. 50:53the encoder that is coming from
  1098. 50:58encoder.
  1099. 51:01So if you look at the original
  1100. 51:04transformer architecture diagram
  1101. 51:08here,
  1102. 51:10you will notice that when encoder
  1103. 51:13completes its work, it sends it its
  1104. 51:16output to this place. You see this is
  1105. 51:19the output of the encoder.
  1106. 51:22So it sends this output to this place.
  1107. 51:26You see this one.
  1108. 51:31Okay. So you can see when the encoder
  1109. 51:35completes its work, it sends its output
  1110. 51:37to decoder at this place. And that is
  1111. 51:41what you will get here. Okay? Or I can
  1112. 51:46say here that is what you will get here.
  1113. 51:51So if I summarize the cross attention
  1114. 51:53block for you, it works exactly like
  1115. 51:56normal head normal multi head attention
  1116. 51:59block just with one big difference.
  1117. 52:04Unlike a normal multi head attention
  1118. 52:06block where you send only one sequence
  1119. 52:09input in cross attention you send two
  1120. 52:12sequences. One is your English sentence
  1121. 52:15coming from encoder and second is your
  1122. 52:18Hindi sentence coming from your
  1123. 52:21decoder's previous step. This is your
  1124. 52:23decoder. Decoder's previous step is
  1125. 52:25here. That means one is coming from here
  1126. 52:26and one is coming from here.
  1127. 52:31Okay. So you do this
  1128. 52:35because as I have told you you need
  1129. 52:37three sets of vectors.
  1130. 52:40Okay. And which are those are which are
  1131. 52:43those three sets of vectors
  1132. 52:45query
  1133. 52:48Q
  1134. 52:50and value. Query
  1135. 52:54Q and value.
  1136. 52:58Okay. So query Q
  1137. 53:04and value.
  1138. 53:06This is what we need.
  1139. 53:09Once you get
  1140. 53:11the query key and value vectors, the
  1141. 53:14process ahead is exactly the same as in
  1142. 53:17normal attention block.
  1143. 53:21Fine.
  1144. 53:24See everyone
  1145. 53:26the query key and value vectors, right?
  1146. 53:30What operations we'll be doing on this?
  1147. 53:34We'll talk about it. But your query
  1148. 53:37vectors or your query vector basically
  1149. 53:40come from your decoder.
  1150. 53:42Okay, as you can see
  1151. 53:45this will give me query vector.
  1152. 53:50Remember this.
  1153. 53:53And your key and value vectors coming
  1154. 53:56from here that is encoder.
  1155. 54:00Okay. your key and value vectors.
  1156. 54:06So this will be query key area. Okay,
  1157. 54:08this will be query. So your key and
  1158. 54:10value vectors
  1159. 54:12will be coming from encoder.
  1160. 54:16Okay, or [clears throat]
  1161. 54:19in our diagram you can see this diagram.
  1162. 54:22This is where this is from where you
  1163. 54:24will get query and this is where you
  1164. 54:26will get key and value. Okay, it was
  1165. 54:28key. I think I written Q. Okay, it is
  1166. 54:32key. Key key and value. Key and value
  1167. 54:34will be coming from encoder and query
  1168. 54:35will be coming from decoder.
  1169. 54:40Fine. And as I've told you once you give
  1170. 54:42the key value and query vectors the
  1171. 54:44process is exactly same as in normal
  1172. 54:46attention block. Okay. So just to make
  1173. 54:50the explanation easy now
  1174. 54:54let's once again come to this diagram
  1175. 54:56here.
  1176. 54:59Okay.
  1177. 55:01So if I can show you this
  1178. 55:03diagrammatically
  1179. 55:05whatever I have discussed right. So
  1180. 55:07please understand first of all last time
  1181. 55:10we were at this point right we got the
  1182. 55:12Z1 dash zed 2 dash zed3 dash and zed4
  1183. 55:15dash.
  1184. 55:18Okay,
  1185. 55:20from the previous mask attention we got
  1186. 55:24Z1 norm, Zed 2 norm, Z3 norm and Z4
  1187. 55:29norm.
  1188. 55:31Okay, that is nothing but normalized
  1189. 55:32vectors. How we got it? Uh I think you
  1190. 55:34understand that.
  1191. 55:38Okay.
  1192. 55:40Now,
  1193. 55:42as I've told you,
  1194. 55:45we got this from our uh previous mass
  1195. 55:49attention. Right? Now, we are going to
  1196. 55:54send this to cross attention.
  1197. 55:57So, as you can see this particular
  1198. 55:58diagram,
  1199. 56:00we were here right now. Whatever the
  1200. 56:03normalized vectors which we got, we are
  1201. 56:05going to send it to the cross attention.
  1202. 56:08But here we will not only send this Z1
  1203. 56:11nom, zed2 nom, zed3 nom, zed4 nom. We
  1204. 56:14will also send the encoder embeddings
  1205. 56:16that are coming here. That means we will
  1206. 56:18send this here to the cross attention.
  1207. 56:20But as well as but as well as you can
  1208. 56:22see uh we will send here from here,
  1209. 56:24[clears throat] right? But as well as
  1210. 56:25what we'll do is we'll also send the
  1211. 56:27encoder embeddings to the cross
  1212. 56:28attention.
  1213. 56:31So from zed 1 nom, zed 22 nom, zed3 nom,
  1214. 56:34zed4 norm we will get query vectors.
  1215. 56:38Okay, that means even this will give me
  1216. 56:40query. This will give me query. This
  1217. 56:42will give me query and this will also
  1218. 56:43give me query vector.
  1219. 56:46And from the encoder's output that is
  1220. 56:48coming,
  1221. 56:50see I I shown you here see this one from
  1222. 56:52the encoder's output that is coming
  1223. 56:55that is this one everyone. That is this
  1224. 56:58one.
  1225. 57:01we will expect key and value vectors. So
  1226. 57:04it means
  1227. 57:06this will give me key and value. This
  1228. 57:09will also give me key and value. Key and
  1229. 57:11value. And this will also give me key
  1230. 57:14and value.
  1231. 57:16Once you get the key and value vectors,
  1232. 57:20you will do all the work that you do in
  1233. 57:22an attention block. And finally you will
  1234. 57:25get your contextual embeddings
  1235. 57:27one for each token of your output
  1236. 57:29sequence.
  1237. 57:33So if your output sentence has four
  1238. 57:36tokens then for each token you will get
  1239. 57:39corresponding contextual embedding
  1240. 57:41vector. Let us call them as Z C1 Z C2 Z
  1241. 57:45C3 Z C4
  1242. 57:47and C here means cross attention output.
  1243. 57:49C means because this is the output of
  1244. 57:51cross attention. So I will name it as Z
  1245. 57:53C1, Z C2 and so on. So C means cross
  1246. 57:56attention.
  1247. 57:59Okay. So at this point we have reached
  1248. 58:03here. We have reached here.
  1249. 58:08We have cross attention output and right
  1250. 58:10ahead again there is add and now.
  1251. 58:14So again the question comes what will be
  1252. 58:16added? Very simple. you will add the
  1253. 58:17cross attention output with the previous
  1254. 58:19steps output which is masked attention
  1255. 58:23output. Okay, you see this residual
  1256. 58:25connection here and this is cross
  1257. 58:28attention output. So mask attention
  1258. 58:30output and cross attention output
  1259. 58:32everyone will be added. So
  1260. 58:36notice that what I have done
  1261. 58:40not only have I sent this Z1 norm, zed2
  1262. 58:43nom, zed3 nom, zed4 norm to cross
  1263. 58:46attention block.
  1264. 58:49Not only this one anyone, but
  1265. 58:52[clears throat]
  1266. 58:55as you can see this zed1 nom, zed2 nom,
  1267. 58:59zed3 nom, zed4 norm.
  1268. 59:02I also send them here
  1269. 59:06where they will be added with Z C1 Z C2
  1270. 59:09Z C3 Z C4 which is cross attention
  1271. 59:13output. So what we'll get is we'll get Z
  1272. 59:16C1 dash, Z C2 dash, Z C3 dash and Z C4
  1273. 59:20dash
  1274. 59:22and then we normalize them using
  1275. 59:26layer normalization after which we get Z
  1276. 59:30C1 norm, Z C2 norm, Z C3 norm, Z C4
  1277. 59:35norm.
  1278. 59:39Okay.
  1279. 59:41[clears throat]
  1280. 59:43So at this point we have reached here on
  1281. 59:48our output journey or decoder journey I
  1282. 59:52can say.
  1283. 59:54Okay as I got normalized
  1284. 59:57as I got normalized thing everyone right
  1285. 1:00:00after add and norm I got normalized
  1286. 1:00:02vector. So here we are in our decoder
  1287. 1:00:04journey
  1288. 1:00:06and the next thing is as you can see
  1289. 1:00:09here the next thing is feed forward
  1290. 1:00:11neural network block.
  1291. 1:00:14Okay.
  1292. 1:00:17So first
  1293. 1:00:21before discussing about this feed
  1294. 1:00:23forward neural network
  1295. 1:00:26first I'll tell you the architecture of
  1296. 1:00:27this feed forward neural network and the
  1297. 1:00:30architecture is the same architecture
  1298. 1:00:32that you have seen during explanation of
  1299. 1:00:34the encoder architecture in the previous
  1300. 1:00:37video something like this one.
  1301. 1:00:41This feed forward neural network
  1302. 1:00:43consists of two layers. The first layer
  1303. 1:00:45has
  1304. 1:00:472048
  1305. 1:00:48neurons.
  1306. 1:00:50Okay, these are neurons. 2048 neurons
  1307. 1:00:55and their activation is rectified linear
  1308. 1:00:59unit railway activation function.
  1309. 1:01:03Okay. The second layer has 512 neurons
  1310. 1:01:10and its activation function is linear.
  1311. 1:01:17Fine.
  1312. 1:01:19Now if you talk about parameters, this
  1313. 1:01:24feed forward neural network expects 512
  1314. 1:01:28dimension input. So from here everyone,
  1315. 1:01:30it will expect 512 dimension input.
  1316. 1:01:34Okay, 512 dimension input.
  1317. 1:01:37So here we have 512.
  1318. 1:01:40Okay.
  1319. 1:01:42And here we have 2 0 48.
  1320. 1:01:45And since it's fully connected neural
  1321. 1:01:48network, the weights here, the weights
  1322. 1:01:51here, everyone, the weights here will be
  1323. 1:01:55512 cross 2048.
  1324. 1:02:01Okay. So many weights you have there.
  1325. 1:02:04After that, every neuron has its own
  1326. 1:02:06bias.
  1327. 1:02:10So in total we have 2048 biases here.
  1328. 1:02:13How many biases? 2048 biases
  1329. 1:02:19because 2048 neurons are here. So we are
  1330. 1:02:22calling this weight let's say as W1.
  1331. 1:02:25This entire weight let's say as W1 and
  1332. 1:02:28the set of biases let's say as B1.
  1333. 1:02:33Okay. Then if you talk about how many
  1334. 1:02:35weights
  1335. 1:02:37are here, how many weights are here? If
  1336. 1:02:40you want to know
  1337. 1:02:42here we have see for that here we have
  1338. 1:02:452048 neurons
  1339. 1:02:48and here in this case we have 512
  1340. 1:02:51right. So again we have
  1341. 1:02:552048 cross 512
  1342. 1:02:59weights these many weights.
  1343. 1:03:03Okay, here because it's a fully
  1344. 1:03:05connected network.
  1345. 1:03:07Let's say we can call this as W2. Okay,
  1346. 1:03:11let's say this was W1 and this is W2.
  1347. 1:03:13And then
  1348. 1:03:16after this here every neuron has its own
  1349. 1:03:19bias here also, right? So there'll be uh
  1350. 1:03:22like 512 biases,
  1351. 1:03:26right? Let's call it as B2.
  1352. 1:03:30Fine.
  1353. 1:03:33So this is the architecture even. Now
  1354. 1:03:36the fun thing is that here we can only
  1355. 1:03:40send 512 dimensional input but we have
  1356. 1:03:44four vectors
  1357. 1:03:46Z C1 NOM Z C2 NOM Z C3 and Z C4 NOM and
  1358. 1:03:50how we got this even that also we have
  1359. 1:03:54already discussed in the previous
  1360. 1:03:56diagram right that's why I've told you
  1361. 1:03:58just uh have that PDF with you everyone
  1362. 1:04:00and then it will make
  1363. 1:04:02you understand each and everything
  1364. 1:04:03easily.
  1365. 1:04:06Fine.
  1366. 1:04:07So as you can see
  1367. 1:04:11as I've told you
  1368. 1:04:13this architecture uh if you talk about
  1369. 1:04:17right
  1370. 1:04:19we can only send 512 dimension input
  1371. 1:04:23and in our case we have four vectors. So
  1372. 1:04:25what we are going to do we are going to
  1373. 1:04:28create a batch.
  1374. 1:04:30We have stacked these four vectors
  1375. 1:04:32together and created a matrix that is
  1376. 1:04:34this one. And this matrix will be what?
  1377. 1:04:37Four vectors each of size 512
  1378. 1:04:40dimensions.
  1379. 1:04:42Now we send this entire batch together.
  1380. 1:04:44This entire batch together
  1381. 1:04:50to this particular neural network. So
  1382. 1:04:53first what will happen when input comes
  1383. 1:04:56when the input comes then it will
  1384. 1:04:59interact with these weights.
  1385. 1:05:01So if you say uh if you say that you are
  1386. 1:05:05collectively calling this as a zed okay
  1387. 1:05:08zed 1 zed c1 nom zed c2 nom and so on.
  1388. 1:05:11If you are correctively calling them as
  1389. 1:05:13zed then which operation will be
  1390. 1:05:15performed a dot product will be
  1391. 1:05:17performed even and it will be like
  1392. 1:05:21zed what is this w what are all these
  1393. 1:05:24weights represented with let's say w1 so
  1394. 1:05:26dot product will be like z dot w1
  1395. 1:05:31okay z dot product w1 plus bias will be
  1396. 1:05:36added plus b1
  1397. 1:05:40so everyone something like this that Z
  1398. 1:05:44dotproduct W1 plus bias B1.
  1399. 1:05:49Okay. And if you want to check the shape
  1400. 1:05:52then the operation is something like
  1401. 1:05:53this even see it's like
  1402. 1:05:56we have this 4 + 512
  1403. 1:06:01right 4 + 512
  1404. 1:06:06it is uh like as I've told you how we
  1405. 1:06:08have stacked all these vectors together
  1406. 1:06:10and we got a matrix
  1407. 1:06:13right so the operation is something like
  1408. 1:06:16this we have 4 + 512 to matrix
  1409. 1:06:21with weights that is these weights and
  1410. 1:06:25these weights are of
  1411. 1:06:28512 these weights okay as I've told you
  1412. 1:06:31512 cross 2048 so 512 cross 2048 so you
  1413. 1:06:36see everyone 512 512 right it means both
  1414. 1:06:41the dimensions match so the resultant
  1415. 1:06:44will be what resultant of these two will
  1416. 1:06:46be 4 cross 2048.
  1417. 1:06:53Okay. So the resultant will be 4 + 208
  1418. 1:06:562048 matrix in this layer.
  1419. 1:07:01And in this we will add 2048 vector of
  1420. 1:07:03biases as I've told you
  1421. 1:07:07right. So again we will get what we will
  1422. 1:07:09get 4 + 2048 matrix which basically
  1423. 1:07:14means that we took our four vectors and
  1424. 1:07:17increase their dimensionality.
  1425. 1:07:20Still have four vectors but each
  1426. 1:07:22vector's dimensionality has changed from
  1427. 1:07:25512 to 248.
  1428. 1:07:30Okay. Each vector's dimensionality is
  1429. 1:07:32now 2048.
  1430. 1:07:36After this what are you doing? You are
  1431. 1:07:39applying ReLU. Okay, we are going to
  1432. 1:07:42apply ReLU on this.
  1433. 1:07:47By applying ReLU, what will happen is
  1434. 1:07:48what will happen is that you will be
  1435. 1:07:51able to introduce nonlinearity.
  1436. 1:07:54Okay, you will be able to introduce
  1437. 1:07:57nonlinearity. This also we have
  1438. 1:07:58discussed even in the previous encoder
  1439. 1:08:00architecture. Okay, the main purpose of
  1440. 1:08:03this entire feed forward neural network
  1441. 1:08:05is to introduce nonlinearity.
  1442. 1:08:08Now you move forward to the next layer
  1443. 1:08:11and in the next layer what are you going
  1444. 1:08:13to do? You are going to multiply this
  1445. 1:08:16entire quantity this entire quantity
  1446. 1:08:19with W2.
  1447. 1:08:22That means whatever the result which we
  1448. 1:08:23got even here we'll multiply with W2.
  1449. 1:08:27Okay. So currently this quantity has
  1450. 1:08:29shape 4 + 2048.
  1451. 1:08:32You will do a dot product with W2 which
  1452. 1:08:34is 2048 + 512. So everyone see
  1453. 1:08:39W2 is what? 2048
  1454. 1:08:43cross 512. I already shown you right
  1455. 1:08:462048 cross 512. We mentioned uh we
  1456. 1:08:49actually have used W2 for it. Right?
  1457. 1:08:51These weights
  1458. 1:08:54right? So here also given both these
  1459. 1:08:56dimensions match. So you will get back
  1460. 1:09:01this particular
  1461. 1:09:03matrix
  1462. 1:09:05of 4 + 512. Why? Because you see four
  1463. 1:09:09cross 512.
  1464. 1:09:11Right? So in this you will add what? You
  1465. 1:09:14will add 512 biases. Obviously first of
  1466. 1:09:17all you will add a biases 512. But
  1467. 1:09:18finally you will get a matrix which is
  1468. 1:09:20of size 4 cross 512.
  1469. 1:09:25Okay. So again you will get 4 + 512
  1470. 1:09:27matrix. So which is again a better way
  1471. 1:09:30of saying that we have four vectors and
  1472. 1:09:33all their dimensionality is 512.
  1473. 1:09:37So what happened is that we sent four
  1474. 1:09:39vectors
  1475. 1:09:41took out four vectors also 512 size was
  1476. 1:09:46sent and 512 was also taken out. Okay.
  1477. 1:09:50You see here
  1478. 1:09:53fine in between what we did?
  1479. 1:09:57We applied RLU rectified linear unit in
  1480. 1:10:01it.
  1481. 1:10:04Fine. And by applying RLU what benefit
  1482. 1:10:07did we get
  1483. 1:10:09that we were able to introduce
  1484. 1:10:11nonlinearity.
  1485. 1:10:14Okay. So the overall uh after this
  1486. 1:10:18entire process
  1487. 1:10:20we reached
  1488. 1:10:23here everyone see I'll show you in our
  1489. 1:10:25uh
  1490. 1:10:27decoder diagram after doing this
  1491. 1:10:29particular stuff even we are here
  1492. 1:10:33okay
  1493. 1:10:36after this entire process we reached
  1494. 1:10:38here now
  1495. 1:10:41we have four vectors all of shape 512
  1496. 1:10:44Right? Y1, Y2, Y3, Y4. So we have four
  1497. 1:10:48vectors and all of the shape 512
  1498. 1:10:51dimension.
  1499. 1:10:54But now these four vectors have the
  1500. 1:10:56power to capture nonlinear information
  1501. 1:10:58too. So I'm calling these as Y1, Y2, Y3,
  1502. 1:11:01Y4.
  1503. 1:11:03So now we have
  1504. 1:11:06as as as we have reached at this
  1505. 1:11:08particular point driven
  1506. 1:11:11right
  1507. 1:11:13feed forward has given us output and we
  1508. 1:11:16are here
  1509. 1:11:19and now again ahead of this is what add
  1510. 1:11:23so again notice that what I have done
  1511. 1:11:27in this particular diagram if you can
  1512. 1:11:29Three.
  1513. 1:11:32What I have done here is this Z C1 NOM,
  1514. 1:11:35Z C2 NOM, Z C3 NOM, right? You see this
  1515. 1:11:40one? This is residual connection,
  1516. 1:11:44right?
  1517. 1:11:45So what I have done is this Z C1 norm, Z
  1518. 1:11:48C2, Z C3, Z C4 was not only sent to the
  1519. 1:11:52feed forward neural network.
  1520. 1:11:55Okay, it was not only sent to the feed
  1521. 1:11:57forward neural network.
  1522. 1:12:01But
  1523. 1:12:03through residual connection
  1524. 1:12:06right through residual connection it was
  1525. 1:12:08sent here as well. You see here as well
  1526. 1:12:11I think you understand right there's a
  1527. 1:12:13residual connection.
  1528. 1:12:16Okay there was a so this is this
  1529. 1:12:18basically sent to the feed forward new
  1530. 1:12:19letter plus through this residual
  1531. 1:12:21connection here also it was sent for
  1532. 1:12:23add.
  1533. 1:12:28Okay. So Z C1 NOM and so on was not only
  1534. 1:12:31sent to the feed forward neural network
  1535. 1:12:33but also it was sent through a residual
  1536. 1:12:35connection here
  1537. 1:12:38and since all these are 512 vectors we
  1538. 1:12:40can perform addition. These are all 512.
  1539. 1:12:43These are also all 512 dimensional
  1540. 1:12:45vectors. From adding them,
  1541. 1:12:48let's say we get y1 dash, y2 dash, y3
  1542. 1:12:52dash, y4 dash. After doing addition,
  1543. 1:12:54which we will normalize again. And since
  1544. 1:12:58many operations have been performed, we
  1545. 1:12:59will perform layer normalization. And
  1546. 1:13:01finally, we will get y1 normalized, y2
  1547. 1:13:04normalized, y3 normalized, and y4
  1548. 1:13:07normalized. Again, all four are still
  1549. 1:13:10512 dimensional vectors.
  1550. 1:13:18Fine. And again
  1551. 1:13:22with that now if I want to show you we
  1552. 1:13:25have reached here everyone.
  1553. 1:13:29Okay. And these four vectors
  1554. 1:13:32y1 nom, y2 nom, y3 nom, y4 nom.
  1555. 1:13:37These are the output of decoder one.
  1556. 1:13:40That is first decoder.
  1557. 1:13:44This is the output of first decoder
  1558. 1:13:46block. Y1 nom, y2 n, y3 n, y4. So we are
  1559. 1:13:49here now.
  1560. 1:13:52So I really hope through this entire
  1561. 1:13:54journey you understood what is happening
  1562. 1:13:55inside a single decoder block.
  1563. 1:14:00Fine. Now, next what happens after this?
  1564. 1:14:04Let's see that.
  1565. 1:14:09Now, as you know,
  1566. 1:14:11we do not have just one decoder. We have
  1567. 1:14:15got six in total six decoder blocks. So
  1568. 1:14:18what will happen is that as soon as you
  1569. 1:14:21get your output from first decoder block
  1570. 1:14:24and that output is y1 norm, y2 nom, y3
  1571. 1:14:28nom and y4 norm right these four
  1572. 1:14:34you will directly send it to the decoder
  1573. 1:14:36block two
  1574. 1:14:39and in decoder block two
  1575. 1:14:44again let's say this decoder block so
  1576. 1:14:47which is again similar to this. So in
  1577. 1:14:49this decoder block two again the same
  1578. 1:14:51operations will be executed exactly as
  1579. 1:14:54they are in the first decoder. The only
  1580. 1:14:56difference would be that parameters here
  1581. 1:15:00will be different but the operations
  1582. 1:15:01will be exactly same. Again you will
  1583. 1:15:03apply
  1584. 1:15:05masked multi head attention
  1585. 1:15:09then normalization on top of it. add a
  1586. 1:15:12normalization. Then you will send it to
  1587. 1:15:14the cross attention block. Then again
  1588. 1:15:17add a normalization and then feed
  1589. 1:15:19forward neural network and then again
  1590. 1:15:21add a normalization. And like this you
  1591. 1:15:23will progress and reach the next block
  1592. 1:15:27and again let's say in this third block
  1593. 1:15:30you will get a set of vectors just like
  1594. 1:15:33you got
  1595. 1:15:35here. Y1 norm Y2 norm Y3 nom Y4 N. Okay,
  1596. 1:15:39you'll again get all this. You will send
  1597. 1:15:42that to the decoder three. From second
  1598. 1:15:44you will send that to decoder three.
  1599. 1:15:49Sorry. And now
  1600. 1:15:53like this even step by step you will go
  1601. 1:15:58all the way to the sixth decoder block
  1602. 1:16:01and from the sixth decoder block you
  1603. 1:16:04will get the final output here.
  1604. 1:16:10So that is what I have shown in this
  1605. 1:16:12particular diagram
  1606. 1:16:14or in detail I can say that is what I
  1607. 1:16:16have shown you in in this particular
  1608. 1:16:18diagram like this one right or if you
  1609. 1:16:22really want to understand those
  1610. 1:16:23operations what happens in every decoder
  1611. 1:16:26that is what I shown you here I think
  1612. 1:16:27you understood that okay
  1613. 1:16:33now [clears throat]
  1614. 1:16:36as I've told you everyone
  1615. 1:16:38there are uh six decoders right
  1616. 1:16:44okay and as I've told you that
  1617. 1:16:48six decoder will give you this final
  1618. 1:16:51right this this this particular final
  1619. 1:16:53output
  1620. 1:16:55so right now you are in decoder one
  1621. 1:16:58let's say okay you are in decoder one
  1622. 1:17:01and you have got the output of decoder
  1623. 1:17:04one this is ready decoder output is
  1624. 1:17:07output uh decoder output is ready. So
  1625. 1:17:09this this is decoders decoder once is
  1626. 1:17:12output. Now after this in between as
  1627. 1:17:15I've told you there are five decoder
  1628. 1:17:18five more decoder blocks because total
  1629. 1:17:20there are six decoder blocks. So there
  1630. 1:17:22are five more decoder layers or the
  1631. 1:17:24blocks and when you process all of them
  1632. 1:17:26one by one you'll finally get your
  1633. 1:17:29vector and I had denoted it as y f_sub_1
  1634. 1:17:32nom y f_sub_2 nom y f3 nom y f4 nom
  1635. 1:17:36where f stands for let's say final and
  1636. 1:17:39this is now the final output which I
  1637. 1:17:42have to process and print the output
  1638. 1:17:46okay
  1639. 1:17:48so now we will discuss the last part of
  1640. 1:17:50this architecture And that is nothing
  1641. 1:17:52but output block. That is nothing but
  1642. 1:17:55this one. This output block is what we
  1643. 1:17:58are going to discuss.
  1644. 1:18:00So guys, now comes the most important
  1645. 1:18:02part and the most interesting part of
  1646. 1:18:04this entire architecture.
  1647. 1:18:08Okay. Until now we have crossed the
  1648. 1:18:13entire decoder six layer stack you can
  1649. 1:18:16say and uh at this point we are sitting
  1650. 1:18:20here if uh if I want to even show you
  1651. 1:18:26original transform architecture as well.
  1652. 1:18:27So you can imagine one decoder lock
  1653. 1:18:29second third fourth fifth sixth and now
  1654. 1:18:31we are here.
  1655. 1:18:33Okay, now we are here.
  1656. 1:18:40Fine. So,
  1657. 1:18:43and and and we have our vectors which
  1658. 1:18:45are final vectors.
  1659. 1:18:48This one yf1 norm, y f2 nom, yf3 nom and
  1660. 1:18:51y4 nom. Now there is one last work.
  1661. 1:18:56I must print a Hindi word for every
  1662. 1:18:59token
  1663. 1:19:01or I must give output. So this see how
  1664. 1:19:05this will happen. For this you must
  1665. 1:19:07understand
  1666. 1:19:09this particular output portion properly.
  1667. 1:19:12You must understand this output portion
  1668. 1:19:14properly.
  1669. 1:19:17This output portion is made up of two
  1670. 1:19:19things.
  1671. 1:19:22Okay. As you can see a linear layer is
  1672. 1:19:24there
  1673. 1:19:26and a softmax layer is there. This is
  1674. 1:19:29not something special everyone. you can
  1675. 1:19:32very easily compare it with an output
  1676. 1:19:34layer of a feed forward neural network.
  1677. 1:19:37So here basically you have a single
  1678. 1:19:39layer and to this layer you can give 512
  1679. 1:19:43dimension input like this.
  1680. 1:19:46Okay
  1681. 1:19:48this I told you why f_sub_1 f_sub_2 and
  1682. 1:19:50so on till f_sub_4.
  1683. 1:19:52Now here in output layer what we have is
  1684. 1:19:57you have a single layer and to this
  1685. 1:19:59single layer you can give 512 dimension
  1686. 1:20:02vector as a input. Okay 512 dimension
  1687. 1:20:06input. Now this layer in this layer how
  1688. 1:20:09many neurons do we have? If you talk
  1689. 1:20:11about this layer how many neurons? See
  1690. 1:20:13this is very interesting. In this layer
  1691. 1:20:16we have
  1692. 1:20:18V number of neurons. Please understand V
  1693. 1:20:21is a predefined number which is decided
  1694. 1:20:23by the fact
  1695. 1:20:26that what is the vocabulary count of
  1696. 1:20:29Hindi words in your entire data set
  1697. 1:20:35see
  1698. 1:20:38so we are doing English to Hindi
  1699. 1:20:41translation I've told you right now look
  1700. 1:20:44at the sentences I am good
  1701. 1:20:47we are ID.
  1702. 1:20:50Fine. So we are doing English to Hindi
  1703. 1:20:53translation. So in one column we have
  1704. 1:20:57all English sentences here
  1705. 1:21:00and in another we have all Hindi
  1706. 1:21:03sentences here.
  1707. 1:21:05Right? These are two columns English and
  1708. 1:21:07Hindi.
  1709. 1:21:10Like here this is my data set. Let's say
  1710. 1:21:13I am good. Corresponding to that we have
  1711. 1:21:16Hindi sentence like my buddy
  1712. 1:21:18corresponding to this this is the Hindi
  1713. 1:21:19sentence
  1714. 1:21:21like this let's say everyone we have
  1715. 1:21:24let's say we have total 5,000
  1716. 1:21:29sentence pairs of English to Hindi
  1717. 1:21:32so what am I going to do I'm going to go
  1718. 1:21:35into my entire Hindi data that is this
  1719. 1:21:39one
  1720. 1:21:42and start counting unique words like one
  1721. 1:21:45unique word is me,
  1722. 1:21:47one unique word is bada,
  1723. 1:21:50then another unique word is who, one
  1724. 1:21:53unique word is h, one unique word is ta
  1725. 1:21:57and another unique word is he and so on
  1726. 1:22:01and then let's say
  1727. 1:22:06h appears in another sentence I will not
  1728. 1:22:09count it again because I have already
  1729. 1:22:11counted Hum
  1730. 1:22:15right in the previous sentence. So in
  1731. 1:22:16this way you make a vocabulary of all
  1732. 1:22:18the unique words
  1733. 1:22:21which are present in your Hindi data. So
  1734. 1:22:24suppose everyone as I've told you there
  1735. 1:22:26are 5,000 Hindi sentences and let's say
  1736. 1:22:30there are
  1737. 1:22:3210,000
  1738. 1:22:35unique Hindi words. How many? 10,000
  1739. 1:22:37unique Hindi words.
  1740. 1:22:40Then this 10,000 is your V value. So
  1741. 1:22:45whatever I was trying to tell you V
  1742. 1:22:48value will be what? 10,000.
  1743. 1:22:54Okay.
  1744. 1:22:56So as I've told you, you make a
  1745. 1:22:58vocabulary of all the unique words that
  1746. 1:23:00are in your Hindi data.
  1747. 1:23:03So we will have 10,000 neurons here. How
  1748. 1:23:08many neurons are even 10,000 neurons?
  1749. 1:23:13And what is interesting is that the
  1750. 1:23:15first neurons represent the first word
  1751. 1:23:17of vocabulary. Let's say which is in our
  1752. 1:23:19case which is in our case this may.
  1753. 1:23:24Okay. So it will be represented by this
  1754. 1:23:27neuron.
  1755. 1:23:29The second neuron represent second word
  1756. 1:23:32that is nothing but let's say bada.
  1757. 1:23:36Okay, that is this one.
  1758. 1:23:39Fine.
  1759. 1:23:41Similarly, this neuron represents who.
  1760. 1:23:46This neuron represents H. This neuron
  1761. 1:23:48represents ta. This neuron represents he
  1762. 1:23:51and so on. And in this way, 10,000
  1763. 1:23:55neurons will represent 10,000 unique
  1764. 1:23:58Hindi words.
  1765. 1:24:01Okay, please understand this.
  1766. 1:24:04Next here we have weights you see here
  1767. 1:24:07we have weights right these are weights
  1768. 1:24:12how many weights
  1769. 1:24:14here 512
  1770. 1:24:17right which is your uh input size and v
  1771. 1:24:21as I've told you is nothing but what
  1772. 1:24:2410,000 so here everyone your weights
  1773. 1:24:26will be 512 cross 10,000
  1774. 1:24:32and every neuron has its own bias.
  1775. 1:24:35So obviously that means there'll be
  1776. 1:24:3810,000 biases.
  1777. 1:24:43So at this point, so at this point I
  1778. 1:24:46have four vectors 1 2 3 4
  1779. 1:24:51one for each token.
  1780. 1:24:53Right? So this first one corresponds to
  1781. 1:24:57start.
  1782. 1:25:00This second one corresponds to hum.
  1783. 1:25:03This corresponds to T. This corresponds
  1784. 1:25:05to H. Since here you can only give 512
  1785. 1:25:11dimension input. What have we done? We
  1786. 1:25:15have stacked these four vectors and made
  1787. 1:25:18a 4 + 512 matrix.
  1788. 1:25:23Okay. All these four vectors we stacked
  1789. 1:25:26and we have made 4 + 512 matrix. Now you
  1790. 1:25:30can say the batch of this layer in a
  1791. 1:25:33batch form. So basically there will be
  1792. 1:25:35parallel processing for all four tokens.
  1793. 1:25:38But let me just show you for one token.
  1794. 1:25:41Suppose we send the first vector to this
  1795. 1:25:44layer. Then our input will be what? Our
  1796. 1:25:46input will be 1 + 512 because I'm saying
  1797. 1:25:50that I'll just uh show you for one
  1798. 1:25:52token. Okay. Just to make the things
  1799. 1:25:55simpler. So input will be what? 1 + 512
  1800. 1:25:59one vector of dimension 512. So first
  1801. 1:26:02what will happen? This y f_sub_1 norm
  1802. 1:26:06this y f1 norm will multiply with these
  1803. 1:26:10weights.
  1804. 1:26:12Y f_sub_1 norm will multiply with these
  1805. 1:26:14weights and how many weights 512 +
  1806. 1:26:1810,000
  1807. 1:26:20the operation will be performed which
  1808. 1:26:21operation given let's say I'll represent
  1809. 1:26:23this as w so the operation which will be
  1810. 1:26:26performed will be like this
  1811. 1:26:28w dot
  1812. 1:26:31y f_sub_1 norm this operation will be
  1813. 1:26:34performed
  1814. 1:26:36so y f1 norm is y f_sub1 norm is of size
  1815. 1:26:411 + 512 right 1 + 512
  1816. 1:26:47and weights as I've told everyone
  1817. 1:26:51weights
  1818. 1:26:52this is 1 + 512
  1819. 1:26:55and weights what we have is 512 + 10,000
  1820. 1:27:00so 512 to 512 match so from this I will
  1821. 1:27:04get what I will get
  1822. 1:27:071 +
  1823. 1:27:1010,000 so basically From every neuron
  1824. 1:27:13one number will come out. From every
  1825. 1:27:16neuron, this one, this one, this one,
  1826. 1:27:18this one, this one, this one, this one.
  1827. 1:27:20One number will come out.
  1828. 1:27:23From every one of these 10,000 neurons,
  1829. 1:27:27a number will emerge. So basically for
  1830. 1:27:30every neuron, you will have unnormalized
  1831. 1:27:32number. Whatever the numbers which you
  1832. 1:27:33will get, those will be unnormalized.
  1833. 1:27:40And as these are numbers are un are not
  1834. 1:27:42normalized. So what I will do? I will
  1835. 1:27:45apply softmax.
  1836. 1:27:49Okay, I'll apply softmax here. So we
  1837. 1:27:51will take all these numbers and run
  1838. 1:27:53softmax on them.
  1839. 1:27:57What does softmax do? It normalizes
  1840. 1:27:59these numbers and normalizes them such
  1841. 1:28:03that their sum becomes one. So basically
  1842. 1:28:05for every word we will have a
  1843. 1:28:08probability value for every word we will
  1844. 1:28:12have probability value.
  1845. 1:28:15So it is possible that let's say maybe
  1846. 1:28:18uh I get 0.1 for the first word 0.02 for
  1847. 1:28:25the second word 0.25
  1848. 1:28:29for the third word and so on.
  1849. 1:28:32Every word will have a corresponding
  1850. 1:28:34probability value. Every word will have
  1851. 1:28:37that. So let's say the probability value
  1852. 1:28:40corresponding to hum is highest.
  1853. 1:28:44Okay, probability value corresponding to
  1854. 1:28:46H is highest.
  1855. 1:28:48So what will we do? We will choose H
  1856. 1:28:51word to be the output for start token.
  1857. 1:28:56Okay, for start token output will be
  1858. 1:28:58what? Hum.
  1859. 1:29:03Fine.
  1860. 1:29:08This means that corresponding to start
  1861. 1:29:10token that is Y1 Y F1 NOM. Corresponding
  1862. 1:29:14to start token means YF1 NOM.
  1863. 1:29:19This network believes that the output
  1864. 1:29:21should be H.
  1865. 1:29:23Similarly, same thing for YF2 NOM, YF3
  1866. 1:29:26NOM and so on. And let's say for YF2 nom
  1867. 1:29:29corresponding word we got is tar for YF3
  1868. 1:29:34norm here and for y f4 nom y f4 norm
  1869. 1:29:39everyone let's say we got e o that is
  1870. 1:29:43nothing but end of sentence
  1871. 1:29:45and as soon as we get us a end of
  1872. 1:29:48sentence it means stop the process
  1873. 1:29:54okay us means what stop the process End
  1874. 1:29:57of sentence like if you remember at the
  1875. 1:29:59start we have used start start token.
  1876. 1:30:02Similarly this is stop token E O
  1877. 1:30:06end of sentence.
  1878. 1:30:08Okay. And as soon as we get this it
  1879. 1:30:12means stop the process. Stop the entire
  1880. 1:30:15process. And this is how the decoder
  1881. 1:30:18architecture works.
  1882. 1:30:22Fine. [clears throat]
  1883. 1:30:23So in the next video we will discuss
  1884. 1:30:25about transformer decoder architecture
  1885. 1:30:28during inference which means how decoder
  1886. 1:30:30works during prediction.
  1887. 1:30:34So I would I would recommend that you
  1888. 1:30:36draw this entire architecture diagram on
  1889. 1:30:38paper
  1890. 1:30:40all these diagrams on paper everyone
  1891. 1:30:45and try to understand it. It will be
  1892. 1:30:48easier if you watched previous encoder
  1893. 1:30:51architecture video. Okay. So, thank you
  1894. 1:30:54everyone. That's it from my side. Thank
  1895. 1:30:56you all of you.

About this transcript

This page contains the full transcript of Transformer Decoder Arch During Training Time - Pen & Paper Explaination | Transformer Series Part2 by yogesh murumkar, generated from the public captions YouTube serves with the video. The transcript has 11,315 words across 1,895 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.