File size: 45,904 Bytes
7049f20 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 | <!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scaling Laws for Neural Language Models</title>
<meta name="description" content="An empirical study of scaling behavior across model size, data, and compute budgets.">
<meta name="author" content="Alice Martin, Bob Chen, Carol Wu">
<!-- Open Graph -->
<meta property="og:type" content="article">
<meta property="og:title" content="Scaling Laws for Neural Language Models">
<meta property="og:description" content="An empirical study of scaling behavior across model size, data, and compute budgets.">
<meta property="article:published_time" content="Apr. 13, 2026">
<meta property="article:author" content="Alice Martin">
<meta property="article:author" content="Bob Chen">
<meta property="article:author" content="Carol Wu">
<!-- Twitter Card -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Scaling Laws for Neural Language Models">
<meta name="twitter:description" content="An empirical study of scaling behavior across model size, data, and compute budgets.">
<!-- KaTeX CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css"
integrity="sha384-zh0CIslj3dQfMxK3pZnPJAb3bprHitCE2vBz9TyOTICAn3fso5GYa90qPNMBclov"
crossorigin="anonymous">
<!-- highlight.js theme -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.9.0/build/styles/github-dark.min.css">
<style>
/* -----------------------------------------------------------------------
Design tokens - Light / Dark theming
Usage: var(--token-name)
Toggle: data-theme="light" or data-theme="dark" on <html>
Default: follows prefers-color-scheme
----------------------------------------------------------------------- */
:root,
[data-theme="light"] {
--text-primary: #1a1a1a;
--text-secondary: #555;
--text-tertiary: #888;
--text-faint: #aaa;
--text-heading: #111;
--text-heading-secondary: #222;
--text-strong: #000;
--bg-primary: #ffffff;
--bg-secondary: #f7f7f7;
--bg-tertiary: #f0f0f0;
--bg-hover: rgba(0, 0, 0, 0.03);
--bg-overlay: rgba(0, 0, 0, 0.5);
--bg-tooltip: #ffffff;
--bg-surface: #ffffff;
--bg-code: rgba(0, 0, 0, 0.04);
--bg-code-block: #fafafa;
--border: #e0e0e0;
--border-light: #eeeeee;
--border-focus: rgba(124, 58, 237, 0.5);
--accent: #7c3aed;
--accent-light: #958DF1;
--accent-bg: rgba(124, 58, 237, 0.08);
--accent-bg-hover: rgba(124, 58, 237, 0.15);
--accent-text: #6d28d9;
--code-text: #d63384;
--code-comment: #6a737d;
--code-keyword: #8250df;
--code-string: #0a6640;
--code-number: #b35900;
--code-variable: #d63384;
--code-type: #b35900;
--code-function: #0550ae;
--code-tag: #d63384;
--code-attr: #b35900;
--code-symbol: #0a6640;
--code-meta: #0550ae;
--code-deletion: #d63384;
--danger: #dc2626;
--danger-bg: rgba(220, 38, 38, 0.08);
--danger-bg-hover: rgba(220, 38, 38, 0.15);
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
--katex-color: #1a1a1a;
}
[data-theme="dark"] {
--text-primary: rgba(255, 255, 255, 0.85);
--text-secondary: rgba(255, 255, 255, 0.5);
--text-tertiary: rgba(255, 255, 255, 0.4);
--text-faint: rgba(255, 255, 255, 0.25);
--text-heading: #fff;
--text-heading-secondary: rgba(255, 255, 255, 0.9);
--text-strong: rgba(255, 255, 255, 0.95);
--bg-primary: #0a0a0a;
--bg-secondary: #1a1a1a;
--bg-tertiary: #1e1e1e;
--bg-hover: rgba(255, 255, 255, 0.03);
--bg-overlay: rgba(0, 0, 0, 0.5);
--bg-tooltip: #1e1e2e;
--bg-surface: #1a1a1a;
--bg-code: rgba(255, 255, 255, 0.06);
--bg-code-block: rgba(255, 255, 255, 0.03);
--border: rgba(255, 255, 255, 0.1);
--border-light: rgba(255, 255, 255, 0.06);
--border-focus: rgba(149, 141, 241, 0.5);
--accent: #7c3aed;
--accent-light: #958DF1;
--accent-bg: rgba(149, 141, 241, 0.15);
--accent-bg-hover: rgba(149, 141, 241, 0.25);
--accent-text: #b4aef7;
--code-text: #e06c75;
--code-comment: #5c6370;
--code-keyword: #c678dd;
--code-string: #98c379;
--code-number: #d19a66;
--code-variable: #e06c75;
--code-type: #e5c07b;
--code-function: #61afef;
--code-tag: #e06c75;
--code-attr: #d19a66;
--code-symbol: #56b6c2;
--code-meta: #61afef;
--code-deletion: #e06c75;
--danger: #e06c75;
--danger-bg: rgba(224, 108, 117, 0.12);
--danger-bg-hover: rgba(224, 108, 117, 0.25);
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
--katex-color: rgba(255, 255, 255, 0.85);
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) {
--text-primary: rgba(255, 255, 255, 0.85);
--text-secondary: rgba(255, 255, 255, 0.5);
--text-tertiary: rgba(255, 255, 255, 0.4);
--text-faint: rgba(255, 255, 255, 0.25);
--text-heading: #fff;
--text-heading-secondary: rgba(255, 255, 255, 0.9);
--text-strong: rgba(255, 255, 255, 0.95);
--bg-primary: #0a0a0a;
--bg-secondary: #1a1a1a;
--bg-tertiary: #1e1e1e;
--bg-hover: rgba(255, 255, 255, 0.03);
--bg-overlay: rgba(0, 0, 0, 0.5);
--bg-tooltip: #1e1e2e;
--bg-surface: #1a1a1a;
--bg-code: rgba(255, 255, 255, 0.06);
--bg-code-block: rgba(255, 255, 255, 0.03);
--border: rgba(255, 255, 255, 0.1);
--border-light: rgba(255, 255, 255, 0.06);
--border-focus: rgba(149, 141, 241, 0.5);
--accent: #7c3aed;
--accent-light: #958DF1;
--accent-bg: rgba(149, 141, 241, 0.15);
--accent-bg-hover: rgba(149, 141, 241, 0.25);
--accent-text: #b4aef7;
--code-text: #e06c75;
--code-comment: #5c6370;
--code-keyword: #c678dd;
--code-string: #98c379;
--code-number: #d19a66;
--code-variable: #e06c75;
--code-type: #e5c07b;
--code-function: #61afef;
--code-tag: #e06c75;
--code-attr: #d19a66;
--code-symbol: #56b6c2;
--code-meta: #61afef;
--code-deletion: #e06c75;
--danger: #e06c75;
--danger-bg: rgba(224, 108, 117, 0.12);
--danger-bg-hover: rgba(224, 108, 117, 0.25);
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
--shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
--katex-color: rgba(255, 255, 255, 0.85);
}
}
/* -----------------------------------------------------------------------
Article content styles
Shared between editor and published version.
Uses CSS variables from tokens.css for light/dark theming.
----------------------------------------------------------------------- */
/* Base typography */
.tiptap {
outline: none;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
font-size: 1rem;
line-height: 1.7;
color: var(--text-primary);
max-width: 780px;
margin-left: auto;
margin-right: auto;
padding: 0 32px 0 64px;
min-height: 100%;
overflow-wrap: break-word;
word-break: break-word;
}
.tiptap > *:first-child {
margin-top: 0;
}
/* Headings */
.tiptap h1 {
font-size: 2rem;
font-weight: 700;
color: var(--text-heading);
line-height: 1.2;
margin: 2em 0 0.4em;
letter-spacing: -0.02em;
}
.tiptap h1:first-child {
margin-top: 0;
}
.tiptap h2 {
font-size: 1.5rem;
font-weight: 600;
color: var(--text-heading-secondary);
line-height: 1.3;
margin: 1.8em 0 0.4em;
letter-spacing: -0.01em;
}
.tiptap h3 {
font-size: 1.2rem;
font-weight: 600;
color: var(--text-primary);
line-height: 1.4;
margin: 1.5em 0 0.3em;
}
/* Paragraphs */
.tiptap p {
margin: 0.5em 0;
}
/* Lists */
.tiptap ul,
.tiptap ol {
padding-left: 1.5rem;
margin: 0.5em 0;
}
.tiptap li {
margin: 0.25em 0;
}
.tiptap li p {
margin: 0.15em 0;
}
/* Blockquote */
.tiptap blockquote {
border-left: 3px solid var(--border);
padding-left: 1rem;
margin: 1em 0;
color: var(--text-secondary);
}
.tiptap blockquote p {
margin: 0.4em 0;
}
/* Inline code */
.tiptap code {
font-family: "SFMono-Regular", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
background: var(--bg-code);
padding: 0.15em 0.4em;
border-radius: 4px;
font-size: 0.88em;
color: var(--code-text);
}
/* Code block */
.tiptap pre {
background: var(--bg-code-block);
border: 1px solid var(--border-light);
border-radius: 8px;
padding: 1rem 1.25rem;
margin: 1em 0;
overflow-x: auto;
}
.tiptap pre code {
background: none;
padding: 0;
color: var(--text-secondary);
font-size: 0.875rem;
line-height: 1.6;
}
/* Syntax highlighting */
.tiptap pre code .hljs-comment,
.tiptap pre code .hljs-quote {
color: var(--code-comment);
font-style: italic;
}
.tiptap pre code .hljs-keyword,
.tiptap pre code .hljs-selector-tag,
.tiptap pre code .hljs-addition {
color: var(--code-keyword);
}
.tiptap pre code .hljs-string,
.tiptap pre code .hljs-meta .hljs-string,
.tiptap pre code .hljs-regexp,
.tiptap pre code .hljs-doctag {
color: var(--code-string);
}
.tiptap pre code .hljs-number,
.tiptap pre code .hljs-literal,
.tiptap pre code .hljs-bullet {
color: var(--code-number);
}
.tiptap pre code .hljs-variable,
.tiptap pre code .hljs-template-variable,
.tiptap pre code .hljs-tag .hljs-attr {
color: var(--code-variable);
}
.tiptap pre code .hljs-type,
.tiptap pre code .hljs-built_in,
.tiptap pre code .hljs-class .hljs-title,
.tiptap pre code .hljs-title.class_ {
color: var(--code-type);
}
.tiptap pre code .hljs-function,
.tiptap pre code .hljs-title,
.tiptap pre code .hljs-section {
color: var(--code-function);
}
.tiptap pre code .hljs-name,
.tiptap pre code .hljs-tag {
color: var(--code-tag);
}
.tiptap pre code .hljs-attr {
color: var(--code-attr);
}
.tiptap pre code .hljs-symbol,
.tiptap pre code .hljs-link {
color: var(--code-symbol);
}
.tiptap pre code .hljs-meta,
.tiptap pre code .hljs-selector-id,
.tiptap pre code .hljs-selector-class {
color: var(--code-meta);
}
.tiptap pre code .hljs-deletion {
color: var(--code-deletion);
}
.tiptap pre code .hljs-emphasis {
font-style: italic;
}
.tiptap pre code .hljs-strong {
font-weight: 700;
}
/* Horizontal rule */
.tiptap hr {
border: none;
border-top: 1px solid var(--border);
margin: 2em 0;
}
/* Tables */
.tiptap table {
border-collapse: collapse;
width: 100%;
margin: 1em 0;
overflow: hidden;
border-radius: 6px;
border: 1px solid var(--border-light);
}
.tiptap th,
.tiptap td {
padding: 0.5rem 0.75rem;
border: 1px solid var(--border-light);
text-align: left;
font-size: 0.875rem;
min-width: 80px;
}
.tiptap th {
background: var(--bg-code);
color: var(--text-secondary);
font-weight: 600;
font-size: 0.8125rem;
text-transform: uppercase;
letter-spacing: 0.03em;
}
.tiptap td {
color: var(--text-primary);
}
.tiptap tr:hover td {
background: var(--bg-hover);
}
/* Links */
.tiptap a,
.tiptap .editor-link {
color: var(--accent-light);
text-decoration: underline;
text-decoration-color: rgba(149, 141, 241, 0.4);
text-underline-offset: 2px;
transition: text-decoration-color 0.15s;
}
.tiptap a:hover,
.tiptap .editor-link:hover {
text-decoration-color: rgba(149, 141, 241, 0.8);
}
/* Bold */
.tiptap strong {
font-weight: 600;
color: var(--text-strong);
}
/* Images */
.tiptap img {
max-width: 100%;
height: auto;
border-radius: 8px;
margin: 1em 0;
}
/* Math - inline */
.tiptap [data-type="inline-math"] .tiptap-mathematics-render {
padding: 0 0.2em;
border-radius: 3px;
transition: background 0.15s;
}
.tiptap [data-type="inline-math"] .tiptap-mathematics-render:hover {
background: var(--bg-code);
}
/* Math - block */
.tiptap [data-type="block-math"] {
margin: 1em 0;
}
.tiptap [data-type="block-math"] .tiptap-mathematics-render {
display: flex;
justify-content: center;
padding: 1rem 0;
border-radius: 8px;
transition: background 0.15s;
}
.tiptap [data-type="block-math"] .tiptap-mathematics-render:hover {
background: var(--bg-hover);
}
/* KaTeX color */
.tiptap .katex {
color: var(--katex-color);
}
/* Citation inline node */
.citation-node {
position: relative;
color: var(--accent-light);
cursor: default;
font-size: 0.9em;
white-space: nowrap;
text-decoration: underline;
text-decoration-color: rgba(149, 141, 241, 0.3);
text-underline-offset: 2px;
transition: text-decoration-color 0.15s;
}
.citation-node:hover {
text-decoration-color: rgba(149, 141, 241, 0.7);
}
/* Citation hover tooltip */
.citation-tooltip {
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
transform: translateX(-50%);
background: var(--bg-tooltip);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.75rem;
min-width: 240px;
max-width: 320px;
box-shadow: var(--shadow-lg);
z-index: 100;
white-space: normal;
pointer-events: auto;
}
.citation-tooltip-title {
color: var(--text-heading-secondary);
font-size: 0.8125rem;
font-weight: 500;
line-height: 1.4;
margin-bottom: 0.35rem;
}
.citation-tooltip-journal {
color: var(--text-secondary);
font-size: 0.75rem;
font-style: italic;
line-height: 1.3;
}
.citation-tooltip-doi {
color: var(--text-tertiary);
font-size: 0.7rem;
font-family: "SFMono-Regular", "Fira Code", monospace;
margin-top: 0.35rem;
overflow: hidden;
text-overflow: ellipsis;
}
.citation-tooltip-remove {
display: block;
margin-top: 0.5rem;
margin-left: auto;
padding: 0.25rem 0.6rem;
border: none;
border-radius: 4px;
background: var(--danger-bg);
color: var(--danger);
font-size: 0.7rem;
font-family: inherit;
cursor: pointer;
transition: background 0.15s;
}
.citation-tooltip-remove:hover {
background: var(--danger-bg-hover);
}
/* Bibliography block */
.bibliography-block {
margin: 2em 0 1em;
padding-top: 1.5em;
border-top: 1px solid var(--border);
}
.bibliography-title {
font-size: 1.3rem;
font-weight: 600;
color: var(--text-heading-secondary);
margin: 0 0 1em;
}
.bibliography-empty {
color: var(--text-faint);
font-size: 0.875rem;
font-style: italic;
}
.bibliography-content {
font-size: 0.875rem;
line-height: 1.7;
color: var(--text-secondary);
}
.bibliography-content .csl-entry {
margin-bottom: 0.75em;
padding-left: 2em;
text-indent: -2em;
}
.bibliography-content .csl-entry i {
font-style: italic;
}
/* Custom component blocks */
.component-content > *:first-child {
margin-top: 0;
}
.component-content > *:last-child {
margin-bottom: 0;
}
/* Glossary inline node */
.glossary-node {
position: relative;
display: inline;
border-bottom: 1px dashed rgba(149, 141, 241, 0.5);
color: rgba(149, 141, 241, 0.9);
cursor: help;
}
.glossary-tooltip {
position: absolute;
bottom: calc(100% + 6px);
left: 50%;
transform: translateX(-50%);
background: var(--bg-tooltip);
border: 1px solid var(--border);
border-radius: 8px;
padding: 10px 14px;
min-width: 200px;
max-width: 320px;
z-index: 50;
box-shadow: var(--shadow-lg);
}
.glossary-tooltip-term {
font-weight: 700;
font-size: 13px;
color: var(--text-heading-secondary);
margin-bottom: 4px;
}
.glossary-tooltip-def {
font-size: 12px;
color: var(--text-secondary);
line-height: 1.5;
}
.glossary-tooltip-remove {
margin-top: 8px;
background: none;
border: none;
color: var(--danger);
font-size: 11px;
cursor: pointer;
padding: 0;
opacity: 0.8;
}
.glossary-tooltip-remove:hover {
opacity: 1;
}
/* Footnote inline node */
.footnote-node {
position: relative;
display: inline;
}
.footnote-marker {
color: rgba(149, 141, 241, 0.9);
cursor: pointer;
font-size: 0.75em;
font-weight: 700;
margin: 0 1px;
}
.footnote-tooltip {
position: absolute;
bottom: calc(100% + 6px);
left: 50%;
transform: translateX(-50%);
background: var(--bg-tooltip);
border: 1px solid var(--border);
border-radius: 8px;
padding: 10px 14px;
min-width: 220px;
max-width: 360px;
z-index: 50;
box-shadow: var(--shadow-lg);
}
.footnote-tooltip-content {
font-size: 12px;
color: var(--text-secondary);
line-height: 1.5;
}
/* Stack columns */
.stack-columns {
display: contents;
}
.stack-columns > div[data-type="stack-column"] {
border: 1px dashed var(--border-light);
border-radius: 6px;
padding: 8px;
min-height: 40px;
}
.stack-columns > div[data-type="stack-column"] > *:first-child {
margin-top: 0;
}
.stack-columns > div[data-type="stack-column"] > *:last-child {
margin-bottom: 0;
}
/* Published article layout */
body {
margin: 0;
padding: 0;
background: var(--bg-primary);
color: var(--text-primary);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
/* Grid: TOC | Article | (empty right) */
.content-grid {
max-width: 1280px;
margin: 0 auto;
padding: 0 24px;
margin-top: 40px;
display: grid;
grid-template-columns: 260px minmax(0, 680px) 260px;
gap: 32px;
align-items: start;
}
.article-header {
margin-bottom: 2rem;
padding-bottom: 1.5rem;
border-bottom: 1px solid var(--border);
}
.article-header h1 {
font-size: 2.5rem;
font-weight: 700;
color: var(--text-heading);
line-height: 1.2;
margin: 0 0 0.5rem;
letter-spacing: -0.02em;
}
.article-header .authors {
color: var(--text-secondary);
font-size: 0.9375rem;
margin-bottom: 0.25rem;
line-height: 1.6;
}
.article-header .author-link {
color: var(--accent-light);
text-decoration: none;
}
.article-header .author-link:hover {
text-decoration: underline;
}
.article-header .author-affiliation {
color: var(--text-tertiary);
font-size: 0.8125rem;
margin-left: 0.25rem;
}
.article-header .author-affiliation::before { content: "("; }
.article-header .author-affiliation::after { content: ")"; }
.article-header .date {
color: var(--text-tertiary);
font-size: 0.8125rem;
}
/* Theme toggle */
.theme-toggle {
position: fixed;
top: 1rem;
right: 1rem;
background: var(--bg-secondary);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.5rem;
cursor: pointer;
font-size: 1.2rem;
line-height: 1;
z-index: 100;
}
/* ---------- Table of Contents (desktop sticky) ---------- */
.table-of-contents {
position: sticky;
top: 32px;
margin-top: 12px;
}
.table-of-contents .title {
font-weight: 600;
font-size: 14px;
margin-bottom: 8px;
color: var(--text-primary);
}
.table-of-contents nav {
border-left: 1px solid var(--border);
padding-left: 16px;
font-size: 13px;
}
.table-of-contents nav ul {
margin: 0 0 6px;
padding-left: 1em;
}
.table-of-contents nav li {
list-style: none;
margin: 0.25em 0;
}
.table-of-contents nav a,
.table-of-contents nav a:link,
.table-of-contents nav a:visited {
color: var(--text-primary);
text-decoration: none;
border-bottom: none;
}
.table-of-contents nav > ul > li > a {
font-weight: 700;
}
.table-of-contents nav a:hover {
text-decoration: underline solid var(--text-tertiary);
}
.table-of-contents nav a.active {
text-decoration: underline;
}
/* Collapsible sub-sections */
.table-of-contents nav.toc-collapsible li > ul,
.toc-mobile-sidebar nav.toc-collapsible li > ul {
overflow: hidden;
transition: height 200ms ease;
}
/* ---------- Mobile TOC toggle ---------- */
.toc-mobile-toggle {
display: none;
position: fixed;
top: 1rem;
left: 1rem;
z-index: 200;
width: 40px;
height: 40px;
border-radius: 50%;
border: 1px solid var(--border);
background: var(--bg-primary);
color: var(--text-primary);
cursor: pointer;
align-items: center;
justify-content: center;
box-shadow: 0 2px 12px rgba(0,0,0,.08);
transition: transform 150ms ease, box-shadow 150ms ease;
}
.toc-mobile-toggle:active { transform: scale(0.92); }
/* ---------- Mobile backdrop ---------- */
.toc-mobile-backdrop {
display: none;
position: fixed;
inset: 0;
z-index: 201;
background: rgba(0,0,0,.4);
opacity: 0;
pointer-events: none;
transition: opacity 250ms ease;
}
.toc-mobile-backdrop.open { opacity: 1; pointer-events: auto; }
/* ---------- Mobile sidebar ---------- */
.toc-mobile-sidebar {
display: none;
position: fixed;
top: 0; left: 0; bottom: 0;
z-index: 202;
width: min(320px, 85vw);
background: var(--bg-primary);
border-right: 1px solid var(--border);
transform: translateX(-100%);
transition: transform 300ms cubic-bezier(.4,0,.2,1);
flex-direction: column;
}
.toc-mobile-sidebar.open { transform: translateX(0); }
.toc-mobile-sidebar__header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--border);
flex-shrink: 0;
}
.toc-mobile-sidebar__title { font-weight: 700; font-size: 15px; color: var(--text-primary); }
.toc-mobile-sidebar__close {
background: none; border: none; color: var(--text-tertiary);
cursor: pointer; padding: 6px; border-radius: 6px;
display: flex; align-items: center; justify-content: center;
transition: color 150ms ease, background 150ms ease;
}
.toc-mobile-sidebar__close:hover { color: var(--text-primary); background: var(--bg-secondary); }
.toc-mobile-sidebar__body {
flex: 1;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
padding: 0.75rem 1rem 1.5rem;
}
.toc-mobile-sidebar nav ul { margin: 0 0 6px; padding-left: 1em; }
.toc-mobile-sidebar nav li { list-style: none; margin: 0.35em 0; }
.toc-mobile-sidebar nav a,
.toc-mobile-sidebar nav a:link,
.toc-mobile-sidebar nav a:visited {
color: var(--text-primary);
text-decoration: none;
border-bottom: none;
font-size: 14px;
line-height: 1.5;
}
.toc-mobile-sidebar nav > ul > li > a { font-weight: 700; }
.toc-mobile-sidebar nav a:hover { text-decoration: underline solid var(--text-tertiary); }
.toc-mobile-sidebar nav a.active { color: var(--accent-light); text-decoration: underline; }
/* ---------- Responsive: collapse below 1100px ---------- */
@media (max-width: 1100px) {
.content-grid {
overflow: hidden;
display: block;
padding: 0 16px;
margin-top: 0.5rem;
}
.table-of-contents { position: static; display: none; }
.toc-mobile-toggle { display: flex; }
.toc-mobile-backdrop { display: block; }
.toc-mobile-sidebar { display: flex; }
}
/* Accordion as details/summary */
details[data-component="accordion"] {
border: 1px solid var(--border);
border-radius: 8px;
padding: 0;
margin: 1em 0;
}
details[data-component="accordion"] > summary {
padding: 0.75rem 1rem;
cursor: pointer;
font-weight: 600;
color: var(--text-heading-secondary);
list-style: none;
user-select: none;
}
details[data-component="accordion"] > summary::-webkit-details-marker { display: none; }
details[data-component="accordion"] > summary::before {
content: "\25B8";
display: inline-block;
margin-right: 0.5rem;
transition: transform 0.2s;
}
details[data-component="accordion"][open] > summary::before { transform: rotate(90deg); }
details[data-component="accordion"] > .accordion-content { padding: 0 1rem 1rem; }
/* Image lightbox dialog */
dialog.lightbox { border: none; background: transparent; padding: 0; max-width: 95vw; max-height: 95vh; }
dialog.lightbox::backdrop { background: rgba(0, 0, 0, 0.85); }
dialog.lightbox img { max-width: 95vw; max-height: 90vh; object-fit: contain; border-radius: 4px; }
/* Print */
@media print {
.table-of-contents, .toc-mobile-toggle, .toc-mobile-backdrop, .toc-mobile-sidebar, .theme-toggle { display: none !important; }
.content-grid { display: block !important; }
}
</style>
</head>
<body>
<button class="theme-toggle" aria-label="Toggle theme" onclick="toggleTheme()">🌓</button>
<!-- Mobile TOC toggle -->
<button class="toc-mobile-toggle" aria-label="Open table of contents" aria-expanded="false">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="3" y1="6" x2="21" y2="6"/><line x1="3" y1="12" x2="21" y2="12"/><line x1="3" y1="18" x2="21" y2="18"/>
</svg>
</button>
<div class="toc-mobile-backdrop" aria-hidden="true"></div>
<aside class="toc-mobile-sidebar" aria-label="Table of Contents">
<div class="toc-mobile-sidebar__header">
<span class="toc-mobile-sidebar__title">Table of Contents</span>
<button class="toc-mobile-sidebar__close" aria-label="Close">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
</svg>
</button>
</div>
<div class="toc-mobile-sidebar__body" id="toc-mobile-placeholder"></div>
</aside>
<section class="content-grid">
<nav class="table-of-contents" aria-label="Table of Contents">
<div class="title">Table of Contents</div>
<div id="toc-placeholder"></div>
</nav>
<article>
<header class="article-header">
<h1>Scaling Laws for Neural Language Models</h1>
<div class="authors"><span class="author"><a href="https://example.com/alice" class="author-link" target="_blank" rel="noopener">Alice Martin</a><span class="author-affiliation">Hugging Face</span></span><span class="author-sep">, </span><span class="author"><span class="author-name">Bob Chen</span><span class="author-affiliation">Hugging Face, MIT</span></span><span class="author-sep">, </span><span class="author"><span class="author-name">Carol Wu</span><span class="author-affiliation">MIT</span></span></div>
<p class="date">April 13, 2026</p>
</header>
<div class="tiptap">
<h1>Welcome to the Collaborative Editor</h1><p>This demo article showcases <strong>every content type</strong> available in the editor. Feel free to edit, delete, or rewrite anything — the AI assistant in the left panel can help you.</p><h2>Text formatting</h2><p>You can make text <strong>bold</strong>, <em>italic</em>, or <s>strikethrough</s>. Combine them for <strong><em>bold italic</em></strong>. Use <code>inline code</code> for technical terms, and add <a target="_blank" rel="noopener noreferrer nofollow" class="editor-link" href="https://huggingface.co">links</a> to external resources.</p><h2>Lists</h2><h3>Unordered list</h3><ul><li><p>First item with some context</p></li><li><p>Second item — supports <strong>rich formatting</strong> inside</p></li><li><p>Third item with <code>inline code</code></p></li></ul><h3>Ordered list</h3><ol><li><p>Prepare the dataset</p></li><li><p>Fine-tune the model</p></li><li><p>Evaluate on the test split</p></li><li><p>Deploy to production</p></li></ol><h2>Blockquote</h2><blockquote><p>"The best way to predict the future is to invent it." — Alan Kay</p></blockquote><h2>Code block</h2><pre><code class="language-python">import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "meta-llama/Llama-3-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
prompt = "The future of AI is"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=100)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))</code></pre><h2>Table</h2><table style="min-width: 100px;"><colgroup><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"><col style="min-width: 25px;"></colgroup><tbody><tr><th colspan="1" rowspan="1"><p>Model</p></th><th colspan="1" rowspan="1"><p>Parameters</p></th><th colspan="1" rowspan="1"><p>MMLU</p></th><th colspan="1" rowspan="1"><p>HellaSwag</p></th></tr><tr><td colspan="1" rowspan="1"><p>LLaMA 3 8B</p></td><td colspan="1" rowspan="1"><p>8B</p></td><td colspan="1" rowspan="1"><p>66.6</p></td><td colspan="1" rowspan="1"><p>82.0</p></td></tr><tr><td colspan="1" rowspan="1"><p>LLaMA 3 70B</p></td><td colspan="1" rowspan="1"><p>70B</p></td><td colspan="1" rowspan="1"><p>79.5</p></td><td colspan="1" rowspan="1"><p>87.3</p></td></tr><tr><td colspan="1" rowspan="1"><p>GPT-4</p></td><td colspan="1" rowspan="1"><p>~1.8T</p></td><td colspan="1" rowspan="1"><p>86.4</p></td><td colspan="1" rowspan="1"><p>95.3</p></td></tr><tr><td colspan="1" rowspan="1"><p>Mixtral 8x7B</p></td><td colspan="1" rowspan="1"><p>46.7B</p></td><td colspan="1" rowspan="1"><p>70.6</p></td><td colspan="1" rowspan="1"><p>84.4</p></td></tr></tbody></table><h2>Mathematics</h2><p>Inline math works with double dollars: the quadratic formula is <span data-latex="x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}" data-type="inline-math"></span> and Euler's identity is <span data-latex="e^{i\pi} + 1 = 0" data-type="inline-math"></span>.</p><p>Block equations use triple dollars. Here is a standard autoregressive loss:</p><div data-latex="\mathcal{L}(\theta) = -\sum_{t=1}^{T} \log P(x_t \mid x_{<t}; \theta)" data-type="block-math"></div><p>And the full variational trajectory decomposition:</p><div data-latex="\begin{aligned} \log p_\theta(\mathcal{D}) &= \log \sum_{i=0}^N p_\theta((o,a)_i) \\ &= \log \sum_{i=0}^N \int_{\text{supp}(Z)} p_\theta((o,a)_i \mid z)\, p(z) \\ &= \log \sum_{i=0}^N \int_{\text{supp}(Z)} \frac{q_\theta(z \mid (o,a)_i)}{q_\theta(z \mid (o,a)_i)} \cdot p_\theta((o,a)_i \mid z)\, p(z) \\ &= \log \sum_{i=0}^N \mathbb{E}_{z \sim p_\theta(\bullet \mid (o,a)_i)} \left[ \frac{p(z)}{q_\theta(z \mid (o,a)_i)} \cdot p_\theta((o,a)_i \mid z) \right] \end{aligned}" data-type="block-math"></div><h2>Scientific references</h2><p>The editor supports academic citations. The Transformer architecture <span key="vaswani2017" label="[vaswani2017]" data-type="citation" class="citation-node">[vaswani2017]</span> revolutionized natural language processing by introducing the self-attention mechanism. Large-scale pretraining <span key="devlin2019" label="[devlin2019]" data-type="citation" class="citation-node">[devlin2019]</span> demonstrated that unsupervised objectives on massive corpora produce powerful general-purpose representations.</p><p>More recently, scaling laws <span key="kaplan2020" label="[kaplan2020]" data-type="citation" class="citation-node">[kaplan2020]</span> have shown predictable relationships between model size, dataset size, and performance.</p><hr><h2>Horizontal rule</h2><p>Use a horizontal rule to visually separate sections:</p><hr><h2>Nested content</h2><p>Lists can contain multiple levels of formatting. Blockquotes can hold structured content:</p><blockquote><p><strong>Note:</strong> This editor supports real-time collaboration. Open this page in another tab to see cursors sync live.</p></blockquote><h3>A deeper heading level</h3><p>Heading levels go from H1 down to H3, giving you a clear document hierarchy. The floating menu on the left lets you insert any block type, and the bubble toolbar appears when you select text.</p><h2>Custom components</h2><p>The editor supports rich custom components from the research article template. Use the <code>/</code> slash menu to insert them.</p><details data-component="accordion">
<summary>Details</summary>
<div class="accordion-content"><p>The model was fine-tuned using LoRA adapters with rank 16 on 4× A100 GPUs. Training took approximately 12 hours on the full dataset. We used a cosine learning rate schedule with warm-up over the first 10% of steps.</p></div>
</details><div title="Important" emoji="💡" variant="info" data-component="note"><p>All experiments were conducted with mixed-precision (bf16) training. Results may vary slightly with different random seeds.</p></div><div author="Ilya Sutskever" source="NeurIPS 2024 keynote" data-component="quoteBlock"><p>If you have a very large neural network and you train it on a very large dataset, you get very good results. It really is that simple.</p></div><div title="Warning" emoji="⚠️" variant="danger" data-component="note"><p>Do not use these scaling estimates for production capacity planning without accounting for inference overhead and memory constraints.</p></div><div data-component="wide"><p>This content stretches beyond the normal column width, useful for wide tables, figures or visualizations that need extra horizontal space.</p></div><div data-component="fullWidth"><p>This content spans the entire page width. It is ideal for large figures, panoramic images, or full-bleed data visualizations.</p></div><div data-component="sidenote"><p>Scaling laws were first systematically studied in the context of neural machine translation before being generalized to language models.</p></div><div id="fig-scaling" caption="Log-linear relationship between compute budget and model performance across three orders of magnitude." data-component="reference"><p>[ Figure placeholder — insert an image or chart here ]</p></div><div src="d3-scaling-chart.html" title="Interactive scaling law visualization" desc="Explore how model size, data, and compute interact." wide="false" downloadable="true" data-component="htmlEmbed"></div><p>The concept of <span term="Scaling law" definition="A power-law relationship between model size, dataset size, compute budget, and performance." data-type="glossary" class="glossary-node" title="A power-law relationship between model size, dataset size, compute budget, and performance." tabindex="0">Scaling law</span> has become central to modern AI research. Early work<span content="Hestness et al. (2017) observed similar scaling behavior in vision and translation tasks before the scaling laws paper formalized the framework." data-type="footnote" class="footnote-node" title="Hestness et al. (2017) observed similar scaling behavior in vision and translation tasks before the scaling laws paper formalized the framework." tabindex="0"><sup class="footnote-marker">*</sup></span> suggested these relationships hold across modalities.</p><div layout="2-column" gap="medium" data-component="stack"><div data-type="stack-column"><p><strong>Column A</strong></p><p>Multi-column layouts let you place content side by side. Each column is fully editable.</p></div><div data-type="stack-column"><p><strong>Column B</strong></p><p>Use the layout selector in the header to switch between 2, 3, or 4 columns.</p></div></div><div username="tfrere" name="Thibaud Frere" url="https://huggingface.co/tfrere" data-component="hfUser"></div><h2>What's next?</h2><p>Try asking the AI assistant to:</p><ul><li><p>Rewrite a paragraph in a different tone</p></li><li><p>Expand a section with more detail</p></li><li><p>Fix grammar or spelling errors</p></li><li><p>Translate content to another language</p></li><li><p>Add a new section on a specific topic</p></li></ul><p>Select some text and use the quick actions, or type a message in the chat panel. All AI edits can be undone with <code>Cmd+Z</code>.</p><div data-type="bibliography" class="bibliography-block"><h2 class="bibliography-title">References</h2><div class="bibliography-content"><div class="csl-bib-body">
<div data-csl-entry-id="devlin2019" class="csl-entry">Devlin, J., Chang, M.-W., Lee, K., & Toutanova, K. (2019). BERT: Pre-training of deep bidirectional transformers for language understanding. <i>Proceedings of NAACL-HLT</i>, 4171–4186. https://doi.org/10.18653/v1/N19-1423</div>
<div data-csl-entry-id="kaplan2020" class="csl-entry">Kaplan, J., McCandlish, S., Henighan, T., Brown, T. B., Chess, B., Child, R., Gray, S., Radford, A., Wu, J., & Amodei, D. (2020). Scaling laws for neural language models. <i>arXiv Preprint arXiv:2001.08361</i>. https://doi.org/10.48550/arXiv.2001.08361</div>
<div data-csl-entry-id="vaswani2017" class="csl-entry">Vaswani, A., Shazeer, N., Parmar, N., Uszkoreit, J., Jones, L., Gomez, A. N., Kaiser, L., & Polosukhin, I. (2017). Attention is all you need. <i>Advances in Neural Information Processing Systems</i>, <i>30</i>. https://doi.org/10.48550/arXiv.1706.03762</div>
</div></div></div><p></p>
</div>
</article>
</section>
<!-- Image lightbox -->
<dialog class="lightbox" id="lightbox">
<img id="lightbox-img" src="" alt="">
</dialog>
<script>
(function() {
// Theme
window.toggleTheme = function() {
var next = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
};
var saved = localStorage.getItem('theme');
if (saved) document.documentElement.setAttribute('data-theme', saved);
// Lightbox
document.querySelectorAll('.tiptap img').forEach(function(img) {
img.style.cursor = 'zoom-in';
img.addEventListener('click', function() {
document.getElementById('lightbox-img').src = img.src;
document.getElementById('lightbox').showModal();
});
});
document.getElementById('lightbox').addEventListener('click', function(e) { if (e.target === this) this.close(); });
// Glossary
document.querySelectorAll('[data-type="glossary"]').forEach(function(el) { el.setAttribute('tabindex', '0'); });
// ---- Table of Contents ----
var holder = document.getElementById('toc-placeholder');
var holderMobile = document.getElementById('toc-mobile-placeholder');
var articleRoot = document.querySelector('.content-grid article');
if (!articleRoot) return;
var headings = articleRoot.querySelectorAll('h2, h3, h4');
if (!headings.length) return;
var headingsArr = Array.from(headings);
// Unique IDs
var usedIds = {};
var slugify = function(s) { return String(s||'').toLowerCase().trim().replace(/\s+/g,'_').replace(/[^a-z0-9_-]/g,''); };
headingsArr.forEach(function(h) {
var id = (h.id||'').trim() || slugify(h.textContent) || 'section';
var c = id, n = 2;
while (usedIds[c]) c = id+'-'+(n++);
if (h.id !== c) h.id = c;
usedIds[c] = true;
});
// Build nested nav with data-heading-idx
var nav = document.createElement('nav');
var ulStack = [document.createElement('ul')];
nav.appendChild(ulStack[0]);
var levelOf = function(tag) { return tag==='H2'?2:tag==='H3'?3:4; };
var prev = 2, hIdx = 0;
headingsArr.forEach(function(h) {
var lvl = levelOf(h.tagName);
while (lvl > prev) { var ul = document.createElement('ul'); var last = ulStack[ulStack.length-1].lastElementChild; if (last) last.appendChild(ul); ulStack.push(ul); prev++; }
while (lvl < prev) { ulStack.pop(); prev--; }
var li = document.createElement('li');
var a = document.createElement('a');
a.href = '#'+h.id; a.textContent = h.textContent;
li.appendChild(a);
li.setAttribute('data-heading-idx', String(hIdx++));
ulStack[ulStack.length-1].appendChild(li);
});
if (holder) holder.appendChild(nav);
var navClone = nav.cloneNode(true);
if (holderMobile) holderMobile.appendChild(navClone);
// Mark navs as collapsible
nav.classList.add('toc-collapsible');
navClone.classList.add('toc-collapsible');
var allLinks = [].concat(
holder ? Array.from(holder.querySelectorAll('a')) : [],
holderMobile ? Array.from(holderMobile.querySelectorAll('a')) : []
);
// ---- Auto-collapse logic ----
var isMobile = window.matchMedia('(max-width: 1100px)');
function getItemsWithChildren(navEl) {
if (!navEl) return [];
return Array.from(navEl.querySelectorAll('li[data-heading-idx]')).filter(function(li) {
return li.querySelector(':scope > ul');
});
}
function getAncestorIndices(items, targetIdx) {
var toExpand = {};
var activeLi = null;
function find(li) {
if (Number(li.getAttribute('data-heading-idx')) === targetIdx) return li;
var ul = li.querySelector(':scope > ul');
if (!ul) return null;
var children = ul.querySelectorAll(':scope > li[data-heading-idx]');
for (var i = 0; i < children.length; i++) { var f = find(children[i]); if (f) return f; }
return null;
}
for (var i = 0; i < items.length; i++) { activeLi = find(items[i]); if (activeLi) break; }
if (!activeLi) return toExpand;
toExpand[targetIdx] = true;
var cur = activeLi;
while (cur) {
var parent = cur.parentElement ? cur.parentElement.closest('li[data-heading-idx]') : null;
if (parent) { toExpand[Number(parent.getAttribute('data-heading-idx'))] = true; cur = parent; }
else break;
}
return toExpand;
}
function applyCollapseState(navEl, activeIdx) {
if (!navEl) return;
var items = getItemsWithChildren(navEl);
var ancestors = getAncestorIndices(items, activeIdx);
items.forEach(function(li) {
var sub = li.querySelector(':scope > ul');
if (!sub) return;
var idx = Number(li.getAttribute('data-heading-idx'));
var allDesc = li.querySelectorAll('li[data-heading-idx]');
var related = [idx];
allDesc.forEach(function(d) { related.push(Number(d.getAttribute('data-heading-idx'))); });
var shouldExpand = related.some(function(i) { return ancestors[i]; });
if (shouldExpand) {
li.classList.remove('collapsed');
sub.style.height = 'auto';
} else {
li.classList.add('collapsed');
sub.style.height = '0px';
}
});
}
function expandAll(navEl) {
if (!navEl) return;
getItemsWithChildren(navEl).forEach(function(li) {
li.classList.remove('collapsed');
var sub = li.querySelector(':scope > ul');
if (sub) sub.style.height = 'auto';
});
}
// Initial state: collapse all except first section
function initCollapse() {
if (isMobile.matches) {
expandAll(holder ? holder.querySelector('nav') : null);
expandAll(holderMobile ? holderMobile.querySelector('nav') : null);
} else {
applyCollapseState(holder ? holder.querySelector('nav') : null, 0);
applyCollapseState(holderMobile ? holderMobile.querySelector('nav') : null, 0);
}
}
initCollapse();
isMobile.addEventListener('change', function() {
if (isMobile.matches) {
expandAll(holder ? holder.querySelector('nav') : null);
expandAll(holderMobile ? holderMobile.querySelector('nav') : null);
} else {
applyCollapseState(holder ? holder.querySelector('nav') : null, prevActiveIdx);
applyCollapseState(holderMobile ? holderMobile.querySelector('nav') : null, prevActiveIdx);
}
});
// ---- Scroll tracking ----
var OFFSET = 60, lastScrollTime = 0, prevActiveIdx = 0;
function onScroll() {
var now = performance.now();
if (now - lastScrollTime < 50) return;
lastScrollTime = now;
requestAnimationFrame(function() {
var activeIdx = -1, activeId = null;
for (var i = headingsArr.length - 1; i >= 0; i--) {
if (headingsArr[i].getBoundingClientRect().top - OFFSET <= 0) {
activeIdx = i; activeId = headingsArr[i].id; break;
}
}
allLinks.forEach(function(l) {
if (activeId && l.getAttribute('href') === '#'+activeId) l.classList.add('active');
else l.classList.remove('active');
});
if (activeIdx !== prevActiveIdx && activeIdx >= 0 && !isMobile.matches) {
prevActiveIdx = activeIdx;
applyCollapseState(holder ? holder.querySelector('nav') : null, activeIdx);
}
if (activeIdx >= 0) prevActiveIdx = activeIdx;
});
}
window.addEventListener('scroll', onScroll, { passive: true });
onScroll();
// ---- Mobile sidebar ----
var sidebar = document.querySelector('.toc-mobile-sidebar');
var backdrop = document.querySelector('.toc-mobile-backdrop');
var toggleBtn = document.querySelector('.toc-mobile-toggle');
var closeBtn = document.querySelector('.toc-mobile-sidebar__close');
function openSidebar() {
sidebar.classList.add('open'); backdrop.classList.add('open');
toggleBtn.setAttribute('aria-expanded','true');
document.body.style.overflow = 'hidden';
requestAnimationFrame(function() {
var active = sidebar.querySelector('a.active');
if (active) {
var body = sidebar.querySelector('.toc-mobile-sidebar__body');
if (body) body.scrollTop = Math.max(0, active.offsetTop - body.offsetTop - body.clientHeight/3);
}
});
}
function closeSidebar() {
sidebar.classList.remove('open'); backdrop.classList.remove('open');
toggleBtn.setAttribute('aria-expanded','false');
document.body.style.overflow = '';
}
if (toggleBtn) toggleBtn.addEventListener('click', openSidebar);
if (closeBtn) closeBtn.addEventListener('click', closeSidebar);
if (backdrop) backdrop.addEventListener('click', closeSidebar);
if (holderMobile) holderMobile.addEventListener('click', function(e) { if (e.target.closest && e.target.closest('a')) closeSidebar(); });
document.addEventListener('keydown', function(e) { if (e.key==='Escape' && sidebar.classList.contains('open')) closeSidebar(); });
// Hash navigation
if (window.location.hash) {
var target = document.querySelector(window.location.hash);
if (target) setTimeout(function() { target.scrollIntoView({block:'start'}); }, 100);
}
window.addEventListener('popstate', function() {
var h = window.location.hash;
if (h) { var t = document.querySelector(h); if (t) t.scrollIntoView({block:'start'}); }
else window.scrollTo({top:0});
});
})();
</script>
</body>
</html> |