-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
3975 lines (3570 loc) · 266 KB
/
index.html
File metadata and controls
3975 lines (3570 loc) · 266 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Complete Transformer Guide</title>
<link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=Source+Serif+4:ital,wght@0,300;0,400;1,300&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0a0f;
--bg2: #111118;
--bg3: #18181f;
--card: #1a1a24;
--border: rgba(255,255,255,0.08);
--border2: rgba(255,255,255,0.15);
--text: #e8e8f0;
--muted: #888898;
--accent: #7c6ef5;
--accent2: #52c8a0;
--accent3: #f0a050;
--accent4: #e05555;
--accent5: #5aaff0;
--glow: rgba(124,110,245,0.15);
}
*{margin:0;padding:0;box-sizing:border-box}
html{scroll-behavior:smooth}
body{background:var(--bg);color:var(--text);font-family:'Source Serif 4',Georgia,serif;font-size:17px;line-height:1.8;overflow-x:hidden}
/* Nav */
nav{position:fixed;top:0;left:0;right:0;z-index:100;background:rgba(10,10,15,0.9);backdrop-filter:blur(16px);border-bottom:1px solid var(--border);padding:12px 0}
.nav-inner{max-width:1100px;margin:0 auto;padding:0 24px;display:flex;align-items:center;justify-content:space-between;gap:16px;flex-wrap:wrap}
.nav-brand{font-family:'Syne',sans-serif;font-weight:800;font-size:16px;color:var(--accent);letter-spacing:-0.5px}
.nav-links{display:flex;gap:4px;flex-wrap:wrap}
.nav-links a{font-family:'Syne',sans-serif;font-size:11px;font-weight:600;color:var(--muted);text-decoration:none;padding:5px 10px;border-radius:6px;transition:all 0.2s;text-transform:uppercase;letter-spacing:0.5px}
.nav-links a:hover{color:var(--text);background:var(--bg3)}
/* Hero */
.hero{min-height:100vh;display:flex;align-items:center;justify-content:center;text-align:center;padding:100px 24px 60px;position:relative;overflow:hidden}
.hero-grid{position:absolute;inset:0;background-image:linear-gradient(rgba(124,110,245,0.04) 1px, transparent 1px),linear-gradient(90deg,rgba(124,110,245,0.04) 1px, transparent 1px);background-size:60px 60px;pointer-events:none}
.hero-glow{position:absolute;top:20%;left:50%;transform:translateX(-50%);width:600px;height:400px;background:radial-gradient(ellipse,rgba(124,110,245,0.12) 0%,transparent 70%);pointer-events:none}
.hero-content{position:relative;max-width:800px}
.hero-badge{display:inline-flex;align-items:center;gap:8px;background:rgba(124,110,245,0.12);border:1px solid rgba(124,110,245,0.25);border-radius:100px;padding:6px 16px;font-family:'Syne',sans-serif;font-size:12px;font-weight:600;color:var(--accent);letter-spacing:1px;text-transform:uppercase;margin-bottom:32px}
.hero h1{font-family:'Syne',sans-serif;font-size:clamp(36px,6vw,80px);font-weight:800;line-height:1.05;letter-spacing:-2px;margin-bottom:24px}
.hero h1 span{background:linear-gradient(135deg,var(--accent),var(--accent5),var(--accent2));-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text}
.hero-sub{font-size:18px;color:var(--muted);font-weight:300;max-width:560px;margin:0 auto 40px;line-height:1.7}
.hero-stats{display:flex;gap:40px;justify-content:center;flex-wrap:wrap}
.stat{text-align:center}
.stat-num{font-family:'Syne',sans-serif;font-size:28px;font-weight:800;color:var(--accent);display:block}
.stat-label{font-size:12px;color:var(--muted);font-family:'Syne',sans-serif;text-transform:uppercase;letter-spacing:1px}
/* Sections */
main{max-width:1100px;margin:0 auto;padding:0 24px}
section{padding:80px 0;border-bottom:1px solid var(--border)}
section:last-child{border-bottom:none}
.sec-header{margin-bottom:48px}
.sec-num{font-family:'Syne',sans-serif;font-size:11px;font-weight:600;color:var(--accent);letter-spacing:2px;text-transform:uppercase;margin-bottom:8px}
.sec-title{font-family:'Syne',sans-serif;font-size:clamp(28px,4vw,44px);font-weight:800;letter-spacing:-1.5px;line-height:1.1;margin-bottom:16px}
.sec-title .hi{color:var(--accent)}
.sec-desc{color:var(--muted);font-size:16px;max-width:600px;font-weight:300}
/* Cards */
.card{background:var(--card);border:1px solid var(--border);border-radius:16px;padding:28px 32px;margin-bottom:20px}
.card-title{font-family:'Syne',sans-serif;font-size:16px;font-weight:700;margin-bottom:10px;color:var(--text)}
.card p{color:var(--muted);font-size:15px;line-height:1.7}
/* Grid layouts */
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:20px}
.grid-3{display:grid;grid-template-columns:repeat(3,1fr);gap:20px}
.grid-4{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}
@media(max-width:768px){.grid-2,.grid-3,.grid-4{grid-template-columns:1fr}}
/* Diagrams */
.diagram{background:var(--bg2);border:1px solid var(--border);border-radius:20px;padding:32px;margin:32px 0;overflow:auto}
.diagram-title{font-family:'Syne',sans-serif;font-size:13px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:2px;margin-bottom:24px}
/* Callout boxes */
.callout{border-radius:12px;padding:20px 24px;margin:24px 0;display:flex;gap:16px;align-items:flex-start}
.callout.blue{background:rgba(90,175,240,0.08);border:1px solid rgba(90,175,240,0.2)}
.callout.green{background:rgba(82,200,160,0.08);border:1px solid rgba(82,200,160,0.2)}
.callout.orange{background:rgba(240,160,80,0.08);border:1px solid rgba(240,160,80,0.2)}
.callout.purple{background:rgba(124,110,245,0.08);border:1px solid rgba(124,110,245,0.2)}
.callout-icon{font-size:20px;flex-shrink:0;margin-top:2px}
.callout-body{font-size:15px;line-height:1.7;color:var(--muted)}
.callout-body strong{color:var(--text);font-weight:600}
/* Tables */
.table-wrap{overflow-x:auto;margin:28px 0;border-radius:16px;border:1px solid var(--border)}
table{width:100%;border-collapse:collapse;font-size:14px}
th{background:var(--bg3);padding:12px 16px;text-align:left;font-family:'Syne',sans-serif;font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:1px;color:var(--muted);border-bottom:1px solid var(--border)}
td{padding:11px 16px;border-bottom:1px solid var(--border);color:var(--text);vertical-align:top}
tr:last-child td{border-bottom:none}
tr:hover td{background:rgba(255,255,255,0.02)}
.badge{display:inline-block;padding:2px 8px;border-radius:100px;font-size:11px;font-family:'Syne',sans-serif;font-weight:600}
.badge.purple{background:rgba(124,110,245,0.2);color:var(--accent)}
.badge.green{background:rgba(82,200,160,0.15);color:var(--accent2)}
.badge.orange{background:rgba(240,160,80,0.15);color:var(--accent3)}
.badge.blue{background:rgba(90,175,240,0.15);color:var(--accent5)}
.badge.red{background:rgba(224,85,85,0.15);color:var(--accent4)}
/* Code */
pre{background:var(--bg3);border:1px solid var(--border);border-radius:12px;padding:20px 24px;font-family:'JetBrains Mono',monospace;font-size:13px;line-height:1.7;overflow-x:auto;margin:20px 0;color:#c8d0f0}
code{font-family:'JetBrains Mono',monospace;font-size:13px;color:var(--accent2);background:rgba(82,200,160,0.1);padding:2px 6px;border-radius:4px}
/* Step indicator */
.steps{counter-reset:step;margin:28px 0}
.step{display:flex;gap:20px;margin-bottom:28px;align-items:flex-start}
.step-num{counter-increment:step;content:counter(step);min-width:40px;height:40px;border-radius:50%;background:linear-gradient(135deg,var(--accent),var(--accent5));display:flex;align-items:center;justify-content:center;font-family:'Syne',sans-serif;font-weight:800;font-size:15px;flex-shrink:0}
.step-num::before{content:counter(step)}
.step-body h4{font-family:'Syne',sans-serif;font-weight:700;font-size:16px;margin-bottom:6px}
.step-body p{color:var(--muted);font-size:15px;line-height:1.7}
/* Token viz */
.tokens{display:flex;gap:8px;flex-wrap:wrap;margin:16px 0}
.token{padding:6px 12px;border-radius:8px;font-family:'JetBrains Mono',monospace;font-size:13px;font-weight:500;border:1px solid}
.token.t1{background:rgba(124,110,245,0.12);border-color:rgba(124,110,245,0.3);color:#b5acff}
.token.t2{background:rgba(82,200,160,0.12);border-color:rgba(82,200,160,0.3);color:#7dddc4}
.token.t3{background:rgba(240,160,80,0.12);border-color:rgba(240,160,80,0.3);color:#f4be6e}
.token.t4{background:rgba(90,175,240,0.12);border-color:rgba(90,175,240,0.3);color:#8eccf5}
.token.t5{background:rgba(224,85,85,0.12);border-color:rgba(224,85,85,0.3);color:#f08888}
.arrow-right{color:var(--muted);font-size:20px;display:flex;align-items:center}
/* Highlight */
.hl{color:var(--accent);font-weight:600}
.hl2{color:var(--accent2);font-weight:600}
.hl3{color:var(--accent3);font-weight:600}
/* Attention demo */
.attn-demo{display:grid;gap:8px;margin:20px 0}
.attn-row{display:flex;gap:8px;align-items:center}
.attn-cell{width:44px;height:44px;border-radius:8px;display:flex;align-items:center;justify-content:center;font-family:'JetBrains Mono',monospace;font-size:12px;font-weight:500}
.attn-word{width:80px;font-size:13px;color:var(--muted);font-family:'Syne',sans-serif;text-align:right;padding-right:12px}
/* Two-col layout */
.two-col{display:grid;grid-template-columns:1fr 1fr;gap:40px;align-items:start}
@media(max-width:768px){.two-col{grid-template-columns:1fr}}
/* Model card */
.model-card{background:var(--card);border:1px solid var(--border);border-radius:16px;padding:24px;transition:border-color 0.2s}
.model-card:hover{border-color:var(--border2)}
.model-name{font-family:'Syne',sans-serif;font-weight:800;font-size:18px;margin-bottom:4px}
.model-maker{font-size:12px;color:var(--muted);font-family:'Syne',sans-serif;text-transform:uppercase;letter-spacing:1px;margin-bottom:16px}
.model-stat{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border);font-size:14px}
.model-stat:last-child{border-bottom:none}
.model-stat-label{color:var(--muted)}
.model-stat-val{font-family:'Syne',sans-serif;font-weight:600;color:var(--text)}
/* Quant visual */
.quant-bar{height:12px;border-radius:6px;margin:6px 0}
.bits-label{font-family:'Syne',sans-serif;font-size:12px;font-weight:600;color:var(--muted);display:flex;justify-content:space-between;margin-bottom:4px}
/* TOC */
.toc{background:var(--bg2);border:1px solid var(--border);border-radius:20px;padding:32px;margin-bottom:60px}
.toc-title{font-family:'Syne',sans-serif;font-weight:800;font-size:18px;margin-bottom:20px;color:var(--text)}
.toc-list{columns:2;column-gap:40px;list-style:none}
.toc-list li{margin-bottom:10px;break-inside:avoid}
.toc-list a{color:var(--muted);text-decoration:none;font-size:14px;font-family:'Syne',sans-serif;transition:color 0.2s;display:flex;align-items:center;gap:8px}
.toc-list a:hover{color:var(--accent)}
.toc-num{font-size:10px;font-weight:700;min-width:20px;color:var(--accent);opacity:0.7}
@media(max-width:600px){.toc-list{columns:1}}
/* SVG diagram text fix */
.diagram svg text{font-family:'Syne',sans-serif}
/* Embed viz */
.embed-row{display:flex;align-items:center;gap:12px;margin:12px 0;flex-wrap:wrap}
.embed-word{font-family:'Syne',sans-serif;font-weight:700;font-size:15px;min-width:100px}
.embed-vec{display:flex;gap:4px}
.embed-box{width:30px;height:30px;border-radius:5px;display:flex;align-items:center;justify-content:center;font-family:'JetBrains Mono',monospace;font-size:9px;font-weight:500;color:rgba(255,255,255,0.7)}
footer{text-align:center;padding:60px 24px;color:var(--muted);font-size:14px;border-top:1px solid var(--border)}
footer a{color:var(--accent);text-decoration:none}
@keyframes pulse-glow{0%,100%{opacity:0.6}50%{opacity:1}}
.pulse{animation:pulse-glow 2s ease-in-out infinite}
</style>
</head>
<body>
<nav>
<div class="nav-inner">
<span class="nav-brand">🧠 Transformer Guide</span>
<div class="nav-links">
<a href="#what-is">Basics</a>
<a href="#tokenization">Tokens</a>
<a href="#attention">Attention</a>
<a href="#architecture">Structure</a>
<a href="#models">Models</a>
<a href="#context">Context</a>
<a href="#training">Training</a>
<a href="#quantization">Quant</a>
<a href="#build">Build</a>
<a href="#agents">Agents</a>
<a href="#voice">Voice/TTS</a>
<a href="#imagegen">Images</a>
<a href="#videogen">Video</a>
</div>
</div>
</nav>
<div class="hero">
<div class="hero-grid"></div>
<div class="hero-glow"></div>
<div class="hero-content">
<div class="hero-badge">✦ Complete Guide — Zero to Expert</div>
<h1>How <span>Transformers</span> Actually Work</h1>
<p class="hero-sub">The complete guide to understanding AI models like Claude, ChatGPT & Gemini — explained so clearly that anyone can understand it, no coding required.</p>
<div class="hero-stats">
<div class="stat"><span class="stat-num">175B+</span><span class="stat-label">GPT-3 Parameters</span></div>
<div class="stat"><span class="stat-num">96</span><span class="stat-label">GPT-4 Layers</span></div>
<div class="stat"><span class="stat-num">2017</span><span class="stat-label">Year Invented</span></div>
<div class="stat"><span class="stat-num">~2M</span><span class="stat-label">Token Contexts</span></div>
</div>
</div>
</div>
<main>
<!-- TOC -->
<div class="toc">
<div class="toc-title">📖 What You'll Learn</div>
<ul class="toc-list">
<li><a href="#what-is"><span class="toc-num">01</span> What is a Transformer?</a></li>
<li><a href="#tokenization"><span class="toc-num">02</span> Tokenization — Text to Numbers</a></li>
<li><a href="#embeddings"><span class="toc-num">03</span> Embeddings — Words as Coordinates</a></li>
<li><a href="#attention"><span class="toc-num">04</span> The Attention Mechanism</a></li>
<li><a href="#architecture"><span class="toc-num">05</span> Full Architecture Diagram</a></li>
<li><a href="#layers"><span class="toc-num">06</span> Layers in Real Models</a></li>
<li><a href="#models"><span class="toc-num">07</span> GPT, Claude, Gemini Compared</a></li>
<li><a href="#context"><span class="toc-num">08</span> Context Windows Explained</a></li>
<li><a href="#training"><span class="toc-num">09</span> Training: How Models Learn</a></li>
<li><a href="#quantization"><span class="toc-num">10</span> Quantization — Smaller = Faster</a></li>
<li><a href="#types"><span class="toc-num">11</span> Types of Transformer Models</a></li>
<li><a href="#build"><span class="toc-num">12</span> Building One from Scratch</a></li>
<li><a href="#agents"><span class="toc-num">13</span> AI Agent Systems — Full Guide</a></li>
<li><a href="#agent-tools"><span class="toc-num">14</span> Tools & Function Calling</a></li>
<li><a href="#agent-memory"><span class="toc-num">15</span> Agent Memory & State</a></li>
<li><a href="#agent-loop"><span class="toc-num">16</span> The ReAct Loop (Think → Act)</a></li>
<li><a href="#multi-agent"><span class="toc-num">17</span> Multi-Agent Systems</a></li>
<li><a href="#agent-build"><span class="toc-num">18</span> Building an Agent from Scratch</a></li>
<li><a href="#voice"><span class="toc-num">19</span> Voice & Text-to-Speech Models</a></li>
<li><a href="#voice-build"><span class="toc-num">20</span> Build Your Own TTS & Voice Clone</a></li>
<li><a href="#imagegen"><span class="toc-num">21</span> Image Generation Models Explained</a></li>
<li><a href="#imagegen-build"><span class="toc-num">22</span> Build Image Generation Apps</a></li>
<li><a href="#videogen"><span class="toc-num">23</span> Video Generation Models</a></li>
<li><a href="#videogen-build"><span class="toc-num">24</span> Build a Video Generation Pipeline</a></li>
</ul>
</div>
<!-- SECTION 1: What is a Transformer -->
<section id="what-is">
<div class="sec-header">
<div class="sec-num">Section 01</div>
<h2 class="sec-title">What is a <span class="hi">Transformer</span>?</h2>
<p class="sec-desc">The revolutionary architecture behind every major AI model today — explained with a simple analogy.</p>
</div>
<div class="callout blue">
<span class="callout-icon">💡</span>
<div class="callout-body"><strong>Simple Analogy:</strong> Imagine you're reading a sentence: <em>"The animal didn't cross the street because it was too tired."</em> What does "it" refer to — the animal or the street? Your brain automatically connects "it" to "animal". A Transformer does exactly this — it figures out which words relate to which other words, no matter how far apart they are.</div>
</div>
<div class="two-col" style="margin-top:32px">
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">Before Transformers (The Old Way)</h3>
<p style="color:var(--muted);font-size:15px;margin-bottom:16px;">Older AI models read text one word at a time, like reading left-to-right. By the time they reached word 100, they'd forgotten word 1. This was called an <strong>RNN (Recurrent Neural Network)</strong>.</p>
<div class="card" style="padding:20px">
<p style="color:var(--accent4);font-size:14px;margin-bottom:8px;font-family:'Syne',sans-serif;font-weight:700">❌ Problem with RNNs</p>
<p style="font-size:14px;color:var(--muted)">Can't handle long sentences. Forgets early words. Can't run in parallel. Slow to train.</p>
</div>
</div>
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">With Transformers (The New Way)</h3>
<p style="color:var(--muted);font-size:15px;margin-bottom:16px;">A Transformer reads ALL words at once and figures out the relationship between every word and every other word simultaneously. This is called <strong>self-attention</strong>.</p>
<div class="card" style="padding:20px">
<p style="color:var(--accent2);font-size:14px;margin-bottom:8px;font-family:'Syne',sans-serif;font-weight:700">✅ Why Transformers Win</p>
<p style="font-size:14px;color:var(--muted)">Handles thousands of words. Never forgets. Runs in parallel. Trains fast on GPUs.</p>
</div>
</div>
</div>
<div class="diagram">
<div class="diagram-title">The core idea: every word "looks at" every other word simultaneously</div>
<svg width="100%" viewBox="0 0 900 220">
<defs>
<marker id="arr" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#7c6ef5" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Words -->
<g>
<rect x="20" y="90" width="90" height="40" rx="8" fill="rgba(124,110,245,0.15)" stroke="rgba(124,110,245,0.4)" stroke-width="1"/>
<text x="65" y="115" fill="#b5acff" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">The</text>
</g>
<g>
<rect x="150" y="90" width="100" height="40" rx="8" fill="rgba(82,200,160,0.15)" stroke="rgba(82,200,160,0.4)" stroke-width="1"/>
<text x="200" y="115" fill="#7dddc4" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">animal</text>
</g>
<g>
<rect x="300" y="90" width="110" height="40" rx="8" fill="rgba(240,160,80,0.15)" stroke="rgba(240,160,80,0.4)" stroke-width="1"/>
<text x="355" y="115" fill="#f4be6e" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">didn't</text>
</g>
<g>
<rect x="460" y="90" width="90" height="40" rx="8" fill="rgba(240,160,80,0.15)" stroke="rgba(240,160,80,0.4)" stroke-width="1"/>
<text x="505" y="115" fill="#f4be6e" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">cross</text>
</g>
<g>
<rect x="600" y="90" width="80" height="40" rx="8" fill="rgba(240,160,80,0.15)" stroke="rgba(240,160,80,0.4)" stroke-width="1"/>
<text x="640" y="115" fill="#f4be6e" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">…</text>
</g>
<g>
<rect x="730" y="90" width="60" height="40" rx="8" fill="rgba(90,175,240,0.25)" stroke="rgba(90,175,240,0.6)" stroke-width="2"/>
<text x="760" y="115" fill="#8eccf5" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">it</text>
</g>
<g>
<rect x="840" y="90" width="50" height="40" rx="8" fill="rgba(240,160,80,0.15)" stroke="rgba(240,160,80,0.4)" stroke-width="1"/>
<text x="865" y="115" fill="#f4be6e" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">was</text>
</g>
<!-- Big attention arrow from "it" to "animal" -->
<path d="M760 90 C760 40, 200 40, 200 90" fill="none" stroke="#7c6ef5" stroke-width="2.5" stroke-dasharray="6,3" marker-end="url(#arr)"/>
<text x="480" y="32" fill="#7c6ef5" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Strong attention: "it" refers to "animal"</text>
<!-- Weak arrow from "it" to "cross" -->
<path d="M730 110 C700 170, 505 170, 505 130" fill="none" stroke="rgba(240,160,80,0.35)" stroke-width="1" marker-end="url(#arr)"/>
<text x="620" y="185" fill="rgba(240,160,80,0.5)" font-family="Syne" font-size="11" text-anchor="middle">Weak attention</text>
</svg>
</div>
<div class="callout purple">
<span class="callout-icon">📅</span>
<div class="callout-body"><strong>History:</strong> The Transformer was invented in 2017 by Google researchers in a paper called <strong>"Attention Is All You Need"</strong>. This paper changed the entire field of AI. Every major AI model since — GPT, Claude, Gemini, LLaMA — is built on this architecture.</div>
</div>
</section>
<!-- SECTION 2: Tokenization -->
<section id="tokenization">
<div class="sec-header">
<div class="sec-num">Section 02</div>
<h2 class="sec-title"><span class="hi">Tokenization</span> — Breaking Text into Pieces</h2>
<p class="sec-desc">Computers can't understand words directly. They need numbers. Tokenization is the first step that converts text into small pieces called "tokens".</p>
</div>
<div class="two-col">
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">What is a Token?</h3>
<p style="color:var(--muted);font-size:15px;margin-bottom:16px;">A token is a small piece of text — it can be a word, part of a word, or even a single character. The AI model never sees actual letters; it sees numbers representing these tokens.</p>
<div class="callout orange">
<span class="callout-icon">🔢</span>
<div class="callout-body"><strong>Rule of thumb:</strong> 1 token ≈ 4 characters in English, or roughly ¾ of a word. So "Hello World" = 2 tokens. A full novel (~80,000 words) ≈ 60,000 tokens.</div>
</div>
</div>
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">Live Example</h3>
<p style="color:var(--muted);font-size:14px;margin-bottom:12px;">The sentence: <strong>"Unhappiness is complex"</strong></p>
<div class="tokens">
<span class="token t1">Un</span>
<span class="arrow-right">→</span>
<span class="token t1">happiness</span>
<span class="arrow-right">→</span>
<span class="token t2"> is</span>
<span class="arrow-right">→</span>
<span class="token t3"> com</span>
<span class="arrow-right">→</span>
<span class="token t3">plex</span>
</div>
<p style="color:var(--muted);font-size:13px;margin-top:8px;">↑ "Unhappiness" gets split into 2 tokens: "Un" + "happiness"</p>
<div class="tokens" style="margin-top:16px">
<span class="token t1" style="font-size:11px">Un=8087</span>
<span class="token t1" style="font-size:11px">happiness=29</span>
<span class="token t2" style="font-size:11px">is=318</span>
<span class="token t3" style="font-size:11px">com=401</span>
<span class="token t3" style="font-size:11px">plex=784</span>
</div>
<p style="color:var(--muted);font-size:13px;margin-top:8px;">↑ Each token gets a unique number (ID)</p>
</div>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-top:40px;margin-bottom:20px;">Types of Tokenizers</h3>
<div class="grid-3">
<div class="card">
<div class="card-title">BPE (Byte Pair Encoding)</div>
<p>Used by GPT models. Starts with individual characters, then merges the most common pairs repeatedly. Very efficient for common words.</p>
<div style="margin-top:12px"><span class="badge purple">GPT-2/3/4</span></div>
</div>
<div class="card">
<div class="card-title">WordPiece</div>
<p>Used by BERT and similar models. Similar to BPE but uses a different scoring method for merges. Adds ## prefix to subwords.</p>
<div style="margin-top:12px"><span class="badge blue">BERT, RoBERTa</span></div>
</div>
<div class="card">
<div class="card-title">SentencePiece</div>
<p>Used by many multilingual models. Works directly on raw text without pre-tokenization. Great for languages without spaces.</p>
<div style="margin-top:12px"><span class="badge green">LLaMA, Gemini</span></div>
</div>
</div>
<div class="diagram">
<div class="diagram-title">The tokenization pipeline</div>
<svg width="100%" viewBox="0 0 900 120">
<defs>
<marker id="arr2" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#888898" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Step 1 -->
<rect x="10" y="30" width="160" height="60" rx="10" fill="rgba(124,110,245,0.12)" stroke="rgba(124,110,245,0.35)" stroke-width="1"/>
<text x="90" y="55" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Raw Text</text>
<text x="90" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">"Hello World!"</text>
<!-- Arrow -->
<line x1="172" y1="60" x2="205" y2="60" stroke="#888898" stroke-width="1.5" marker-end="url(#arr2)"/>
<!-- Step 2 -->
<rect x="210" y="30" width="160" height="60" rx="10" fill="rgba(82,200,160,0.12)" stroke="rgba(82,200,160,0.35)" stroke-width="1"/>
<text x="290" y="55" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Tokenizer</text>
<text x="290" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">BPE / WordPiece</text>
<!-- Arrow -->
<line x1="372" y1="60" x2="405" y2="60" stroke="#888898" stroke-width="1.5" marker-end="url(#arr2)"/>
<!-- Step 3 -->
<rect x="410" y="30" width="180" height="60" rx="10" fill="rgba(240,160,80,0.12)" stroke="rgba(240,160,80,0.35)" stroke-width="1"/>
<text x="500" y="55" fill="#f4be6e" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Token IDs</text>
<text x="500" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">[15496, 2159, 0]</text>
<!-- Arrow -->
<line x1="592" y1="60" x2="625" y2="60" stroke="#888898" stroke-width="1.5" marker-end="url(#arr2)"/>
<!-- Step 4 -->
<rect x="630" y="30" width="200" height="60" rx="10" fill="rgba(90,175,240,0.12)" stroke="rgba(90,175,240,0.35)" stroke-width="1"/>
<text x="730" y="55" fill="#8eccf5" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Embedding Lookup</text>
<text x="730" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">[0.3, -0.1, 0.8, ...]</text>
</svg>
</div>
</section>
<!-- SECTION 3: Embeddings -->
<section id="embeddings">
<div class="sec-header">
<div class="sec-num">Section 03</div>
<h2 class="sec-title">Embeddings — <span class="hi">Words as Coordinates</span></h2>
<p class="sec-desc">How does the AI understand that "King" and "Queen" are related? Through embeddings — turning words into lists of numbers that capture their meaning.</p>
</div>
<div class="callout blue">
<span class="callout-icon">🗺️</span>
<div class="callout-body"><strong>Think of it like a map:</strong> On a regular map, cities that are geographically close are shown close together. In an embedding space, words with similar meanings are placed "close" to each other. "Dog" and "Cat" are near each other. "Dog" and "Car" are far apart.</div>
</div>
<div class="two-col" style="margin-top:32px">
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">Each Word = A List of Numbers</h3>
<p style="color:var(--muted);font-size:15px;margin-bottom:20px;">A word gets converted into a vector — a list of hundreds or thousands of decimal numbers. These numbers encode the word's meaning, context, and relationships.</p>
<div style="margin-bottom:12px">
<div class="embed-row">
<span class="embed-word" style="color:#b5acff">King</span>
<div class="embed-vec">
<div class="embed-box" style="background:rgba(124,110,245,0.6)">.82</div>
<div class="embed-box" style="background:rgba(124,110,245,0.4)">.31</div>
<div class="embed-box" style="background:rgba(124,110,245,0.7)">-.6</div>
<div class="embed-box" style="background:rgba(124,110,245,0.3)">.14</div>
<div class="embed-box" style="background:rgba(124,110,245,0.5)">.72</div>
<div class="embed-box" style="background:rgba(124,110,245,0.35)">-.2</div>
<span style="color:var(--muted);font-size:12px;align-self:center;margin-left:4px">... ×768</span>
</div>
</div>
<div class="embed-row">
<span class="embed-word" style="color:#7dddc4">Queen</span>
<div class="embed-vec">
<div class="embed-box" style="background:rgba(82,200,160,0.55)">.79</div>
<div class="embed-box" style="background:rgba(82,200,160,0.35)">.28</div>
<div class="embed-box" style="background:rgba(82,200,160,0.65)">-.5</div>
<div class="embed-box" style="background:rgba(82,200,160,0.4)">.60</div>
<div class="embed-box" style="background:rgba(82,200,160,0.5)">.68</div>
<div class="embed-box" style="background:rgba(82,200,160,0.3)">.55</div>
<span style="color:var(--muted);font-size:12px;align-self:center;margin-left:4px">... ×768</span>
</div>
</div>
<div class="embed-row">
<span class="embed-word" style="color:#f08888">Car</span>
<div class="embed-vec">
<div class="embed-box" style="background:rgba(224,85,85,0.2)">-.1</div>
<div class="embed-box" style="background:rgba(224,85,85,0.5)">.65</div>
<div class="embed-box" style="background:rgba(224,85,85,0.3)">.22</div>
<div class="embed-box" style="background:rgba(224,85,85,0.25)">-.4</div>
<div class="embed-box" style="background:rgba(224,85,85,0.4)">.09</div>
<div class="embed-box" style="background:rgba(224,85,85,0.2)">-.7</div>
<span style="color:var(--muted);font-size:12px;align-self:center;margin-left:4px">... ×768</span>
</div>
</div>
</div>
<p style="color:var(--muted);font-size:13px;margin-top:8px;">Notice: King & Queen have similar patterns. Car is completely different.</p>
</div>
<div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin-bottom:16px;">The Famous Equation</h3>
<div class="card" style="background:var(--bg3);text-align:center;padding:28px">
<p style="font-family:'JetBrains Mono',monospace;font-size:18px;color:var(--accent);margin-bottom:16px">King - Man + Woman = Queen</p>
<p style="color:var(--muted);font-size:14px">This works with math! Subtract the "man" direction from King's vector, add the "woman" direction — and you land very close to Queen's vector in the embedding space.</p>
</div>
<div class="callout green" style="margin-top:16px">
<span class="callout-icon">📏</span>
<div class="callout-body"><strong>Dimension sizes vary by model:</strong><br>
GPT-2 Small: 768 dimensions<br>
GPT-3: 12,288 dimensions<br>
BERT Base: 768 dimensions<br>
Larger = more nuance captured</div>
</div>
</div>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:40px 0 20px;">Positional Encoding — Where in the Sentence?</h3>
<p style="color:var(--muted);margin-bottom:20px;">Since Transformers read all tokens at once (not one by one), they need a way to know the <em>order</em> of words. Positional encoding adds position information to each embedding.</p>
<div class="diagram">
<div class="diagram-title">Positional encoding: same word in different positions gets different vectors</div>
<svg width="100%" viewBox="0 0 900 160">
<!-- Position 1: "I" -->
<rect x="20" y="20" width="120" height="50" rx="8" fill="rgba(124,110,245,0.12)" stroke="rgba(124,110,245,0.3)" stroke-width="1"/>
<text x="80" y="41" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Word "I"</text>
<text x="80" y="58" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Position 1</text>
<!-- + -->
<text x="158" y="50" fill="#888898" font-size="24" text-anchor="middle">+</text>
<rect x="170" y="20" width="120" height="50" rx="8" fill="rgba(82,200,160,0.12)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="230" y="41" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Pos(1)</text>
<text x="230" y="58" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">sin/cos values</text>
<text x="308" y="50" fill="#888898" font-size="20" text-anchor="middle">=</text>
<rect x="320" y="20" width="140" height="50" rx="8" fill="rgba(240,160,80,0.12)" stroke="rgba(240,160,80,0.3)" stroke-width="1"/>
<text x="390" y="41" fill="#f4be6e" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Final Vector</text>
<text x="390" y="58" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">[0.31, -0.2, 0.85…]</text>
<!-- Position 5: "I" -->
<rect x="20" y="100" width="120" height="50" rx="8" fill="rgba(124,110,245,0.12)" stroke="rgba(124,110,245,0.3)" stroke-width="1"/>
<text x="80" y="121" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Word "I"</text>
<text x="80" y="138" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Position 5</text>
<!-- + -->
<text x="158" y="130" fill="#888898" font-size="24" text-anchor="middle">+</text>
<rect x="170" y="100" width="120" height="50" rx="8" fill="rgba(82,200,160,0.12)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="230" y="121" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Pos(5)</text>
<text x="230" y="138" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">different values</text>
<text x="308" y="130" fill="#888898" font-size="20" text-anchor="middle">=</text>
<rect x="320" y="100" width="140" height="50" rx="8" fill="rgba(90,175,240,0.12)" stroke="rgba(90,175,240,0.3)" stroke-width="1"/>
<text x="390" y="121" fill="#8eccf5" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Different Vector</text>
<text x="390" y="138" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">[0.55, 0.12, -0.3…]</text>
<!-- note -->
<rect x="490" y="55" width="390" height="50" rx="8" fill="rgba(255,255,255,0.03)" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<text x="685" y="76" fill="#888898" font-family="Syne" font-size="12" text-anchor="middle">Same word "I" — but different position</text>
<text x="685" y="94" fill="#7dddc4" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">→ different final vector</text>
</svg>
</div>
</section>
<!-- SECTION 4: Attention -->
<section id="attention">
<div class="sec-header">
<div class="sec-num">Section 04</div>
<h2 class="sec-title">The <span class="hi">Attention Mechanism</span></h2>
<p class="sec-desc">The most important innovation in AI. How does a model know what to focus on? Through queries, keys, and values.</p>
</div>
<div class="callout orange">
<span class="callout-icon">🔍</span>
<div class="callout-body"><strong>Real-life analogy:</strong> Imagine you're at a library. You have a <strong>Query</strong> (what you're looking for: "books about cooking"). The library has <strong>Keys</strong> (book titles, topics, descriptions). You compare your query to all keys, find the best matches, then retrieve the <strong>Values</strong> (the actual book contents). Attention works exactly the same way!</div>
</div>
<div class="grid-3" style="margin-top:32px">
<div class="card" style="border-color:rgba(124,110,245,0.3)">
<div class="card-title" style="color:var(--accent)">🔎 Query (Q)</div>
<p>"What am I looking for?" Each word asks a question about the sentence. The word "it" asks: "Which other word do I refer to?"</p>
</div>
<div class="card" style="border-color:rgba(82,200,160,0.3)">
<div class="card-title" style="color:var(--accent2)">🗝️ Key (K)</div>
<p>"What do I represent?" Each word advertises what information it contains. "animal" says "I'm a living creature that can be tired."</p>
</div>
<div class="card" style="border-color:rgba(240,160,80,0.3)">
<div class="card-title" style="color:var(--accent3)">📦 Value (V)</div>
<p>"What's my actual content?" The information that gets passed forward. Once "animal" is identified as relevant, its full meaning is included.</p>
</div>
</div>
<div class="diagram" style="margin-top:32px">
<div class="diagram-title">Attention score calculation: Q × K → scores → softmax → weight V</div>
<svg width="100%" viewBox="0 0 900 200">
<defs>
<marker id="arr3" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#888898" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Step 1 -->
<rect x="10" y="60" width="140" height="80" rx="10" fill="rgba(124,110,245,0.1)" stroke="rgba(124,110,245,0.3)" stroke-width="1"/>
<text x="80" y="90" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Q × Kᵀ</text>
<text x="80" y="112" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Dot product =</text>
<text x="80" y="128" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">raw scores</text>
<!-- arrow -->
<line x1="152" y1="100" x2="195" y2="100" stroke="#888898" stroke-width="1.5" marker-end="url(#arr3)"/>
<!-- Step 2 -->
<rect x="200" y="60" width="140" height="80" rx="10" fill="rgba(82,200,160,0.1)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="270" y="90" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">÷ √d_k</text>
<text x="270" y="112" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Scale down to</text>
<text x="270" y="128" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">prevent explosion</text>
<!-- arrow -->
<line x1="342" y1="100" x2="385" y2="100" stroke="#888898" stroke-width="1.5" marker-end="url(#arr3)"/>
<!-- Step 3 -->
<rect x="390" y="60" width="140" height="80" rx="10" fill="rgba(240,160,80,0.1)" stroke="rgba(240,160,80,0.3)" stroke-width="1"/>
<text x="460" y="90" fill="#f4be6e" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Softmax</text>
<text x="460" y="112" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Converts to</text>
<text x="460" y="128" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">probabilities 0–1</text>
<!-- arrow -->
<line x1="532" y1="100" x2="575" y2="100" stroke="#888898" stroke-width="1.5" marker-end="url(#arr3)"/>
<!-- Step 4 -->
<rect x="580" y="60" width="140" height="80" rx="10" fill="rgba(90,175,240,0.1)" stroke="rgba(90,175,240,0.3)" stroke-width="1"/>
<text x="650" y="90" fill="#8eccf5" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">× V</text>
<text x="650" y="112" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Weighted sum</text>
<text x="650" y="128" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">of values</text>
<!-- arrow -->
<line x1="722" y1="100" x2="765" y2="100" stroke="#888898" stroke-width="1.5" marker-end="url(#arr3)"/>
<!-- Output -->
<rect x="770" y="60" width="120" height="80" rx="10" fill="rgba(124,110,245,0.2)" stroke="rgba(124,110,245,0.5)" stroke-width="1.5"/>
<text x="830" y="90" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Output</text>
<text x="830" y="112" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Context-aware</text>
<text x="830" y="128" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">representation</text>
</svg>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:40px 0 20px;">Multi-Head Attention — Many Perspectives at Once</h3>
<p style="color:var(--muted);margin-bottom:20px;">Instead of one set of Q, K, V — the model runs attention <em>multiple times in parallel</em>, each "head" learning different relationships. It's like having 8–96 experts each focusing on a different aspect of the sentence.</p>
<div class="grid-3">
<div class="card">
<div class="card-title">Head 1: Grammar</div>
<p style="font-size:14px">Focuses on subject-verb relationships. Connects "it" to its antecedent.</p>
<div style="margin-top:10px;height:4px;background:linear-gradient(90deg,var(--accent),transparent);border-radius:2px"></div>
</div>
<div class="card">
<div class="card-title">Head 2: Meaning</div>
<p style="font-size:14px">Connects semantically similar words. Groups synonyms and antonyms.</p>
<div style="margin-top:10px;height:4px;background:linear-gradient(90deg,var(--accent2),transparent);border-radius:2px"></div>
</div>
<div class="card">
<div class="card-title">Head 3: Context</div>
<p style="font-size:14px">Tracks long-range dependencies across paragraphs.</p>
<div style="margin-top:10px;height:4px;background:linear-gradient(90deg,var(--accent3),transparent);border-radius:2px"></div>
</div>
</div>
<div class="diagram" style="margin-top:24px">
<div class="diagram-title">Multi-head attention: 8 heads running in parallel, then combined</div>
<svg width="100%" viewBox="0 0 900 180">
<defs>
<marker id="arr4" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#888898" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Input -->
<rect x="20" y="70" width="100" height="40" rx="8" fill="rgba(124,110,245,0.15)" stroke="rgba(124,110,245,0.4)" stroke-width="1"/>
<text x="70" y="95" fill="#b5acff" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Input</text>
<!-- Lines to heads -->
<line x1="122" y1="90" x2="170" y2="30" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="122" y1="90" x2="170" y2="60" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="122" y1="90" x2="170" y2="90" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="122" y1="90" x2="170" y2="120" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="122" y1="90" x2="170" y2="150" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<!-- Heads -->
<rect x="175" y="15" width="100" height="30" rx="6" fill="rgba(124,110,245,0.12)" stroke="rgba(124,110,245,0.3)" stroke-width="1"/>
<text x="225" y="35" fill="#b5acff" font-family="Syne" font-size="11" font-weight="700" text-anchor="middle">Head 1</text>
<rect x="175" y="50" width="100" height="30" rx="6" fill="rgba(82,200,160,0.12)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="225" y="70" fill="#7dddc4" font-family="Syne" font-size="11" font-weight="700" text-anchor="middle">Head 2</text>
<rect x="175" y="75" width="100" height="30" rx="6" fill="rgba(240,160,80,0.12)" stroke="rgba(240,160,80,0.3)" stroke-width="1"/>
<text x="225" y="95" fill="#f4be6e" font-family="Syne" font-size="11" font-weight="700" text-anchor="middle">Head 3</text>
<rect x="175" y="100" width="100" height="30" rx="6" fill="rgba(90,175,240,0.12)" stroke="rgba(90,175,240,0.3)" stroke-width="1"/>
<text x="225" y="120" fill="#8eccf5" font-family="Syne" font-size="11" font-weight="700" text-anchor="middle">Head 4</text>
<rect x="175" y="130" width="100" height="30" rx="6" fill="rgba(224,85,85,0.12)" stroke="rgba(224,85,85,0.3)" stroke-width="1"/>
<text x="225" y="150" fill="#f08888" font-family="Syne" font-size="11" font-weight="700" text-anchor="middle">… Heads</text>
<!-- Lines from heads to concat -->
<line x1="277" y1="30" x2="450" y2="80" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="277" y1="65" x2="450" y2="84" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="277" y1="90" x2="450" y2="90" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="277" y1="115" x2="450" y2="96" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<line x1="277" y1="145" x2="450" y2="100" stroke="#888898" stroke-width="1" marker-end="url(#arr4)"/>
<!-- Concat -->
<rect x="455" y="60" width="120" height="60" rx="10" fill="rgba(124,110,245,0.12)" stroke="rgba(124,110,245,0.3)" stroke-width="1"/>
<text x="515" y="86" fill="#b5acff" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Concatenate</text>
<text x="515" y="104" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">all heads</text>
<!-- Line to linear -->
<line x1="577" y1="90" x2="620" y2="90" stroke="#888898" stroke-width="1.5" marker-end="url(#arr4)"/>
<!-- Linear -->
<rect x="625" y="60" width="120" height="60" rx="10" fill="rgba(82,200,160,0.12)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="685" y="86" fill="#7dddc4" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Linear</text>
<text x="685" y="104" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">projection</text>
<!-- Line to output -->
<line x1="747" y1="90" x2="790" y2="90" stroke="#888898" stroke-width="1.5" marker-end="url(#arr4)"/>
<!-- Output -->
<rect x="795" y="60" width="100" height="60" rx="10" fill="rgba(240,160,80,0.15)" stroke="rgba(240,160,80,0.4)" stroke-width="1.5"/>
<text x="845" y="86" fill="#f4be6e" font-family="Syne" font-size="12" font-weight="700" text-anchor="middle">Output</text>
<text x="845" y="104" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">rich context</text>
</svg>
</div>
</section>
<!-- SECTION 5: Full Architecture -->
<section id="architecture">
<div class="sec-header">
<div class="sec-num">Section 05</div>
<h2 class="sec-title">The <span class="hi">Full Architecture</span></h2>
<p class="sec-desc">Putting it all together — the complete Transformer block, layer by layer.</p>
</div>
<div class="diagram">
<div class="diagram-title">One Transformer block (this repeats N times = N layers)</div>
<svg width="100%" viewBox="0 0 900 560">
<defs>
<marker id="arr5" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#888898" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Input Tokens row -->
<text x="450" y="30" fill="#888898" font-family="Syne" font-size="12" font-weight="600" text-anchor="middle" text-transform="uppercase">INPUT: TOKEN EMBEDDINGS + POSITIONAL ENCODING</text>
<rect x="50" y="45" width="800" height="44" rx="10" fill="rgba(124,110,245,0.08)" stroke="rgba(124,110,245,0.25)" stroke-width="1"/>
<text x="100" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"The"</text>
<text x="200" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"cat"</text>
<text x="300" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"sat"</text>
<text x="400" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"on"</text>
<text x="500" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"the"</text>
<text x="600" y="72" fill="#b5acff" font-family="JetBrains Mono" font-size="12" text-anchor="middle">"mat"</text>
<text x="700" y="72" fill="#888898" font-family="JetBrains Mono" font-size="12" text-anchor="middle">...</text>
<!-- Arrow down -->
<line x1="450" y1="92" x2="450" y2="115" stroke="#888898" stroke-width="1.5" marker-end="url(#arr5)"/>
<!-- ===== TRANSFORMER BLOCK START ===== -->
<!-- Outer block border -->
<rect x="30" y="120" width="840" height="380" rx="16" fill="rgba(255,255,255,0.015)" stroke="rgba(255,255,255,0.08)" stroke-width="1" stroke-dasharray="6,3"/>
<text x="60" y="140" fill="#888898" font-family="Syne" font-size="11" font-weight="600" letter-spacing="2">TRANSFORMER BLOCK × N LAYERS</text>
<!-- Multi-Head Self-Attention -->
<rect x="60" y="155" width="780" height="70" rx="12" fill="rgba(124,110,245,0.1)" stroke="rgba(124,110,245,0.4)" stroke-width="1.5"/>
<text x="450" y="183" fill="#b5acff" font-family="Syne" font-size="15" font-weight="700" text-anchor="middle">Multi-Head Self-Attention</text>
<text x="450" y="202" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Q, K, V projections → 8–96 attention heads → concatenate → linear</text>
<!-- Residual + LayerNorm -->
<line x1="450" y1="227" x2="450" y2="250" stroke="#888898" stroke-width="1.5" marker-end="url(#arr5)"/>
<rect x="160" y="252" width="580" height="44" rx="8" fill="rgba(82,200,160,0.08)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="450" y="279" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Add & Normalize (Residual Connection + LayerNorm)</text>
<!-- Feed-Forward Network -->
<line x1="450" y1="298" x2="450" y2="320" stroke="#888898" stroke-width="1.5" marker-end="url(#arr5)"/>
<rect x="60" y="322" width="780" height="70" rx="12" fill="rgba(240,160,80,0.1)" stroke="rgba(240,160,80,0.4)" stroke-width="1.5"/>
<text x="450" y="350" fill="#f4be6e" font-family="Syne" font-size="15" font-weight="700" text-anchor="middle">Feed-Forward Network (FFN)</text>
<text x="450" y="370" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Linear → ReLU/GELU activation → Linear (4× wider than attention)</text>
<!-- Residual + LayerNorm again -->
<line x1="450" y1="394" x2="450" y2="416" stroke="#888898" stroke-width="1.5" marker-end="url(#arr5)"/>
<rect x="160" y="418" width="580" height="44" rx="8" fill="rgba(82,200,160,0.08)" stroke="rgba(82,200,160,0.3)" stroke-width="1"/>
<text x="450" y="445" fill="#7dddc4" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Add & Normalize (Residual Connection + LayerNorm)</text>
<!-- Residual skip connections on the side -->
<path d="M42 170 L20 170 L20 458 L158 458" fill="none" stroke="rgba(82,200,160,0.3)" stroke-width="1.5" stroke-dasharray="4,3"/>
<text x="12" y="315" fill="rgba(82,200,160,0.5)" font-family="Syne" font-size="10" font-weight="600" text-anchor="middle" transform="rotate(-90,12,315)">SKIP / RESIDUAL</text>
<!-- ===== END BLOCK ===== -->
<line x1="450" y1="500" x2="450" y2="522" stroke="#888898" stroke-width="1.5" marker-end="url(#arr5)"/>
<!-- Output -->
<rect x="200" y="524" width="500" height="30" rx="8" fill="rgba(90,175,240,0.12)" stroke="rgba(90,175,240,0.3)" stroke-width="1"/>
<text x="450" y="544" fill="#8eccf5" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Output (repeat for next layer / final: logits over vocabulary)</text>
</svg>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:32px 0 16px">What is a Residual Connection?</h3>
<div class="callout green">
<span class="callout-icon">🔁</span>
<div class="callout-body"><strong>Think of it as a highway bypass:</strong> Instead of sending information only through the attention layer, you also send a copy of the input directly to the output and add them together. This prevents the "vanishing gradient" problem — without it, deep networks stop learning because gradients become zero during training. The formula: <code>Output = LayerNorm(x + AttentionLayer(x))</code></div>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:32px 0 16px">What is Layer Normalization?</h3>
<div class="callout blue">
<span class="callout-icon">⚖️</span>
<div class="callout-body"><strong>Think of it as re-centering:</strong> After every operation, numbers can become very large or very small. Layer normalization rescales them back to a stable range (mean=0, variance=1). This keeps training stable and fast. Without it, the model's numbers would explode or vanish after just a few layers.</div>
</div>
</section>
<!-- SECTION 6 & 7: Layers in Real Models -->
<section id="layers">
<div class="sec-header">
<div class="sec-num">Section 06–07</div>
<h2 class="sec-title">Layers in <span class="hi">Real Models</span></h2>
<p class="sec-desc">How deep do real AI models go? Here's every major model ever created, their layers, and parameters.</p>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Model</th>
<th>Company</th>
<th>Year</th>
<th>Layers</th>
<th>Attention Heads</th>
<th>Hidden Size</th>
<th>Parameters</th>
<th>Context</th>
</tr>
</thead>
<tbody>
<tr><td><strong>Original Transformer</strong></td><td>Google</td><td>2017</td><td>6+6</td><td>8</td><td>512</td><td>~65M</td><td>512 tokens</td></tr>
<tr><td><strong>BERT Base</strong></td><td>Google</td><td>2018</td><td>12</td><td>12</td><td>768</td><td>110M</td><td>512 tokens</td></tr>
<tr><td><strong>BERT Large</strong></td><td>Google</td><td>2018</td><td>24</td><td>16</td><td>1024</td><td>340M</td><td>512 tokens</td></tr>
<tr><td><strong>GPT-1</strong></td><td>OpenAI</td><td>2018</td><td>12</td><td>12</td><td>768</td><td>117M</td><td>512 tokens</td></tr>
<tr><td><strong>GPT-2 Small</strong></td><td>OpenAI</td><td>2019</td><td>12</td><td>12</td><td>768</td><td>117M</td><td>1,024 tokens</td></tr>
<tr><td><strong>GPT-2 Large</strong></td><td>OpenAI</td><td>2019</td><td>36</td><td>20</td><td>1280</td><td>774M</td><td>1,024 tokens</td></tr>
<tr><td><strong>GPT-2 XL</strong></td><td>OpenAI</td><td>2019</td><td>48</td><td>25</td><td>1600</td><td>1.5B</td><td>1,024 tokens</td></tr>
<tr><td><strong>T5 Base</strong></td><td>Google</td><td>2020</td><td>12+12</td><td>12</td><td>768</td><td>220M</td><td>512 tokens</td></tr>
<tr><td><strong>T5 11B</strong></td><td>Google</td><td>2020</td><td>24+24</td><td>128</td><td>1024</td><td>11B</td><td>512 tokens</td></tr>
<tr><td><strong>GPT-3</strong></td><td>OpenAI</td><td>2020</td><td>96</td><td>96</td><td>12,288</td><td><span class="badge purple">175B</span></td><td>4,096 tokens</td></tr>
<tr><td><strong>Codex</strong></td><td>OpenAI</td><td>2021</td><td>96</td><td>96</td><td>12,288</td><td>12B</td><td>4,096 tokens</td></tr>
<tr><td><strong>PaLM</strong></td><td>Google</td><td>2022</td><td>118</td><td>48</td><td>18,432</td><td><span class="badge orange">540B</span></td><td>2,048 tokens</td></tr>
<tr><td><strong>Chinchilla</strong></td><td>DeepMind</td><td>2022</td><td>80</td><td>64</td><td>8,192</td><td>70B</td><td>2,048 tokens</td></tr>
<tr><td><strong>LLaMA 7B</strong></td><td>Meta</td><td>2023</td><td>32</td><td>32</td><td>4,096</td><td>7B</td><td>2,048 tokens</td></tr>
<tr><td><strong>LLaMA 65B</strong></td><td>Meta</td><td>2023</td><td>80</td><td>64</td><td>8,192</td><td>65B</td><td>2,048 tokens</td></tr>
<tr><td><strong>Claude 1</strong></td><td>Anthropic</td><td>2023</td><td>~60+</td><td>~64</td><td>—</td><td>~52B est.</td><td>9,000 tokens</td></tr>
<tr><td><strong>GPT-4</strong></td><td>OpenAI</td><td>2023</td><td>~96+</td><td>~128</td><td>—</td><td><span class="badge red">~1.8T est.</span></td><td>32K–128K</td></tr>
<tr><td><strong>Gemini Ultra</strong></td><td>Google</td><td>2023</td><td>—</td><td>—</td><td>—</td><td>~540B+ est.</td><td>32K tokens</td></tr>
<tr><td><strong>Mistral 7B</strong></td><td>Mistral</td><td>2023</td><td>32</td><td>32</td><td>4,096</td><td>7.3B</td><td>8,192 tokens</td></tr>
<tr><td><strong>LLaMA 2 70B</strong></td><td>Meta</td><td>2023</td><td>80</td><td>64</td><td>8,192</td><td>70B</td><td>4,096 tokens</td></tr>
<tr><td><strong>Claude 2</strong></td><td>Anthropic</td><td>2023</td><td>—</td><td>—</td><td>—</td><td>—</td><td><span class="badge green">200K tokens</span></td></tr>
<tr><td><strong>Claude 3 Opus</strong></td><td>Anthropic</td><td>2024</td><td>—</td><td>—</td><td>—</td><td>—</td><td>200K tokens</td></tr>
<tr><td><strong>Gemini 1.5 Pro</strong></td><td>Google</td><td>2024</td><td>—</td><td>—</td><td>—</td><td>—</td><td><span class="badge blue">1M–2M tokens</span></td></tr>
<tr><td><strong>LLaMA 3 70B</strong></td><td>Meta</td><td>2024</td><td>80</td><td>64</td><td>8,192</td><td>70B</td><td>8K tokens</td></tr>
<tr><td><strong>LLaMA 3.1 405B</strong></td><td>Meta</td><td>2024</td><td>126</td><td>128</td><td>16,384</td><td>405B</td><td>128K tokens</td></tr>
<tr><td><strong>Mistral Large</strong></td><td>Mistral</td><td>2024</td><td>~64</td><td>32</td><td>—</td><td>~123B</td><td>128K tokens</td></tr>
<tr><td><strong>Deepseek V3</strong></td><td>DeepSeek</td><td>2024</td><td>61</td><td>128</td><td>7,168</td><td><span class="badge purple">671B MoE</span></td><td>128K tokens</td></tr>
<tr><td><strong>Claude 3.5 Sonnet</strong></td><td>Anthropic</td><td>2024</td><td>—</td><td>—</td><td>—</td><td>—</td><td>200K tokens</td></tr>
<tr><td><strong>Gemini 2.0 Flash</strong></td><td>Google</td><td>2025</td><td>—</td><td>—</td><td>—</td><td>—</td><td>1M tokens</td></tr>
<tr><td><strong>GPT-4o</strong></td><td>OpenAI</td><td>2024</td><td>—</td><td>—</td><td>—</td><td>~200B est.</td><td>128K tokens</td></tr>
</tbody>
</table>
</div>
<div class="callout purple">
<span class="callout-icon">💡</span>
<div class="callout-body"><strong>Why don't all companies reveal their layer counts?</strong> Most cutting-edge models (GPT-4, Claude, Gemini) keep their exact architecture secret for competitive reasons. The figures marked "est." are community estimates. Smaller open-source models like LLaMA publish full details.</div>
</div>
</section>
<!-- SECTION 8: Context Windows -->
<section id="context">
<div class="sec-header">
<div class="sec-num">Section 08</div>
<h2 class="sec-title">Context <span class="hi">Windows</span></h2>
<p class="sec-desc">How much can the AI "see" at once? The context window is the AI's "working memory" — everything it can consider when generating a response.</p>
</div>
<div class="callout blue">
<span class="callout-icon">📺</span>
<div class="callout-body"><strong>Analogy:</strong> Think of a context window like a TV screen showing your conversation. The AI can only see what's on screen right now. Older messages scroll off the top and are forgotten. A bigger context window = a bigger screen = remembers more conversation history.</div>
</div>
<div class="table-wrap" style="margin-top:32px">
<table>
<thead>
<tr>
<th>Context Size</th>
<th>Tokens</th>
<th>Approx. Words</th>
<th>What Fits</th>
<th>Models</th>
</tr>
</thead>
<tbody>
<tr>
<td><span class="badge red">Tiny</span></td>
<td>512</td>
<td>~380 words</td>
<td>A short paragraph</td>
<td>Original BERT, GPT-1</td>
</tr>
<tr>
<td><span class="badge orange">Small</span></td>
<td>2,048–4,096</td>
<td>~1,500–3,000 words</td>
<td>A short article, a code file</td>
<td>GPT-2, GPT-3, LLaMA 1</td>
</tr>
<tr>
<td><span class="badge purple">Medium</span></td>
<td>8K–32K</td>
<td>6,000–24,000 words</td>
<td>A long essay, a short story</td>
<td>Mistral 7B, GPT-4 base</td>
</tr>
<tr>
<td><span class="badge blue">Large</span></td>
<td>128K–200K</td>
<td>95,000–150,000 words</td>
<td>An entire novel, a codebase</td>
<td>Claude 2/3, GPT-4 Turbo, LLaMA 3.1</td>
</tr>
<tr>
<td><span class="badge green">Massive</span></td>
<td>1M–2M</td>
<td>750,000–1.5M words</td>
<td>Multiple books, entire codebases</td>
<td>Gemini 1.5 Pro/Flash, Claude (future)</td>
</tr>
</tbody>
</table>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:40px 0 20px">Types of Context Window Techniques</h3>
<div class="grid-2">
<div class="card">
<div class="card-title">Sliding Window Attention</div>
<p>Each token only attends to a window of nearby tokens (e.g., 4,096), not the whole sequence. Used by Mistral. Allows infinite sequences with limited memory, but can't connect distant information.</p>
<div style="margin-top:12px"><span class="badge purple">Mistral 7B</span></div>
</div>
<div class="card">
<div class="card-title">RoPE (Rotary Positional Embedding)</div>
<p>Instead of fixed position codes, RoPE uses rotation matrices. Makes it easier to extend context beyond training length. Used by LLaMA, Mistral, and most modern open-source models.</p>
<div style="margin-top:12px"><span class="badge green">LLaMA 2/3</span> <span class="badge orange" style="margin-left:4px">Mistral</span></div>
</div>
<div class="card">
<div class="card-title">ALiBi (Attention with Linear Biases)</div>
<p>Adds a penalty to attention scores based on distance — farther tokens get a stronger penalty. Very simple but effective for extending context. Used by BLOOM.</p>
<div style="margin-top:12px"><span class="badge blue">BLOOM</span></div>
</div>
<div class="card">
<div class="card-title">Flash Attention</div>
<p>Not a new position encoding — it's an algorithm that makes attention computation much faster and memory-efficient. Enables large contexts on practical hardware. Used by nearly all modern models.</p>
<div style="margin-top:12px"><span class="badge purple">GPT-4</span> <span class="badge green" style="margin-left:4px">LLaMA 3</span></div>
</div>
<div class="card">
<div class="card-title">Grouped Query Attention (GQA)</div>
<p>Instead of one K/V pair per head, several query heads share one K/V pair. Reduces memory significantly while keeping quality. Used by LLaMA 2/3, Mistral.</p>
<div style="margin-top:12px"><span class="badge green">LLaMA 2 70B</span></div>
</div>
<div class="card">
<div class="card-title">Sparse / Mixture-of-Experts (MoE)</div>
<p>Instead of activating all model parameters for every token, only a subset of "expert" networks activate per token. Allows massive parameter counts (DeepSeek: 671B) with only 37B active at once.</p>
<div style="margin-top:12px"><span class="badge red">DeepSeek V3</span> <span class="badge orange" style="margin-left:4px">GPT-4 est.</span></div>
</div>
</div>
</section>
<!-- SECTION 9: Training -->
<section id="training">
<div class="sec-header">
<div class="sec-num">Section 09</div>
<h2 class="sec-title">How Models <span class="hi">Learn</span></h2>
<p class="sec-desc">Building a brain from scratch — the three phases of training an AI model.</p>
</div>
<div class="diagram">
<div class="diagram-title">The three-phase training pipeline for modern AI assistants</div>
<svg width="100%" viewBox="0 0 900 130">
<defs>
<marker id="arr6" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto">
<path d="M2 1L8 5L2 9" fill="none" stroke="#888898" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</marker>
</defs>
<!-- Phase 1 -->
<rect x="10" y="25" width="240" height="80" rx="12" fill="rgba(124,110,245,0.1)" stroke="rgba(124,110,245,0.4)" stroke-width="1.5"/>
<text x="130" y="55" fill="#b5acff" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">Phase 1: Pre-training</text>
<text x="130" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Predict next token on</text>
<text x="130" y="90" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">billions of web pages</text>
<!-- Arrow -->
<line x1="252" y1="65" x2="308" y2="65" stroke="#888898" stroke-width="1.5" marker-end="url(#arr6)"/>
<!-- Phase 2 -->
<rect x="313" y="25" width="240" height="80" rx="12" fill="rgba(82,200,160,0.1)" stroke="rgba(82,200,160,0.4)" stroke-width="1.5"/>
<text x="433" y="55" fill="#7dddc4" font-family="Syne" font-size="14" font-weight="700" text-anchor="middle">Phase 2: Fine-tuning</text>
<text x="433" y="74" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Train on human-written</text>
<text x="433" y="90" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Q&A, instructions, examples</text>
<!-- Arrow -->
<line x1="555" y1="65" x2="611" y2="65" stroke="#888898" stroke-width="1.5" marker-end="url(#arr6)"/>
<!-- Phase 3 -->
<rect x="616" y="25" width="274" height="80" rx="12" fill="rgba(240,160,80,0.1)" stroke="rgba(240,160,80,0.4)" stroke-width="1.5"/>
<text x="753" y="50" fill="#f4be6e" font-family="Syne" font-size="13" font-weight="700" text-anchor="middle">Phase 3: RLHF</text>
<text x="753" y="68" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">Humans rank responses, model</text>
<text x="753" y="84" fill="#888898" font-family="Syne" font-size="11" text-anchor="middle">learns to maximize human preference</text>
</svg>
</div>
<div class="grid-3" style="margin-top:24px">
<div class="card" style="border-color:rgba(124,110,245,0.3)">
<div class="card-title" style="color:var(--accent)">Phase 1: Pre-training</div>
<p style="font-size:14px">The model reads the entire internet (books, Wikipedia, code, articles) — <strong>trillions of tokens</strong>. It learns by predicting the next word. This takes weeks on thousands of GPUs and costs $10M–$100M+.</p>
<p style="margin-top:12px;font-size:13px;color:var(--muted)">Example training data: "The cat sat on the ___" → model predicts "mat"</p>
</div>
<div class="card" style="border-color:rgba(82,200,160,0.3)">
<div class="card-title" style="color:var(--accent2)">Phase 2: Supervised Fine-Tuning (SFT)</div>
<p style="font-size:14px">Human experts write example conversations — ideal question and answer pairs. The model is fine-tuned to respond like a helpful assistant. Much cheaper but needs careful curation.</p>
<p style="margin-top:12px;font-size:13px;color:var(--muted)">~10,000–1,000,000 high-quality examples</p>
</div>
<div class="card" style="border-color:rgba(240,160,80,0.3)">
<div class="card-title" style="color:var(--accent3)">Phase 3: RLHF</div>
<p style="font-size:14px">Reinforcement Learning from Human Feedback. The model generates multiple answers. Humans rank them. A "reward model" is trained on these rankings. Then the main model is optimized to score higher.</p>
<p style="margin-top:12px;font-size:13px;color:var(--muted)">Makes models helpful, harmless, honest</p>
</div>
</div>
<h3 style="font-family:'Syne',sans-serif;font-weight:700;margin:40px 0 16px">What Actually Happens During Training?</h3>
<div class="steps">
<div class="step">
<div class="step-num"></div>
<div class="step-body">
<h4>Forward Pass</h4>