<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Arko Sengupta on Medium]]></title>
        <description><![CDATA[Stories by Arko Sengupta on Medium]]></description>
        <link>https://medium.com/@arko_sengupta?source=rss-05dccf25463b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yh6prYimszI4F1k4Lh64Bg.png</url>
            <title>Stories by Arko Sengupta on Medium</title>
            <link>https://medium.com/@arko_sengupta?source=rss-05dccf25463b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 19:18:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arko_sengupta/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Vision Transformer: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/vision-transformer-a-comprehensive-guide-02484dfbc4b3?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/02484dfbc4b3</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[vision-transformer]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 19:39:43 GMT</pubDate>
            <atom:updated>2026-10-29T19:39:43.388Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 99</h4><h4>Explore detailed Vision Transformer</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q7MpalAo0Eie35tmbGSrfw.png" /><figcaption>Data Science &amp; Machine Learning — Article 99</figcaption></figure><h3>Introduction</h3><p>Every architecture in this series has assumed a discrete vocabulary, and an image has none.</p><p>Tokens must therefore be invented, and the patch size that invents them fixes everything downstream: n = (S/P)² + 1, so at 224 pixels with P = 16 there are 197 tokens.</p><p>Three exact identities follow. The patch embedding <strong>is</strong> a strided convolution, not an analogy for one, verified at 3.553×10⁻¹⁵.</p><p>At ViT-Base’s P = 16 with d = 768 the map is exactly square, since 3 × 1⁶² = 768, so patchification is a change of basis that discards nothing, while P=32 compresses 4× and loses at least 2304 dimensions per patch by rank alone.</p><p>And without position embeddings a ViT is exactly permutation-invariant over patches, measured at 1.776×10⁻¹⁵: a shuffled image is literally the same input, with 196 patches collapsing 1214.8 bits of arrangement.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is a Vision Transformer</li><li>Core Components of a Vision Transformer</li><li>Mathematical Foundation</li><li>Types of Patch and Position Schemes</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is a Vision Transformer</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*31ekpTlLdhjm6W-YCtmnQQ.png" /></figure><ul><li>A Vision Transformer cuts an image into non-overlapping P × P patches, maps each through one shared linear layer, adds a position embedding, and applies a standard transformer encoder:</li><li>Everything after E is Article 91’s architecture unchanged, so the 12d² block and the n/(2d+n) cost share both apply directly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_8c1d3E6g4mhXoBacRYR8Q.png" /></figure><h4><strong>What changes relative to a language model</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xfQK8En1YorLOlPeKGsdjg.png" /></figure><ul><li>The fourth row is the substantive one.</li><li>In a language model n is a property of the input; here it is a hyperparameter, and Section 5 shows it to be the most consequential one in the architecture.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIlmIRXJD2zdXHRmq4C-mw.png" /></figure><h3>Core Components of a Vision Transformer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WI3RFSB87dLLzZSwRaRtg.png" /></figure><h4><strong>The patch size sets the sequence length and the cost</strong></h4><ul><li>At P = 4 the quadratic term is 67.13% of attention cost, so the sequence-length problem that Article 91 located at n = 2d arrives through a choice of patch size rather than through a long document.</li></ul><h3>Mathematical Foundation</h3><h4><strong>The P⁻⁴ scaling, and where it is not exact</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*EPrGNcdnLhXwxaBbElpDpw.png" /></figure><p>Since n ≈ (S/P)², the quadratic term 2n²d scales as P⁻⁴:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cipLBKW7ey8BZZwQEuYlzw.png" /></figure><p><strong>The measured ratios approach 16 without reaching it</strong>, and the entire shortfall is the single class token: removing it recovers 16.0000 exactly at every step.</p><p>The power law is exact in the patch count and only asymptotic in n.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzqIeaL7XkmZC0NOaYxyvw.png" /></figure><p>Per-layer cost at d = 768, using Article 91’s 4nd² + 2n²d:</p><p><strong>Halving the patch size from 16 to 8 costs 5.3368×</strong>, not 16×, because the projection term is only linear in n and still dominates at these lengths.</p><h4><strong>The patch embedding is a strided convolution</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GneTuoK14tnn4-U7o07bg.png" /></figure><p>Cutting into non-overlapping patches, flattening each, and applying one shared linear map is identical to a convolution with kernel P and stride P. This is an identity, checkable directly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Ab2IkRGQGCXNIMOb196xEQ.png" /></figure><p>The identity is that flattening a patch and applying a shared matrix is the same contraction as a convolution evaluated at a stride-P offset:</p><p><strong>So a ViT’s first layer is a convolution, and the only one in the model.</strong></p><p>The consequence is exact: a stride-P kernel-P convolution has receptive field exactly P with no overlap, so within-patch structure is seen once by a linear map and <strong>no convolution ever crosses a patch boundary</strong>.</p><h4><strong>At ViT-Base the patch embedding is exactly square</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hwzAoqX83jO6oLeNkjez_Q.png" /></figure><p>Whether patchification can be lossless depends entirely on 3P² against d:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*had_OV81Xt_ou19Mc7nKjw.png" /></figure><p>The rank of the map is bounded by the smaller of its two dimensions, which decides the question outright:</p><p>At ViT-Base/16 the numbers coincide: 3 × 1⁶² = 768 = d. <strong>The patch embedding is a square matrix, so patchification is a change of basis that discards nothing in principle.</strong></p><p>Solving for the original patch recovers it to 3.972×10⁻¹³ at a condition number of 7.6398×1⁰³.</p><p>At P = 32 the map is 3072 → 768, discarding at least 2304 dimensions per patch by rank alone and retaining 0.2500. At P = 8 it is 192 → 768, an expansion whose rank is at most 192, or 25.0000% of the embedding space.</p><p>That is Article 99’s rank argument again, now on the input side of a vision model rather than a vocabulary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ojwz8f8gj-VKmiXOqdaoYg.png" /></figure><h4><strong>Without position embeddings a ViT is a bag of patches</strong></h4><p>Article 91 measured attention as permutation-equivariant to 1.332×10⁻¹⁵, and for images the consequence is sharper because patches carry no intrinsic order.</p><p><strong>A shuffled image is literally the same input</strong>, and the positive control confirms the measurement means something: with position embeddings the same quantity reaches 5.380.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tHY5ICsc4Au8idvi6Y7VWg.png" /></figure><p>Article 95 priced permutation at log₂ s! bits, and the same formula applies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SNgz8mI4lJi9C10Hv9X4og.png" /></figure><p>At P = 16 that is 1214.8 bits, larger than any corruption measured in Article 95, whose maximum was 1510.92 bits for deleting 77 tokens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jYq7yFJ6BdifluYlZaqu5w.png" /></figure><h4><strong>Layers needed to relate opposite corners</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*207wfmiGpE5-VQLfLnfVOQ.png" /></figure><p>The two counts come from different growth laws, one linear in depth and one geometric:</p><p>The stride-1 figure of 112 layers is not a fair comparison, and it is worth saying so.</p><p>Real convolutional networks downsample, and with a stride-2 reduction every second layer the receptive field grows geometrically, spanning 224 pixels in <strong>12 layers</strong>.</p><p>So the honest statement is 1 against roughly a dozen. What remains exactly true is that <strong>attention needs one layer at any image size</strong>, while any convolutional stack needs a count that grows with the image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKarL7wEbDLH5EeO1mbRWQ.png" /></figure><h4><strong>The embedding problem nearly vanishes</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wUE0oruaInKGV7xSllme5g.png" /></figure><p>All three land within 1.2%, the closest agreement in this series. And the embedding share collapses:</p><p><strong>Articles 98 and 99’s compression problem essentially does not exist here.</strong> There is no vocabulary to factorize, and the ceiling on embedding-side savings is under one percent rather than 21.77%.</p><p>What remains is the block share at 99.13% to 99.83%, where layer removal and cross-layer sharing apply unchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dceS8bSfP6HgBcIj49ZaJg.png" /></figure><h3>Types of Patch and Position Schemes</h3><h4><strong>Learned position embeddings tie the model to one resolution</strong></h4><ul><li>The table is n × d, so changing S or P changes n and invalidates it.</li><li>Interpolating the table is the standard remedy and it is an approximation, whereas Article 91’s sinusoidal encodings satisfy PE(p+k) = RₖPE(p) exactly at any length.</li><li><strong>The choice is between a table that must be resized and a function that need not be.</strong></li></ul><h4><strong>Overlapping patches break the identity</strong></h4><ul><li>Section 5’s equivalence holds because stride equals kernel.</li><li>With overlap the first layer is still a convolution but no longer a partition, so token count rises above (S/P)² and the clean P⁻⁴ accounting no longer applies.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cP0gjUF0DaRkSPl7U4UGyw.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The permutation check is the same diagnostic as Article 91&#39;s</strong></h4><ul><li>A residual near 10⁻¹⁵ means position embeddings are not reaching the model, and the consequence for images is that the model sees a set.</li><li>The positive control matters equally: with embeddings present the same quantity reached 5.380, so a small residual is informative only against a large one.</li></ul><h4><strong>Report the patch size before any cost figure</strong></h4><ul><li>Since P determines n and n determines the quadratic share, a cost or latency claim about a ViT is meaningless without it.</li><li>The same model at P = 32 and P = 8 differs by 22.98× in per-layer arithmetic, which is a larger spread than most architectural changes in this series produce.</li></ul><h3>Selecting Evaluation Metrics</h3><h4>Choosing the patch size</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZ60-tHJhpAUs_jho2V8GA.png" /></figure><h4><strong>What this series has established about where costs are exact</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdNzw854vFPxcb9w9AoTGA.png" /></figure><h4><strong>Two of this series’ recurring lessons apply directly</strong></h4><ul><li>First, an exact ceiling is not an achievement: the 99.83% block share of ViT-Huge bounds what compression can save without indicating what it costs in accuracy, exactly as Article 98’s 77.69% did.</li><li>Second, a rule verified across many models is still a rule about a configuration.</li><li>Article 91’s 12d² reproduced BERT, all four GPT-2 sizes, BART and every ViT here to within 1.2%, and <strong>failed by 16× for T5–11B</strong> in Article 94.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MTWKtHFgxmoTbYp8vkMoSA.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the convolution identity</strong></h4><ul><li>The equivalence is exact for non-overlapping patches with a shared linear map and holds at machine precision across the configurations tested.</li><li>It says nothing about whether a ViT behaves like a CNN overall: after the first layer the two differ entirely, and the identity concerns only patchification.</li></ul><h4><strong>On the corner-distance comparison</strong></h4><ul><li>The 112-layer figure assumes stride-1 convolutions throughout, which no practical network uses, and the strided calculation gives 12.</li><li>The article reports both because the first alone would overstate the case. <strong>What is exactly true is the scaling</strong>: one attention layer at any image size against a convolutional count that grows with it.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02484dfbc4b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ALBERT: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/albert-a-comprehensive-guide-9b988808e7f3?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b988808e7f3</guid>
            <category><![CDATA[albert]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 19:30:41 GMT</pubDate>
            <atom:updated>2026-10-29T19:30:41.734Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 98</h4><h4>Explore detailed ALBERT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AmXM6uG_krVQjKDN-a3o7Q.png" /><figcaption>Data Science &amp; Machine Learning — Article 98</figcaption></figure><h3>Introduction</h3><p>Article 98 left two parameter blocks to attack, and ALBERT attacks both.</p><p>Factorizing the embedding through a width-E bottleneck helps exactly when E &lt; VH/(V+H), which at V = 30,000 and H = 768 is 748.83: a threshold so close to H that any real bottleneck saves.</p><p>Cross-layer sharing saves exactly (L-1)/L of the block parameters, which is 0.9167 at twelve layers, and <strong>exactly zero compute</strong>, since the same matrices are applied the same number of times.</p><p>That zero is the central point. Sharing decouples parameters from arithmetic completely, so the two move in opposite directions: ALBERT-xxlarge has 0.7012 times the parameters of BERT-large and 6.8000 times the compute at n = 512.</p><p>By count it is a compression of BERT-large; by arithmetic it emphatically is not. Sharing also changes what the stack computes, since applying one function L times is an iterated map.</p><p><strong>The residual form does not converge at all</strong>, and it does so whether or not weights are shared.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is ALBERT</li><li>Core Components of ALBERT</li><li>Mathematical Foundation</li><li>Types of Parameter Reduction</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is ALBERT</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C2n9uyi1jqo-AjU2cmN2sg.png" /></figure><ul><li>ALBERT is BERT with two parameter reductions and a replaced auxiliary objective. The embedding becomes a product through a bottleneck, and one encoder block is reused at every depth:</li><li>The single parameter set θ is shared, so the stack computes fθˡ rather than f(θ_L) ∘ ⋯ ∘ f(θ_1).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RuIXUQqs0Em-nCtOpGLhTg.png" /></figure><h4><strong>What each change targets</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vj1iBBkMAwRfxBwjkGGvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPIgw85f0_mCH-efp7vZHA.png" /></figure><h3>Core Components of ALBERT</h3><h4><strong>Which technique contributes more</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-hjK0Wnxh5p6ZTqXzUi9mA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xKHfEUhu0lAqeevBSDE_Kw.png" /></figure><ul><li><strong>Sharing contributes 3.93 times more than factorization</strong> at base scale, 71.21% against 18.12%.</li><li>And the gap widens with width, because a block grows as H² while the factorized embedding grows only as VE + EH:</li></ul><h3>Mathematical Foundation</h3><h4><strong>The factorization break-even is exact</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/1*ROFFyJajXavN2M9hL_1CAQ.png" /></figure><p>A single V × H matrix becomes V × E plus E × H, so factorization helps precisely when</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*312CcOztv5X1p3wG4H0jmg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ungd8-SDUs-W-WExdWl1jw.png" /></figure><p><strong>The threshold approaches H as V grows</strong>, so it is not a real constraint: any bottleneck narrower than the hidden width saves, and the saving tends to V(H-E).</p><p>The last row is the control. At E = H the factorization must be a pure loss, since it inserts an H × H matrix for nothing, and it costs exactly 589,824 extra. <strong>A saving reported at E = H would indicate a bug in the accounting.</strong></p><p>What it costs is rank. The product has rank at most E, so the embedding is confined to a rank-128 subspace: 16.6667% of the available dimensions at H = 768 and only 3.1250% at H = 4096.</p><p>The constraint applies to the input embedding alone and the model still uses all H dimensions internally, which is why so narrow a bottleneck is tolerable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iaOUiL9RfO_AV0GItqpJQA.png" /></figure><h4><strong>Sharing saves exactly (L-1)/L and exactly zero compute</strong></h4><p>At L = 12, d = 768, n = 512 the stack costs 19, 327, 352, 832 multiply-accumulates whether shared or not.</p><p><strong>Sharing is the extreme case of Article 98’s finding</strong> that a parameter count is not a latency proxy: up to (L-1)/L of block parameters saved, and none of the arithmetic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lK_dkYCrKJhHDSQoeWmESQ.png" /></figure><h4><strong>Parameters and compute, fully decoupled</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*J4x7hInfTRcXxE7p_-7PbA.png" /></figure><p>Sharing divides the parameter count by L while leaving the cost untouched, so the two ratios are governed by different quantities entirely:</p><p>ALBERT-xxlarge has 0.7012 times the parameters of BERT-large and 6.8000 times the compute.</p><p><strong>It is the smaller model by parameter count and nearly seven times the larger by arithmetic.</strong></p><p>Parameters per billion multiply-accumulates falls from 5,202,086.77 to 536,423.54, a factor of 9.70, and that ratio is exactly what sharing manipulates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1aJte1ATaEyRjBOdPKDlA.png" /></figure><p>The same divergence appears within ALBERT’s own family:</p><h4><strong>A shared stack is an iterated map</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7fQrubFvVxvydQKhZz3wWg.png" /></figure><p>Unshared layers apply L different functions; a shared stack applies one function L times, so the representation follows an orbit.</p><p>If f is a contraction with modulus κ &lt; 1, the step size decays geometrically and the orbit converges to the unique fixed point:</p><p>Every layer past convergence then contributes nothing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*02J8Qugb8458UwFcsIfzPQ.png" /></figure><p>Measured on a plain, non-residual map, the step size collapses:</p><p>The shared stack contracts harder than the unshared one at both gains, by 0.076678 against 0.000000 and 0.372474 against 0.074773, which is what iterating a single contraction predicts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZl26R9JQ5FkMAwLtr3oow.png" /></figure><p>Iterating to convergence locates the fixed point exactly:</p><p>At gain 0.5 the orbit is within 10⁻¹² of its fixed point in 20 layers, so <strong>effective depth is set by the contraction rate rather than by L</strong>, and layers past that point change the output by less than machine precision.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NhBVsALKCu41MYcou-2m6g.png" /></figure><h4><strong>But the residual form does not converge</strong></h4><p><strong>Every residual configuration grows rather than shrinking</strong>, by factors from 1.667962 to 2.397955 over 24 layers.</p><p>A residual update x + h(x) is not a contraction unless h is small, so the fixed-point argument does not apply and the stack keeps moving.</p><p>Crucially, <strong>the growth appears whether the weights are shared or not</strong>, so failing to contract is a property of the residual connection rather than of sharing.</p><p>Which of the two grows faster is not stable: shared exceeds unshared at gain 0.5, 2.397955 against 1.669411, and the ordering reverses at gain 1.0, 1.667962 against 1.989650.</p><p>That reversal is why the comparison between them should not be read as a finding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fqW5FhzZFwZ8jTz-supM9g.png" /></figure><p>This bounds the iterated-map result to the plain case rather than to transformers as built, and it is why real shared architectures do not collapse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0ZUjASiT3DO4p9MWwWrCQ.png" /></figure><h4><strong>Configurations against published totals</strong></h4><p>All four land <strong>below</strong> their published figures, by 7.6% to 12.4%, and the deficit grows with width.</p><p>That is a consistent under-count rather than rounding, so this accounting captures the structure of both techniques but is missing a component that scales with H.</p><p><strong>The honest claim is that the mechanisms and their exact savings are established here; the totals are not reproduced</strong>, unlike the BERT, GPT-2 and BART counts in earlier articles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x_-SFLB8HRJew6ln-068ew.png" /></figure><h4><strong>Sentence-order prediction carries exactly what NSP did</strong></h4><p>At V = 30,000 the MLM term is 1142.2214 bits and a binary sentence label is 1 bit, so the auxiliary objective is 0.0875% of the signal, matching Article 97’s 0.0873%.</p><p><strong>Replacing NSP with SOP changes nothing about the size of the signal</strong>, because both ask one binary question.</p><p>What changes is the shortcut available. NSP negatives come from a different document, so a topic cue suffices.</p><p>SOP negatives are the <em>same two sentences</em> swapped, so the topic is identical and order must be represented.</p><p>Article 95 priced exactly that operation: sentence permutation over two sentences is log₂ 2! = 1 bit and preserves the token multiset entirely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngz3I7mm3BcBmwk0hgjYqg.png" /></figure><h3>Types of Parameter Reduction</h3><h4><strong>Sharing and layer removal are opposites at equal parameter saving</strong></h4><ul><li>Removing half the layers saves 0.5 of block parameters and 0.5 of compute.</li><li>Sharing across twelve layers saves 0.9167 of block parameters and 0 of compute.</li><li><strong>So at a larger parameter saving, sharing delivers no speedup whatsoever</strong>, and choosing between them depends entirely on whether the binding constraint is memory or latency.</li></ul><h4><strong>Factorization is the only one that leaves compute essentially untouched for a different reason</strong></h4><ul><li>Its saving is in a lookup table, and a lookup is constant time regardless of vocabulary.</li><li>The added E × H projection does cost arithmetic, but nEH against the block’s 4nH² is small: at E=128, H=768 it is 128/(4 × 768) = 4.17% of one block’s projection cost.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhmR06AcCxlh3Ai6KYzYOQ.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>Reporting a parameter count alone is misleading for a shared model</strong></h4><ul><li>ALBERT-xxlarge is smaller than BERT-large by parameters and 6.80× larger by arithmetic.</li><li>Since sharing saves exactly zero compute, <strong>the parameter count of a shared model carries no information about its cost to run</strong>, and the two numbers must be reported together.</li></ul><h4><strong>Measure the step size before claiming effective depth</strong></h4><ul><li>The iterated-map argument gives a striking result for plain maps and does not apply to residual ones, where the step size grew by 2.12 instead of shrinking.</li><li>So the diagnostic is the measured step norm across depth, not the sharing scheme: <strong>a shared residual stack is not obviously wasting its layers</strong>, and the plain-map figures do not transfer.</li></ul><h3>Selecting Evaluation Metrics</h3><h4><strong>Choosing between the two techniques</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lqm1JJWAKrbLXUGopwxjPw.png" /></figure><h4><strong>When factorization is worth more than sharing</strong></h4><ul><li>Never, at any width tested: the ratio ran from 4.01× at H=768 to 18.37× at H = 4096, always favoring sharing.</li><li>Factorization wins only when V is enormous relative to H² L, since its saving is linear in V while sharing’s is quadratic in H.</li><li><strong>At a 250,000-token vocabulary the break-even E is 765.65</strong>, so the technique still applies, but the block term dominates any realistic configuration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYcXikg4x_f23jpZEIgJ0A.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DVj8nVUdHbXtd7Mi6I_fA.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the iterated-map result</strong></h4><ul><li>The convergence figures come from a plain two-matrix map with tanh, not from a transformer block, and the residual measurement shows the conclusion reversing for the form actually used.</li><li><strong>What transfers is the question, not the answer</strong>: a shared stack may be applying an inert map, the step norm across depth is the way to check, and the check is cheap. The specific layer counts describe the plain case only.</li></ul><h4><strong>On the parameter totals</strong></h4><ul><li>Unlike the BERT, GPT-2, T5-small and BART counts in earlier articles, these do not reproduce their published values, falling short by 7.6% to 12.4% with the deficit growing in H.</li><li>The savings formulas are exact and verified; the totals indicate a missing component and are reported as such rather than adjusted to fit.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b988808e7f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DistilBERT: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/distilbert-a-comprehensive-guide-5b65fed0ce81?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b65fed0ce81</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[distilbert]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 19:20:19 GMT</pubDate>
            <atom:updated>2026-10-29T19:20:19.045Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 97</h4><h4>Explore detailed DistilBERT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7brtPGjp09pjk7DJfrI2xQ.png" /><figcaption>Data Science &amp; Machine Learning — Article 97</figcaption></figure><h3>Introduction</h3><p>Article 97 ended on the arithmetic ceilings for compression: blocks are 77.69% of BERT-base and embeddings 21.77%, so a method that removes layers cannot save more than the first figure however clever it is.</p><p>Distil BERT halves the depth, which saves exactly half the block share at 38.84%, and adds the pooler and token-type table for a total of 39.3848%.</p><p><strong>The compute saving is a different number entirely, and it is exactly 50% at every sequence length</strong>, because depth multiplies both the projection and quadratic terms equally while embeddings hold parameters without costing arithmetic.</p><p>Distillation itself has a quantifiable rationale. A hard label gives the target’s identity; a soft target gives the whole conditional row, and at τ = 4 that row carries 2.678132 bits of shape over 8 classes.</p><p>The consequence is a sample-complexity result rather than a vague one: a student learning from soft targets reaches <strong>exactly</strong> the teacher’s error after enough observations to visit each state once, while a hard-label student trained on twenty times more data still carried excess.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is DistilBERT</li><li>Core Components of DistilBERT</li><li>Mathematical Foundation</li><li>Types of Compression</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is DistilBERT</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*FRE-jnJ3K0Nh2kHyAcwU2Q.png" /></figure><ul><li>DistilBERT is a six-layer BERT trained to match a twelve-layer teacher’s output distribution rather than the data’s hard labels.</li><li>The loss combines a temperature-scaled soft term with the original masked-language objective:</li><li>The τ² factor is not arbitrary, and Section 5 derives exactly what it corrects for.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Y2XITqHY4LmyFJ0mflw4Q.png" /></figure><h4><strong>What is removed</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UZQVEPuLsdvzCkz2J81jmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cL7boHsteEfgGSzO0l2ThA.png" /></figure><h3>Core Components of DistilBERT</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-ix_c_eUs7qNrM5AL0LcA.png" /></figure><h4><strong>The reduction, decomposed exactly</strong></h4><ul><li>The residual is exactly 109,482,240–43,119,360 = 66,362,880, matching the published figure.</li><li><strong>The token-type table is a rounding error at 0.0014%</strong>, so removing it is a tidiness decision rather than a compression one.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ousHQHVvScQB1r-2fa19bw.png" /></figure><h4><strong>The embedding share rises under compression</strong></h4><ul><li>The embedding numerator barely changed while the denominator shrank, so <strong>layer removal makes the embedding matrix the dominant remaining target</strong>.</li><li>That is a structural consequence of compressing one part, and it sets up the next article’s approach.</li></ul><h3>Mathematical Foundation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d4Y4pkD66YEeyd6VLZPlEw.png" /></figure><h4><strong>What fraction of the ceiling is reached</strong></h4><p>Halving the depth reaches exactly half the layer-removal ceiling, which is arithmetic rather than a finding.</p><p>What is not arithmetic is how much accuracy survives, and no amount of parameter counting predicts that.</p><h4><strong>The τ² factor, derived</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*9CPLTaznknY0Uw5XTg13Bg.png" /></figure><p>Differentiating the soft loss with respect to the student logits gives</p><p>For large τ the softmax approaches uniform with pᵢτ ≈ 1/K(1 + (zᵢ — z̄)/τ), so the difference carries a second factor of 1/τ and the gradient scales as 1/τ². Multiplying by τ² therefore normalizes it.</p><p>Verified by central finite differences, the analytic form matched to a worst relative deviation of 1.342×10⁻⁸.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_Kn3IvQXiHHiKaghYP6zQ.png" /></figure><p>Whether the normalization actually works is a separate question, and a single logit pair answers it badly. Averaged over 500 independent logit pairs over 8 classes: Each row doubles τ, so the predicted ratio is 4 throughout.</p><p><strong>The measured ratio rises to 4 from below, slightly overshoots to 4.0065 at τ = 16, then settles from above</strong> at 4.0032, 4.0014, 4.0007 and 4.0003 as τ continues doubling to 256, where the scaled value reaches its limit of 0.904667.</p><p>The scaled gradient is within 1% of that limit from τ = 4 onward, while the ratio is within 1% of 4 only from τ = 8.</p><p>Over the range actually used in distillation, τ ∈ [2, 8], the scaled gradient varies by only 1.0296×, so <strong>the τ² factor does its job in practice</strong> even though it is exact only asymptotically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L5FHFrH2-oR2LAAIekAygA.png" /></figure><p>The asymptotic regime begins where τ exceeds the logit spread, which is why τ = 1 sits outside it:</p><p>With a logit standard deviation of 2.0031 and a mean range of 5.6594, larger logits push the 4× ratio further out in τ, exactly as the near-uniform argument predicts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*k3zuU6qCRkv1b6rPSeemsQ.png" /></figure><p>The dependence is not merely qualitative. Scaling the logits by s and the temperatures by s together leaves the ratio <strong>exactly</strong> unchanged, since softmax(sz/sτ) = softmax(z/τ) and the two 1/τ prefactors cancel in the ratio:</p><p>Measured at s=2 this gives 3.367496 against 3.367496, agreeing to six decimals.</p><p><strong>Only τ relative to the logit scale matters</strong>, so the temperature is not a transferable constant: a value tuned for one teacher is the wrong setting for another whose logits differ in scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqssF9cENjHW3ZRHE2Adkg.png" /></figure><h4><strong>What temperature exposes</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*66mfK3xD3nHzGJD9NQBcww.png" /></figure><p>With log₂ K = 3.0000 bits, τ = 0.5 gives an effective class count of 1.014634, so the soft target is nearly a hard label and carries almost nothing extra.</p><p>At τ = 32 the effective count is 7.972540 of 8, so the distribution is nearly uniform and carries almost nothing about the input.</p><p><strong>The usable signal is in between</strong>, which is why temperature is a hyperparameter and not a limit to be pushed.</p><h4><strong>The sample-complexity result</strong></h4><p>Article 97 gave the hard-label law 𝔼[D(KL)] = K(K-1)/(2N): each observation supplies one sampled outcome, so estimating a row takes many visits.</p><p>A soft target supplies the entire row per visit, so the student needs only to <strong>visit</strong> each context, which is a coupon-collector count of order Klog K.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6liPjHR_tHp7xDiCtGckyA.png" /></figure><p>Measured with the true chain as teacher, an upper bound on any real teacher:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ME54uL-G62D5m9iDVVDBiA.png" /></figure><p>The two requirements scale differently, which is the whole result:</p><p>The hard-label count grows as the accuracy target tightens while the soft-target count does not depend on ε at all.</p><p>The coupon-collector expectations are 8.05 and 23.03 steps, and the soft-target error hits exactly zero once all states have been seen.</p><p><strong>The crossover is at the visit count, not at any accuracy target</strong>: at K=10, N=100 the soft student is exact while the hard-label student at N=1000, ten times more data, still carries 0.04317260 nats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2lowhO64p2MfkmPC14gTCQ.png" /></figure><h4><strong>And the teacher’s error is a hard floor</strong></h4><p>The student matches the teacher <strong>exactly</strong>, at a ratio of 1.0000, using one to two orders of magnitude fewer samples than the teacher needed.</p><p>It never beats the teacher, because the soft targets <em>are</em> the teacher’s rows. That is the precise statement of what distillation transfers and what it cannot: <strong>sample efficiency, not accuracy beyond the source.</strong></p><h4><strong>Inference cost</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2UnjjTi8lcCUeNasClQUWg.png" /></figure><p>Depth multiplies both attention terms equally, so per-token compute falls by exactly the layer ratio:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*q2_Nm9tHs9ryEwzqNilwog.png" /></figure><p>Depth appears as a common factor in both cost terms, so it cancels out of the ratio entirely:</p><p>independent of n and d. <strong>So compute falls 50% while parameters fall 39.38%</strong>, and the two differ because embeddings hold parameters but cost essentially no arithmetic.</p><p>A lookup is constant time regardless of vocabulary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpdczSWkktxR_cmFGTTM_Q.png" /></figure><h3>Types of Compression</h3><h4><strong>Three of these have very different compute profiles at the same parameter saving</strong></h4><ul><li>Layer removal cuts compute proportionally, which is why DistilBERT’s 39.38% parameter reduction comes with a 50% compute reduction. Embedding factorization saves parameters with almost no compute effect.</li><li>Weight sharing saves parameters with <strong>zero</strong> compute effect, since the same matrices are still applied the same number of times.</li><li><strong>A parameter count is therefore not a proxy for latency</strong>, and the three approaches are not interchangeable despite reporting comparable headline numbers.</li></ul><h4><strong>Width reduction is the only one that is quadratic</strong></h4><ul><li>Since a block is 12d², halving d removes 75% of block parameters and 75% of the projection compute, against 50% for halving depth.</li><li>It also halves the representation size, which layer removal does not, so the two are not comparable at equal parameter saving.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zg_lND5dCbpdotVAZqicIA.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The student/teacher ratio has a floor of one</strong></h4><ul><li>Soft targets are the teacher’s distributions, so a student trained purely on them cannot fall below the teacher’s error.</li><li>Measuring a ratio of 1.0000 means distillation worked perfectly.</li><li>A ratio below 1 would mean something other than the soft targets was supplying information, which in practice is the retained hard-label term.</li><li><strong>Reporting a student that beats its teacher is therefore a claim about the data term, not about distillation.</strong></li></ul><h4><strong>Check the effective class count before tuning anything else</strong></h4><ul><li>At τ = 0.5 the effective class count was 1.014634, so the soft target was nearly a hard label and the distillation term was contributing almost nothing regardless of α.</li><li>That is a one-line diagnostic and it distinguishes a badly chosen temperature from a badly weighted loss.</li></ul><h3>Selecting Evaluation Metrics</h3><h4><strong>Choosing what to compress</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqCFk11oOMCnFCZX8YOIyQ.png" /></figure><h4><strong>Deciding the temperature from the teacher’s logits</strong></h4><ul><li>The asymptotic table showed the 4× ratio arriving at τ = 8 for logits of standard deviation 2.0031, and at τ = 2 when the logits were halved.</li><li><strong>So the temperature should be set relative to the teacher’s logit scale</strong>, and a value transferred from another model with different logit statistics is not the same setting.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3EYl5eZkHRsZHr5s0s4o9g.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><ul><li>The last row connects directly. At τ = 32 the teacher’s distribution had 7.972540 effective classes of 8, which is the same saturation-toward-uniform phenomenon Article 91 measured from the opposite direction.</li><li>There the concern was a softmax collapsing to a hard argmax at large d, here it is a softmax flattening to uniform at large τ.</li><li><strong>Both are the same statement about where a softmax carries information.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XxwLvHUS1OzgOG4syvbtbQ.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the sample-complexity measurement</strong></h4><ul><li>The soft-target student here copies the teacher’s row on every visited state, which makes its advantage exact but also idealized.</li><li>A real student fits a parametric function and has approximation error the measurement excludes.</li><li><strong>What transfers is the mechanism and its scaling</strong>, that one observation conveys a whole distribution rather than one sample from it, and that the requirement is coverage rather than accuracy.</li><li>The absolute figures describe the idealized case.</li></ul><h4><strong>On what parameter counting cannot say</strong></h4><ul><li>Every ceiling in this article is arithmetic and therefore certain. How much accuracy survives removing half the layers is not, and nothing here bears on it.</li><li>The counts bound what can be saved; they say nothing about what it costs to save it.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b65fed0ce81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RoBERTa: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/roberta-a-comprehensive-guide-22b6cec557b2?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b6cec557b2</guid>
            <category><![CDATA[roberta]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Thu, 29 Oct 2026 19:09:20 GMT</pubDate>
            <atom:updated>2026-10-29T19:09:20.793Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 96</h4><h4>Explore detailed RoBERTa</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clPsX2YXHD41s7c1fBbfKA.png" /><figcaption>Data Science &amp; Machine Learning — Article 96</figcaption></figure><h3>Introduction</h3><p>RoBERTa changes no part of BERT’s architecture, so Article 91’s 12d² block and Article 92’s parameter totals carry over untouched.</p><p>What changes is the recipe, and several of its choices were quantifiable before any ablation. Article 92 put next sentence prediction at 1.2853% of the training signal by prediction count.</p><p>That accounting is generous to it: a binary label carries at most 1 bit while 76.8 masked tokens over a 30,522-token vocabulary carry 1144.1328 bits, so <strong>NSP is 0.0873% by information</strong>.</p><p>The largest change, an order of magnitude more data, obeys an exactly derivable law.</p><p>For a plug-in estimator the expected excess loss is K(K-1)/(2N), in which the stationary distribution cancels exactly, so <strong>doubling the data halves the excess loss regardless of the state count</strong>.</p><p>Static masking is the other quantifiable choice: ten fixed patterns leave 19.69% of every sequence never predicted at all, while dynamic masking has about 1⁰⁹³ patterns available.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is RoBERTa</li><li>Core Components of RoBERTa</li><li>Mathematical Foundation</li><li>Types of Recipe Changes</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is RoBERTa</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*ehZ78kR7Ml5sfRbaoQE5hA.png" /></figure><ul><li>RoBERTa is BERT with the next-sentence objective removed and the training procedure changed. The objective reduces to masked language modeling alone:</li><li>The expectation over mask sets M is the substantive difference from Article 92: BERT fixed M per copy of the data, while RoBERTa resamples it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xOcbh0t-zgunGXeeTC27uA.png" /></figure><h4><strong>The five changes, and whether each was predictable</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zlupK5GSJP8O_kxyB8fc1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZueXFY00qm47Kya75o2wsw.png" /></figure><h3>Core Components of RoBERTa</h3><h4><strong>NSP measured two ways</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3p4VOFGl646p_1hDGhNoRw.png" /></figure><ul><li>Article 92 counted predictions: 76.8 masked tokens against one sentence label. Counting information instead requires the vocabulary:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*3dzruJeZmoHLvZiAUCBONQ.png" /></figure><ul><li>Writing both shares side by side shows where the discrepancy comes from:</li><li>The denominators differ by exactly the factor log₂ V, so <strong>the count accounting overstates NSP by log₂ V = 14.8976</strong>, up to the additive terms. Both accountings predicted that dropping NSP would cost little.</li><li>The information one predicted it would cost about fourteen times less.</li></ul><h3>Mathematical Foundation</h3><h4><strong>Static masking leaves part of every sequence unpredicted</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ge2_qFGHTrtj9oM0AlPssA.png" /></figure><p>BERT duplicated the corpus ten times with one fixed mask each. A position is masked in a given pattern with probability r, so after P patterns:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CdR2Rc5HmdqDV2GzwyhRYw.png" /></figure><p><strong>Ten static patterns leave 19.69% of every sequence never predicted</strong>, which is 100.80 of 512 positions. Forty patterns leave 0.15%.</p><p>Dynamic masking draws from C(512, 77) patterns, which Article 95 measured at 308.40 bits, or about 1⁰⁹³. The birthday bound over 40 epochs gives a collision probability of roughly 10⁻⁹⁰, so a mask is never reused.</p><p><strong>The cost is zero</strong>: the same compute yields 40 distinct prediction problems per sequence instead of 10.</p><h4><strong>The data scaling law</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*8VERJSXlaZtu_4txXgPhTQ.png" /></figure><p>For a multinomial over K categories estimated from m samples, the expected KL from the truth is asymptotically (K-1)/(2m).</p><p>A Markov chain has K rows, and row a receives mₐ = Nπₐ samples, so</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgOJ5vPxNnPFz_gA6Moizw.png" /></figure><p><strong>The stationary distribution cancels exactly.</strong> The excess loss depends on K and N only, not on how unevenly the states are visited. Measured over 400 trials per point:</p><p>Ratios span 0.9400 to 1.0045 with a mean of 0.9679. They sit <strong>systematically below one</strong>, which is expected: the estimator uses add-0.5 smoothing, and shrinking toward uniform reduces the KL slightly.</p><p>The formula’s constant is asymptotic and shows visible bias at small N, which is exactly where the approximation is not supposed to hold.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aCCUV87BrJdQ7SIa7DRHlg.png" /></figure><p>The slope is the part the claim rests on:</p><p>And measured directly, quadrupling the data cut excess loss to 0.2441, 0.2660, 0.2434, 0.2490, 0.2569 and 0.2600 of its previous value, against a predicted 0.2500.</p><p><strong>So RoBERTa’s roughly tenfold data increase removes about 90% of the estimation component of the loss, independent of vocabulary size</strong>, since K appears only in the numerator.</p><h4><strong>What the scaling law does not touch</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RpWtcVnRCrCyD-Ec2Dt5vw.png" /></figure><p>The law governs estimation error alone. The process entropy is irreducible:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5hGZrOhckxXjINTIHLz_A.png" /></figure><p>At a conditional entropy of 1.280264 nats, the estimation term is already under 1% of the total by N = 1⁰³ for this five-state chain.</p><p><strong>More data has sharply diminishing returns once estimation error falls below the irreducible entropy</strong>, and the crossover is computable in advance as N = K(K-1)/(2ε H).</p><h4><strong>Batch size arithmetic</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-gOlg4yQwhptxgG6IFSYw.png" /></figure><p>For a fixed token budget, steps = tokens/(B · n):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*bHOCPYHWiH_WjmVyiy06dg.png" /></figure><p>The gradient standard error falls as 1/√B, so the signal-to-noise ratio per step improves by √32 = 5.6569.</p><p>Under the linear scaling rule the learning rate scales with B, and the two factors cancel:</p><p>The batch size drops out entirely, so the product is <strong>exactly constant</strong>: the same total displacement in fewer, larger steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SMtM-_mXzmj2CbyzX7SloA.png" /></figure><h4><strong>Tokenizer cost</strong></h4><p>Byte-level BPE includes every byte, so any string is representable and <strong>the UNK rate is exactly zero</strong> rather than small. The cost is 15,162,624 extra parameters, or 13.85% of BERT-base’s 109,482,240 total from Article 92.</p><h4><strong>Sequence length</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJThuOjkp6ig8i50xdaGpA.png" /></figure><p>BERT trained 90% of steps at length 128 and 10% at 512, giving a mean of 0.9 × 128 + 0.1 × 512 = 166.4. RoBERTa used full length throughout, a ratio of 3.0769. The consequences are Article 91’s and Article 92&#39;s:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cx8v4BTd1L7I3A-6FOFuhg.png" /></figure><h3>Types of Recipe Changes</h3><h4><strong>Two of these are free</strong></h4><ul><li>Dropping NSP and resampling the mask both cost nothing in compute or parameters.</li><li>That makes them unusual: the first removes a head, and the second is a different choice of the same number of random draws.</li><li><strong>Any recipe change that is free and measurably positive should be adopted without an ablation</strong>, and both were computable in advance.</li></ul><h4><strong>Full-length sequences are not free</strong></h4><ul><li>Going from a mean of 166.4 to 512 raises the quadratic share from 0.0769 to 0.2500, so a larger fraction of attention cost becomes the term that scales badly.</li><li>The compensation is exact: 4× the masked predictions per sequence, from 19.2 to 76.8, and 4× the mean context.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0K5q1rpQn-vBDjQpXPN3aw.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>Counting predictions is the wrong unit for comparing objectives</strong></h4><ul><li>A binary classification and a 30,522-way prediction are not one unit each.</li><li>Article 92’s 1.2853% and this article’s 0.0873% differ by 14.72× purely from the choice of unit, and the bits accounting is the defensible one because it reflects how much the model must learn to succeed.</li><li><strong>Any comparison of auxiliary objectives should use bits</strong>, or it will systematically favor whichever objective has the smallest output space.</li></ul><h4><strong>The slope matters more than the constant</strong></h4><ul><li>The scaling law’s constant K(K-1)/2 is asymptotic and was measured 3% to 6% low because of smoothing.</li><li>The exponent is what supports the practical claim, and it measured -0.9930 and -0.9846.</li><li><strong>Reporting the constant as exact would be overclaiming; reporting the exponent as approximately -1 is supported.</strong></li></ul><h3>Selecting Evaluation Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKRpzbzr-2PsuALjrVXi5g.png" /></figure><h4><strong>Deciding whether more data will help</strong></h4><ul><li>The last row is the one the scaling law cannot answer.</li><li>K(K-1)/(2N) is the error of an estimator that can represent the truth exactly, so it bounds what data alone can fix.</li><li><strong>A model that cannot express the target pays a separate, non-vanishing cost</strong>, which is exactly Article 96’s position-unaware floor of 0.114901 bits: no quantity of data removes it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vLZXNbZy6XSEJA1vOpeosA.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><ul><li>Article 92’s row is a revision rather than an extension.</li><li>The earlier figure was correctly computed for the unit it used, and the unit was the wrong one for the comparison being made.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgOFkXMbfmOKdrf2U5fgeA.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the scaling law’s scope</strong></h4><ul><li>The derivation assumes a correctly specified model estimated by counting, and it gives the estimation component only.</li><li>Real pretraining has approximation error and optimization error on top, and text is not a first-order chain over a handful of states.</li><li><strong>What transfers is the exponent and the cancellation</strong>: the 1/N rate, and the fact that state imbalance does not change it. The absolute magnitudes are specific to the chains tested.</li></ul><h4><strong>On the batch-size figures</strong></h4><ul><li>Steps and gradient variance are exact arithmetic.</li><li>The claim that a √B SNR gain translates into equivalent optimization is not: the linear scaling rule holds empirically over a range and fails at extremes, and nothing measured here tests that.</li><li>The step counts and the constant displacement product are exact; the conclusion that large batches are equivalent is not established by them.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b6cec557b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[XLNet: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/xlnet-a-comprehensive-guide-f965201fcd45?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f965201fcd45</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[xlnet]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 08:30:52 GMT</pubDate>
            <atom:updated>2026-10-28T08:30:52.353Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 95</h4><h4>Explore detailed XLNet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vxx8XCXdBuetfOgI-t12JA.png" /><figcaption>Data Science &amp; Machine Learning — Article 95</figcaption></figure><h3>Introduction</h3><p>Article 95 ended on the possibility of predicting tokens in a permuted order rather than corrupting the input.</p><p>The chain rule licenses it exactly: every permutation of the factorization gives the identical joint probability, verified here at a worst relative error of 4.190×10⁻¹⁶ across eight orders including the reverse.</p><p>With log₂(512!) = 3875.17 bits of distinct orderings, a sequence is essentially never seen the same way twice, and no corruption is needed because conditioning on an arbitrary subset is already licensed.</p><p>Two exact facts make the method work. The standard softmax parameterization has <strong>no dependence on which position is being predicted</strong>, so it must emit one distribution for every target sharing a context, and that degeneracy costs 0.114901 bits per prediction on a test chain.</p><p>No training removes it. The two-stream fix has a checkable requirement: perturbing the target must leave the query stream <strong>exactly</strong> unchanged, and across 1200 perturbations spanning five orders of magnitude not one produced any change.</p><p>Partial prediction turns out to be load bearing rather than an optimization, since over full permutations the mean context is (n-1)/2 = 255.50, only 0.5871 of BERT’s 435.20.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is XLNet</li><li>Core Components of XLNet</li><li>Mathematical Foundation</li><li>Types of Factorization and Prediction Schemes</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is XLNet</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*efkJxOgXZRUSQUWRXktsHg.png" /></figure><ul><li>XLNet maximizes the expected log-likelihood over random factorization orders. For a permutation z of the positions,</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*GBQsJ45upic1KIqwoTLUVw.png" /></figure><ul><li>The chain rule holds for every z, not just the identity, so each term is a genuine conditional of the true joint:</li><li>Which means the objective needs no corrupted tokens at all.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DUVwS0tD6SQh1M19faUeug.png" /></figure><h4><strong>What that removes</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TVan9sZ9UGXPNhNgKTP5ow.png" /></figure><ul><li>The third row is the substantive one. BERT predicts all masked positions in parallel from the same context, treating them as conditionally independent.</li><li>A permuted factorization conditions each target on the previously predicted ones, so no such assumption is made.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXJXJXHQ0b8FFUOG6jZOBg.png" /></figure><h3>Core Components of XLNet</h3><h4><strong>Partial prediction, and the premium it fixes</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f3i__RV4MxXWuxPllBI54Q.png" /></figure><ul><li>XLNet predicts only the final 1/K of the permutation, using the first n(1–1/K) tokens as context:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3yEL6rZlXhLmSDoWoBqeZA.png" /></figure><ul><li>Predicting the final 1/K of the order gives</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoZBtq9HEdZNdiLmipmIpw.png" /></figure><ul><li>So <strong>the premium is exactly K</strong>, since a fraction 1/K of positions is predicted.</li><li>At K = 6 that is 6, marginally better than Article 92’s 6.67 for BERT, while yielding both more predictions and more context:</li></ul><h3>Mathematical Foundation</h3><h4><strong>Order invariance, verified</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f75enFYvtVerZ3YtP68DKw.png" /></figure><p>The chain rule gives P(x) = Πₜ P(x(z_t) ∣ xz(&lt;t)) for every permutation z, not just the identity.</p><p>On a five-position Markov chain over three states, where each conditional is computable by exact marginalization:</p><p>Worst relative error over eight orders: 4.190×10⁻¹⁶. <strong>This is what makes the objective unbiased</strong>, and it is a property of the chain rule rather than of the architecture, so it holds for any z at any n.</p><h4><strong>The parameterization cannot see its own target</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tg3g5s1ciTYDKifEyme9KQ.png" /></figure><p>The usual output layer is P(x(z_t) = v ∣ xz(&lt;t)) = softmax (e(v)⊤ h(xz(&lt;t))). The hidden state depends only on the context, and nothing in the expression mentions zₜ.</p><p>So for a fixed context the model must emit <strong>one distribution for every candidate target</strong>, while the true conditionals differ:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fs2ItLY-UVWwjM29NP_3RA.png" /></figure><p>The optimal position-unaware distribution is the mixture, and the excess cross-entropy is the weighted average KL to it:</p><p><strong>No amount of training removes this</strong>, because the parameterization cannot express a dependence on zₜ. It is a representational floor, not an optimization failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zKDkN7pkwic6T0aSsFqAA.png" /></figure><p>The size of the floor depends on how much the conditionals differ, and the pattern is not simply about how far apart the targets are:</p><p>Positions 3 and 4 are adjacent and cost almost nothing, while 1 and 4 are the most expensive pair.</p><p><strong>The driver is the spread in mixing distance from the context, not adjacency.</strong></p><p>Both 3 and 4 are far enough from position 0 that the chain has largely mixed, so both conditionals sit near the stationary distribution and a single distribution serves both.</p><p>The control confirms the computation rather than the claim. For an i.i.d. chain every conditional equals π regardless of position, so a position-unaware model should lose nothing, and the measured excess is -2.030×10⁻¹⁷.</p><h4><strong>The two-stream requirement, as a perturbation identity</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/1*EiY2t5vhMoEPPXtPH3a3Jw.png" /></figure><p>Two streams resolve the degeneracy. The content stream h(z_t) sees both x(z_t) and zₜ and serves as context for later predictions; the query stream g(z_t) sees zₜ but <strong>not</strong> x(z_t) and does the predicting.</p><p>The requirement is exact:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJ3ctvIJLk6y9i04ZkYqMg.png" /></figure><p>Averaging over 200 independent perturbation directions at each of six scales:</p><p>Across all 1200 perturbations, <strong>not a single one produced any query-stream change</strong>: the count of nonzero cases is exactly zero, and the invariance holds even at scale 10⁻⁶ where the content response is only 6.881×10⁻⁷.</p><p>The separation is exact at every scale, not merely where the content response is large.</p><p>Both halves of the check are needed. The first is the correctness condition; the second is the positive control, since a query stream that ignored the target token <em>and</em> everything else would also pass the first test.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jTVEF9QnkYQcPoKSRYyjsw.png" /></figure><p><strong>The content response is monotone increasing and does not saturate</strong>, growing almost exactly linearly with the perturbation over the first four decades.</p><p>That is worth pinning down, because Article 91’s entropy collapse suggests the softmax should saturate and stop responding. It does saturate, and the output still grows:</p><p>The weight is bounded in [0,1] and reaches 1.000000 exactly as Article 91 predicts, but the norm of the value vector it is averaging grows linearly, because perturbing x(z_t) scales V(tgt) = x(z_t)Wᵥ itself.</p><p><strong>A bounded weight times an unbounded value is unbounded</strong>, so saturation of the weights does not bound the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Q4FSwJ84v4NNp3TOGKM5Q.png" /></figure><p>A single-stream model that uses the target’s own content as its query is exactly the failure this prevents: its query would move by the amounts in the content column, which is the leak.</p><h4><strong>Why partial prediction is load bearing</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LxAPpn05x_zxecKRlJ6e-Q.png" /></figure><p>Predicting every position of a random permutation gives n predictions, but the token at rank t sees only t-1 context tokens, and t is uniform, so the mean context is (n-1)/2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eLWpAaWMHhZAbkNKx_FNwA.png" /></figure><p><strong>So permutation language modeling without partial prediction has strictly worse context than the masking it was meant to improve on</strong>, at 0.5871 of it. The distribution is what makes this concrete:</p><p>The bottom decile of predictions sees 51 tokens or fewer. Restricting to the final 1/6 raises the minimum context to 426.7 and the mean to 468.83, above BERT’s 435.20.</p><p><strong>Partial prediction is not an efficiency tweak; it is what makes the method competitive at all.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9WLgyBFTM4sRS-4NARAww.png" /></figure><h3>Types of Factorization and Prediction Schemes</h3><h4><strong>The first two rows have the same mean context</strong></h4><ul><li>A left-to-right factorization and a random one both give a rank-t token exactly t-1 predecessors, so the mean is (n-1)/2 either way.</li><li>What differs is <em>which</em> tokens those are: left-to-right always supplies a contiguous prefix, while a permutation supplies a scattered subset that can include positions from the far right.</li><li><strong>The gain from permutation is in the diversity of contexts, not their size</strong>, and Article 92’s measurement applies directly, since that diversity is only useful insofar as right context carries information the left does not.</li></ul><h4><strong>Choosing K is choosing a point on an exact curve</strong></h4><ul><li>Raising K raises both the premium and the mean context, monotonically. Going from K = 2 to K = 8 takes the premium from 2 to 8 while the mean context rises only from 383.50 to 479.50, a gain of 25% for a 4× cost.</li><li><strong>The returns on context are sharply diminishing</strong> because the mean is already bounded above by n-1.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rXFVSBBNRGmheYA59uuIw.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The two-stream check needs both halves</strong></h4><ul><li>A query stream that is invariant to the target token passes the correctness condition.</li><li>So does a query stream that is invariant to everything, including a bug that zeroes it out entirely.</li><li><strong>Only the content-stream column distinguishes the two</strong>, which is why the positive control is not optional here any more than it was for Article 93’s prefix consistency.</li></ul><h4><strong>And it needs more than one perturbation direction</strong></h4><ul><li>A single direction at a single scale is a poor probe: at scale 1⁰⁰ the content response ranged from 0.236304 to 3.904082 across directions, a spread of 16.5×, and the mean of 0.900566 sits well above the median of 0.645062.</li><li>Averaging over directions turns a noisy single number into a monotone curve. Sweeping scales as well costs nothing and confirms the response is linear rather than saturating.</li></ul><h3>Selecting Evaluation Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gZj88W2n9ooxZL7cuaDUcg.png" /></figure><h4><strong>Reading the diagnostics together</strong></h4><ul><li>The second row is the dangerous one for the same reason it was in Article 93: a model that conditions on the answer trains to a very low loss and has learned nothing, and <strong>the loss curve gives no warning</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACzgY6Aq-yoquFfu4f7_xA.png" /></figure><h4><strong>Deciding whether the objective is worth its complexity</strong></h4><ul><li>The second row is worth restating. XLNet removes BERT’s corruption and its independence assumption, but both fixes only matter to the extent that bidirectional information exists in the data.</li><li>Article 92’s cyclic chain gained exactly zero from bidirectional context while changing 35.0% of predictions, and <strong>on such data XLNet’s entire apparatus buys nothing</strong> while costing two attention streams.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJ5fCTx65y_6UsDMNA4BPw.png" /></figure><h4><strong>What carries over</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i5CoezkY_l3Hr94BUuLl4w.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the scope of the excess-loss figure</strong></h4><ul><li>The 0.079643 nats comes from a specific three-state chain with a single observed position, and it is exact for that setting rather than an estimate for text.</li><li>What generalizes is the argument: the excess equals a Jensen gap between the true conditionals and their mixture, so it is <strong>zero exactly when the conditionals coincide</strong> and grows with their spread.</li><li>The i.i.d. control at -2.030×10⁻¹⁷ is the boundary case.</li></ul><h4><strong>On the perturbation check</strong></h4><ul><li>Perturbing the input embedding tests one layer of one attention block, which is where the leak would occur, but a full model has residual connections and normalization that could reintroduce the dependence.</li><li>The check should be run end to end on the actual query stream output, not on a single block, and the positive control run alongside it.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f965201fcd45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BART: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/bart-a-comprehensive-guide-75802c933e48?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/75802c933e48</guid>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[bart]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 08:12:09 GMT</pubDate>
            <atom:updated>2026-10-28T08:12:09.311Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 94</h4><h4>Explore detailed BART</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1ZGPEnOLC1itIq48MVZP2Q.png" /><figcaption>Data Science &amp; Machine Learning — Article 94</figcaption></figure><h3>Introduction</h3><p>At n = 512 document rotation creates only 9.00 bits of ambiguity, sentence permutation over 20 sentences creates 61.08, and deleting 77 tokens creates 1510.92.</p><p><strong>Masking and deletion differ by exactly log₂C(n, k)</strong>, which is 308.40 bits at those settings: that is the price of not knowing where the gaps are.</p><p>Rotation is weaker than deletion by a factor of 167.9, so calling both corruption hides a two-order-of-magnitude difference.</p><p>Whether that ambiguity translates into lost accuracy is a separate question, and on a Markov chain both posteriors can be enumerated exactly.</p><p>Masking beat deletion at every setting tested, with deletion still well above the chance floor. BART’s other choice is to reconstruct the <strong>entire</strong> document rather than only the corrupted spans, which removes Article 92’s 6.67× premium outright.</p><p>It is not free: BART pays 24.81× the decoder attention for 6.67× the predictions, so cost per prediction is 3.72× worse.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is BART</li><li>Core Components of BART</li><li>Mathematical Foundation</li><li>Types of Corruption</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is BART</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*EJwwdD_b4F9BfKkKSJ8DXA.png" /></figure><ul><li>BART is an encoder-decoder transformer trained as a denoising autoencoder over text.</li><li>A corruption C damages the input, and the decoder reconstructs the original document in full:</li><li>The sum runs over all n positions, not only the corrupted ones. That single choice separates BART from T5 and drives most of what follows.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FO-PqHLWmkx_4b2BKCaDbg.png" /></figure><h4><strong>How that differs from the two neighbors</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jZ3IMXIzSJYtPCFCE_5KFQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHXsWDOA0Ip8wHwho718aw.png" /></figure><h3>Core Components of BART</h3><h4><strong>The zero-length span is deliberate</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rq0UO6iH9wqqPSIZ-LRvgQ.png" /></figure><ul><li>BART draws span lengths from Poisson(λ = 3), and a length-zero span inserts a mask token where <strong>nothing was deleted</strong>:</li><li>So P(0) = e⁻³ = 0.049787, and 4.98% of spans mark nothing at all. At r = 0.30 and n = 512 that is 51.20 spans of which 2.55 are empty.</li><li>Their purpose is exact: they teach the model that a mask token does not guarantee missing content, which is the same shortcut-breaking role Article 92’s 1.5% unchanged tokens played for BERT.</li><li>Because every position is predicted regardless, <strong>the corruption rate does not change the prediction count at all.</strong></li><li>BART uses twice T5’s rate and still gets 512 predictions. Raising r changes only the difficulty.</li></ul><h3>Mathematical Foundation</h3><h4><strong>Ambiguity in bits, per corruption</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OoF2oHlNrOXZGoAS5OYDyg.png" /></figure><p>A corruption leaves some set of originals consistent with what the model sees.</p><p>The log of that count is what the model must supply from its prior:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PbsENJ5sxlFlWq9MTqfspQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ELAs7QGMyvmQUN_OjwdqA.png" /></figure><p>Subtracting the two gives the position term alone, with the identity term cancelling exactly:</p><p>which is 0.2565 of the 1202.53 bits of identity ambiguity. <strong>Deletion is strictly harder, and by a computable amount</strong> rather than a vague one.</p><p>The spread across corruptions is the striking part. Rotation costs 9.00 bits against deletion’s 1510.92, a factor of 167.9.</p><p>And permutation over 20 sentences costs 61.08 bits, only 6.7864 times rotation, so both of the order-scrambling corruptions sit far below the content-destroying ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lggVGJBCKDhs6oFbKIFlbA.png" /></figure><h4><strong>But bits are not the same as unrecoverability</strong></h4><p>Rotation and permutation preserve the token multiset exactly, so no content is destroyed and the task is purely one of ordering.</p><p><strong>Only masking preserves length while destroying content</strong>, which is why it alone permits a position-aligned target; the others force the decoder to infer the output length as well.</p><h4><strong>Exact reconstruction accuracy, masking against deletion</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3h6N_SQkRxUH8PnW5SkcA.png" /></figure><p>On a Markov chain both posteriors can be enumerated. With masking, the corrupted positions are known, so there are Kᵏ fillings.</p><p>With deletion they are not, so there are C(n, k)Kᵏ hypotheses, each scored by the chain likelihood. Reconstructing with the per-position marginal MAP maximizes expected accuracy:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*QUASPV7tv17Uu7a0OqDZ0g.png" /></figure><p>Masking wins at every setting, and that ordering is forced rather than empirical. The deletion posterior is the masking posterior with the gap locations summed out:</p><p>A mixture of posteriors is no sharper than its sharpest component, so <strong>the deletion accuracy cannot exceed the masking accuracy</strong> for any data distribution.</p><p>The control that makes the enumeration credible is the chance floor.</p><p>Deletion stays above 0.333333 everywhere, and at concentration 3.0 it sits at 0.337500, only just above it, which is the regime where the chain is nearly uniform and neither corruption can be inverted.</p><p>The gap is <strong>non-monotone</strong> in concentration, at 0.075000, 0.137500, 0.075000.</p><p>At low concentration the chain is so predictable that knowing the positions adds little; at high concentration nothing helps; the cost of positional uncertainty is largest in between.</p><h4><strong>Full reconstruction removes the premium and pays for it</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nYSgvkz_ZdwY4Xduzo3m6Q.png" /></figure><p>T5 emits corrupted spans plus sentinels, so its target is about 0.2n. BART emits everything:</p><p>BART pays 24.81× the decoder attention for 6.67× the predictions, so cost per prediction is 3.72× worse.</p><p><strong>The extra predictions are not free</strong>, and the exchange rate is exact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8l2fs2vrUvETa7WsSfDsBw.png" /></figure><p>At the whole-architecture level the picture is much milder, because the encoder is identical and dominates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*dZNJGqk6TD1EhukXo7K0ZQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9AAdDs5P7OtXoZGwRTtzQ.png" /></figure><p>So a 24.81× decoder becomes only 2.0497× overall.</p><p>Article 94’s finding that the encoder carries 88.27% of the budget is what absorbs it, and it means <strong>the choice of target length matters far less to total cost than it appears in isolation.</strong></p><h4><strong>Parameter counts</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yCH0R5Epw9ZhWkCsy5sVUg.png" /></figure><p>BART uses the standard configuration, so Article 91’s 12d² encoder block and Article 94’s 16d² decoder block both apply, unlike the large T5 variants:</p><p>Both land within 1.6%. The measured block multipliers are 12.0169d² and 16.0247d² at d = 768, the excess being biases and layer norms, with a decoder-to-encoder ratio of 1.3335 against the exact 4/3 Article 94 derived.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vnx4nocyeps5fXZfHwEN4Q.png" /></figure><h3>Types of Corruption</h3><h4><strong>Rotation is the weakest by a wide margin</strong></h4><ul><li>At 9.00 bits it asks the model to identify one of 512 starting points, against deletion’s 1510.92 bits.</li><li>Since the multiset is preserved, no content inference is involved at all. Reporting that rotation “underperforms” as a pretraining objective is not an empirical surprise; the objective supplies 167.9 times less to invert.</li></ul><h4><strong>Why infilling is the strongest single corruption</strong></h4><ul><li>Infilling combines all three unknowns: which content is missing, where the boundaries are, and how many tokens each span held. Masking supplies the position and the count.</li><li>Deletion supplies neither but has no marker; infilling marks the location while hiding the count, and the Poisson(3) distribution means the count is unknown over an effectively unbounded range with P(0) = 0.049787 of the marks being empty.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nqDjkBgdGmyZZY1OOjT-qA.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>Bits overstate the difference between order and content corruptions</strong></h4><ul><li>Rotation’s 9.00 bits and deletion’s 1510.92 differ by 167.9×, but rotation preserves the entire token multiset while deletion destroys 77 tokens permanently.</li><li>A corruption with few bits of ambiguity can still be the one that removes recoverable information, and a corruption with many can leave everything present in scrambled order.</li><li><strong>The bit count measures how many hypotheses exist, not whether the right one is identifiable</strong>, and the multiset column is the check on it.</li></ul><h4><strong>The chance floor is the control that validates the accuracy numbers</strong></h4><ul><li>At concentration 3.0, deletion reconstructs at 0.337500 against a floor of 0.333333.</li><li>That near-coincidence is the signal that the enumeration is behaving: a result <em>below</em> chance would mean the marginal MAP was misimplemented, and a result far above it on a near-uniform chain would mean the posterior was leaking the answer.</li></ul><h3>Selecting Evaluation Metrics</h3><h4><strong>Choosing a corruption</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDEyvYQyXeZDFQh8_SDS8Q.png" /></figure><h4><strong>Choosing the target length</strong></h4><p>The isolated decoder comparison makes full reconstruction look expensive at 24.81×, and the whole-architecture comparison makes it look cheap at 2.0497×.</p><p>Both are correct, and the second is the one that matters for a total budget.</p><p><strong>So the argument against full reconstruction is not cost</strong>, it is that 3.72× worse cost per prediction may buy predictions that are individually less informative, since most positions in a lightly corrupted document are trivially copied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sShBeg7LWDph20B2rq8XEw.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*10YEhGYotCKNpKwWrkL1zA.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the scope of the reconstruction measurements</strong></h4><ul><li>The exact accuracies come from a first-order Markov chain of length 8 with 2 corrupted positions over 3 states, enumerated in full.</li><li>They establish the ordering and the mechanism, not the magnitude on text: real language is neither first-order nor over three symbols, and the gap between masking and deletion on a real corpus is not 0.0750.</li><li><strong>What transfers is that the gap is forced to be non-negative by a marginalization argument</strong>, and that it is largest at intermediate predictability rather than at either extreme.</li></ul><h4><strong>On the bit counts</strong></h4><ul><li>These count hypotheses under an idealized corruption with k and s known to the model.</li><li>A real implementation reveals the number of mask tokens, which removes part of the deletion ambiguity, so 1510.92 is an upper bound on what an actual BART must resolve.</li><li>The comparison between corruptions is the useful content; the absolute figures are ceilings.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75802c933e48" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[T5: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/t5-a-comprehensive-guide-99e025e6d1c9?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/99e025e6d1c9</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[t5]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 07:58:04 GMT</pubDate>
            <atom:updated>2026-10-28T07:58:04.592Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 93</h4><h4>Explore detailed T5</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DQ-y-JJO7LAjCKw1S-YGoA.png" /><figcaption>Data Science &amp; Machine Learning — Article 93</figcaption></figure><h3>Introduction</h3><p>Counting it properly reverses the conclusion. A decoder-only model on a concatenated stream is causal, so it pays (m+k)(m+k+1)/2 score entries, while an encoder-decoder pays a <strong>full</strong> m² on the input because the encoder is bidirectional.</p><p>At m = 512, k = 64 that is 296, 992 against 166, 176, a ratio of 1.7872, and the ratio approaches exactly 2 as the input grows.</p><p><strong>The encoder-decoder is the more expensive architecture</strong>, and 88.27% of its attention budget goes to reading the input rather than to cross-attention.</p><p>Article 91’s rule that a transformer block costs 12d² also fails here, and not marginally.</p><p>T5–3B and T5–11B hold d(model) = 1024 fixed while scaling the attention inner width to 4d and 16d and the feed-forward width to 16d and 64d, giving true block multipliers of 48 and 192 rather than 12: understatements of exactly 4× and 16×.</p><p>Yet one ratio survives untouched. The decoder-to-encoder block ratio is exactly 1.3333 for all five variants, because T5 scaled both widths in the one proportion that keeps attention at precisely half the feed-forward.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is T5</li><li>Core Components of T5</li><li>Mathematical Foundation</li><li>Types of Corruption and Position Schemes</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is T5</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*6y8UqZDyj_fr4J45npjvhw.png" /></figure><ul><li>T5 casts every task as mapping an input string to an output string, and implements that with an encoder-decoder transformer. The encoder reads the input bidirectionally.</li><li>The decoder generates the output causally while attending to the encoder output:</li><li>Because targets are always text, classification and regression need no task-specific head, so the output layer has exactly zero task-dependent parameters.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVTEZqtjhZMQl7jjuPeQ_Q.png" /></figure><h4><strong>Where the three attention blocks sit</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c-6tRA1DAxqhKBpnX5Y29A.png" /></figure><ul><li>The encoder row is the one that matters. It is unmasked, so it pays a full square where Article 93’s causal prefill paid a triangle, and Section 5 shows that this single term dominates the architecture’s cost.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3lI11drXzLhcznqwkeFzw.png" /></figure><h3>Core Components of T5</h3><h4><strong>The second stack’s parameter cost</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*MQTMQOuEcDkEo0gl5bAxOQ.png" /></figure><ul><li>An encoder block is Article 91’s 12d². A decoder block adds cross-attention, so it is 4 + 4 + 8 = 16d²:</li><li>So matching an L-layer decoder-only model with L encoder plus L decoder layers costs exactly 1.166667 times the parameters, independent of L and of d.</li></ul><h4><strong>Relative position bias is nearly free in parameters</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZEXvjaFWIOMEOacOxwFqw.png" /></figure><ul><li>T5 discards absolute positional encodings entirely and adds a learned scalar bias to each score, indexed by a bucketed relative distance.</li><li>The table is heads × buckets and is <strong>shared across all layers</strong>:</li><li>Against Article 91’s sinusoidal encodings, which cost zero parameters and satisfy PE(p+k) = RₖPE(p) exactly, T5 pays a few hundred parameters.</li><li>What it buys is translation invariance that does not have to be learned; what it gives up is measured in Section 5.</li></ul><h3>Mathematical Foundation</h3><h4><strong>The corrected cost comparison</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSPJRAhut3W3iEYx8AP_vg.png" /></figure><p>A decoder-only model on the concatenation is causal, so the naive (m+k)² overstates it by nearly half. The correct comparison is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PVsgsBghxEdGG16QWThgVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z0pCPyA8blBz9HyU2q6LAw.png" /></figure><p><strong>The encoder-decoder is more expensive in every case.</strong></p><p>The ratio approaches exactly 2 as the input grows with the output fixed, because m² against m(m+1)/2 dominates everything else:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m0hNYTLeCxlk3tx5_G0f0w.png" /></figure><p>And the budget does not go where the architecture’s name suggests. At m = 512, k = 64: So an encoder-decoder does not spend its budget on cross-attention.</p><p>It spends it on reading the input bidirectionally, which is precisely the thing being purchased, and Article 92 measured that purchase as worth between 0.026172 and 0.251591 in accuracy, <strong>or exactly zero</strong>.</p><h4><strong>When the premium is recovered</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_QVT8dW6kPfqx3Hr04CMiw.png" /></figure><p>The encoder output does not depend on the output sequence, so it can be computed once and reused across many candidate outputs. Generating N alternatives for one input:</p><p><strong>The premium is fixed and the per-candidate cost is nearly identical</strong>, so the ratio falls toward 1 as N grows. At N = 64 it is 1.0554.</p><p>That makes the architecture well suited to beam search and multi-sample decoding and poorly suited to producing one output per input.</p><h4><strong>What the relative position bucketing loses</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XTn1fawbVdusSBfL3yr7FA.png" /></figure><p>T5 keeps small distances exact, then buckets logarithmically to a maximum distance, then clamps. With 32 buckets and a maximum distance of 128, over distances 0 to 200:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rtlsBi3p3O02VWzHjDP6wg.png" /></figure><p><strong>Only 8 distances get their own bucket.</strong> Everything past the maximum distance collapses into one, so over the range 0 to 2000 the final bucket holds 1910 distinct distances:</p><p>Two tokens 200 apart and two tokens 1000 apart are <strong>indistinguishable</strong> to the model by construction.</p><p>That is a deliberate trade: resolution where it matters against a fixed parameter budget and unbounded extrapolation range.</p><h4><strong>Span corruption, accounted exactly</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C8pyhIE_y283YJxxvLGsLA.png" /></figure><p>T5 corrupts a fraction r of tokens in contiguous spans of mean length ℓ, replacing each span with one sentinel token:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MegL1-FvV0-KFGJigdEXRQ.png" /></figure><p>At ℓ = 1 the scheme reduces to single-token masking and the target is 153.6 tokens, <strong>exactly twice</strong> the 76.8 corrupted tokens, because every corrupted token needs its own sentinel. Longer spans amortize sentinels away.</p><p>Critically, the corrupted count is 76.8 at every span length, so <strong>span corruption does not reduce Article 92’s 6.67× premium at all</strong>.</p><p>What it reduces is the decoder’s cost, since the target length enters quadratically: k²/2 falls from 11,796 entries at ℓ=1 to 3,732 at ℓ=8.</p><h4><strong>Where the 12d² rule breaks</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HDbI_aIecM7GRsHjvFItiA.png" /></figure><p>Article 91 assumed heads partition d, so the projections are d × d, and that d(ff) = 4d. T5 violates both above T5-large:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*epD3MEOxQfoem6J7_UNmnQ.png" /></figure><p>The block cost becomes 4d(h dₖᵥ) + 2d d(ff) rather than 12d²:</p><p>Splitting T5–11B’s encoder block: attention is 4 · 1024 · 16,384 = 67,108,864 = 64d² and the feed-forward is 2 · 1024 · 65,536 = 134,217,728 = 128d², totaling 201,326,592 = 192d².</p><p><strong>The feed-forward is 66.7% of it</strong>, so T5–11B is largely a stack of very wide feed-forward layers rather than a wider attention model.</p><h4><strong>The ratio that survives</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M-V8CLorruB2matfyihVSQ.png" /></figure><p>The natural expectation is that scaling the feed-forward so aggressively would swamp the extra cross-attention and drive the decoder-to-encoder ratio toward 1.</p><p>It does not move at all:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*THjV7TiZ0O5d4LMD_tSPZw.png" /></figure><p>A decoder block is an encoder block plus one more attention, so the ratio is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zGE3EPHBEkZ1Dok6cXRtlQ.png" /></figure><p>which is fixed whenever attention and feed-forward scale together. T5 chose h dₖᵥ = 4d with d(ff) = 16d, and h dₖᵥ = 16d with d(ff) = 64d: in both cases attention is 4 · (h dₖᵥ/d) = exactly half the feed-forward’s 2 (d(ff)/d).</p><p><strong>The 4/3 ratio is preserved by design across a 16× change in block size.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFBHVnwbq2IgiqOcTP_1GQ.png" /></figure><h4><strong>Totals against published figures</strong></h4><p>Four of five land within 3%. <strong>T5-large is off by 4.2%, which is too large to be rounding</strong>, so the honest claim is that this accounting captures the structure of the standard variants and demonstrates that 12d² fails for the large ones, not that it reproduces every published total.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ShJX3cP4cfxnNQmx_PVsmA.png" /></figure><h3>Types of Corruption and Position Schemes</h3><h4><strong>Choosing the span length is choosing the decoder cost</strong></h4><ul><li>The corrupted-token count is rn regardless of ℓ, so the training signal by prediction count is fixed.</li><li>What ℓ controls is how many sentinels appear, and therefore the target length, which enters the decoder’s self-attention quadratically.</li><li>Going from ℓ = 1 to ℓ = 8 cuts decoder self-attention entries from 11, 796 to 3, 732 while leaving the number of predicted tokens untouched at 76.8.</li></ul><h4><strong>Why the bucketing has no exact shift property</strong></h4><ul><li>Article 91’s sinusoidal encodings satisfy an exact rotation identity, so relative position is a fixed linear function of the encodings.</li><li>A bucketed bias has no analogous structure: the bias for distance 91 and distance 200 is literally the same learned scalar.</li><li>The scheme is not an approximation to the sinusoidal one; it is a different object with a different failure mode, namely deliberate blindness beyond the maximum distance.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-TaYvCGed8El9RzcE2OajA.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The metric that misleads</strong></h4><ul><li>Comparing (m + k)² against m² + k² + km suggests separation saves km entries and gives a ratio of 0.75 at m = k.</li><li>That comparison forgets the causal mask on the decoder-only baseline, and correcting it moves the ratio from 0.75 to 1.2493 at m = k and to 1.7872 at T5-style summarization shapes.</li><li><strong>The direction of the conclusion reverses</strong>, which is why the mask has to be in the count.</li></ul><h4><strong>Check the block multiplier before quoting any d² rule</strong></h4><ul><li>The multiplier 4(h dₖᵥ/d) + 2(d(ff)/d) takes one line to compute and reduces to 12 only under the standard configuration.</li><li>Quoting 12d² for T5–11B understates its block by 16×, so a capacity or memory estimate built on the rule would be wrong by more than an order of magnitude.</li></ul><h3>Selecting Evaluation Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KcETfam3SxhVPmunxLloIQ.png" /></figure><h4><strong>Deciding between the architectures</strong></h4><ul><li>The last two rows are the operative ones, and Article 92 supplied the test: measure the error reduction against a matched causal baseline on the actual data.</li><li><strong>A cyclic-chain-like dataset yields exactly zero gain</strong>, in which case the encoder-decoder pays between 1.25× and 1.99× the attention cost plus 1.166667× the parameters for no benefit at all.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKVQzbHJ_pXLQEpjWjjvMg.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><ul><li>Article 91’s row is the one worth noting, because that rule reproduced BERT and all four GPT-2 sizes to within a percent and then failed here by 16×.</li><li><strong>A rule that has held across six models is still a rule about a configuration, not about transformers.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OU_-NRVhz5-hp13ts-m6nQ.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the cost figures</strong></h4><ul><li>These count score-matrix entries and are proportional to the attention arithmetic, not to wall-clock time.</li><li>An encoder’s m² is fully parallel while a decoder’s k steps are sequential, so a ratio of 1.7872 in entries can correspond to a much better or much worse latency depending on batch size and hardware.</li><li>The entry count is the right quantity for comparing architectures and the wrong one for predicting throughput.</li></ul><h4><strong>On the parameter totals</strong></h4><ul><li>Four of the five variants match published figures within 3% and T5-large is 4.2% low.</li><li>That residual is unexplained here, so the parameter tables should be read as establishing the structure and the failure of the 12d² rule rather than as an exact reproduction of every checkpoint.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99e025e6d1c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GPT: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/gpt-a-comprehensive-guide-af504302e572?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/af504302e572</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 03:19:31 GMT</pubDate>
            <atom:updated>2026-10-26T03:19:31.116Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 92</h4><h4>Explore detailed GPT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n1sVgIQV66hsmBjEs82FPg.png" /><figcaption>Data Science &amp; Machine Learning — Article 92</figcaption></figure><h3>Introduction</h3><p>A causal model pays none of that, and the reason it can is a property checkable to machine precision.</p><p>Causal attention at position i is <strong>identical</strong> to running the model on the prefix x₁ … xᵢ alone, measured here at a worst residual of 8.882×10⁻¹⁶, while an unmasked model fails the same test by 2.107.</p><p>That identity is what makes teacher forcing valid: all n predictions come from one pass because each one already equals its own inference-time computation.</p><p>The costs are equally countable. A causal mask discards (n-1)/(2n) of the score matrix, which at n=512, d=768 is 12.48% of attention’s arithmetic and at n=32768 is 47.76%.</p><p>Generating n tokens without a key-value cache is O(n³d) against O(n²d) with one, a measured speedup of 555.16× at n=1024.</p><p>And the standard claim that autoregressive errors compound without bound turns out to be <strong>false for a mixing model.</strong></p><p>On a Markov chain the drift saturates at exactly TV(π, π̂), agreeing to ten decimal places, so exposure bias has a computable ceiling rather than an unbounded trajectory.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is GPT</li><li>Core Components of GPT</li><li>Mathematical Foundation</li><li>Types of Decoding Strategies</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is GPT</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*0klipxEykm3oio0Ut6j_pA.png" /></figure><ul><li>GPT is a transformer decoder stack in which attention is restricted to earlier positions, so the model factorizes the sequence probability by the chain rule and is trained to predict every token from its prefix:</li><li>The restriction is applied by setting the score to -∞ wherever j &gt; i before the SoftMax, which makes those positions receive exactly zero weight.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yXahcZ3Lo9rvDEaKZ7j_qQ.png" /></figure><h4><strong>What the restriction buys and costs</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Paui9JsqzpXlGkZ3mJuALQ.png" /></figure><ul><li>The final two rows are the same fact.</li><li><strong>A model can generate exactly when its training-time computation at each position equals its inference-time computation</strong>, and Section 5 measures that as an identity rather than asserting it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PwNP2qDJq7lJEtx9iVDJPA.png" /></figure><h3>Core Components of GPT</h3><h4><strong>What the mask discards, exactly</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*hY_niezhxcQbRsYS6JqhKw.png" /></figure><p>The mask keeps entry (i,j) only for j ≤ i, so it keeps n(n+1)/2 of n² entries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXomGqC0xC3iapK73ql_Kw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SUgEuhNc5hpuTWy-Ej2hug.png" /></figure><ul><li>The kept fraction approaches 1/2 from above, never below. Combining with Article 91’s quadratic share n/(2d+n) gives the discarded work as a fraction of all attention cost:</li><li>So at d = 768 and n = 512 a naive implementation that computes the full matrix and masks it wastes 12.48% of attention arithmetic, which is real but not fatal.</li><li>At n = 32768 it wastes 47.76%, and the waste is nearly all of the quadratic term.</li></ul><h3>Mathematical Foundation</h3><h4><strong>Prefix consistency, and the control that must fail</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*gMA4Egg00L7wkMgHbmqxVQ.png" /></figure><p>Teacher forcing computes all n predictions from one pass over the full sequence.</p><p>That is valid only if the output at position i does not depend on positions after i, which is checkable directly by comparing the full-sequence output against the prefix-only output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VzDG41tmTYknBvw_Pmaraw.png" /></figure><p>The causal residual is at machine precision everywhere; the unmasked residual reaches 2.107.</p><p><strong>The positive control is what makes this measurement worth anything</strong>: an unmasked model fails at every position except the last, where the full sequence is its own prefix and the residual is exactly zero.</p><p>That final row is the reason a masked encoder cannot generate, stated as an identity rather than an intuition.</p><h4><strong>Key-value caching, exactly</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQFFeY8twRCBIaC9YrVYIw.png" /></figure><p>Generating one token at a time without a cache recomputes the whole prefix at every step, so step t costs 4td² + 2t²d. Summing gives a cubic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*1T5qdXB94_HLdYMDy2_c0Q.png" /></figure><p>With a cache, step t projects one token and attends over t stored keys, costing 4d² + 2td:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oxmAj104ggEclmp9c1_dCQ.png" /></figure><p>The speedup grows without bound because the exponents differ, and the price is memory linear in n: the cache holds 2ndL floats, which is 75.50 MB at n = 1024, L = 12 in fp32 and 1, 207.96 MB at n = 4096, L = 48.</p><p>At d = 768, L = 12 the cache equals the block parameter count of 84,934,656 at exactly n = 4,608.</p><h4><strong>Exposure bias has a closed-form ceiling</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*lwNeKlcrOgnNDlMcB73sgQ.png" /></figure><p>Teacher forcing conditions on true prefixes while generation conditions on the model’s own output, and on a Markov chain the consequence is exactly computable.</p><p>With true transitions T and learned T̂, the one-step error is maxₐ TV(Tₐ, T̂ₐ) and does not depend on t, while the generated marginal drifts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xk1b9p3i3c1tAQ9TvDJFdA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBSiLA0rcGk8g1eeAs-n2A.png" /></figure><p>The drift grows, slightly overshoots, and then flattens. It does not grow without bound, and the ceiling is not approximate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JY9RwYeKDv4_6KfmK2NUdQ.png" /></figure><p><strong>The saturation value is exactly the total variation between the two stationary distributions</strong>, agreeing to ten decimal places, because both chains forget their starting point at their own mixing rate.</p><p>So for an ergodic model the compounding stops, and the often-repeated claim that autoregressive errors accumulate indefinitely does not hold. Two details are worth keeping honest.</p><p>The drift is <strong>non-monotone</strong>, peaking at 0.012210 for δ = 0.02 before settling to 0.012092.</p><p>And the drift at t=1 is <em>below</em> the one-step TV, 0.008760 against 0.014806, because the one-step figure is a maximum over rows while the drift averages over π.</p><h4><strong>Temperature and truncation</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5x7mnxw1r1ApguV56YDMag.png" /></figure><p>Temperature rescales logits, pᵢ ∝ exp(zᵢ/τ). On a synthetic logit vector over a 50,257-token vocabulary, where log V = 10.824905 is the entropy ceiling:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Xga6W4YW76q2jzTrJf8Yg.png" /></figure><p>Halving the temperature from 1.00 to 0.50 cut the tokens needed for 90% of the mass from 11, 895 to 259, a factor of 45.9. That is the quantitative content of “temperature controls diversity.”</p><p><strong>Top-k retains a mass that depends on how peaked the step is</strong>, from 0.016289 at k=1 to 0.476944 at k=1000 here, while top-p fixes the mass and lets k vary.</p><p>These figures describe a synthetic distribution, not a trained model, and are meant to show the mechanism rather than to characterize GPT’s output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aWZCeVc-nlcAgdX9pMEpZA.png" /></figure><h4><strong>Parameter counts across the GPT-2 family</strong></h4><p>All four reproduce from Article 91’s 12d² block plus tied embeddings.</p><p>The embedding share collapses with scale, from 31.65% to 5.27%, while blocks rise from 68.35% to 94.73%, and the quadratic share at the full 1024-token context falls from 0.4000 to 0.2424 as d grows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*daUteJxO6K6ytSEmfSuX3w.png" /></figure><h3>Types of Decoding Strategies</h3><h4><strong>Why top-p exists</strong></h4><ul><li>The tables above make the difference concrete. At k=40 the retained mass on this distribution is 0.116046.</li><li>On a sharply peaked step the same k would retain nearly everything. Top-k therefore applies a fixed cut to a varying distribution, while top-p applies a fixed mass and lets the cut move, which needed k = 11,895 here for 0.90.</li></ul><h4><strong>Why beam search suits translation better than open generation</strong></h4><ul><li>Beam search maximizes total sequence log-probability. For a task with one roughly correct output that is what is wanted.</li><li>For open generation the highest-probability continuation is systematically bland, because probability mass concentrates on generic completions.</li><li>That is a property of the objective, not a defect of the search.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c0FO5zVTvYE-JOKSDVLTdg.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>Perplexity measures the wrong regime</strong></h4><ul><li>Teacher-forced perplexity conditions every prediction on a true prefix, which is the one situation that never occurs at generation time.</li><li>Section 5 quantified the gap: the one-step error was 0.014806 while the free-running drift settled at 0.012092, and the two are different quantities computed under different conditioning.</li><li><strong>A model can have identical teacher-forced loss and very different generated distributions</strong>, since the drift depends on T̂ through its stationary distribution rather than through its rows individually.</li></ul><h4><strong>The one diagnostic that should be run once</strong></h4><ul><li>The prefix-consistency residual is cheap and catches a whole class of bugs: an off-by-one in the mask, a bidirectional layer left in the stack, or a normalization that mixes across positions.</li><li>A residual of 2.107 rather than 10⁻¹⁶ means the model cannot be run forward at all, and no amount of training will fix it.</li></ul><h3>Selecting Evaluation Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wp_NGYtTYo1e5Zk7dTYNgQ.png" /></figure><h4><strong>Reading the diagnostics together</strong></h4><ul><li>The third row matters because the loss looks fine. A model that leaks future information trains to a low teacher-forced loss and cannot generate, so <strong>the loss curve gives no warning at all</strong> and only the residual check does.</li></ul><h4><strong>Deciding whether drift is worth attacking</strong></h4><ul><li>Since the drift saturates at TV(π,π̂), that ceiling is the right target rather than the per-step error.</li><li>At δ = 0.10 the per-step error was 0.074030 while the ceiling was 0.056805, so reducing per-step error by a given factor does not reduce the ceiling by the same factor.</li><li><strong>The ceiling is a property of the stationary mismatch</strong>, and methods aimed at per-step accuracy address it only indirectly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IBdvfcwiFtErOq-rsICAjw.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p866d3_YRlt4KHFzSebNZg.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the scope of the drift result</strong></h4><ul><li>The saturation is exact for a finite ergodic Markov chain, where both the true and learned chains mix to unique stationary distributions.</li><li>A model with absorbing states, or one whose learned chain is not ergodic, has no such ceiling, and a long-range dependency structure is not first-order to begin with.</li><li>What transfers is the structural point: <strong>compounding error is bounded by a mixing property, so “errors accumulate” is a claim requiring a non-mixing model rather than a general truth.</strong></li><li>The non-monotonicity, with an overshoot to 0.012210 above a limit of 0.012092, is a further sign that the trajectory is not the simple exponential the usual argument assumes.</li></ul><h4><strong>On the sampling figures</strong></h4><ul><li>The temperature and truncation numbers come from a synthetic Gaussian logit vector, so they demonstrate the mechanism and the exact relationships but are not measurements of any trained model.</li><li>A real model’s logits are far more peaked, so the tokens-for-90% figures would all be much smaller.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af504302e572" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BERT: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/bert-a-comprehensive-guide-fc94c2aac07b?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc94c2aac07b</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[bert]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 03:08:48 GMT</pubDate>
            <atom:updated>2026-10-26T03:08:48.286Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 91</h4><h4>Explore detailed BERT</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAhzx2G9geHWrMFnyqntrQ.png" /><figcaption>Data Science &amp; Machine Learning — Article 91</figcaption></figure><h3>Introduction</h3><p>At n = 512 with a mask rate of 0.15, a masked objective yields 76.8 training predictions per sequence against an autoregressive model’s 512, so reaching the same number of prediction events costs exactly 6.67 times more passes over the corpus.</p><p>The naive optimum is not 0.15 either: maximizing predictions times context, p(1-p)n², peaks at p = 0.50, so the product is evidently the wrong criterion.</p><p>What the premium buys can be computed exactly rather than asserted. On a stationary Markov chain both the left-only and the bidirectional Bayes accuracies have closed forms, and across nine random chains the gain ran from 0.026172 to 0.251591.</p><p>But a noisy cyclic shift gave a gain of <strong>exactly zero</strong> at every noise level, despite carrying 0.239605 nats of conditional mutual information and changing the predicted token on 35.0% of contexts.</p><p>Information gain, prediction changes, and accuracy gain are three different quantities, and only the third is what bidirectionality is bought for.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is BERT</li><li>Core Components of BERT</li><li>Mathematical Foundation</li><li>Types of BERT Objectives and Variants</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is BERT</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*K4RRKN58FLJRyHAUHMlATA.png" /></figure><ul><li>BERT is a transformer encoder stack trained without a causal mask, so every position attends to the entire sequence.</li><li>Since an unmasked model can see the token it would be asked to predict, the next-token objective is unusable, and BERT replaces it by corrupting a fraction p of positions and predicting them from the rest:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FlosIHSYEIctX6D83PF-yQ.png" /></figure><h4><strong>What changes relative to an autoregressive stack</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D24n0GwPHcVIsxGNFsW9fg.png" /></figure><ul><li>Nothing in Article 91’s parameter or cost accounting changes: the block is still exactly 12d², and the quadratic share is still n/(2d+n).</li><li><strong>Only the objective differs</strong>, and every consequence below follows from that.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yogL43Np39SBi3-NI6nmKA.png" /></figure><h3>Core Components of BERT</h3><h4><strong>The 80/10/10 corruption, accounted exactly</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uOCeZovRdCox3s9DctEGcg.png" /></figure><ul><li>Of the 15% selected, 80% become [MASK], 10% become a random token, and 10% are left unchanged:</li><li>At fine-tuning time [MASK] never appears, so the input distribution shifts by exactly the 12.0% of positions that carried it.</li><li>The remaining 3.0% exists to break a shortcut: on those positions the model must predict from an uncorrupted or wrongly corrupted input, so <strong>it cannot use the presence of the marker as the cue to do work</strong>.</li></ul><h4><strong>Next sentence prediction is small by construction</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*KXlgNLTmB5ZJcaklvq3Gvw.png" /></figure><ul><li>At n = 512 and p = 0.15, one sequence yields 76.8 token predictions and exactly one binary sentence label:</li><li>So NSP is 1.2853% of the training signal by prediction count. That is the quantitative form of the later finding that removing it costs very little, and it was computable before running the ablation.</li></ul><h3>Mathematical Foundation</h3><h4><strong>An exact bound on what bidirectional context is worth</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*KfhovogeMYLGp2OQC5bOBQ.png" /></figure><p>Take a stationary Markov chain over K states with transition matrix T and stationary distribution π. Predicting xᵢ from the left neighbor alone, the Bayes-optimal accuracy is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jKN6yeBHZutW4y7SKFjG0w.png" /></figure><p>Given both neighbors, the rest of the chain is conditionally independent, so the posterior is a product of the forward and backward factors:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAZVdNOv5nPLfyFGjoGfAg.png" /></figure><p>Both are closed form. No training, no seeds, no estimation error.</p><p>The gain is never negative, which is forced: conditioning on more variables cannot lower the Bayes accuracy. Two exact controls confirm the computation rather than the claim.</p><p>For an i.i.d. chain, where identical rows make neighbors uninformative, both accuracies equal maxⱼ πⱼ = 0.4177311877 with a gap of 1.110×10⁻¹⁶; any nonzero gap there would mean the bidirectional code was cheating.</p><h4><strong>The result that contradicted the expectation</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DPUq8CucfJgkN_q-mEd_Ww.png" /></figure><p>The second control was meant to be the opposite extreme. A noisy cyclic shift, T(a,a+1) = 1-ε with the rest spread uniformly, is not reversible, so the right neighbor should have carried something the left one lacked. It did not:</p><p><strong>The gain is exactly zero while the conditional mutual information is large.</strong> The right neighbor supplies up to 0.392908 nats about xᵢ beyond the left neighbor and converts none of it into accuracy.</p><h4><strong>Neither information nor prediction changes explain the gain</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D1xnAqQddPBgIyy9fMUPgA.png" /></figure><p>The natural repair is to bound the gain by that mutual information. The bound holds, with zero violations across all twelve chains, but it is loose enough to be useless as a predictor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QDjtqcNhoNgrq2dihYOinQ.png" /></figure><p>The second repair is to count how often the right neighbor moves the predicted token, that is, how often arg maxⱼ TₐⱼT(jc) ≠ arg maxⱼ Tₐⱼ. That fails too, and more sharply:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1lRtdTTpNMwUyaYSBs-V0Q.png" /></figure><p>The cyclic chain changes the predicted token on 35.0% of contexts and gains exactly nothing, because the symmetry of the chain makes those changes correct exactly as often as they are wrong: <strong>the gains and the losses cancel to machine precision.</strong></p><p>So a bidirectional model can differ from a causal one on a third of its predictions while being no better, and measuring disagreement between the two tells you nothing about which is more accurate.</p><h4><strong>Verifying the closed forms with an estimator</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLq8oq4UEmprAaDlSjtFFg.png" /></figure><p>Analytic optima are worth only as much as their agreement with something fitted. Simulating 400,000 steps and using plug-in argmax predictors over the empirical conditional tables:</p><p>Worst deviation 0.001804, so the closed forms are the right quantities and the gain is a property of the data rather than a modeling artifact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tla0-4FCROgAdbzhJDV3Dw.png" /></figure><h4><strong>Parameter counts, from Article 91’s accounting</strong></h4><p>BERT-large is 3.06× base in total parameters but 3.55× in the block stack alone, since embeddings scale with vocabulary rather than depth.</p><p>And at BERT’s full 512-token context the quadratic share is 512/(2d+512), giving 0.2500 for base and 0.2000 for large: <strong>even at maximum context the projections dominate</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aSE84VCXi1bq2csMaHG0xA.png" /></figure><h3>Types of BERT Objectives and Variants</h3><h4><strong>Two variants attack two different halves</strong></h4><ul><li>The parameter table above makes the split explicit. In BERT-base, embeddings are 21.77% and blocks 77.69%.</li><li>In BERT-large the same figures are 9.48% and 90.20%.</li><li>A method that factorizes the embedding matrix therefore has four times the headroom on base than on large, while layer sharing or distillation has more on large.</li><li><strong>These are the addressable fractions</strong>, and they bound what either approach can save before any of it is implemented.</li></ul><h4><strong>ELECTRA addresses the 6.67× directly</strong></h4><ul><li>Section 5’s premium came from predicting at only pn positions. Replaced-token detection asks a binary question at every position instead, restoring n predictions per sequence and removing the factor entirely.</li><li>That is the one variant aimed at the sample-efficiency term rather than at the parameter count.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AcH9ksJkFdR3TbXycn1LwA.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The disagreement metric is the trap</strong></h4><ul><li>It is tempting to validate a bidirectional model by showing it predicts differently from a causal one.</li><li>Section 5 measured the exact counterexample: the cyclic chain disagrees on 35.0% of contexts with a gain of 0.000000.</li><li><strong>Disagreement rate and accuracy gain are unrelated quantities</strong>, and only a matched-baseline comparison separates them.</li></ul><h4><strong>Why raw MLM accuracy will not compare across mask rates</strong></h4><ul><li>Changing p changes both the number of predictions and the context each one gets, so accuracy at p = 0.15 and p = 0.50 are not measuring the same task.</li><li>The error-reduction column in Section 5 is the comparable quantity, because it normalizes by the headroom the baseline left: at K = 3, c = 0.3 a gain of 0.178836 is a 0.446025 error reduction, while at K = 10, c = 0.3 a larger gain of 0.251591 is a nearly identical 0.445021 reduction.</li></ul><h3>Selecting Evaluation Metrics</h3><h4><strong>Deciding whether bidirectionality is worth the premium</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9O2VGnf-88JG2ZNx3sMjQ.png" /></figure><ul><li>The last row is the operative one. A dataset can look like it needs bidirectional context, in the sense that the right neighbor carries real information, and still yield no accuracy at all.</li></ul><h4><strong>The only defensible test is a matched causal baseline on the same data.</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1KNGu7qoxO8Vt4vCmX_CjQ.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><ul><li>Article 82 found aggregate coverage of 0.9488 against an exact 0.9491 while pointwise variances were wrong by factors of 0.70 to 1.38.</li><li>An aggregate can be exactly right while the quantities composing it are individually wrong in offsetting directions, so <strong>matching on an aggregate is never evidence that the parts match.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QguWbaXaCPzAHUDOijkQXA.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the scope of the Section 5 results</strong></h4><ul><li>The closed forms are exact for a first-order stationary Markov chain, where two neighbors screen off the rest of the sequence.</li><li>Natural language is neither first-order nor stationary, so the numbers are not estimates of what BERT gains on text.</li><li>What transfers is the structural conclusion, which does not depend on the order: <strong>conditioning on more context cannot hurt, can be worth a great deal, and can be worth exactly nothing while still changing a third of the predictions.</strong></li><li>The cyclic chain is a proof that the third case exists.</li></ul><h4><strong>On the plug-in verification</strong></h4><ul><li>The estimator matched the analytic optimum to 0.001804 across four chains, which validates the closed forms but not any claim about neural estimators.</li><li>A trained model has approximation and optimization error on top of the statistical error measured here, so these accuracies are ceilings.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc94c2aac07b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Transformers: A Comprehensive Guide]]></title>
            <link>https://medium.com/@arko_sengupta/transformers-a-comprehensive-guide-3b5a14d4c116?source=rss-05dccf25463b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b5a14d4c116</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transformers]]></category>
            <dc:creator><![CDATA[Arko Sengupta]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 02:56:18 GMT</pubDate>
            <atom:updated>2026-10-26T02:56:18.097Z</atom:updated>
            <content:encoded><![CDATA[<h4>Data Science &amp; Machine Learning — Article 90</h4><h4>Explore detailed Transformers</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vgZOflrxmO1suheuPUMuzg.png" /><figcaption>Data Science &amp; Machine Learning — Article 90</figcaption></figure><h3>Introduction</h3><p>Attention removes the bound by comparing every position with every other in one step, and both the benefit and the cost are exactly countable.</p><p>Relating positions n apart needs ⌈ (n-1)/(k-1)⌉ convolution layers, which is 2,048 layers at n = 4096 with k=3, against exactly one attention layer at any length.</p><p>That capability comes with an exact requirement and an exact price. Attention is permutation-equivariant to machine precision, measured at 1.332×10⁻¹⁵, so <strong>without positional encoding the architecture cannot represent order at all.</strong></p><p>It is a set function. Sinusoidal encodings satisfy PE(p+k) = Rₖ PE(p) for an orthogonal Rₖ depending on k alone, verified to 2.142×10⁻¹⁴, which is why relative position is recoverable by a linear map.</p><p>The 1/√d factor exists because Var(q· k) = dσ⁴: without it, attention entropy on length-16 sequences fell monotonically from 1.306609 to 0.064045 as d went 8 to 2048, against a maximum of log 16 = 2.772589.</p><p>And the parameter count is exactly 12d² per block, which reproduces BERT-base at 109,482,240 and GPT-2 small at 124,439,808.</p><h3>Table of Contents</h3><ul><li>Introduction</li><li>Table of Contents</li><li>What is a Transformer</li><li>Core Components of a Transformer</li><li>Mathematical Foundation</li><li>Types of Attention</li><li>Evaluation Metrics</li><li>Selecting Evaluation Metrics</li><li>Assumptions and Practical Considerations</li></ul><h3>What is a Transformer</h3><h4><strong>Definition</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XL1kryBi-A5sfxZRHBc0Lw.png" /></figure><ul><li>A transformer replaces recurrence and convolution with scaled dot-product attention, in which every position forms a query and compares it against every key:</li><li>Every pair of positions is related in a single operation, so there is no receptive field to grow layer by layer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ybyi0xm4f8M6t4NFT9Hr7Q.png" /></figure><h4><strong>What that replaces</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLtyA8lDg-XG1R_zkNYK6w.png" /></figure><ul><li>The recurrence row is Article 68’s result: a signal crossing n steps is multiplied by n Jacobians and decays as ρⁿ.</li><li>The convolution row is Article 90’s. Attention’s column of ones is the property being purchased, and Section 5 counts what it costs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZBjf9v30-0K2mMDeo1_bw.png" /></figure><h3>Core Components of a Transformer</h3><h4><strong>Attention cannot see order</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*ubHdW-0qL9y02S7qeEwxYg.png" /></figure><ul><li>Permuting the input rows permutes Q, K and V identically, so the score matrix is conjugated by the permutation and the output is permuted:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bx9wlmW54dO8XOxFzYvyyw.png" /></figure><ul><li>And the consequence for an order-invariant readout is that two permutations of the same sequence are indistinguishable: mean-pooled outputs differed by 1.110×10⁻¹⁶.</li><li><strong>Positional encoding is not an enhancement. Without it the architecture is a set function and order is unrepresentable.</strong></li></ul><h3>Mathematical Foundation</h3><h4><strong>Sinusoidal encodings shift by an orthogonal rotation</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*Be-MYY3erw3zFPyibaNFGw.png" /></figure><p>With ωᵢ = 10000(-2i/d) and PE(p)₂ᵢ = sin(ωᵢ p), PE(p)₂ᵢ₊₁ = cos(ωᵢ p), angle addition gives for each frequency pair</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jIu4MVG6u9DOHcWejsxhmw.png" /></figure><p>so PE(p+k) = Rₖ PE(p) with Rₖ block-diagonal and <strong>dependent on k alone</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0WTtStIqvowBsRraqvJoiA.png" /></figure><p>Worst residual over all pairs tested: 2.142×10⁻¹⁴. Two further consequences are exact:</p><p>At d = 64 the dot products were 30.916832 at k=1, 21.051629 at k=10 and 15.673797 at k=50, identical across four widely separated base positions.</p><p><strong>So relative position is available as a fixed linear function of the encodings</strong>, which is what allows a learned projection to extract it. A learned positional embedding table has no such guarantee.</p><h4><strong>Why the 1/√d factor is necessary</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*q6gUxk2bBx19K5O2sc2TdA.png" /></figure><p>For q, k with independent zero-mean entries of variance σ², the dot product is a sum of d independent terms:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uWui5SX1dE0NOMnv79vfJg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NezTjGWUtcm8BqQhpnjSRQ.png" /></figure><p>Entropies are averaged over 2000 independent sequences, and the averaging is not cosmetic.</p><p>Over 400 seeds, a single-draw estimate is close to unbiased but badly dispersed, and the dispersion grows relative to the gap it must resolve:</p><p>So one draw ranks the 512 → 2048 pair backwards 14.75% of the time, and every adjacent pair is invertible by some seed pair.</p><p>The bias is small, with a single-draw mean of 1.296976 at d=8 against the 2000-sequence value 1.306609; the problem is variance. The overall trend is robust regardless, with P(H₈ &lt; H₂₀₄₈) = 0.0000 over 400 paired draws.</p><p>Maximum entropy for a length-16 sequence is log 16 = 2.772589.</p><p><strong>Unscaled, attention collapses toward a hard argmax as width grows</strong>, monotonically from 1.306609 at d = 8 to 0.064045 at d = 2048, and a saturated softmax has vanishing gradient by the same mechanism Article 83 measured for the discriminator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*3BzOM3N3LBHQWIEeCh4fAw.png" /></figure><p>The decay rate is itself informative. Each fourfold increase in d roughly halves the entropy, with successive ratios 2.171, 2.168, 2.066 and 2.098, so</p><p>which is what the variance result predicts: the softmax sharpens in proportion to the spread it is given.</p><p>Scaled, the entropy is essentially flat, ranging only 2.355421 to 2.370321 across a 256-fold change in width, a spread of 0.014900, and staying above 84.95% of the maximum at every width.</p><h4><strong>A block has exactly 12d² parameters</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/694/1*5NFCy_jplIDBjJnE0GqZ8A.png" /></figure><p>Multi-head attention uses four d× d projections regardless of head count, since heads partition d rather than adding to it. The feed-forward block is d → 4d → d:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QYHMgMnfQXNczbVAdz_X5Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVzqbuogCbSbTDFAlqTvCQ.png" /></figure><p>Reproducing published totals from that accounting alone:</p><p>Both land within a percent, so 12d² per block plus embeddings is the whole story. Note the two models have <strong>identical</strong> block parameters at 85,054,464 and differ only in vocabulary and context length.</p><h4><strong>The cost crossover against convolution is exact</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*poYsIk2mlMVF6hcxH95rlQ.png" /></figure><p>Counting multiply-accumulates per layer: attention projections cost 4nd², scores and mixing cost 2n²d, and a k-wide convolution costs nkd². So</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hzuHqidQuGVr2siV9YK23w.png" /></figure><p><strong>Below 1,152 tokens at d = 768, attention’s quadratic term costs less than a single 3-wide convolution layer.</strong></p><p>The quadratic cost is not intrinsically prohibitive; it becomes so only at long context.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tC5P5dtEfNUn9qIlKYiygw.png" /></figure><p>Within attention itself the quadratic share has a closed form, 2n²d/(4nd² + 2n²d) = n/(2d+n), so it passes one half at exactly n = 2d:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zE-prTmjWDuv6IInMAG2xg.png" /></figure><p>At d = 768 and n = 512 the quadratic term is 25% of attention’s own cost and the projections dominate. It reaches half at n = 1536 and 95.5% at 32,768, <strong>which is why long-context work targets that term specifically and leaves the projections alone.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OK_0Twtq4XRs5PWV51Ed_w.png" /></figure><h4><strong>Layers needed to connect two positions</strong></h4><p>The path length matters for gradients as well as expressiveness: Article 68 measured that a signal crossing L multiplicative stages decays geometrically, and here L is 2,048 against 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Bw0sQNMAox2__LO1yGJyQ.png" /></figure><h3>Types of Attention</h3><h4><strong>Local attention reintroduces exactly what attention removed</strong></h4><ul><li>A window of w gives a receptive field that grows layer by layer, so relating positions n apart needs ⌈ (n-1)/(w-1)⌉ layers, the same recursion as Article 90’s convolution.</li><li>That is a coherent trade rather than a defect, but it means local attention inherits the blindness result: block permutations above the effective field are invisible at that layer.</li></ul><h4><strong>Flash attention changes the constant, not the exponent</strong></h4><ul><li>It computes the same function with the same O(n²d) arithmetic, avoiding the O(n²) materialisation of the score matrix.</li><li>So it moves the memory bound without moving the crossover in Section 5, and reports of it “solving” quadratic attention conflate memory with arithmetic.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_-8rs-muNTj-nKlWAUX-Q.png" /></figure><h3>Evaluation Metrics</h3><h4><strong>The two cheapest diagnostics are exact formulas</strong></h4><ul><li>The quadratic share needs no profiler: at d and n it is n/(2d+n), so a model at n = 512, d = 768 spends 25% of its attention cost on the quadratic term and no optimisation of that term can save more than a quarter.</li><li>And the logit variance should be O(1) after scaling; measuring O(d) means the scaling is missing or misapplied, with the entropy consequence in Section 5.</li></ul><h4><strong>A permutation sensitivity check that should be run once</strong></h4><ul><li>Section 4 established that attention without positional information is exactly permutation-equivariant.</li><li>So permuting the input and measuring the output difference tests whether positional information is reaching the model at all.</li><li>A residual near 10⁻¹⁵ means it is not, and that is a wiring bug rather than a training problem.</li></ul><h3>Selecting Evaluation Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_mxlGlQTq5b6Zb24fwhqdg.png" /></figure><h4><strong>Reading the diagnostics together</strong></h4><ul><li>The third row is the one worth care. Low entropy is a symptom of saturation only when the logit variance is also large.</li><li>A well-scaled model that has learned to attend sharply is behaving correctly.</li><li><strong>The diagnostic is the variance, not the entropy</strong>, because the variance distinguishes a scaling bug from a learned preference.</li></ul><h4><strong>On the quadratic cost as a design consideration</strong></h4><ul><li>Section 5 makes the tradeoff quantitative rather than rhetorical.</li><li>At n ≤ 2d the projections dominate, so a sparse-attention variant that leaves 4nd² untouched can save at most n/(2d+n) of the attention cost, which is under half.</li><li>At n = 32,768 the same variant addresses 95.5%. <strong>The value of any long-context method is bounded by that fraction at the target length</strong>, and it is computable before implementing anything.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*F2zaBTGjo2B2pSdpAy0uyg.png" /></figure><h4><strong>What carries over from earlier articles</strong></h4><ul><li>The last row is worth noting: Article 81 wanted permutation equivariance because node ordering was arbitrary, and here the same property is an obstacle because sequence order is meaningful.</li><li>The mathematics is identical; only the desirability differs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UWzVKiCw24VBBepGnvGwYg.png" /></figure><h3>Assumptions and Practical Considerations</h3><h4><strong>On the feed-forward multiplier</strong></h4><ul><li>The 12d² accounting assumes d(ff) = 4d. At d(ff) = 8d the block is 20d² and at 2d it is 8d², so a model described only by d and depth is underspecified by a factor approaching two.</li><li>The published BERT and GPT-2 totals reproduce exactly because both use 4d.</li></ul><h4><strong>On what these results cover</strong></h4><ul><li>The equivariance, rotation and variance results are algebraic and hold at any size.</li><li>The parameter accounting is exact for the standard block and was checked against two published models.</li><li>The cost figures count multiply-accumulates only and ignore memory traffic, softmax and normalization arithmetic, which is why Flash attention improves wall-clock without changing the crossover.</li><li><strong>The crossover is a statement about arithmetic, not about time.</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b5a14d4c116" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>