[{"data":1,"prerenderedAt":2072},["ShallowReactive",2],{"blog:page:\u002Fen\u002Fblog\u002Fattention-from-vectors-to-probabilities":3,"blog:articles:en":1950,"blog:articles:en:fallback-inventory":2043,"blog:translations:\u002Fen\u002Fblog\u002Fattention-from-vectors-to-probabilities":2060,"blog:article-locale-inventory:\u002Fen\u002Fblog\u002Fattention-from-vectors-to-probabilities":2062,"blog:identity-records":2069},{"id":4,"title":5,"articleId":6,"author":7,"body":8,"contentType":1931,"cover":1932,"coverAlt":1933,"date":1934,"description":1935,"extension":1936,"featured":1937,"level":1938,"meta":1939,"navigation":1940,"path":1941,"prerequisites":1942,"relatedArticleIds":1942,"reviewer":1942,"seo":1943,"seriesId":1944,"seriesOrder":551,"stem":1945,"tags":1946,"updatedAt":1942,"__hash__":1949},"blog\u002Fen\u002Fblog\u002F7.attention-from-vectors-to-probabilities\u002Findex.md","Attention, from vectors to probabilities","attention-from-vectors-to-probabilities","John Martin",{"type":9,"value":10,"toc":1924},"minimark",[11,14,18,23,26,485,488,869,1011,1016,1020,1023,1547,1550,1884,1917,1921],[12,13,5],"h1",{"id":6},[15,16,17],"p",{},"Every transformer article assumes you already know scaled dot-product attention.\nThis one does not. We build the equation from three plain vectors, watch each\nsymbol earn its place, and end at the exact form used in the original paper.",[19,20,22],"h2",{"id":21},"three-vectors-walk-into-a-layer","Three vectors walk into a layer",[15,24,25],{},"For a single query, attention compares:",[27,28,29,217,349],"ul",{},[30,31,32,33,37,38,216],"li",{},"a ",[34,35,36],"strong",{},"query"," vector ",[39,40,43,86],"span",{"className":41},[42],"katex",[39,44,47],{"className":45},[46],"katex-mathml",[48,49,51],"math",{"xmlns":50},"http:\u002F\u002Fwww.w3.org\u002F1998\u002FMath\u002FMathML",[52,53,54,81],"semantics",{},[55,56,57,61,65],"mrow",{},[58,59,60],"mi",{},"q",[62,63,64],"mo",{},"∈",[66,67,68,72],"msup",{},[58,69,71],{"mathvariant":70},"double-struck","R",[73,74,75,78],"msub",{},[58,76,77],{},"d",[58,79,80],{},"k",[82,83,85],"annotation",{"encoding":84},"application\u002Fx-tex","q \\in \\mathbb{R}^{d_k}",[39,87,91,118],{"className":88,"ariaHidden":90},[89],"katex-html","true",[39,92,95,100,106,111,115],{"className":93},[94],"base",[39,96],{"className":97,"style":99},[98],"strut","height:0.7335em;vertical-align:-0.1944em;",[39,101,60],{"className":102,"style":105},[103,104],"mord","mathnormal","margin-right:0.03588em;",[39,107],{"className":108,"style":110},[109],"mspace","margin-right:0.2778em;",[39,112,64],{"className":113},[114],"mrel",[39,116],{"className":117,"style":110},[109],[39,119,121,125],{"className":120},[94],[39,122],{"className":123,"style":124},[98],"height:0.8491em;",[39,126,128,132],{"className":127},[103],[39,129,71],{"className":130},[103,131],"mathbb",[39,133,136],{"className":134},[135],"msupsub",[39,137,140],{"className":138},[139],"vlist-t",[39,141,144],{"className":142},[143],"vlist-r",[39,145,148],{"className":146,"style":124},[147],"vlist",[39,149,151,156],{"style":150},"top:-3.063em;margin-right:0.05em;",[39,152],{"className":153,"style":155},[154],"pstrut","height:2.7em;",[39,157,163],{"className":158},[159,160,161,162],"sizing","reset-size6","size3","mtight",[39,164,166],{"className":165},[103,162],[39,167,169,172],{"className":168},[103,162],[39,170,77],{"className":171},[103,104,162],[39,173,175],{"className":174},[135],[39,176,179,207],{"className":177},[139,178],"vlist-t2",[39,180,182,202],{"className":181},[143],[39,183,186],{"className":184,"style":185},[147],"height:0.3448em;",[39,187,189,193],{"style":188},"top:-2.3488em;margin-left:0em;margin-right:0.0714em;",[39,190],{"className":191,"style":192},[154],"height:2.5em;",[39,194,198],{"className":195},[159,196,197,162],"reset-size3","size1",[39,199,80],{"className":200,"style":201},[103,104,162],"margin-right:0.03148em;",[39,203,206],{"className":204},[205],"vlist-s","​",[39,208,210],{"className":209},[143],[39,211,214],{"className":212,"style":213},[147],"height:0.1512em;",[39,215],{}," - what this position is looking for;",[30,218,32,219,37,222,348],{},[34,220,221],{},"key",[39,223,225,251],{"className":224},[42],[39,226,228],{"className":227},[46],[48,229,230],{"xmlns":50},[52,231,232,248],{},[55,233,234,236,238],{},[58,235,80],{},[62,237,64],{},[66,239,240,242],{},[58,241,71],{"mathvariant":70},[73,243,244,246],{},[58,245,77],{},[58,247,80],{},[82,249,250],{"encoding":84},"k \\in \\mathbb{R}^{d_k}",[39,252,254,273],{"className":253,"ariaHidden":90},[89],[39,255,257,261,264,267,270],{"className":256},[94],[39,258],{"className":259,"style":260},[98],"height:0.7335em;vertical-align:-0.0391em;",[39,262,80],{"className":263,"style":201},[103,104],[39,265],{"className":266,"style":110},[109],[39,268,64],{"className":269},[114],[39,271],{"className":272,"style":110},[109],[39,274,276,279],{"className":275},[94],[39,277],{"className":278,"style":124},[98],[39,280,282,285],{"className":281},[103],[39,283,71],{"className":284},[103,131],[39,286,288],{"className":287},[135],[39,289,291],{"className":290},[139],[39,292,294],{"className":293},[143],[39,295,297],{"className":296,"style":124},[147],[39,298,299,302],{"style":150},[39,300],{"className":301,"style":155},[154],[39,303,305],{"className":304},[159,160,161,162],[39,306,308],{"className":307},[103,162],[39,309,311,314],{"className":310},[103,162],[39,312,77],{"className":313},[103,104,162],[39,315,317],{"className":316},[135],[39,318,320,340],{"className":319},[139,178],[39,321,323,337],{"className":322},[143],[39,324,326],{"className":325,"style":185},[147],[39,327,328,331],{"style":188},[39,329],{"className":330,"style":192},[154],[39,332,334],{"className":333},[159,196,197,162],[39,335,80],{"className":336,"style":201},[103,104,162],[39,338,206],{"className":339},[205],[39,341,343],{"className":342},[143],[39,344,346],{"className":345,"style":213},[147],[39,347],{}," - what each position offers;",[30,350,32,351,37,354,484],{},[34,352,353],{},"value",[39,355,357,384],{"className":356},[42],[39,358,360],{"className":359},[46],[48,361,362],{"xmlns":50},[52,363,364,381],{},[55,365,366,369,371],{},[58,367,368],{},"v",[62,370,64],{},[66,372,373,375],{},[58,374,71],{"mathvariant":70},[73,376,377,379],{},[58,378,77],{},[58,380,368],{},[82,382,383],{"encoding":84},"v \\in \\mathbb{R}^{d_v}",[39,385,387,406],{"className":386,"ariaHidden":90},[89],[39,388,390,394,397,400,403],{"className":389},[94],[39,391],{"className":392,"style":393},[98],"height:0.5782em;vertical-align:-0.0391em;",[39,395,368],{"className":396,"style":105},[103,104],[39,398],{"className":399,"style":110},[109],[39,401,64],{"className":402},[114],[39,404],{"className":405,"style":110},[109],[39,407,409,412],{"className":408},[94],[39,410],{"className":411,"style":124},[98],[39,413,415,418],{"className":414},[103],[39,416,71],{"className":417},[103,131],[39,419,421],{"className":420},[135],[39,422,424],{"className":423},[139],[39,425,427],{"className":426},[143],[39,428,430],{"className":429,"style":124},[147],[39,431,432,435],{"style":150},[39,433],{"className":434,"style":155},[154],[39,436,438],{"className":437},[159,160,161,162],[39,439,441],{"className":440},[103,162],[39,442,444,447],{"className":443},[103,162],[39,445,77],{"className":446},[103,104,162],[39,448,450],{"className":449},[135],[39,451,453,475],{"className":452},[139,178],[39,454,456,472],{"className":455},[143],[39,457,460],{"className":458,"style":459},[147],"height:0.1645em;",[39,461,463,466],{"style":462},"top:-2.357em;margin-left:0em;margin-right:0.0714em;",[39,464],{"className":465,"style":192},[154],[39,467,469],{"className":468},[159,196,197,162],[39,470,368],{"className":471,"style":105},[103,104,162],[39,473,206],{"className":474},[205],[39,476,478],{"className":477},[143],[39,479,482],{"className":480,"style":481},[147],"height:0.143em;",[39,483],{}," - what each position contributes.",[15,486,487],{},"The raw match score is a dot product, which is just a similarity meter:",[39,489,492],{"className":490},[491],"katex-display",[39,493,495,573],{"className":494},[42],[39,496,498],{"className":497},[46],[48,499,501],{"xmlns":50,"display":500},"block",[52,502,503,570],{},[55,504,505,509,513,515,518,520,523,526,528,531,533,535,558,564],{},[506,507,508],"mtext",{},"score",[62,510,512],{"stretchy":511},"false","(",[58,514,60],{},[62,516,517],{"separator":90},",",[58,519,80],{},[62,521,522],{"stretchy":511},")",[62,524,525],{},"=",[58,527,60],{},[62,529,530],{},"⋅",[58,532,80],{},[62,534,525],{},[536,537,538,541,552],"munderover",{},[62,539,540],{},"∑",[55,542,543,546,548],{},[58,544,545],{},"i",[62,547,525],{},[549,550,551],"mn",{},"1",[73,553,554,556],{},[58,555,77],{},[58,557,80],{},[73,559,560,562],{},[58,561,60],{},[58,563,545],{},[73,565,566,568],{},[58,567,80],{},[58,569,545],{},[82,571,572],{"encoding":84},"\\text{score}(q, k) = q \\cdot k = \\sum_{i=1}^{d_k} q_i k_i",[39,574,576,621,642,661],{"className":575,"ariaHidden":90},[89],[39,577,579,583,590,594,597,601,605,608,612,615,618],{"className":578},[94],[39,580],{"className":581,"style":582},[98],"height:1em;vertical-align:-0.25em;",[39,584,587],{"className":585},[103,586],"text",[39,588,508],{"className":589},[103],[39,591,512],{"className":592},[593],"mopen",[39,595,60],{"className":596,"style":105},[103,104],[39,598,517],{"className":599},[600],"mpunct",[39,602],{"className":603,"style":604},[109],"margin-right:0.1667em;",[39,606,80],{"className":607,"style":201},[103,104],[39,609,522],{"className":610},[611],"mclose",[39,613],{"className":614,"style":110},[109],[39,616,525],{"className":617},[114],[39,619],{"className":620,"style":110},[109],[39,622,624,628,631,635,639],{"className":623},[94],[39,625],{"className":626,"style":627},[98],"height:0.6389em;vertical-align:-0.1944em;",[39,629,60],{"className":630,"style":105},[103,104],[39,632],{"className":633,"style":634},[109],"margin-right:0.2222em;",[39,636,530],{"className":637},[638],"mbin",[39,640],{"className":641,"style":634},[109],[39,643,645,649,652,655,658],{"className":644},[94],[39,646],{"className":647,"style":648},[98],"height:0.6944em;",[39,650,80],{"className":651,"style":201},[103,104],[39,653],{"className":654,"style":110},[109],[39,656,525],{"className":657},[114],[39,659],{"className":660,"style":110},[109],[39,662,664,668,782,785,828],{"className":663},[94],[39,665],{"className":666,"style":667},[98],"height:3.1306em;vertical-align:-1.2777em;",[39,669,673],{"className":670},[671,672],"mop","op-limits",[39,674,676,773],{"className":675},[139,178],[39,677,679,770],{"className":678},[143],[39,680,683,705,718],{"className":681,"style":682},[147],"height:1.853em;",[39,684,686,690],{"style":685},"top:-1.8723em;margin-left:0em;",[39,687],{"className":688,"style":689},[154],"height:3.05em;",[39,691,693],{"className":692},[159,160,161,162],[39,694,696,699,702],{"className":695},[103,162],[39,697,545],{"className":698},[103,104,162],[39,700,525],{"className":701},[114,162],[39,703,551],{"className":704},[103,162],[39,706,708,711],{"style":707},"top:-3.05em;",[39,709],{"className":710,"style":689},[154],[39,712,713],{},[39,714,540],{"className":715},[671,716,717],"op-symbol","large-op",[39,719,721,724],{"style":720},"top:-4.3169em;margin-left:0em;",[39,722],{"className":723,"style":689},[154],[39,725,727],{"className":726},[159,160,161,162],[39,728,730],{"className":729},[103,162],[39,731,733,736],{"className":732},[103,162],[39,734,77],{"className":735},[103,104,162],[39,737,739],{"className":738},[135],[39,740,742,762],{"className":741},[139,178],[39,743,745,759],{"className":744},[143],[39,746,748],{"className":747,"style":185},[147],[39,749,750,753],{"style":188},[39,751],{"className":752,"style":192},[154],[39,754,756],{"className":755},[159,196,197,162],[39,757,80],{"className":758,"style":201},[103,104,162],[39,760,206],{"className":761},[205],[39,763,765],{"className":764},[143],[39,766,768],{"className":767,"style":213},[147],[39,769],{},[39,771,206],{"className":772},[205],[39,774,776],{"className":775},[143],[39,777,780],{"className":778,"style":779},[147],"height:1.2777em;",[39,781],{},[39,783],{"className":784,"style":604},[109],[39,786,788,791],{"className":787},[103],[39,789,60],{"className":790,"style":105},[103,104],[39,792,794],{"className":793},[135],[39,795,797,819],{"className":796},[139,178],[39,798,800,816],{"className":799},[143],[39,801,804],{"className":802,"style":803},[147],"height:0.3117em;",[39,805,807,810],{"style":806},"top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;",[39,808],{"className":809,"style":155},[154],[39,811,813],{"className":812},[159,160,161,162],[39,814,545],{"className":815},[103,104,162],[39,817,206],{"className":818},[205],[39,820,822],{"className":821},[143],[39,823,826],{"className":824,"style":825},[147],"height:0.15em;",[39,827],{},[39,829,831,834],{"className":830},[103],[39,832,80],{"className":833,"style":201},[103,104],[39,835,837],{"className":836},[135],[39,838,840,861],{"className":839},[139,178],[39,841,843,858],{"className":842},[143],[39,844,846],{"className":845,"style":803},[147],[39,847,849,852],{"style":848},"top:-2.55em;margin-left:-0.0315em;margin-right:0.05em;",[39,850],{"className":851,"style":155},[154],[39,853,855],{"className":854},[159,160,161,162],[39,856,545],{"className":857},[103,104,162],[39,859,206],{"className":860},[205],[39,862,864],{"className":863},[143],[39,865,867],{"className":866,"style":825},[147],[39,868],{},[15,870,871,872,1010],{},"Dividing by ",[39,873,875,896],{"className":874},[42],[39,876,878],{"className":877},[46],[48,879,880],{"xmlns":50},[52,881,882,893],{},[55,883,884],{},[885,886,887],"msqrt",{},[73,888,889,891],{},[58,890,77],{},[58,892,80],{},[82,894,895],{"encoding":84},"\\sqrt{d_k}",[39,897,899],{"className":898,"ariaHidden":90},[89],[39,900,902,906],{"className":901},[94],[39,903],{"className":904,"style":905},[98],"height:1.04em;vertical-align:-0.1828em;",[39,907,910],{"className":908},[103,909],"sqrt",[39,911,913,1001],{"className":912},[139,178],[39,914,916,998],{"className":915},[143],[39,917,920,975],{"className":918,"style":919},[147],"height:0.8572em;",[39,921,925,929],{"className":922,"style":924},[923],"svg-align","top:-3em;",[39,926],{"className":927,"style":928},[154],"height:3em;",[39,930,933],{"className":931,"style":932},[103],"padding-left:0.833em;",[39,934,936,939],{"className":935},[103],[39,937,77],{"className":938},[103,104],[39,940,942],{"className":941},[135],[39,943,945,967],{"className":944},[139,178],[39,946,948,964],{"className":947},[143],[39,949,952],{"className":950,"style":951},[147],"height:0.3361em;",[39,953,955,958],{"style":954},"top:-2.55em;margin-left:0em;margin-right:0.05em;",[39,956],{"className":957,"style":155},[154],[39,959,961],{"className":960},[159,160,161,162],[39,962,80],{"className":963,"style":201},[103,104,162],[39,965,206],{"className":966},[205],[39,968,970],{"className":969},[143],[39,971,973],{"className":972,"style":825},[147],[39,974],{},[39,976,978,981],{"style":977},"top:-2.8172em;",[39,979],{"className":980,"style":928},[154],[39,982,986],{"className":983,"style":985},[984],"hide-tail","min-width:0.853em;height:1.08em;",[987,988,994],"svg",{"xmlns":989,"width":990,"height":991,"viewBox":992,"preserveAspectRatio":993},"http:\u002F\u002Fwww.w3.org\u002F2000\u002Fsvg","400em","1.08em","0 0 400000 1080","xMinYMin slice",[995,996],"path",{"d":997},"M95,702\nc-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14\nc0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54\nc44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10\ns173,378,173,378c0.7,0,35.3,-71,104,-213c68.7,-142,137.5,-285,206.5,-429\nc69,-144,104.5,-217.7,106.5,-221\nl0 -0\nc5.3,-9.3,12,-14,20,-14\nH400000v40H845.2724\ns-225.272,467,-225.272,467s-235,486,-235,486c-2.7,4.7,-9,7,-19,7\nc-6,0,-10,-1,-12,-3s-194,-422,-194,-422s-65,47,-65,47z\nM834 80h400000v40h-400000z",[39,999,206],{"className":1000},[205],[39,1002,1004],{"className":1003},[143],[39,1005,1008],{"className":1006,"style":1007},[147],"height:0.1828em;",[39,1009],{}," keeps the variance of the score stable as vectors grow",[27,1012,1013],{},[30,1014,1015],{},"without it, long vectors push the softmax into regions with vanishing\ngradients.",[19,1017,1019],{"id":1018},"from-scores-to-a-probability-distribution","From scores to a probability distribution",[15,1021,1022],{},"The softmax turns raw scores into weights that sum to one:",[39,1024,1026],{"className":1025},[491],[39,1027,1029,1118],{"className":1028},[42],[39,1030,1032],{"className":1031},[46],[48,1033,1034],{"xmlns":50,"display":500},[52,1035,1036,1115],{},[55,1037,1038,1041,1043,1045,1047,1050,1052,1055,1057,1059,1067,1074,1077,1109],{},[506,1039,1040],{},"Attention",[62,1042,512],{"stretchy":511},[58,1044,60],{},[62,1046,517],{"separator":90},[58,1048,1049],{},"K",[62,1051,517],{"separator":90},[58,1053,1054],{},"V",[62,1056,522],{"stretchy":511},[62,1058,525],{},[1060,1061,1062,1064],"munder",{},[62,1063,540],{},[58,1065,1066],{},"j",[73,1068,1069,1072],{},[506,1070,1071],{},"softmax",[58,1073,1066],{},[506,1075,1076],{}," ⁣",[55,1078,1079,1081,1107],{},[62,1080,512],{"fence":90},[1082,1083,1084,1099],"mfrac",{},[55,1085,1086,1088],{},[58,1087,60],{},[1089,1090,1091,1093,1095],"msubsup",{},[58,1092,80],{},[58,1094,1066],{},[58,1096,1098],{"mathvariant":1097},"normal","⊤",[885,1100,1101],{},[73,1102,1103,1105],{},[58,1104,77],{},[58,1106,80],{},[62,1108,522],{"fence":90},[73,1110,1111,1113],{},[58,1112,368],{},[58,1114,1066],{},[82,1116,1117],{"encoding":84},"\\text{Attention}(q, K, V) = \\sum_j \\text{softmax}_j\\!\\left(\\frac{q k_j^\\top}{\\sqrt{d_k}}\\right) v_j",[39,1119,1121,1171],{"className":1120,"ariaHidden":90},[89],[39,1122,1124,1127,1133,1136,1139,1142,1145,1149,1152,1155,1159,1162,1165,1168],{"className":1123},[94],[39,1125],{"className":1126,"style":582},[98],[39,1128,1130],{"className":1129},[103,586],[39,1131,1040],{"className":1132},[103],[39,1134,512],{"className":1135},[593],[39,1137,60],{"className":1138,"style":105},[103,104],[39,1140,517],{"className":1141},[600],[39,1143],{"className":1144,"style":604},[109],[39,1146,1049],{"className":1147,"style":1148},[103,104],"margin-right:0.07153em;",[39,1150,517],{"className":1151},[600],[39,1153],{"className":1154,"style":604},[109],[39,1156,1054],{"className":1157,"style":1158},[103,104],"margin-right:0.22222em;",[39,1160,522],{"className":1161},[611],[39,1163],{"className":1164,"style":110},[109],[39,1166,525],{"className":1167},[114],[39,1169],{"className":1170,"style":110},[109],[39,1172,1174,1178,1225,1228,1273,1277,1280,1504,1507],{"className":1173},[94],[39,1175],{"className":1176,"style":1177},[98],"height:3.1638em;vertical-align:-1.4138em;",[39,1179,1181],{"className":1180},[671,672],[39,1182,1184,1216],{"className":1183},[139,178],[39,1185,1187,1213],{"className":1186},[143],[39,1188,1191,1203],{"className":1189,"style":1190},[147],"height:1.05em;",[39,1192,1193,1196],{"style":685},[39,1194],{"className":1195,"style":689},[154],[39,1197,1199],{"className":1198},[159,160,161,162],[39,1200,1066],{"className":1201,"style":1202},[103,104,162],"margin-right:0.05724em;",[39,1204,1205,1208],{"style":707},[39,1206],{"className":1207,"style":689},[154],[39,1209,1210],{},[39,1211,540],{"className":1212},[671,716,717],[39,1214,206],{"className":1215},[205],[39,1217,1219],{"className":1218},[143],[39,1220,1223],{"className":1221,"style":1222},[147],"height:1.4138em;",[39,1224],{},[39,1226],{"className":1227,"style":604},[109],[39,1229,1231,1237],{"className":1230},[103],[39,1232,1234],{"className":1233},[103,586],[39,1235,1071],{"className":1236},[103],[39,1238,1240],{"className":1239},[135],[39,1241,1243,1264],{"className":1242},[139,178],[39,1244,1246,1261],{"className":1245},[143],[39,1247,1249],{"className":1248,"style":803},[147],[39,1250,1252,1255],{"style":1251},"top:-2.55em;margin-right:0.05em;",[39,1253],{"className":1254,"style":155},[154],[39,1256,1258],{"className":1257},[159,160,161,162],[39,1259,1066],{"className":1260,"style":1202},[103,104,162],[39,1262,206],{"className":1263},[205],[39,1265,1267],{"className":1266},[143],[39,1268,1271],{"className":1269,"style":1270},[147],"height:0.2861em;",[39,1272],{},[39,1274],{"className":1275,"style":1276},[109],"margin-right:-0.1667em;",[39,1278],{"className":1279,"style":604},[109],[39,1281,1284,1294,1498],{"className":1282},[1283],"minner",[39,1285,1289],{"className":1286,"style":1288},[593,1287],"delimcenter","top:0em;",[39,1290,512],{"className":1291},[1292,1293],"delimsizing","size4",[39,1295,1297,1301,1495],{"className":1296},[103],[39,1298],{"className":1299},[593,1300],"nulldelimiter",[39,1302,1304],{"className":1303},[1082],[39,1305,1307,1486],{"className":1306},[139,178],[39,1308,1310,1483],{"className":1309},[143],[39,1311,1314,1407,1418],{"className":1312,"style":1313},[147],"height:1.6339em;",[39,1315,1317,1320],{"style":1316},"top:-2.2528em;",[39,1318],{"className":1319,"style":928},[154],[39,1321,1323],{"className":1322},[103],[39,1324,1326],{"className":1325},[103,909],[39,1327,1329,1399],{"className":1328},[139,178],[39,1330,1332,1396],{"className":1331},[143],[39,1333,1335,1384],{"className":1334,"style":919},[147],[39,1336,1338,1341],{"className":1337,"style":924},[923],[39,1339],{"className":1340,"style":928},[154],[39,1342,1344],{"className":1343,"style":932},[103],[39,1345,1347,1350],{"className":1346},[103],[39,1348,77],{"className":1349},[103,104],[39,1351,1353],{"className":1352},[135],[39,1354,1356,1376],{"className":1355},[139,178],[39,1357,1359,1373],{"className":1358},[143],[39,1360,1362],{"className":1361,"style":951},[147],[39,1363,1364,1367],{"style":954},[39,1365],{"className":1366,"style":155},[154],[39,1368,1370],{"className":1369},[159,160,161,162],[39,1371,80],{"className":1372,"style":201},[103,104,162],[39,1374,206],{"className":1375},[205],[39,1377,1379],{"className":1378},[143],[39,1380,1382],{"className":1381,"style":825},[147],[39,1383],{},[39,1385,1386,1389],{"style":977},[39,1387],{"className":1388,"style":928},[154],[39,1390,1392],{"className":1391,"style":985},[984],[987,1393,1394],{"xmlns":989,"width":990,"height":991,"viewBox":992,"preserveAspectRatio":993},[995,1395],{"d":997},[39,1397,206],{"className":1398},[205],[39,1400,1402],{"className":1401},[143],[39,1403,1405],{"className":1404,"style":1007},[147],[39,1406],{},[39,1408,1410,1413],{"style":1409},"top:-3.23em;",[39,1411],{"className":1412,"style":928},[154],[39,1414],{"className":1415,"style":1417},[1416],"frac-line","border-bottom-width:0.04em;",[39,1419,1421,1424],{"style":1420},"top:-3.7848em;",[39,1422],{"className":1423,"style":928},[154],[39,1425,1427,1430],{"className":1426},[103],[39,1428,60],{"className":1429,"style":105},[103,104],[39,1431,1433,1436],{"className":1432},[103],[39,1434,80],{"className":1435,"style":201},[103,104],[39,1437,1439],{"className":1438},[135],[39,1440,1442,1474],{"className":1441},[139,178],[39,1443,1445,1471],{"className":1444},[143],[39,1446,1448,1460],{"className":1447,"style":124},[147],[39,1449,1451,1454],{"style":1450},"top:-2.4413em;margin-left:-0.0315em;margin-right:0.05em;",[39,1452],{"className":1453,"style":155},[154],[39,1455,1457],{"className":1456},[159,160,161,162],[39,1458,1066],{"className":1459,"style":1202},[103,104,162],[39,1461,1462,1465],{"style":150},[39,1463],{"className":1464,"style":155},[154],[39,1466,1468],{"className":1467},[159,160,161,162],[39,1469,1098],{"className":1470},[103,162],[39,1472,206],{"className":1473},[205],[39,1475,1477],{"className":1476},[143],[39,1478,1481],{"className":1479,"style":1480},[147],"height:0.3948em;",[39,1482],{},[39,1484,206],{"className":1485},[205],[39,1487,1489],{"className":1488},[143],[39,1490,1493],{"className":1491,"style":1492},[147],"height:0.93em;",[39,1494],{},[39,1496],{"className":1497},[611,1300],[39,1499,1501],{"className":1500,"style":1288},[611,1287],[39,1502,522],{"className":1503},[1292,1293],[39,1505],{"className":1506,"style":604},[109],[39,1508,1510,1513],{"className":1509},[103],[39,1511,368],{"className":1512,"style":105},[103,104],[39,1514,1516],{"className":1515},[135],[39,1517,1519,1539],{"className":1518},[139,178],[39,1520,1522,1536],{"className":1521},[143],[39,1523,1525],{"className":1524,"style":803},[147],[39,1526,1527,1530],{"style":806},[39,1528],{"className":1529,"style":155},[154],[39,1531,1533],{"className":1532},[159,160,161,162],[39,1534,1066],{"className":1535,"style":1202},[103,104,162],[39,1537,206],{"className":1538},[205],[39,1540,1542],{"className":1541},[143],[39,1543,1545],{"className":1544,"style":1270},[147],[39,1546],{},[15,1548,1549],{},"In matrix form for a whole sequence at once:",[39,1551,1553],{"className":1552},[491],[39,1554,1556,1619],{"className":1555},[42],[39,1557,1559],{"className":1558},[46],[48,1560,1561],{"xmlns":50,"display":500},[52,1562,1563,1616],{},[55,1564,1565,1567,1569,1572,1574,1576,1578,1580,1582,1584,1586,1588,1614],{},[506,1566,1040],{},[62,1568,512],{"stretchy":511},[58,1570,1571],{},"Q",[62,1573,517],{"separator":90},[58,1575,1049],{},[62,1577,517],{"separator":90},[58,1579,1054],{},[62,1581,522],{"stretchy":511},[62,1583,525],{},[506,1585,1071],{},[506,1587,1076],{},[55,1589,1590,1592,1612],{},[62,1591,512],{"fence":90},[1082,1593,1594,1604],{},[55,1595,1596,1598],{},[58,1597,1571],{},[66,1599,1600,1602],{},[58,1601,1049],{},[58,1603,1098],{"mathvariant":1097},[885,1605,1606],{},[73,1607,1608,1610],{},[58,1609,77],{},[58,1611,80],{},[62,1613,522],{"fence":90},[58,1615,1054],{},[82,1617,1618],{"encoding":84},"\\text{Attention}(Q, K, V) = \\text{softmax}\\!\\left(\\frac{QK^\\top}{\\sqrt{d_k}}\\right)V",[39,1620,1622,1670],{"className":1621,"ariaHidden":90},[89],[39,1623,1625,1628,1634,1637,1640,1643,1646,1649,1652,1655,1658,1661,1664,1667],{"className":1624},[94],[39,1626],{"className":1627,"style":582},[98],[39,1629,1631],{"className":1630},[103,586],[39,1632,1040],{"className":1633},[103],[39,1635,512],{"className":1636},[593],[39,1638,1571],{"className":1639},[103,104],[39,1641,517],{"className":1642},[600],[39,1644],{"className":1645,"style":604},[109],[39,1647,1049],{"className":1648,"style":1148},[103,104],[39,1650,517],{"className":1651},[600],[39,1653],{"className":1654,"style":604},[109],[39,1656,1054],{"className":1657,"style":1158},[103,104],[39,1659,522],{"className":1660},[611],[39,1662],{"className":1663,"style":110},[109],[39,1665,525],{"className":1666},[114],[39,1668],{"className":1669,"style":110},[109],[39,1671,1673,1677,1683,1686,1689,1878,1881],{"className":1672},[94],[39,1674],{"className":1675,"style":1676},[98],"height:2.4761em;vertical-align:-0.95em;",[39,1678,1680],{"className":1679},[103,586],[39,1681,1071],{"className":1682},[103],[39,1684],{"className":1685,"style":1276},[109],[39,1687],{"className":1688,"style":604},[109],[39,1690,1692,1698,1872],{"className":1691},[1283],[39,1693,1695],{"className":1694,"style":1288},[593,1287],[39,1696,512],{"className":1697},[1292,161],[39,1699,1701,1704,1869],{"className":1700},[103],[39,1702],{"className":1703},[593,1300],[39,1705,1707],{"className":1706},[1082],[39,1708,1710,1861],{"className":1709},[139,178],[39,1711,1713,1858],{"className":1712},[143],[39,1714,1717,1809,1817],{"className":1715,"style":1716},[147],"height:1.5261em;",[39,1718,1719,1722],{"style":1316},[39,1720],{"className":1721,"style":928},[154],[39,1723,1725],{"className":1724},[103],[39,1726,1728],{"className":1727},[103,909],[39,1729,1731,1801],{"className":1730},[139,178],[39,1732,1734,1798],{"className":1733},[143],[39,1735,1737,1786],{"className":1736,"style":919},[147],[39,1738,1740,1743],{"className":1739,"style":924},[923],[39,1741],{"className":1742,"style":928},[154],[39,1744,1746],{"className":1745,"style":932},[103],[39,1747,1749,1752],{"className":1748},[103],[39,1750,77],{"className":1751},[103,104],[39,1753,1755],{"className":1754},[135],[39,1756,1758,1778],{"className":1757},[139,178],[39,1759,1761,1775],{"className":1760},[143],[39,1762,1764],{"className":1763,"style":951},[147],[39,1765,1766,1769],{"style":954},[39,1767],{"className":1768,"style":155},[154],[39,1770,1772],{"className":1771},[159,160,161,162],[39,1773,80],{"className":1774,"style":201},[103,104,162],[39,1776,206],{"className":1777},[205],[39,1779,1781],{"className":1780},[143],[39,1782,1784],{"className":1783,"style":825},[147],[39,1785],{},[39,1787,1788,1791],{"style":977},[39,1789],{"className":1790,"style":928},[154],[39,1792,1794],{"className":1793,"style":985},[984],[987,1795,1796],{"xmlns":989,"width":990,"height":991,"viewBox":992,"preserveAspectRatio":993},[995,1797],{"d":997},[39,1799,206],{"className":1800},[205],[39,1802,1804],{"className":1803},[143],[39,1805,1807],{"className":1806,"style":1007},[147],[39,1808],{},[39,1810,1811,1814],{"style":1409},[39,1812],{"className":1813,"style":928},[154],[39,1815],{"className":1816,"style":1417},[1416],[39,1818,1820,1823],{"style":1819},"top:-3.677em;",[39,1821],{"className":1822,"style":928},[154],[39,1824,1826,1829],{"className":1825},[103],[39,1827,1571],{"className":1828},[103,104],[39,1830,1832,1835],{"className":1831},[103],[39,1833,1049],{"className":1834,"style":1148},[103,104],[39,1836,1838],{"className":1837},[135],[39,1839,1841],{"className":1840},[139],[39,1842,1844],{"className":1843},[143],[39,1845,1847],{"className":1846,"style":124},[147],[39,1848,1849,1852],{"style":150},[39,1850],{"className":1851,"style":155},[154],[39,1853,1855],{"className":1854},[159,160,161,162],[39,1856,1098],{"className":1857},[103,162],[39,1859,206],{"className":1860},[205],[39,1862,1864],{"className":1863},[143],[39,1865,1867],{"className":1866,"style":1492},[147],[39,1868],{},[39,1870],{"className":1871},[611,1300],[39,1873,1875],{"className":1874,"style":1288},[611,1287],[39,1876,522],{"className":1877},[1292,161],[39,1879],{"className":1880,"style":604},[109],[39,1882,1054],{"className":1883,"style":1158},[103,104],[15,1885,1886,1887,1916],{},"That is the entire operation. Multi-head attention runs it ",[39,1888,1890,1904],{"className":1889},[42],[39,1891,1893],{"className":1892},[46],[48,1894,1895],{"xmlns":50},[52,1896,1897,1902],{},[55,1898,1899],{},[58,1900,1901],{},"h",[82,1903,1901],{"encoding":84},[39,1905,1907],{"className":1906,"ariaHidden":90},[89],[39,1908,1910,1913],{"className":1909},[94],[39,1911],{"className":1912,"style":648},[98],[39,1914,1901],{"className":1915},[103,104]," times in\nparallel subspaces and concatenates the results.",[19,1918,1920],{"id":1919},"what-to-read-next","What to read next",[15,1922,1923],{},"The natural follow-up is why sequences need positional information once\nattention is permutation-invariant - that article lands later in this series.",{"title":1925,"searchDepth":1926,"depth":1926,"links":1927},"",2,[1928,1929,1930],{"id":21,"depth":1926,"text":22},{"id":1018,"depth":1926,"text":1019},{"id":1919,"depth":1926,"text":1920},"theory","\u002Fassets\u002Fcover-url-model.svg","Cover illustration: three matrices meeting at a softmax curve","2026-10-14","A worked walkthrough of scaled dot-product attention - the one equation every transformer article assumes you already know.","md",false,"foundational",{},true,"\u002Fen\u002Fblog\u002Fattention-from-vectors-to-probabilities",null,{"title":5,"description":1935},"llm-foundations","en\u002Fblog\u002F7.attention-from-vectors-to-probabilities\u002Findex",[1947,1948],"ai","attention","T1hlNpxt4s6zHZ2xT9AawayLrEcaakg7opXPnkeIRbk",[1951,1962,1968,1978,1992,2006,2020,2031],{"path":1952,"stem":1953,"title":1954,"description":1955,"date":1956,"author":7,"tags":1957,"featured":1937,"articleId":1959,"seriesId":1944,"seriesOrder":1926,"contentType":1931,"level":1938,"prerequisiteIds":1960,"relatedArticleIds":1961},"\u002Fen\u002Fblog\u002Ftokenization-is-where-models-learn-your-language","en\u002Fblog\u002F8.tokenization-is-where-models-learn-your-language\u002Findex","Tokenization is where models learn your language","Byte-pair encoding explained by building one - and why tokenization silently shapes what a model can and cannot do.","2026-10-16",[1947,1958],"tokenization","tokenization-is-where-models-learn-your-language",[6],[],{"path":1941,"stem":1945,"title":5,"description":1935,"date":1934,"author":7,"tags":1963,"featured":1937,"cover":1964,"articleId":6,"seriesId":1944,"seriesOrder":1965,"contentType":1931,"level":1938,"prerequisiteIds":1966,"relatedArticleIds":1967},[1947,1948],{"src":1932,"alt":1933},1,[],[],{"path":1969,"stem":1970,"title":1971,"description":1972,"date":1973,"author":7,"tags":1974,"featured":1937,"prerequisiteIds":1976,"relatedArticleIds":1977},"\u002Fen\u002Fblog\u002Fdemo-content-note","en\u002Fblog\u002F6.demo-content-note\u002Findex","What this blog is (and is not)","This is a demo vertical slice - real layout, real pipelines, deliberately editorial content.","2026-10-07",[1975],"meta",[],[],{"path":1979,"stem":1980,"title":1981,"description":1982,"date":1983,"author":7,"tags":1984,"featured":1937,"cover":1987,"prerequisiteIds":1990,"relatedArticleIds":1991},"\u002Fen\u002Fblog\u002Freading-first-design","en\u002Fblog\u002F5.reading-first-design\u002Findex","A reading page is not a documentation page","Why the blog article layout deliberately differs from the docs layout - hierarchy, width, and restraint.","2026-09-30",[1985,1986],"design","typography",{"src":1988,"alt":1989},"\u002Fassets\u002Fcover-reading-first.svg","Cover illustration: a narrow single-column article layout chosen over a cluttered multi-column layout",[],[],{"path":1993,"stem":1994,"title":1995,"description":1996,"date":1997,"author":7,"tags":1998,"featured":1937,"cover":2001,"prerequisiteIds":2004,"relatedArticleIds":2005},"\u002Fen\u002Fblog\u002Fstatic-deployment","en\u002Fblog\u002F4.static-deployment\u002Findex","Deploying a blog as static assets","No Worker script, no database binding - the whole deployment is a directory of files and a 404 page.","2026-09-23",[1999,2000],"deployment","cloudflare",{"src":2002,"alt":2003},"\u002Fassets\u002Fcover-static-deployment.svg","Cover illustration: a folder of HTML and SVG files flowing onto a globe of CDN edge nodes",[],[],{"path":2007,"stem":2008,"title":2009,"description":2010,"date":2011,"author":7,"tags":2012,"featured":1937,"cover":2015,"prerequisiteIds":2018,"relatedArticleIds":2019},"\u002Fen\u002Fblog\u002Flocale-switching","en\u002Fblog\u002F3.locale-switching\u002Findex","Locale switching that never lies","A language switcher should only offer what exists. Here is how the link list is derived from real content.","2026-09-16",[2013,2014],"i18n","ux",{"src":2016,"alt":2017},"\u002Fassets\u002Ftwo-locales-one-page.svg","Cover illustration: two locale paths joining into one shared page layout",[],[],{"path":2021,"stem":2022,"title":2023,"description":2024,"date":2025,"author":7,"tags":2026,"featured":1937,"prerequisiteIds":2029,"relatedArticleIds":2030},"\u002Fen\u002Fblog\u002Fbuild-time-content","en\u002Fblog\u002F2.build-time-content\u002Findex","Content is resolved at build time","Why this blog ships as prerendered files instead of a content API - and what that buys.","2026-09-09",[2027,2028],"architecture","static-sites",[],[],{"path":2032,"stem":2033,"title":2034,"description":2035,"date":2036,"author":7,"tags":2037,"featured":1940,"cover":2039,"prerequisiteIds":2041,"relatedArticleIds":2042},"\u002Fen\u002Fblog\u002Furl-model","en\u002Fblog\u002F1.url-model\u002Findex","One URL model for every public page","How \u002Flocale\u002Fmount\u002Fpath keeps every public page predictable - and why we enforce it instead of hoping for it.","2026-09-02",[2027,2038],"urls",{"src":1932,"alt":2040},"Cover illustration: a single address bar splitting into locale, mount and path segments",[],[],[2044,2046,2048,2050,2052,2054,2056,2058],{"path":1952,"stem":1953,"title":1954,"description":1955,"date":1956,"author":7,"tags":2045,"featured":1937,"seriesId":1944},[1947,1958],{"path":1941,"stem":1945,"title":5,"description":1935,"date":1934,"author":7,"tags":2047,"featured":1937,"seriesId":1944},[1947,1948],{"path":1969,"stem":1970,"title":1971,"description":1972,"date":1973,"author":7,"tags":2049,"featured":1937},[1975],{"path":1979,"stem":1980,"title":1981,"description":1982,"date":1983,"author":7,"tags":2051,"featured":1937},[1985,1986],{"path":1993,"stem":1994,"title":1995,"description":1996,"date":1997,"author":7,"tags":2053,"featured":1937},[1999,2000],{"path":2007,"stem":2008,"title":2009,"description":2010,"date":2011,"author":7,"tags":2055,"featured":1937},[2013,2014],{"path":2021,"stem":2022,"title":2023,"description":2024,"date":2025,"author":7,"tags":2057,"featured":1937},[2027,2028],{"path":2032,"stem":2033,"title":2034,"description":2035,"date":2036,"author":7,"tags":2059,"featured":1940},[2027,2038],[2061],"en",[2032,2021,2007,1993,1979,1969,1941,1952,2063,2064,2065,2066,2067,2068],"\u002Fvi\u002Fblog\u002Furl-model","\u002Fvi\u002Fblog\u002Fbuild-time-content","\u002Fvi\u002Fblog\u002Flocale-switching","\u002Fvi\u002Fblog\u002Fstatic-deployment","\u002Fvi\u002Fblog\u002Freading-first-design","\u002Fvi\u002Fblog\u002Fdemo-content-note",[2070,2071],{"articleId":6,"locale":2061,"path":1941,"title":5},{"articleId":1959,"locale":2061,"path":1952,"title":1954},1791876184776]