{
  "id": 42,
  "slug": "scientific-paper-interactive",
  "name": "Interactive Scientific Monograph",
  "kind": "style",
  "family": "Scientific & Editorial",
  "sourceSite": {
    "name": "Distill",
    "url": "https://distill.pub/",
    "verifiedStatus": 200
  },
  "tagline": "Warm archival ivory research article with Tufte-style marginalia and inline interactive parameter figures.",
  "whyUnique": "Merges peer-reviewed academic typography with reactive mathematical diagrams embedded directly in the reading column so concepts can be manipulated while reading.",
  "theme": "light",
  "mobileStrength": "high",
  "tags": [
    "scientific",
    "interactive-paper",
    "marginalia",
    "editorial",
    "data-viz",
    "warm-paper"
  ],
  "bestFor": [
    "Machine learning and scientific research explainers",
    "Technical essays with live mathematical simulations",
    "Interactive engineering whitepapers and RFCs"
  ],
  "palette": [
    {
      "role": "canvas",
      "hex": "#FAF8F4",
      "name": "Archival Ivory"
    },
    {
      "role": "surface",
      "hex": "#FFFFFF",
      "name": "Figure Plate"
    },
    {
      "role": "ink",
      "hex": "#1D1F21",
      "name": "Scholarly Charcoal"
    },
    {
      "role": "accent",
      "hex": "#C84B31",
      "name": "Terracotta Ink"
    },
    {
      "role": "muted",
      "hex": "#6B7280",
      "name": "Footnote Slate"
    }
  ],
  "typography": {
    "display": "Newsreader",
    "body": "Source Serif 4",
    "mono": "IBM Plex Mono",
    "googleFontsUrl": "https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,wght@0,400;0,600;1,400&family=Source+Serif+4:ital,wght@0,400;0,600;1,400&display=swap",
    "scaleNotes": "Generous 62-68ch serif prose column at 18px/1.7 leading, flanked by 13px sans/mono margin notes and crisp figure captions."
  },
  "layoutNotes": "Asymmetric 3-track academic grid: sticky section outline on left, centered readable prose with full-bleed interactive figure breaks, and aligned right-hand marginalia.",
  "interactionNotes": "Inline parameter sliders update live SVG/Canvas mathematical plots in real time; numbered footnotes expand smoothly without losing scroll position.",
  "mobileNotes": "Right-hand margin notes fold into inline tap-to-expand disclosure callouts and section navigation moves into a sticky top pill bar at 390px.",
  "agentGuardrails": {
    "do": [
      "Preserve generous reading line-height (1.65-1.75) and warm paper contrast",
      "Pair every interactive diagram with concrete parameter readouts and explanatory captions",
      "Use terracotta sparingly for active curves, equation highlights, and citation anchors"
    ],
    "dont": [
      "Do not stretch body prose across the full viewport width",
      "Do not use marketing hero banners or SaaS pricing cards in a scientific monograph"
    ]
  },
  "demoFile": "demos/scientific-paper-interactive.html",
  "thumbDesktop": "thumbs/scientific-paper-interactive-desktop.webp",
  "thumbMobile": "thumbs/scientific-paper-interactive-mobile.webp",
  "urls": {
    "page": "https://templates.michaelpitts.net/t/scientific-paper-interactive",
    "markdown": "https://templates.michaelpitts.net/t/scientific-paper-interactive.md",
    "api": "https://templates.michaelpitts.net/api/templates/scientific-paper-interactive",
    "demo": "https://templates.michaelpitts.net/demos/scientific-paper-interactive.html",
    "thumbDesktop": "https://templates.michaelpitts.net/thumbs/scientific-paper-interactive-desktop.webp",
    "thumbMobile": "https://templates.michaelpitts.net/thumbs/scientific-paper-interactive-mobile.webp"
  },
  "agentPrompt": "Design & build using template #042 \"Interactive Scientific Monograph\" (style / Scientific & Editorial, light theme).\nFull AI blueprint & standalone starter code: https://templates.michaelpitts.net/t/scientific-paper-interactive.md\nLive demo: https://templates.michaelpitts.net/demos/scientific-paper-interactive.html\nReal-world inspiration: Distill (https://distill.pub/)\n\nCore aesthetic: Merges peer-reviewed academic typography with reactive mathematical diagrams embedded directly in the reading column so concepts can be manipulated while reading.\nPalette: canvas: #FAF8F4 (Archival Ivory), surface: #FFFFFF (Figure Plate), ink: #1D1F21 (Scholarly Charcoal), accent: #C84B31 (Terracotta Ink), muted: #6B7280 (Footnote Slate)\nTypography: Display=\"Newsreader\", Body=\"Source Serif 4\", Mono=\"IBM Plex Mono\"\nLayout: Asymmetric 3-track academic grid: sticky section outline on left, centered readable prose with full-bleed interactive figure breaks, and aligned right-hand marginalia.\nInteractions: Inline parameter sliders update live SVG/Canvas mathematical plots in real time; numbered footnotes expand smoothly without losing scroll position.\nMobile: Right-hand margin notes fold into inline tap-to-expand disclosure callouts and section navigation moves into a sticky top pill bar at 390px.\n\nGuardrails:\n- DO: Preserve generous reading line-height (1.65-1.75) and warm paper contrast\n- DO: Pair every interactive diagram with concrete parameter readouts and explanatory captions\n- DO: Use terracotta sparingly for active curves, equation highlights, and citation anchors\n- DON'T: Do not stretch body prose across the full viewport width\n- DON'T: Do not use marketing hero banners or SaaS pricing cards in a scientific monograph",
  "sourceCode": "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>Temperature Scaling & Entropy Collapse in Multi-Head Attention</title>\n  <link rel=\"preconnect\" href=\"https://fonts.googleapis.com\">\n  <link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin>\n  <link href=\"https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap\" rel=\"stylesheet\">\n  <style>\n    :root {\n      --canvas: #FAF8F4;\n      --surface: #FFFFFF;\n      --ink: #1D1F21;\n      --accent: #C84B31;\n      --accent-soft: rgba(200, 75, 49, 0.1);\n      --muted: #6B7280;\n      --rule: #E6E1D8;\n      --serif: 'Newsreader', Georgia, serif;\n      --sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;\n      --mono: 'IBM Plex Mono', ui-monospace, monospace;\n    }\n\n    *, *::before, *::after {\n      box-sizing: border-box;\n    }\n\n    html {\n      scroll-behavior: smooth;\n    }\n\n    body {\n      margin: 0;\n      background: var(--canvas);\n      color: var(--ink);\n      font-family: var(--serif);\n      font-size: 18px;\n      line-height: 1.72;\n      overflow-x: hidden;\n    }\n\n    /* Top Journal Masthead */\n    .masthead {\n      position: sticky;\n      top: 0;\n      z-index: 40;\n      background: rgba(250, 248, 244, 0.94);\n      backdrop-filter: blur(10px);\n      border-bottom: 1px solid var(--rule);\n    }\n\n    .masthead-inner {\n      max-width: 1200px;\n      margin: 0 auto;\n      padding: 0 24px;\n      height: 56px;\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      font-family: var(--sans);\n    }\n\n    .journal-id {\n      display: flex;\n      align-items: center;\n      gap: 10px;\n      font-size: 0.85rem;\n      font-weight: 700;\n      letter-spacing: 0.06em;\n      text-transform: uppercase;\n      color: var(--ink);\n      text-decoration: none;\n    }\n\n    .journal-dot {\n      width: 9px;\n      height: 9px;\n      border-radius: 2px;\n      background: var(--accent);\n    }\n\n    .masthead-nav {\n      display: flex;\n      align-items: center;\n      gap: 20px;\n      font-size: 0.82rem;\n    }\n\n    .masthead-nav a {\n      color: var(--muted);\n      text-decoration: none;\n      font-weight: 500;\n    }\n\n    .masthead-nav a:hover {\n      color: var(--accent);\n    }\n\n    .toc-toggle {\n      display: none;\n      min-height: 44px;\n      min-width: 44px;\n      padding: 0 12px;\n      border: 1px solid var(--rule);\n      border-radius: 6px;\n      background: var(--surface);\n      color: var(--ink);\n      font-family: var(--sans);\n      font-size: 0.8rem;\n      font-weight: 600;\n      cursor: pointer;\n    }\n\n    /* Paper Hero */\n    .paper-header {\n      max-width: 1200px;\n      margin: 0 auto;\n      padding: 56px 24px 36px;\n      border-bottom: 1px solid var(--rule);\n    }\n\n    .kicker {\n      font-family: var(--sans);\n      font-size: 0.76rem;\n      font-weight: 700;\n      letter-spacing: 0.12em;\n      text-transform: uppercase;\n      color: var(--accent);\n      margin-bottom: 14px;\n    }\n\n    .paper-header h1 {\n      font-family: var(--sans);\n      font-size: clamp(1.9rem, 3.8vw, 3rem);\n      line-height: 1.14;\n      letter-spacing: -0.025em;\n      margin: 0 0 18px;\n      max-width: 24ch;\n    }\n\n    .subtitle {\n      font-size: 1.2rem;\n      color: var(--muted);\n      max-width: 62ch;\n      margin: 0 0 28px;\n    }\n\n    .byline-grid {\n      display: grid;\n      grid-template-columns: repeat(4, minmax(0, 1fr));\n      gap: 16px;\n      padding-top: 20px;\n      border-top: 1px solid var(--rule);\n      font-family: var(--sans);\n      font-size: 0.82rem;\n    }\n\n    .byline-grid dt {\n      font-size: 0.68rem;\n      text-transform: uppercase;\n      letter-spacing: 0.08em;\n      color: var(--muted);\n      margin-bottom: 4px;\n    }\n\n    .byline-grid dd {\n      margin: 0;\n      font-weight: 500;\n      color: var(--ink);\n    }\n\n    /* Three-Column Distill Layout: Sticky TOC | Main Prose | Margin Notes */\n    .monograph-shell {\n      max-width: 1200px;\n      margin: 0 auto;\n      padding: 40px 24px 96px;\n      display: grid;\n      grid-template-columns: 196px minmax(0, 650px) minmax(0, 260px);\n      gap: 36px;\n      align-items: start;\n    }\n\n    .toc-rail {\n      position: sticky;\n      top: 78px;\n      font-family: var(--sans);\n    }\n\n    .toc-label {\n      font-size: 0.68rem;\n      font-weight: 700;\n      letter-spacing: 0.1em;\n      text-transform: uppercase;\n      color: var(--muted);\n      margin-bottom: 12px;\n    }\n\n    .toc-list {\n      list-style: none;\n      margin: 0;\n      padding: 0;\n      border-left: 1px solid var(--rule);\n    }\n\n    .toc-list a {\n      display: block;\n      padding: 7px 0 7px 14px;\n      font-size: 0.82rem;\n      color: var(--muted);\n      text-decoration: none;\n      border-left: 2px solid transparent;\n      margin-left: -1px;\n      transition: color 0.15s, border-color 0.15s;\n    }\n\n    .toc-list a.active, .toc-list a:hover {\n      color: var(--accent);\n      border-left-color: var(--accent);\n      font-weight: 600;\n    }\n\n    /* Main Column */\n    .prose {\n      min-width: 0;\n    }\n\n    .prose h2 {\n      font-family: var(--sans);\n      font-size: 1.45rem;\n      letter-spacing: -0.015em;\n      margin: 44px 0 14px;\n      padding-top: 10px;\n      scroll-margin-top: 76px;\n    }\n\n    .prose h2:first-child {\n      margin-top: 0;\n    }\n\n    .prose p {\n      margin: 0 0 18px;\n    }\n\n    .note-trigger {\n      display: inline-flex;\n      align-items: center;\n      justify-content: center;\n      min-width: 20px;\n      height: 20px;\n      padding: 0 5px;\n      margin-left: 2px;\n      border-radius: 99px;\n      border: 1px solid var(--accent);\n      background: var(--accent-soft);\n      color: var(--accent);\n      font-family: var(--mono);\n      font-size: 0.68rem;\n      font-weight: 600;\n      vertical-align: super;\n      cursor: pointer;\n    }\n\n    .inline-popover {\n      display: none;\n      margin: 10px 0 16px;\n      padding: 12px 14px;\n      background: var(--surface);\n      border: 1px solid var(--rule);\n      border-left: 3px solid var(--accent);\n      border-radius: 6px;\n      font-family: var(--sans);\n      font-size: 0.85rem;\n      line-height: 1.55;\n      color: var(--muted);\n    }\n\n    .inline-popover.open {\n      display: block;\n    }\n\n    /* Equation Callout */\n    .equation-card {\n      margin: 26px 0;\n      padding: 20px 22px;\n      background: var(--surface);\n      border: 1px solid var(--rule);\n      border-radius: 8px;\n      display: flex;\n      align-items: center;\n      justify-content: space-between;\n      gap: 16px;\n      overflow-x: auto;\n    }\n\n    .eq-formula {\n      font-family: var(--mono);\n      font-size: 0.96rem;\n      color: var(--ink);\n      white-space: nowrap;\n    }\n\n    .eq-num {\n      font-family: var(--mono);\n      font-size: 0.78rem;\n      color: var(--muted);\n      flex-shrink: 0;\n    }\n\n    /* Interactive Figure */\n    .interactive-figure {\n      margin: 30px 0;\n      background: var(--surface);\n      border: 1px solid var(--rule);\n      border-radius: 10px;\n      padding: 20px;\n      box-shadow: 0 8px 24px rgba(29, 31, 33, 0.04);\n    }\n\n    .fig-header {\n      display: flex;\n      flex-wrap: wrap;\n      align-items: baseline;\n      justify-content: space-between;\n      gap: 8px;\n      margin-bottom: 14px;\n      font-family: var(--sans);\n    }\n\n    .fig-title {\n      font-size: 0.92rem;\n      font-weight: 700;\n      color: var(--ink);\n    }\n\n    .fig-badge {\n      font-family: var(--mono);\n      font-size: 0.74rem;\n      color: var(--accent);\n      background: var(--accent-soft);\n      padding: 3px 8px;\n      border-radius: 4px;\n    }\n\n    .controls-bar {\n      display: grid;\n      grid-template-columns: repeat(2, minmax(0, 1fr));\n      gap: 16px;\n      margin-bottom: 18px;\n      padding: 14px;\n      background: var(--canvas);\n      border-radius: 8px;\n      border: 1px solid var(--rule);\n      font-family: var(--sans);\n    }\n\n    .slider-field {\n      display: flex;\n      flex-direction: column;\n      gap: 6px;\n    }\n\n    .slider-field label {\n      display: flex;\n      justify-content: space-between;\n      font-size: 0.78rem;\n      font-weight: 600;\n      color: var(--ink);\n    }\n\n    .slider-field output {\n      font-family: var(--mono);\n      color: var(--accent);\n    }\n\n    .slider-field input[type=\"range\"] {\n      width: 100%;\n      accent-color: var(--accent);\n      min-height: 28px;\n      cursor: pointer;\n    }\n\n    .preset-row {\n      display: flex;\n      flex-wrap: wrap;\n      gap: 8px;\n      margin-bottom: 16px;\n    }\n\n    .preset-btn {\n      min-height: 44px;\n      padding: 0 12px;\n      border: 1px solid var(--rule);\n      border-radius: 6px;\n      background: var(--canvas);\n      color: var(--ink);\n      font-family: var(--sans);\n      font-size: 0.78rem;\n      font-weight: 600;\n      cursor: pointer;\n    }\n\n    .preset-btn.active {\n      border-color: var(--accent);\n      background: var(--accent-soft);\n      color: var(--accent);\n    }\n\n    #attnSvg {\n      width: 100%;\n      height: auto;\n      display: block;\n    }\n\n    #lossCanvas {\n      width: 100%;\n      height: 210px;\n      display: block;\n      border-radius: 6px;\n      background: #FDFCFA;\n      border: 1px solid var(--rule);\n    }\n\n    .fig-caption {\n      margin-top: 12px;\n      font-family: var(--sans);\n      font-size: 0.8rem;\n      line-height: 1.5;\n      color: var(--muted);\n    }\n\n    /* Right Margin Notes Rail */\n    .margin-rail {\n      display: flex;\n      flex-direction: column;\n      gap: 28px;\n      padding-top: 6px;\n      font-family: var(--sans);\n    }\n\n    .margin-note {\n      font-size: 0.8rem;\n      line-height: 1.55;\n      color: var(--muted);\n      padding-left: 14px;\n      border-left: 2px solid var(--rule);\n    }\n\n    .margin-note strong {\n      color: var(--accent);\n      font-family: var(--mono);\n      margin-right: 4px;\n    }\n\n    .margin-note.highlight {\n      border-left-color: var(--accent);\n      color: var(--ink);\n    }\n\n    /* Mobile TOC Drawer */\n    .mobile-toc-sheet {\n      display: none;\n      background: var(--surface);\n      border-bottom: 1px solid var(--rule);\n      padding: 12px 24px 18px;\n      font-family: var(--sans);\n    }\n\n    .mobile-toc-sheet.open {\n      display: block;\n    }\n\n    .mobile-toc-sheet a {\n      display: flex;\n      align-items: center;\n      min-height: 44px;\n      color: var(--ink);\n      text-decoration: none;\n      font-size: 0.88rem;\n      border-bottom: 1px solid var(--rule);\n    }\n\n    .mobile-toc-sheet a:last-child {\n      border-bottom: none;\n    }\n\n    @media (max-width: 1040px) {\n      .monograph-shell {\n        grid-template-columns: 180px minmax(0, 1fr);\n      }\n\n      .margin-rail {\n        display: none;\n      }\n    }\n\n    @media (max-width: 760px) {\n      .masthead-nav {\n        display: none;\n      }\n\n      .toc-toggle {\n        display: inline-flex;\n        align-items: center;\n        justify-content: center;\n      }\n\n      .paper-header {\n        padding: 32px 18px 26px;\n      }\n\n      .byline-grid {\n        grid-template-columns: repeat(2, minmax(0, 1fr));\n      }\n\n      .monograph-shell {\n        grid-template-columns: 1fr;\n        padding: 28px 18px 72px;\n      }\n\n      .toc-rail {\n        display: none;\n      }\n\n      .controls-bar {\n        grid-template-columns: 1fr;\n      }\n\n      .note-trigger {\n        min-width: 30px;\n        height: 30px;\n        font-size: 0.75rem;\n      }\n    }\n  </style>\n</head>\n<body>\n  <header class=\"masthead\">\n    <div class=\"masthead-inner\">\n      <a class=\"journal-id\" href=\"#top\">\n        <span class=\"journal-dot\" aria-hidden=\"true\"></span>\n        <span>MONOLITH // INTERACTIVE ML MONOGRAPHS</span>\n      </a>\n      <nav class=\"masthead-nav\" aria-label=\"Paper navigation\">\n        <a href=\"#sec-intro\">Introduction</a>\n        <a href=\"#sec-softmax\">Temperature Lab</a>\n        <a href=\"#sec-dynamics\">Gradient Dynamics</a>\n        <a href=\"#sec-conclusion\">Findings</a>\n      </nav>\n      <button class=\"toc-toggle\" id=\"tocToggle\" type=\"button\" aria-expanded=\"false\" aria-controls=\"mobileToc\">Sections</button>\n    </div>\n    <div class=\"mobile-toc-sheet\" id=\"mobileToc\">\n      <a href=\"#sec-intro\">1. Problem Statement</a>\n      <a href=\"#sec-softmax\">2. Softmax Temperature Geometry</a>\n      <a href=\"#sec-dynamics\">3. Optimization & LR Curvature</a>\n      <a href=\"#sec-conclusion\">4. Practical Prescriptions</a>\n    </div>\n  </header>\n\n  <section class=\"paper-header\" id=\"top\">\n    <div class=\"kicker\">Interactive Research Note · Vol. 9, Issue 4</div>\n    <h1>Temperature Scaling and Entropy Collapse in Multi-Head Attention</h1>\n    <p class=\"subtitle\">\n      Why uncalibrated query-key inner products drive attention heads into brittle one-hot attractors—and how inverse-temperature schedules preserve gradient flow across deep transformer stacks.\n    </p>\n    <dl class=\"byline-grid\">\n      <div>\n        <dt>Authors</dt>\n        <dd>E. Lindholm, R. Subramanian</dd>\n      </div>\n      <div>\n        <dt>Affiliation</dt>\n        <dd>ETH Zurich · Vector Lab</dd>\n      </div>\n      <div>\n        <dt>Published</dt>\n        <dd>December 2026</dd>\n      </div>\n      <div>\n        <dt>DOI</dt>\n        <dd>10.23915/mono.00048</dd>\n      </div>\n    </dl>\n  </section>\n\n  <div class=\"monograph-shell\">\n    <aside class=\"toc-rail\" aria-label=\"Table of contents\">\n      <div class=\"toc-label\">Contents</div>\n      <ul class=\"toc-list\">\n        <li><a href=\"#sec-intro\" class=\"active\">1. Problem Statement</a></li>\n        <li><a href=\"#sec-softmax\">2. Temperature Geometry</a></li>\n        <li><a href=\"#sec-dynamics\">3. LR Curvature</a></li>\n        <li><a href=\"#sec-conclusion\">4. Prescriptions</a></li>\n      </ul>\n    </aside>\n\n    <article class=\"prose\">\n      <h2 id=\"sec-intro\">1. The Pathology of Sharp Attention</h2>\n      <p>\n        Scaled dot-product attention divides raw query-key logits by the square root of head dimension to keep pre-softmax variance near unity at initialization.<button class=\"note-trigger\" type=\"button\" data-note=\"1\" aria-label=\"Read margin note 1\">1</button>\n        Yet as parameter norms grow during long-horizon pretraining, the effective logit standard deviation drifts upward, pushing individual heads toward near-zero Shannon entropy.\n      </p>\n      <div class=\"inline-popover\" id=\"popover-1\">\n        <strong>Note [1]:</strong> For independent zero-mean unit-variance vectors q and k of length d, Var(q·k) = d. Scaling by 1/√d restores unit variance only at step t = 0 before weight norms inflate.\n      </div>\n      <p>\n        When a head collapses onto a single token—often the sequence delimiter or an early sink token—its Jacobian with respect to the remaining keys vanishes. Downstream layers receive rank-deficient context mixtures, stalling representation diversity.<button class=\"note-trigger\" type=\"button\" data-note=\"2\" aria-label=\"Read margin note 2\">2</button>\n      </p>\n      <div class=\"inline-popover\" id=\"popover-2\">\n        <strong>Note [2]:</strong> Empirical audits on 12B-parameter models show up to 34% of middle-layer heads fall below 0.35 bits of entropy after 60B tokens without QK-Norm.\n      </div>\n\n      <div class=\"equation-card\" role=\"math\" aria-label=\"Temperature-scaled softmax attention equation\">\n        <span class=\"eq-formula\">α<sub>i</sub>(τ) = exp(z<sub>i</sub> / τ) / Σ<sub>j</sub> exp(z<sub>j</sub> / τ) &nbsp;&nbsp;|&nbsp;&nbsp; H(α) = −Σ<sub>i</sub> α<sub>i</sub> log<sub>2</sub> α<sub>i</sub></span>\n        <span class=\"eq-num\">(Eq. 1)</span>\n      </div>\n\n      <h2 id=\"sec-softmax\">2. Interactive Softmax Temperature Geometry</h2>\n      <p>\n        Adjust the attention temperature <em>τ</em> and logit dispersion <em>σ</em> below to observe how probability mass concentrates across six candidate context tokens. Notice the sharp phase transition below τ = 0.45 where entropy collapses and the dominant key absorbs over 90% of the weight.\n      </p>\n\n      <figure class=\"interactive-figure\">\n        <div class=\"fig-header\">\n          <span class=\"fig-title\">Figure 1: Token Attention Mass vs. Temperature τ</span>\n          <span class=\"fig-badge\" id=\"entropyReadout\">H(α) = 1.84 bits</span>\n        </div>\n\n        <div class=\"preset-row\" role=\"group\" aria-label=\"Temperature regime presets\">\n          <button class=\"preset-btn\" type=\"button\" data-tau=\"0.25\" data-sigma=\"1.4\">Collapsed (τ=0.25)</button>\n          <button class=\"preset-btn active\" type=\"button\" data-tau=\"0.90\" data-sigma=\"1.0\">Balanced (τ=0.90)</button>\n          <button class=\"preset-btn\" type=\"button\" data-tau=\"2.20\" data-sigma=\"0.8\">Diffuse (τ=2.20)</button>\n        </div>\n\n        <div class=\"controls-bar\">\n          <div class=\"slider-field\">\n            <label for=\"tauSlider\"><span>Temperature τ</span><output id=\"tauVal\">0.90</output></label>\n            <input id=\"tauSlider\" type=\"range\" min=\"0.15\" max=\"3.00\" step=\"0.05\" value=\"0.90\">\n          </div>\n          <div class=\"slider-field\">\n            <label for=\"sigmaSlider\"><span>Logit Norm σ</span><output id=\"sigmaVal\">1.00</output></label>\n            <input id=\"sigmaSlider\" type=\"range\" min=\"0.40\" max=\"2.20\" step=\"0.05\" value=\"1.00\">\n          </div>\n        </div>\n\n        <svg id=\"attnSvg\" viewBox=\"0 0 600 220\" role=\"img\" aria-label=\"Bar chart of attention weights across six tokens\"></svg>\n        <figcaption class=\"fig-caption\">\n          Base query-key logits z = [2.4, 1.8, 0.9, 0.3, −0.4, −1.1] scaled by σ/τ. Dashed vertical guide marks uniform maximum entropy (log₂6 ≈ 2.58 bits).\n        </figcaption>\n      </figure>\n\n      <h2 id=\"sec-dynamics\">3. Optimization Curvature & Learning Rate Stability</h2>\n      <p>\n        Entropy collapse directly alters the Hessian spectrum of the cross-entropy objective. Because softmax saturation shrinks gradient magnitudes on non-dominant keys while amplifying curvature along the winning logit, aggressive learning rates induce oscillatory loss spikes.<button class=\"note-trigger\" type=\"button\" data-note=\"3\" aria-label=\"Read margin note 3\">3</button>\n      </p>\n      <div class=\"inline-popover\" id=\"popover-3\">\n        <strong>Note [3]:</strong> Warmup schedules mitigate early instability, yet late-stage logit growth still triggers spikes unless QK-RMSNorm or temperature decay bounds the spectral norm.\n      </div>\n\n      <figure class=\"interactive-figure\">\n        <div class=\"fig-header\">\n          <span class=\"fig-title\">Figure 2: Simulated Validation Loss Trajectory</span>\n          <span class=\"fig-badge\" id=\"lossBadge\">Stable Convergence</span>\n        </div>\n\n        <div class=\"controls-bar\">\n          <div class=\"slider-field\">\n            <label for=\"lrSlider\"><span>Peak Learning Rate (×10⁻⁴)</span><output id=\"lrVal\">3.0</output></label>\n            <input id=\"lrSlider\" type=\"range\" min=\"1.0\" max=\"8.0\" step=\"0.2\" value=\"3.0\">\n          </div>\n          <div class=\"slider-field\">\n            <label for=\"warmupSlider\"><span>Warmup Steps</span><output id=\"warmupVal\">2,000</output></label>\n            <input id=\"warmupSlider\" type=\"range\" min=\"200\" max=\"4000\" step=\"200\" value=\"2000\">\n          </div>\n        </div>\n\n        <canvas id=\"lossCanvas\" width=\"600\" height=\"210\" aria-label=\"Validation loss curve under varying learning rate and warmup\"></canvas>\n        <figcaption class=\"fig-caption\">\n          Solid terracotta trace: QK-Norm + cosine decay. Muted grey trace: unnormalized dot-product attention exhibiting spike instability at high learning rates.\n        </figcaption>\n      </figure>\n\n      <h2 id=\"sec-conclusion\">4. Practical Prescriptions</h2>\n      <p>\n        Across our 1.3B and 7B ablations, applying per-head RMS normalization to queries and keys before the inner product eliminates 96% of late-training entropy collapses while adding less than 0.4% step-time overhead. When modifying pretrained checkpoints without retraining, clamping τ ≥ 0.85 during fine-tuning recovers lost multi-hop retrieval accuracy.\n      </p>\n    </article>\n\n    <aside class=\"margin-rail\" aria-label=\"Margin notes\">\n      <div class=\"margin-note\" id=\"margin-1\">\n        <strong>[1]</strong> For independent zero-mean unit-variance vectors <em>q</em> and <em>k</em> of length <em>d</em>, Var(q·k) = d. Scaling by 1/√d restores unit variance only at initialization before parameter norms drift.\n      </div>\n      <div class=\"margin-note\" id=\"margin-2\">\n        <strong>[2]</strong> Empirical audits on 12B-parameter models show up to 34% of middle-layer heads fall below 0.35 bits of entropy after 60B tokens without QK-Norm.\n      </div>\n      <div class=\"margin-note\" id=\"margin-3\">\n        <strong>[3]</strong> Warmup schedules mitigate early instability, yet late-stage logit growth still triggers loss spikes unless spectral bounds constrain the query-key product.\n      </div>\n    </aside>\n  </div>\n\n  <script>\n    (() => {\n      const TOKENS = ['[BOS]', 'theorem', 'implies', 'compact', 'manifold', 'bound'];\n      const BASE_LOGITS = [2.4, 1.8, 0.9, 0.3, -0.4, -1.1];\n\n      const tauSlider = document.getElementById('tauSlider');\n      const sigmaSlider = document.getElementById('sigmaSlider');\n      const tauVal = document.getElementById('tauVal');\n      const sigmaVal = document.getElementById('sigmaVal');\n      const entropyReadout = document.getElementById('entropyReadout');\n      const attnSvg = document.getElementById('attnSvg');\n\n      function renderAttention() {\n        const tau = parseFloat(tauSlider.value);\n        const sigma = parseFloat(sigmaSlider.value);\n        tauVal.textContent = tau.toFixed(2);\n        sigmaVal.textContent = sigma.toFixed(2);\n\n        const scaled = BASE_LOGITS.map((z) => (z * sigma) / tau);\n        const maxZ = Math.max(...scaled);\n        const exps = scaled.map((z) => Math.exp(z - maxZ));\n        const sum = exps.reduce((a, b) => a + b, 0);\n        const probs = exps.map((e) => e / sum);\n        const entropy = -probs.reduce((acc, p) => acc + (p > 1e-9 ? p * Math.log2(p) : 0), 0);\n\n        entropyReadout.textContent = `H(α) = ${entropy.toFixed(2)} bits`;\n\n        const svgNS = 'http://www.w3.org/2000/svg';\n        attnSvg.innerHTML = '';\n\n        const padL = 92;\n        const padR = 54;\n        const barW = 600 - padL - padR;\n\n        probs.forEach((p, idx) => {\n          const y = 16 + idx * 32;\n          const w = Math.max(2, p * barW);\n\n          const label = document.createElementNS(svgNS, 'text');\n          label.setAttribute('x', padL - 10);\n          label.setAttribute('y', y + 15);\n          label.setAttribute('text-anchor', 'end');\n          label.setAttribute('font-family', 'IBM Plex Mono, monospace');\n          label.setAttribute('font-size', '12');\n          label.setAttribute('fill', '#1D1F21');\n          label.textContent = TOKENS[idx];\n          attnSvg.appendChild(label);\n\n          const track = document.createElementNS(svgNS, 'rect');\n          track.setAttribute('x', padL);\n          track.setAttribute('y', y + 2);\n          track.setAttribute('width', barW);\n          track.setAttribute('height', 18);\n          track.setAttribute('rx', 3);\n          track.setAttribute('fill', '#F3EFE7');\n          attnSvg.appendChild(track);\n\n          const bar = document.createElementNS(svgNS, 'rect');\n          bar.setAttribute('x', padL);\n          bar.setAttribute('y', y + 2);\n          bar.setAttribute('width', w.toFixed(1));\n          bar.setAttribute('height', 18);\n          bar.setAttribute('rx', 3);\n          bar.setAttribute('fill', idx === 0 && p > 0.7 ? '#C84B31' : '#D9735B');\n          attnSvg.appendChild(bar);\n\n          const pct = document.createElementNS(svgNS, 'text');\n          pct.setAttribute('x', padL + barW + 8);\n          pct.setAttribute('y', y + 15);\n          pct.setAttribute('font-family', 'IBM Plex Mono, monospace');\n          pct.setAttribute('font-size', '11.5');\n          pct.setAttribute('fill', '#6B7280');\n          pct.textContent = `${(p * 100).toFixed(1)}%`;\n          attnSvg.appendChild(pct);\n        });\n      }\n\n      // Figure 2: Loss Canvas\n      const lrSlider = document.getElementById('lrSlider');\n      const warmupSlider = document.getElementById('warmupSlider');\n      const lrVal = document.getElementById('lrVal');\n      const warmupVal = document.getElementById('warmupVal');\n      const lossBadge = document.getElementById('lossBadge');\n      const lossCanvas = document.getElementById('lossCanvas');\n      const lctx = lossCanvas.getContext('2d');\n\n      function renderLossCurve() {\n        const lr = parseFloat(lrSlider.value);\n        const warmup = parseInt(warmupSlider.value, 10);\n        lrVal.textContent = lr.toFixed(1);\n        warmupVal.textContent = warmup.toLocaleString();\n\n        const w = lossCanvas.width;\n        const h = lossCanvas.height;\n        lctx.clearRect(0, 0, w, h);\n\n        // Grid\n        lctx.strokeStyle = '#EAE4DA';\n        lctx.lineWidth = 1;\n        for (let i = 1; i < 4; i++) {\n          const y = (h / 4) * i;\n          lctx.beginPath();\n          lctx.moveTo(42, y);\n          lctx.lineTo(w - 16, y);\n          lctx.stroke();\n        }\n\n        const steps = 120;\n        const instability = Math.max(0, (lr - 3.6) * 0.42 - warmup / 9000);\n        lossBadge.textContent = instability > 0.55 ? 'Divergent Spikes' : instability > 0.2 ? 'Marginal Oscillation' : 'Stable Convergence';\n\n        // Baseline unnormalized curve\n        lctx.beginPath();\n        lctx.strokeStyle = '#9CA3AF';\n        lctx.lineWidth = 1.8;\n        for (let i = 0; i <= steps; i++) {\n          const t = i / steps;\n          let loss = 3.4 * Math.exp(-t * (2.2 + lr * 0.14)) + 1.45;\n          if (instability > 0.12 && t > 0.28) {\n            loss += Math.sin(i * 0.9) * Math.sin(i * 0.27) * instability * 1.15 * t;\n          }\n          const x = 42 + t * (w - 58);\n          const y = h - 22 - ((loss - 1.1) / 3.9) * (h - 38);\n          if (i === 0) lctx.moveTo(x, y);\n          else lctx.lineTo(x, Math.max(12, Math.min(h - 14, y)));\n        }\n        lctx.stroke();\n\n        // QK-Norm stabilized curve\n        lctx.beginPath();\n        lctx.strokeStyle = '#C84B31';\n        lctx.lineWidth = 2.4;\n        for (let i = 0; i <= steps; i++) {\n          const t = i / steps;\n          const warmFactor = Math.min(1, (t * 10000) / warmup);\n          const loss = 3.4 * Math.exp(-t * (2.5 + lr * 0.16) * (0.65 + 0.35 * warmFactor)) + 1.32 + Math.max(0, lr - 6.4) * 0.08 * t;\n          const x = 42 + t * (w - 58);\n          const y = h - 22 - ((loss - 1.1) / 3.9) * (h - 38);\n          if (i === 0) lctx.moveTo(x, y);\n          else lctx.lineTo(x, y);\n        }\n        lctx.stroke();\n\n        // Axis labels\n        lctx.fillStyle = '#6B7280';\n        lctx.font = '11px IBM Plex Mono, monospace';\n        lctx.fillText('4.5', 8, 22);\n        lctx.fillText('2.8', 8, h / 2);\n        lctx.fillText('1.2', 8, h - 18);\n        lctx.fillText('0k', 42, h - 6);\n        lctx.fillText('50k steps', w - 76, h - 6);\n      }\n\n      tauSlider.addEventListener('input', renderAttention);\n      sigmaSlider.addEventListener('input', renderAttention);\n      lrSlider.addEventListener('input', renderLossCurve);\n      warmupSlider.addEventListener('input', renderLossCurve);\n\n      document.querySelectorAll('.preset-btn').forEach((btn) => {\n        btn.addEventListener('click', () => {\n          document.querySelectorAll('.preset-btn').forEach((b) => b.classList.remove('active'));\n          btn.classList.add('active');\n          tauSlider.value = btn.dataset.tau;\n          sigmaSlider.value = btn.dataset.sigma;\n          renderAttention();\n        });\n      });\n\n      // Margin note triggers (highlight desktop margin note & toggle mobile popover)\n      document.querySelectorAll('.note-trigger').forEach((btn) => {\n        btn.addEventListener('click', () => {\n          const id = btn.dataset.note;\n          const pop = document.getElementById(`popover-${id}`);\n          const margin = document.getElementById(`margin-${id}`);\n          if (window.innerWidth <= 1040) {\n            pop.classList.toggle('open');\n          } else if (margin) {\n            document.querySelectorAll('.margin-note').forEach((n) => n.classList.remove('highlight'));\n            margin.classList.add('highlight');\n          }\n        });\n      });\n\n      // Mobile TOC toggle\n      const tocToggle = document.getElementById('tocToggle');\n      const mobileToc = document.getElementById('mobileToc');\n      tocToggle.addEventListener('click', () => {\n        const open = mobileToc.classList.toggle('open');\n        tocToggle.setAttribute('aria-expanded', String(open));\n      });\n      mobileToc.querySelectorAll('a').forEach((a) => {\n        a.addEventListener('click', () => {\n          mobileToc.classList.remove('open');\n          tocToggle.setAttribute('aria-expanded', 'false');\n        });\n      });\n\n      renderAttention();\n      renderLossCurve();\n    })();\n  </script>\n</body>\n</html>\n"
}
