Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
2298 lines (2154 loc) · 134 KB
/
Copy pathindex.html
File metadata and controls
2298 lines (2154 loc) · 134 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How a (small) language model walks</title>
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='6' fill='%231a1d24'/%3E%3Cline x1='9' y1='10' x2='23' y2='10' stroke='%235cc8c0' stroke-width='2'/%3E%3Cline x1='9' y1='10' x2='16' y2='22' stroke='%23f0a868' stroke-width='2'/%3E%3Ccircle cx='9' cy='10' r='3' fill='%23f0a868'/%3E%3Ccircle cx='23' cy='10' r='3' fill='%235cc8c0'/%3E%3Ccircle cx='16' cy='22' r='3' fill='%23b48ce0'/%3E%3C/svg%3E">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,500;0,600;1,400&family=Fraunces:opsz,wght@9..144,400;9..144,500;9..144,600&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<style>
/* =================================================================
Aesthetic: a 1948 Bell Labs technical monograph rendered as a live
instrument. Spectral/Fraunces serif for prose and figure titles,
IBM Plex Mono for the token machinery and the graph. Ink on warm
paper; hairline rules; plotter-pen inks for the branch colors;
printed figure-number labels. Light, typeset, restrained motion.
This is a STYLE layer only -- every class the JS touches keeps its
name, so the model/walk logic is untouched.
================================================================= */
:root {
--bg: #f4efe4; /* warm paper */
--bg2: #efe8d8; /* deeper paper (margins, gutters) */
--panel: #fbf8f0; /* a printed plate, slightly brighter than the page */
--panel2: #f0e9da; /* recessed field (inputs, chips) */
--ink: #1c1a17; /* near-black ink */
--ink2: #3a352e; /* body ink */
--muted: #6e6456; /* faded marginalia (darkened to clear WCAG AA 4.5:1 on paper) */
--line: #d8cdb6; /* hairline rule */
--line2: #c4b89c; /* heavier rule */
--accent: #9a2f1f; /* vermilion -- the "current word" / red printer pass */
--opt0: #1f5f6b; /* pen 1: deep teal */
--opt1: #b8761b; /* pen 2: ochre */
--stop: #7a3f7d; /* pen: plum (the hidden STOP) */
--good: #2f6b3a; /* field green */
--bad: #9a2f1f;
--warn: #9a6a14;
--serif: "Spectral", Georgia, "Times New Roman", serif;
--display:"Fraunces", "Spectral", Georgia, serif;
--mono: "IBM Plex Mono", "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; max-width: 100%; }
html, body {
margin: 0; background: var(--bg); color: var(--ink2);
font: 16px/1.6 var(--serif);
-webkit-font-smoothing: antialiased;
/* faint paper grain + a hair of vignette so it doesn't read as flat #fff */
background-image:
radial-gradient(ellipse 120% 80% at 50% -10%, rgba(255,255,255,.5), transparent 60%),
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
}
::selection { background: rgba(154,47,31,.18); }
/* ---- masthead: a journal title block ---- */
header {
padding: 30px 40px 18px; border-bottom: 2px solid var(--ink);
background: var(--bg);
}
h1 {
margin: 0 0 10px; font-family: var(--display); font-weight: 600;
font-size: clamp(24px, 3.4vw, 38px); line-height: 1.1; letter-spacing: -.015em;
color: var(--ink); max-width: 100%; text-wrap: balance; text-align: center;
}
header p {
/* Centered block, text left-aligned. Capping the measure for readability but
centering the block (margin-inline:auto) balances the left/right margins,
so it never reads as a hardcoded break the way a left-pinned 74ch column
did (dead right margin). Text inside stays left-aligned for easy reading. */
margin: 0 auto; color: var(--ink2); max-width: 92ch; font-size: 14.5px; line-height: 1.62; text-align: center;
text-wrap: pretty;
}
header p b { color: var(--accent); font-weight: 600; }
.wrap { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 20px; padding: 26px 40px 64px; max-width: 1280px; }
@media (max-width: 920px) { .wrap { grid-template-columns: minmax(0,1fr); padding: 22px 22px 48px; } header { padding: 22px 22px 16px; } }
.panel { min-width: 0; } /* let grid children shrink instead of forcing track width */
/* ---- panels as printed figure-plates ---- */
.panel {
background: var(--panel); border: 1px solid var(--line2); border-radius: 2px;
padding: 18px 20px 20px; min-height: 60px; position: relative;
box-shadow: 1px 2px 0 rgba(28,26,23,.06);
}
.panel h2 {
margin: 0 0 12px; font-family: var(--mono); font-size: 11px; letter-spacing: .16em;
text-transform: uppercase; color: var(--muted); font-weight: 600;
padding-bottom: 7px; border-bottom: 1px solid var(--line);
}
.full { grid-column: 1 / -1; }
/* ---- training text: the model's corpus, set like body copy ---- */
#training { line-height: 2.3; font-size: 17px; font-family: var(--serif); color: var(--ink2); }
.tok {
display: inline-block; padding: 1px 4px; margin: 0 1px; border-radius: 2px;
transition: background .15s, color .15s, box-shadow .15s, transform .15s;
}
.tok.period { opacity: .5; margin-left: -3px; padding-left: 0; }
.tok.occ-faint { background: rgba(154,47,31,.12); }
.tok.cursor {
background: var(--accent); color: #fbf3ec; font-weight: 600;
box-shadow: 0 0 0 2px rgba(154,47,31,.28); transform: translateY(-1px);
}
.tok.cand0 { box-shadow: inset 0 0 0 2px var(--opt0); }
.tok.cand1 { box-shadow: inset 0 0 0 2px var(--opt1); }
.tok.chosen { animation: pop .35s ease; }
@keyframes pop { 0%{transform:scale(1);} 40%{transform:scale(1.16);} 100%{transform:scale(1);} }
/* ---- generated output: typewriter / teletype line ---- */
#output { font-family: var(--mono); font-size: 17px; line-height: 2; min-height: 40px; letter-spacing: -.01em; }
#output .gen { display: inline-block; margin: 0 2px; padding: 0 2px; border-radius: 2px; }
#output .gen.punct { margin-left: -2px; }
#output .gen.start { color: var(--accent); font-weight: 600; }
#output .caret { color: var(--accent); animation: blink 1.05s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
/* ---- branch widget ---- */
#branch { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 38px; }
.chip {
padding: 5px 13px; border-radius: 2px; font-size: 14px; border: 1px solid var(--line2);
background: var(--panel2); font-family: var(--mono); letter-spacing: -.01em;
}
.chip.from { background: var(--accent); color: #fbf3ec; font-weight: 600; border-color: var(--accent); }
.chip.o0 { border-color: var(--opt0); color: var(--opt0); }
.chip.o1 { border-color: var(--opt1); color: var(--opt1); }
.chip.ostop { border-color: var(--stop); color: var(--stop); }
.chip.picked { box-shadow: 0 0 0 2px currentColor; font-weight: 700; }
/* tappable chips: a candidate chip picks that word as the next step; the
current-word chip (.from) takes a random step. */
.chip[data-i], .chip.from { cursor: pointer; transition: background .1s, box-shadow .1s, filter .1s; }
.chip[data-i]:hover { background: var(--panel); box-shadow: 0 0 0 1px currentColor; }
.chip[data-i]:active { background: var(--bg2); }
.chip.from:hover { filter: brightness(1.12); }
.chip.from:active { filter: brightness(0.92); }
.arrow { color: var(--muted); font-family: var(--mono); }
/* ---- controls: a brass-instrument console row ---- */
#controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
/* on-screen +/- fallback for the arrow keys (click/touch) */
.nudgegroup { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12.5px; color: var(--ink2); }
.nudgegroup .nudgelabel { margin-right: 2px; }
.nudgegroup button { padding: 3px 9px; min-width: 26px; font-size: 14px; line-height: 1; }
/* arrow-key CTA chips (replace the old sliders): show the keys and current value */
.cta { font-family: var(--mono); font-size: 12.5px; color: var(--ink2); display: inline-flex;
align-items: center; gap: 4px; }
.cta kbd { font-size: 11px; padding: 1px 6px; min-width: 16px; }
.cta b { color: var(--accent); font-weight: 600; margin-left: 2px; }
button {
background: var(--panel2); color: var(--ink); border: 1px solid var(--line2);
border-radius: 2px; padding: 7px 15px; font-size: 13.5px; cursor: pointer;
font-family: var(--mono); letter-spacing: .01em;
transition: background .12s, color .12s, border-color .12s, transform .06s;
}
button:hover { border-color: var(--ink); background: var(--bg2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: #fbf3ec; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #841f12; border-color: #841f12; }
button:disabled { opacity: .42; cursor: not-allowed; }
label { color: var(--ink2); font-size: 13px; display: inline-flex; align-items: center; gap: 7px; font-family: var(--mono); }
input[type=range] { width: 132px; vertical-align: middle; accent-color: var(--accent); }
select {
background: var(--panel2); color: var(--ink); border: 1px solid var(--line2);
border-radius: 2px; padding: 6px 10px; font-size: 13px; font-family: var(--mono);
}
/* ---- printed keyboard legend (the Space/Return/R answer, made legible) ---- */
.keyhint {
display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
margin-top: 14px; padding-top: 12px; border-top: 1px dotted var(--line2);
font-family: var(--serif); font-size: 13.5px; color: var(--ink2);
}
.keyhint span { margin-right: 14px; }
/* small top strip: same shortcuts, compact, centered, at the very top */
.keyhint-top {
margin-top: 0; padding: 8px 14px; border-top: none;
justify-content: center; font-size: 12px; gap: 5px 7px;
background: var(--panel); border: 1px solid var(--line); border-radius: 2px;
color: var(--muted);
}
.keyhint-top span { margin-right: 10px; }
.keyhint-top kbd { font-size: 11px; padding: 1px 6px; min-width: 16px; }
kbd {
font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--ink);
background: linear-gradient(#fffdf7, #ece3d0);
border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px;
padding: 2px 7px; min-width: 20px; text-align: center; box-shadow: 0 1px 0 rgba(28,26,23,.08);
}
/* kbd inside a panel heading: small, inline, lowercase-friendly */
.panel h2 kbd {
font-size: 10px; padding: 1px 5px; min-width: 14px; border-bottom-width: 1px;
text-transform: none; letter-spacing: 0; vertical-align: middle;
}
/* tappable keyboard glyphs in the "Generated language" heading: a phone user can
tap them to drive the walk (step / play-pause / slower / faster). */
kbd.keytap { cursor: pointer; transition: background .1s, box-shadow .1s; }
kbd.keytap:hover { background: linear-gradient(#fff, #e3d8c2); box-shadow: 0 0 0 2px var(--accent); }
kbd.keytap:active { background: var(--accent); color: #fbf3ec; }
/* ---- verifier ---- */
#verdict { font-weight: 600; padding: 9px 13px; border-radius: 2px; margin-bottom: 12px; font-family: var(--mono); font-size: 13.5px; }
#verdict.ok { background: rgba(47,107,58,.12); color: var(--good); border: 1px solid rgba(47,107,58,.4); }
#verdict.fail { background: rgba(154,47,31,.12); color: var(--bad); border: 1px solid rgba(154,47,31,.45); }
#verdict.stats { background: rgba(31,95,107,.1); color: var(--opt0); border: 1px solid rgba(31,95,107,.35); }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-family: var(--mono); }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; font-size: 11px; }
td.bad { color: var(--bad); font-weight: 600; }
td.warn { color: var(--warn); font-weight: 600; }
.histwrap { display: flex; align-items: flex-end; gap: 8px; }
.hist { display: flex; gap: 12px; align-items: flex-end; height: 62px; margin: 10px 0 6px; }
.histaxis { color: var(--muted); font-size: 11px; }
.histaxis-y { line-height: 1.15; text-align: right; padding-bottom: 24px; }
.histaxis-x { margin: 2px 0 6px; }
.bar { width: 34px; background: var(--opt0); border-radius: 1px; position: relative; }
.bar span { position: absolute; bottom: -19px; left: 0; right: 0; text-align: center; color: var(--muted); font-size: 11px; font-family: var(--mono); }
.bar b { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--ink); font-family: var(--mono); }
/* ---- graph plate ---- */
#graphwrap { overflow-x: auto; }
svg text { font-size: 11px; fill: var(--ink2); font-family: var(--mono); }
.gnode { fill: var(--panel2); stroke: var(--line2); stroke-width: 1.5; }
.gnode.active { fill: var(--accent); stroke: var(--accent); }
.gedge { stroke: var(--line2); stroke-width: 1.4; fill: none; marker-end: url(#arrow); opacity: .6; transition: opacity .12s, stroke-width .12s; }
.gedge.lit0 { stroke: var(--opt0) !important; stroke-width: 2.5; }
.gedge.lit1 { stroke: var(--opt1) !important; stroke-width: 2.5; }
.gedge.fired { stroke: var(--accent) !important; stroke-width: 3; opacity: 1; }
svg.dimmable .gedge { opacity: .12; }
svg.dimmable .gedge.hl { opacity: 1; stroke-width: 2.5; }
svg.dimmable .gnode.hl { stroke: var(--accent); stroke-width: 2; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12px; margin-top: 6px; font-family: var(--mono); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.note { color: var(--muted); font-size: 13px; margin-top: 10px; font-style: italic; font-family: var(--serif); }
/* build-stamped "last updated" footer, repeated at the bottom of every tab */
.pagefooter { grid-column: 1 / -1; text-align: center; color: var(--muted);
font-family: var(--mono); font-size: 11.5px; letter-spacing: .02em;
margin: 28px 0 0; padding-top: 14px; border-top: 1px dotted var(--line2); }
/* the footer hugs the foot of the demo page: cancel the .wrap bottom padding
beneath it so it is the last visible thing, not floating above empty space. */
.wrap > .pagefooter { margin-bottom: -64px; padding-bottom: 8px; }
@media (max-width: 920px) { .wrap > .pagefooter { margin-bottom: -48px; } }
/* monospace "code" link in the footer, pointing at the public source repo */
.pagefooter .codelink, #lastUpdated .codelink {
font-family: var(--mono); color: var(--accent); text-decoration: none;
border-bottom: 1px dotted var(--accent); padding-bottom: 1px; }
.pagefooter .codelink::before, #lastUpdated .codelink::before { content: "<"; opacity: .5; }
.pagefooter .codelink::after, #lastUpdated .codelink::after { content: "/>"; opacity: .5; }
.pagefooter .codelink:hover, #lastUpdated .codelink:hover { color: var(--ink); border-color: var(--ink); }
/* ---- N-way plotter-pen palette (kept on the same class names) ---- */
.pal0{--c:#1f5f6b;} .pal1{--c:#b8761b;} .pal2{--c:#7a3f7d;}
.pal3{--c:#3a6b2f;} .pal4{--c:#9a2f5c;} .pal5{--c:#5a6b14;}
#output .gen.b0{color:#1f5f6b;} #output .gen.b1{color:#b8761b;} #output .gen.b2{color:#7a3f7d;}
#output .gen.b3{color:#3a6b2f;} #output .gen.b4{color:#9a2f5c;} #output .gen.b5{color:#5a6b14;}
#output .gen.stopword{color:var(--stop); font-weight:600;}
.chip.o0{border-color:#1f5f6b;color:#1f5f6b;} .chip.o1{border-color:#b8761b;color:#b8761b;}
.chip.o2{border-color:#7a3f7d;color:#7a3f7d;} .chip.o3{border-color:#3a6b2f;color:#3a6b2f;}
.chip.o4{border-color:#9a2f5c;color:#9a2f5c;} .chip.o5{border-color:#5a6b14;color:#5a6b14;}
.chip small{opacity:.7; font-weight:400;}
.tok.cand0{box-shadow:inset 0 0 0 2px #1f5f6b;} .tok.cand1{box-shadow:inset 0 0 0 2px #b8761b;}
.tok.cand2{box-shadow:inset 0 0 0 2px #7a3f7d;} .tok.cand3{box-shadow:inset 0 0 0 2px #3a6b2f;}
.tok.cand4{box-shadow:inset 0 0 0 2px #9a2f5c;} .tok.cand5{box-shadow:inset 0 0 0 2px #5a6b14;}
/* ---- tabs: a journal contents bar ---- */
nav.tabs { display:flex; flex-direction:column; align-items:center; gap:2px; padding: 4px 40px 0; border-bottom:2px solid var(--ink); background: var(--bg2); }
nav.tabs .tabrow { display:flex; gap:2px; justify-content:center; flex-wrap:wrap; }
nav.tabs button { background:transparent; border:none; border-bottom:3px solid transparent; border-radius:0; color:var(--muted); padding:11px 15px; font-size:13px; font-family:var(--mono); letter-spacing:.02em; transition: color .12s, border-color .12s; }
nav.tabs button.active { color:var(--accent); border-bottom-color:var(--accent); font-weight:600; }
nav.tabs button:hover { color:var(--ink); background: var(--panel); }
@media (max-width: 920px) { nav.tabs { padding: 0 12px; } }
.source-panel { padding: 16px 40px; border-bottom:1px solid var(--line); background:var(--panel); display:none; }
.source-panel.active { display:block; }
/* roomy bottom space on the prose tabs so the last content (e.g. the Methods
Pareto graph) clears the viewport and is easy to scroll to fully. */
body.about-mode .source-panel.active { padding-bottom: 30vh; border-bottom: none; }
.source-panel textarea { width:100%; min-height:90px; background:var(--panel2); color:var(--ink2); border:1px solid var(--line2); border-radius:2px; padding:11px; font:13px/1.55 var(--mono); resize:vertical; }
.source-panel input[type=text] { width:100%; background:var(--panel2); color:var(--ink2); border:1px solid var(--line2); border-radius:2px; padding:8px 10px; font-size:13px; font-family:var(--mono); }
.source-panel .row { display:flex; gap:10px; align-items:center; margin-top:8px; flex-wrap:wrap; }
.source-panel p.hint { color:var(--ink2); font-size:13.5px; margin:0 auto 9px; max-width: 78ch; line-height: 1.55; text-align: center; }
.source-panel p.hint code { background: var(--panel2); border: 1px solid var(--line); border-radius: 2px; padding: 0 4px; font-family: var(--mono); font-size: 12px; }
@media (max-width: 920px) { .source-panel { padding: 14px 22px; } }
#urlStatus, #stdStatus { color:var(--muted); font-size:12.5px; font-family:var(--mono); }
/* ---- long-form prose tabs (Method / About / Words / References) ---- */
.about-prose { max-width: 74ch; margin-inline: auto; } /* centered column, text stays left-aligned for readability */
.about-prose h3 { font-family: var(--display); font-weight: 600; font-size: 19px; margin: 22px 0 6px; color: var(--ink); }
.about-prose p { margin: 0 0 12px; color: var(--ink2); font-size: 15.5px; line-height: 1.68; }
.about-prose a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.about-prose a:hover { background: rgba(154,47,31,.1); }
.about-prose ul.sources { margin: 4px 0 12px; padding-left: 20px; max-width: 76ch; }
.about-prose ul.sources li { margin: 0 0 7px; color: var(--ink2); font-size: 14.5px; line-height: 1.55; }
.about-prose .lede { font-family: var(--display); font-weight: 400; font-size: 18px; line-height: 1.5; color: var(--ink); margin: 4px 0 18px; }
.about-prose .appendix { font-size: 13.5px; line-height: 1.55; color: var(--ink2); margin: 0 0 12px; padding-left: 16px; border-left: 2px solid var(--line); max-width: 76ch; }
.about-prose .appendix b { font-family: var(--mono); font-size: 12px; letter-spacing: .02em; color: var(--ink); }
.about-prose code { background: var(--panel2); border: 1px solid var(--line); border-radius: 2px; padding: 0 4px; font-size: 13px; font-family: var(--mono); }
.about-prose blockquote { margin: 14px 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--accent);
font-family: var(--display); font-weight: 400; font-style: italic; font-size: 16px; line-height: 1.6; color: var(--ink); }
.about-prose blockquote cite { display: block; margin-top: 8px; font-family: var(--mono); font-style: normal;
font-size: 12px; color: var(--muted); letter-spacing: .02em; }
.about-prose blockquote cite a { color: var(--muted); }
.about-prose.method ol { max-width: 76ch; padding-left: 24px; }
.about-prose.method ol li { margin: 0 0 9px; color: var(--ink2); font-size: 15.5px; line-height: 1.68; }
body.about-mode .wrap { display: none; }
/* ---- the gate: a sealed title page ---- */
#gate { position: fixed; inset: 0; background: var(--bg); z-index: 1000;
display: flex; align-items: center; justify-content: center;
background-image:
radial-gradient(ellipse 100% 70% at 50% 0%, rgba(255,255,255,.5), transparent 65%),
url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E"); }
#gate.hidden { display: none; }
#gateForm { background: var(--panel); border: 1px solid var(--ink); border-top: 4px solid var(--accent);
border-radius: 2px; padding: 38px 40px 32px; width: min(380px, 90vw); text-align: center;
box-shadow: 2px 6px 0 rgba(28,26,23,.1); position: relative; }
#gateForm::before { content: "PRIVATE \2014 BY KEY"; position: absolute; top: 13px; left: 0; right: 0;
font: 600 10px/1 var(--mono); letter-spacing: .26em; color: var(--muted); }
#gateForm h2 { margin: 14px 0 6px; font-family: var(--display); font-weight: 600; font-size: 22px; color: var(--ink); line-height: 1.12; }
#gateForm p { margin: 0 0 18px; color: var(--ink2); font-size: 14px; }
#gateForm input { width: 100%; padding: 11px 13px; margin-bottom: 13px; border-radius: 2px;
border: 1px solid var(--line2); background: var(--panel2); color: var(--ink);
font-size: 15px; font-family: var(--mono); text-align: center; letter-spacing: .12em; }
#gateForm input:focus { outline: none; border-color: var(--accent); }
#gateForm input::placeholder { color: var(--muted); opacity: 1; letter-spacing: .04em; }
#gateForm button { width: 100%; }
#gateErr { color: var(--bad); font-size: 13px; margin-top: 11px; min-height: 16px; font-family: var(--mono); }
body.locked { overflow: hidden; }
/* =================================================================
Mobile (phones). The monograph keeps its character; it just folds
to a single readable column with finger-sized controls, a tab
strip that scrolls instead of stacking three rows, and a graph
figure scaled to fit the screen instead of forcing a pan.
================================================================= */
@media (max-width: 640px) {
html, body { font-size: 16px; }
header { padding: 20px 18px 16px; }
h1 { font-size: clamp(23px, 7vw, 30px); }
header p { font-size: 14px; }
/* one figure-plate per row, edge-to-edge breathing room */
.wrap { padding: 18px 14px 56px; gap: 16px; }
.panel { padding: 15px 15px 17px; }
/* the graph: scale the whole SVG to the column width (the SVG carries
its intrinsic max-width via svgWrap, so this never upscales on desktop).
The wrapper still allows a pan as a fallback for very wide lattices. */
#graphwrap svg { width: 100%; height: auto; }
/* tab bar on mobile: keep the two centered rows, but let each row scroll
horizontally if it overflows. Momentum scroll on iOS; snap each tab; hide
the scrollbar. */
nav.tabs { padding: 4px 0 0; }
nav.tabs .tabrow {
flex-wrap: nowrap; overflow-x: auto; max-width: 100%; padding: 0 14px;
justify-content: flex-start;
-webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
scrollbar-width: none;
}
nav.tabs .tabrow::-webkit-scrollbar { display: none; }
nav.tabs button { flex: 0 0 auto; white-space: nowrap; padding: 12px 13px; scroll-snap-align: start; }
/* finger-sized targets (>= 44px) for every control */
#controls button, .source-panel button { padding: 11px 16px; min-height: 44px; }
#controls select, .source-panel select, .source-panel input[type=text] { min-height: 44px; padding: 9px 12px; }
/* tappable chips: bigger touch area + room between them on a phone */
#branch { gap: 8px 6px; }
.chip[data-i], .chip.from { padding: 10px 14px; font-size: 15px; }
/* the tappable keyboard glyphs in the heading need a finger-sized hit area */
.panel h2 kbd.keytap { font-size: 14px; padding: 7px 11px; min-width: 22px;
display: inline-block; margin: 2px 1px; }
/* source-panel input rows stack on a phone so the dropdown + button + status
each take a full-width line instead of overflowing off the right edge. */
.source-panel .row { flex-direction: column; align-items: stretch; gap: 8px; }
.source-panel .row > * { width: 100%; box-sizing: border-box; }
.source-panel .row label { display: flex; flex-direction: column; gap: 4px; }
.source-panel .row label select { width: 100%; }
#controls label { font-size: 13.5px; }
input[type=range] { width: 100%; min-width: 140px; height: 28px; }
/* sliders get their own full-width rows so the thumb is easy to grab */
#controls label:has(input[type=range]) { flex: 1 1 100%; }
#controls select { flex: 1 1 100%; }
.source-panel { padding: 14px; }
/* the footer "code" link gets a bigger touch area on a phone (it is a small
inline link otherwise). Extra vertical padding, no layout shift. */
.pagefooter .codelink, #lastUpdated .codelink { padding: 6px 4px; display: inline-block; }
/* keyboard legend is desktop-only guidance; on a touch device there is no
keyboard, so reclaim the space. (The on-screen buttons do the same jobs.) */
.keyhint { display: none; }
/* generated output / training text sized for a small screen */
#training { font-size: 16px; line-height: 2.15; }
#output { font-size: 15px; }
.chip { font-size: 13px; padding: 7px 12px; }
/* prose tabs: comfortable reading measure on a phone */
.about-prose p, .about-prose.method ol li { font-size: 15px; line-height: 1.62; }
.about-prose .lede { font-size: 16.5px; }
.about-prose h3 { font-size: 17px; }
/* gate fills the small screen pleasantly */
#gateForm { padding: 34px 26px 28px; width: min(92vw, 360px); }
}
/* very small phones: let long mono words break rather than push width */
@media (max-width: 380px) {
#training, #output { word-break: break-word; overflow-wrap: anywhere; }
nav.tabs button { font-size: 12.5px; padding: 12px 11px; }
}
/* respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
</style>
</head>
<body>
<!-- Password gate removed: the site is public. (Earlier it was behind a
client-side password as obfuscation only; the markup and the locking script
below have been disabled so the page is open to everyone.) -->
<header>
<h1>How a (small) language model walks through its training text</h1>
<p>Language models are not magic. They are mathematical games for exploring the text on which they are trained. This particular game, the simplest of them, dates from 1945 (see the <b>About / History</b> tab) and shows two things at once: how much the training text matters, and how a plain random walk through that text can be generative. Start with the <b>Designed</b> tab, then try your own text. Explore and enjoy.</p>
</header>
<nav class="tabs" id="tabs">
<div class="tabrow">
<button data-tab="designed">Designed text</button>
<button data-tab="paste">Write (or paste) your own text</button>
<button data-tab="url">From URL(s)</button>
<button data-tab="standard" class="active">Standard texts</button>
</div>
<div class="tabrow">
<button data-tab="method">Method</button>
<button data-tab="about">About / History</button>
<button data-tab="words">Word sources</button>
<button data-tab="sources">References</button>
</div>
</nav>
<div class="source-panel" id="sp-designed"></div>
<div class="source-panel" id="sp-paste">
<p class="hint">Paste/write any text. It is analyzed as-is: the real bigram graph is built with frequencies, and the walk samples likelier continuations more often. Out-degrees vary wildly, the opposite of the designed demo's uniform branching.</p>
<textarea id="pasteText" placeholder="Paste training text here..."></textarea>
<div class="row"><button id="pasteGo" class="primary">Analyze this text</button></div>
</div>
<div class="source-panel" id="sp-url">
<p class="hint">Enter one or more URLs (comma- or newline-separated). The local backend fetches each page and uses BeautifulSoup to strip it to plain text, then analyzes the combined result. Requires running <code>python3 src/server.py</code>.</p>
<textarea id="urlList" placeholder="https://www.gutenberg.org/files/1342/1342-0.txt https://example.com/article"></textarea>
<div class="row"><button id="urlGo" class="primary">Fetch & analyze</button><span id="urlStatus"></span></div>
</div>
<div class="source-panel active" id="sp-standard">
<p class="hint">Text excerpts bundled with the app. Pick one to build its real bigram graph and walk it. <i>Eugene Onegin</i> is the text Andrey Markov used in 1913 for the first Markov chain — see the About / History tab.</p>
<div class="row">
<label>Text <select id="stdSelect"></select></label>
<button id="stdGo" class="primary">Load & analyze</button>
<span id="stdStatus"></span>
</div>
</div>
<div class="source-panel" id="sp-method">
<div class="about-prose method">
<p class="lede">The "Designed" tab builds a training text by construction, so the bigram
model's branching is small and controlled instead of whatever a real corpus happens to
give. Here is the shared machinery, the four ways the dropdown authors the text, and the
two checks that keep it honest.</p>
<h3>A bigram graph</h3>
<p>A bigram model reads a token sequence and records, for each word, the set of words seen
immediately after it. Write that as a directed graph: vertices are the distinct words, and
there is an edge <code>u → v</code> whenever <code>v</code> follows <code>u</code>
somewhere in the text. A word's <b>out-degree</b> is the number of <em>distinct</em> words
that follow it. The generative step is a random walk on this graph, sampling each next word
in proportion to how often it followed the current one; the out-degree is the branching factor
of that choice. The point of the Designed tab is to make that branching uniform and low
(mostly 2) so the generative process is legible.</p>
<h3>Constructing the lattice</h3>
<p>Lay out a cyclic part-of-speech template (DET → ADJ → NOUN → VERB → DET
→ …) and fill each slot with a column of <code>m</code> distinct words. Number
each column's words <code>0…m-1</code>. Word <code>i</code> points to words in the
next column at indices <code>2i mod m</code> and <code>2i+1 mod m</code>; for
<code>m ≥ 2</code> those are distinct, so each word gets out-degree 2. There is no
displayed "END" token: the period "." is a real token that plays the role of end-of-
sequence. The <code>m</code> (words per slot) is what the <b>Length</b> slider sets, so the
slider is really a vocabulary control.</p>
<h3>Out-degree counts strings, not slots</h3>
<p>The subtle hazard is that out-degree aggregates over <em>every occurrence of a surface
string</em>, not over a grammatical slot. Put "the" in two columns and the graph unions its
successors, silently landing it at out-degree 4. The per-slot regularity is invisible; only
string identity counts. The fix is a discipline: give every column a <b>disjoint word
pool</b>, so each surface string lives in exactly one slot. Then the empirical out-degree
equals the assigned one — provided every assigned edge actually appears in the
displayed text. That proviso drives the covering walk below.</p>
<h3>Five strategies (the Strategy dropdown)</h3>
<p>All five keep a word-level bigram model and a one-word reading head; they differ only in how
the training text is authored, which changes the out-degree profile:</p>
<ul>
<li><b>lattice (strict k=2)</b> — every word has exactly 2 successors; a verb can also
take the period (out-degree 3) to end a sentence. The cleanest case, and the one the math
above describes exactly. The self-check asserts a hard pass/fail here.</li>
<li><b>mixed (k = 2 or 3)</b> — each word gets 2 <em>or</em> 3 successors at random, so
the branching reads less mechanically while staying tightly bounded.</li>
<li><b>prose (objects + conjunctions)</b> — clauses take objects
(DET ADJ NOUN VERB NOUN) and join mid-sentence with "and"/"yet". Verbs reach out-degree 3-4
(a real word, an object, the period, a conjunction); the model still just learns the
adjacencies.</li>
<li><b>natural (optional adjectives + prepositions)</b> — the <b>default</b>. Two edges
relax the rigid slot order toward real English: a determiner can go straight to a noun
(so "the machine" appears alongside "the tender machine"), and a noun can open a
<em>prepositional phrase</em> instead of taking its verb ("the idea in the meadow sleeps").
Most words still have out-degree 2; the graph stays one strongly-connected piece so the
covering walk and guard still hold.</li>
<li><b>free function words</b> — content words stay at 2, but determiners and the period
branch widely, the way real function words do, giving natural connective tissue.</li>
</ul>
<p>The strict lattice asserts a flat 2/3/2 pass/fail; the other four run in <b>report mode</b>,
showing the real out-degree histogram instead, because their whole point is to relax the
flat-k=2 claim for readability. (Agreement and tense are not varied, and there are no relative
clauses — those would either need more word forms or balloon the branching past what you
can follow by eye.)</p>
<h3>Covering every edge in the walk</h3>
<p>The displayed text is a walk, so it shows at most (tokens − 1) edges; to exhibit all
the graph's edges it needs at least (edges + 1) tokens, achieved only by an Eulerian path.
But the lattice is not <b>balanced</b> (the first determiners are pointed at more often than
they point out), so no single Eulerian pass covers every edge once, and a naive routine
would "jump" at the seams and emit pairs that are not real edges. So we solve the directed
<a href="https://en.wikipedia.org/wiki/Chinese_postman_problem" target="_blank">route-
inspection (Guan's route) problem</a>: measure each vertex's imbalance, add the fewest
duplicate edges (along shortest paths) to balance it, then take an Eulerian circuit with
<a href="https://en.wikipedia.org/wiki/Eulerian_path#Hierholzer's_algorithm" target="_blank">Hierholzer's
algorithm</a> and rotate it to end on a period. The leftover phrase repetition is structural:
the imbalanced nodes sit on opposite sides of the cycle, so the duplicate paths are long.</p>
<h3>Two checks that keep it honest</h3>
<p>None of this is taken on faith. First, a <b>build-time coverage guard</b> runs for every
strategy: it recomputes the bigram graph from the emitted tokens and requires it to equal
the designed graph — no spurious adjacency, no uncovered edge. If they differ it shows
a "GRAPH/TEXT MISMATCH" banner and disables generation, so the text you read can never
silently diverge from the graph the panel draws. Second, the <b>self-check</b> panel reports
the out-degrees: a hard PASS/FAIL for the strict lattice (2 for ordinary words, 3 for
sentence-enders, 2 for the period), or the real histogram for the report-mode strategies.
The model is Shannon's 1948 first-order word model throughout; the construction only rigs
the training text so its branching is something you can follow by eye.</p>
<h3>How lively is the generated text? Scale is not the whole story</h3>
<p>The <em>generative</em> liveliness of a bigram model is how much its next word is in doubt:
the per-step conditional entropy of the source, weighted by how often each word actually occurs,
<code>H̄ = ∑<sub>w₁</sub> (n(w₁)/N) H[p(w₂|w₁)]</code> in bits,
from the text's bigram counts. A word with one successor (out-degree k=1) contributes 0 bits;
a word that never recurs (k=0, a dead end) also contributes 0 and drags the average down. This
is the conditional entropy of <a href="https://people.math.harvard.edu/~ctm/home/text/others/shannon/entropy/entropy.pdf" target="_blank">Shannon's
n-gram model</a> (1948; and <a href="https://www.princeton.edu/~wbialek/rome/refs/shannon_51.pdf" target="_blank"><i>Prediction and Entropy of Printed English</i></a>, 1951). You might
expect a bigger vocabulary to mean a livelier model, but the curves below show that liveliness
depends as much on the <em>structure</em> of the training text as on its size: each curve is the
most entropy reachable at each vocabulary size, over every contiguous whole-sentence excerpt of
one short text.</p>
<div id="paretowrap"></div>
<p class="note">Three repetitive texts, same axes. Aristophanes' frog chorus (<i>The Frogs</i>,
405 BC) wrings real entropy out of a 3-word vocabulary (0.67 bits/step): tiny but structured.
The cumulative rhyme <i>The House That Jack Built</i> (1755) climbs highest because its
high-traffic words ("that", "the") branch heavily as the verse accumulates. Same scale, very
different liveliness, depending on how the words connect.</p>
<h3>Appendix: the texts</h3>
<p>The three public-domain texts behind the curves above. (The House That Jack Built and Ring a
Ring o' Roses are also in the Standard-texts tab, to walk directly.)</p>
<p class="appendix"><b>The Frogs</b> (Aristophanes, 405 BC):<br>
Brekekekex koax koax. Brekekekex koax koax. We children of the fountain and the lake. Let us
raise our harmonious song, koax koax. The fair notes of our music, brekekekex koax koax.</p>
<p class="appendix"><b>Ring a Ring o' Roses</b> (traditional):<br>
Ring a ring o' roses. A pocket full of posies. A-tishoo. A-tishoo. We all fall down.</p>
<p class="appendix"><b>The House That Jack Built</b> (1755):<br>
This is the house that Jack built. This is the malt that lay in the house that Jack built. This
is the rat that ate the malt that lay in the house that Jack built. This is the cat that killed
the rat that ate the malt that lay in the house that Jack built. This is the dog that worried
the cat that killed the rat that ate the malt that lay in the house that Jack built. This is the
cow with the crumpled horn that tossed the dog that worried the cat that killed the rat that ate
the malt that lay in the house that Jack built.</p>
</div>
</div>
<div class="source-panel" id="sp-about">
<div class="about-prose">
<h3>Shannon, 1945</h3>
<p>The bigram model you are watching first appears, fully formed, in a classified
<a href="https://en.wikipedia.org/wiki/Bell_Labs" target="_blank">Bell Labs</a> war memorandum by
<a href="https://en.wikipedia.org/wiki/Claude_Shannon" target="_blank">Claude Shannon</a>,
<a href="https://www.iacr.org/museum/shannon45.html" target="_blank"><i>A Mathematical
Theory of Cryptography</i></a> (1 September 1945). It is all there: transition
probabilities p<sub>i</sub>(j), the probability that letter i is followed by letter j;
digram and trigram tables; and the famous "series of approximations to English," where
you generate text by sampling each letter (then each word) from the frequencies with
which it followed what came before. The bigram walk in this demo is exactly Shannon's
first-order word approximation. The version most people cite, <i>A Mathematical Theory of
Communication</i> (1948), reused these passages three years later; the language model
itself is wartime work. (Earlier still, <a href="https://en.wikipedia.org/wiki/Andrey_Markov" target="_blank">Andrey
Markov</a> had in 1913 counted vowel/consonant transitions across 20,000 letters of
Pushkin's <i>Eugene Onegin</i> — the
<a href="https://spectrum.ieee.org/andrey-markov-and-claude-shannon-built-the-first-language-generation-models" target="_blank">first
chain of its kind</a>. Markov counted letters; Shannon's step was to make those counts
<em>generative</em> — a model that does not just measure language but produces it. You can run the bigram walk on Markov's own text in the
Standard texts tab.)</p>
<h3>Turing and Shannon, over tea at Bell Labs</h3>
<p>Shannon wrote it as a codebreaker. A cipher is attacked through the statistical
structure of the underlying language — its redundancy, the predictability that a
letter constrains the next. The same n-gram statistics that let Shannon's model
<em>generate</em> English-like text let a cryptanalyst <em>recognize</em> it emerging
from a partly-broken cipher. The 1945 memo treats the language model and the attack as
two sides of one mathematics. It was written after the Allied codebreaking effort had
industrialized: <a href="https://en.wikipedia.org/wiki/Colossus_computer" target="_blank">Colossus</a>, the
electronic machine built to break the German Lorenz cipher at
<a href="https://en.wikipedia.org/wiki/Bletchley_Park" target="_blank">Bletchley Park</a>, was running by the end of
1943.</p>
<p>The Allied lead in this mathematics had itself come from Poland. Three mathematicians of
the Polish Cipher Bureau — <a href="https://en.wikipedia.org/wiki/Marian_Rejewski" target="_blank">Marian
Rejewski</a>, <a href="https://en.wikipedia.org/wiki/Henryk_Zygalski" target="_blank">Henryk Zygalski</a>, and
<a href="https://en.wikipedia.org/wiki/Jerzy_R%C3%B3%C5%BCycki" target="_blank">Jerzy Różycki</a> — had broken
Enigma years before the British, treating the cipher as a problem in the statistics and
structure of its messages. With engineers from the
<a href="https://en.wikipedia.org/wiki/AVA_Radio_Company" target="_blank">AVA Radio Company</a> they built the
<i>bomba</i> to search Enigma settings, and at a secret meeting in the
<a href="https://www.gchq.gov.uk/information/the-pyry-forest-meeting" target="_blank">Pyry
forest</a> south of Warsaw, on 25 July 1939, handed reconstructed machines and their
methods to French and British intelligence — weeks before the war began.</p>
<p>For about two months from January 1943, <a href="https://en.wikipedia.org/wiki/Alan_Turing" target="_blank">Alan
Turing</a> — who had reported to Bletchley on 4 September 1939, the day after
Britain declared war, and who led the attack on the naval
<a href="https://en.wikipedia.org/wiki/Enigma_machine" target="_blank">Enigma</a> — was at Bell Labs on
<a href="https://en.wikipedia.org/wiki/SIGSALY" target="_blank">SIGSALY</a> secure-speech work. He and Shannon took
tea together, by Shannon's account daily.</p>
<h3>Language, communication, and stochastic walks</h3>
<p>The walk samples each next word in proportion to how often it followed the current word
in the training text. That is all Shannon's model does; there is no temperature or other
sampling knob (those came later, with neural language models). The "Designed" tab rigs
the training text so every word has exactly two choices, to make the branching visible;
the other tabs show what real text looks like, where a word like "the" may have dozens of
continuations.</p>
<p>Shannon's bigram model already made a machine "use language," after a fashion — a small
generative engine — even before the term <i>artificial intelligence</i> was coined, in a
1955 proposal for the 1956 <a href="https://en.wikipedia.org/wiki/Dartmouth_workshop" target="_blank">Dartmouth
summer workshop on artificial intelligence</a> (which Shannon co-authored).</p>
<h3>McCarthy, Shannon, and the “AI”: the brand</h3>
<p>The man who coined <i>artificial intelligence</i>, <a href="https://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist)" target="_blank">John
McCarthy</a> — a Princeton mathematics instructor, having taken his PhD there in 1951 —
spent the summer of 1952 working with Shannon at Bell Labs, where the two went on to co-edit
<i>Automata Studies</i> (Princeton University Press, 1956). In his own account:</p>
<blockquote>
I invented the term artificial intelligence. I invented it because when we were trying to get
money for a summer study, I had a previous bad experience. In 1952 Claude Shannon and I decided
to collect a batch of studies which we hoped would contribute to launching this field, and
Shannon thought that artificial intelligence was too flashy a term and might attract unfavorable
notice. So we agreed to call it <i>Automata studies</i>, and I was terribly disappointed when the
papers we received were about automata, and very few of them had anything to do with the goal
that at least I was interested in. So I decided not to fly any false flags anymore, but to say
that this is study aimed at the long-term goal of achieving human-level intelligence.
<cite>John McCarthy, <a href="https://en.wikipedia.org/wiki/Lighthill_report" target="_blank">Lighthill debate</a>, 1973 (<a href="https://www.youtube.com/watch?v=pyU9pm1hmYs&t=153s" target="_blank">video, from 2:33</a>)</cite>
</blockquote>
<h3>Credits</h3>
<p>Vibecoded/spellcast by Chris Wiggins (<a href="mailto:chris.wiggins@gmail.com">chris.wiggins@gmail.com</a>),
inspired by the work in <a href="https://wwnorton.com/books/how-data-happened" target="_blank"><i>How
Data Happened: A History from the Age of Reason to the Age of Algorithms</i></a> and the course
<a href="https://data-ppf.github.io/" target="_blank"><i>Data: Past, Present, and Future</i></a>,
authored and designed, respectively, with <a href="https://en.wikipedia.org/wiki/Matthew_L._Jones" target="_blank">Matthew L. Jones</a>.</p>
<p>Source code (MIT-licensed) is on GitHub:
<a href="https://github.com/chrishwiggins/shannon-language-model" target="_blank">github.com/chrishwiggins/shannon-language-model</a>.
Clone it and run <code>make</code> to serve the site locally.</p>
<p class="hint" id="lastUpdated">last updated: run the build to stamp the time</p>
</div>
</div>
<div class="source-panel" id="sp-words">
<div class="about-prose">
<h3>Where the words come from</h3>
<p>The "Designed" tab's vocabulary is not random. Its words are drawn from a small canon of
texts about language, machines, and whether fluent output amounts to understanding —
so even the nonsense the model emits carries an echo of that argument.</p>
<ul class="sources">
<li><b>Christopher Strachey's love letters (1952).</b> On the
<a href="https://en.wikipedia.org/wiki/Strachey_love_letter_algorithm" target="_blank">Ferranti
Mark 1 at Manchester</a>, Strachey filled a fixed template — "YOU ARE MY [adjective]
[noun]..." — from word lists drawn from Roget's Thesaurus, signed "M.U.C." It is the
direct ancestor of this demo: a grammatical template filled from pools, twelve years before
ELIZA. The romantic words here (darling, adoring, tender, heart, yearns, adores) are its register.</li>
<li><b>Chomsky, <i>Syntactic Structures</i> (1957).</b> The specimen sentence
<a href="https://en.wikipedia.org/wiki/Colorless_green_ideas_sleep_furiously" target="_blank"><i>colorless
green ideas sleep furiously</i></a> — perfectly grammatical, perfectly meaningless.
Exactly what a bigram chain produces; "colorless," "green," "idea," "sleeps" come from it.</li>
<li><b>Brautigan, <i>All Watched Over by Machines of Loving Grace</i> (1967).</b> The
<a href="https://en.wikipedia.org/wiki/Richard_Brautigan" target="_blank">poem</a>'s vision of
machines and nature in harmony gives "meadow" and "machine."</li>
<li><b>"Daisy Bell" (Harry Dacre, 1892).</b> Sung by an IBM mainframe at Bell Labs in 1961,
the <a href="https://en.wikipedia.org/wiki/Daisy_Bell" target="_blank">first recording of a
computer singing</a> — a touchstone for the whole lineage (the demo cites it by title;
its full public-domain lyric is not used).</li>
<li><b>Weizenbaum, on <a href="https://en.wikipedia.org/wiki/ELIZA" target="_blank">ELIZA</a>
(1976).</b> "What I had not realized is that extremely short exposures to a relatively simple
computer program could induce powerful delusional thinking in quite normal people." A bigram
walk is such a program.</li>
<li><b>Searle, the <a href="https://en.wikipedia.org/wiki/Chinese_room" target="_blank">Chinese
Room</a> (1980).</b> "Syntax is not sufficient for semantics." The model has the syntax (which
word follows which) and none of the semantics (no idea what any of it means).</li>
<li><b>Orwell, <a href="https://en.wikipedia.org/wiki/Politics_and_the_English_Language" target="_blank">"Politics
and the English Language"</a> (1946).</b> As Strunk and White put it in
<a href="https://en.wikipedia.org/wiki/The_Elements_of_Style" target="_blank">The Elements of
Style</a>: to show what happens when strong writing is deprived of its vigor, Orwell took a
passage from Ecclesiastes and drained it of its blood. The result begins "Objective
considerations of contemporary phenomena compel the conclusion that success or failure in
competitive activities exhibits no tendency to be commensurate with innate capacity..." That
is grammar smothering sense, the failure mode this demo makes visible.</li>
</ul>
<h3>Appendix: the words, by source</h3>
<p>The designed tab draws from a fixed pool of words, each evoking one of the sources above. Any
single training text uses only a shuffled slice (its size set by the <kbd>↑</kbd><kbd>↓</kbd>
tokens control), so a given walk shows a subset; raise the token count to see more. That is why a
word like "delusional" or "semantics" appears only sometimes.</p>
<ul class="sources">
<li><b>Chomsky</b> (<i>colorless green ideas sleep furiously</i>): colorless, green, idea, sleeps</li>
<li><b>Brautigan</b> (<i>All Watched Over...</i>): cybernetic, meadow, loving; and the words "machine," "the," "and"</li>
<li><b>White / Orwell</b> (the Ecclesiastes parody, quoted in <i>The Elements of Style</i>): objective, machine; and the function words this, every, that, and, yet</li>
<li><b>McCarthy / Dartmouth</b> (the 1955 proposal): intelligent, abstract, intelligence, conjecture, concept, language, simulates, reasons; and some, each, then</li>
<li><b>Weizenbaum</b> (the ELIZA "delusional thinking" line): delusional, program</li>
<li><b>Searle</b> (the Chinese Room): formal, syntax, semantics</li>
<li><b>Strachey</b> (his love-letter word lists): tender, wistful, passionate, darling, heart, yearns, adores, loves, treasures, woos</li>
<li><b>prepositions</b> (for the "natural" strategy's prepositional phrases, each verbatim in the sources above): in, of, with</li>
</ul>
<p class="note">Every word the demo can emit is verbatim from one of these sources; there are no
invented filler words. (Some words appear in more than one source, e.g. "machine.")</p>
<p class="note">The words are slotted by true part of speech so the lattice still composes into
grammatical clauses; the verbs are third person singular.</p>
</div>
</div>
<div class="source-panel" id="sp-sources">
<div class="about-prose">
<h3>References</h3>
<ul class="sources">
<li>A. A. Markov, "An Example of Statistical Investigation of the Text <i>Eugene Onegin</i> Concerning the Connection of Samples in Chains," lecture 23 Jan 1913 (Eng. trans. <i>Science in Context</i> 19(4), 2006). <a href="https://www.americanscientist.org/article/first-links-in-the-markov-chain" target="_blank">overview</a></li>
<li>C. E. Shannon, <i>A Mathematical Theory of Cryptography</i> (classified Bell Labs memo, 1 Sep 1945). <a href="https://www.iacr.org/museum/shannon45.html" target="_blank">IACR scan</a></li>
<li>C. E. Shannon, <a href="https://en.wikipedia.org/wiki/A_Mathematical_Theory_of_Communication" target="_blank"><i>A Mathematical Theory of Communication</i></a> (Bell System Technical Journal, 1948).</li>
<li>A. Hodges, <i>Alan Turing: The Enigma</i> (1983) — the source for <a href="https://en.wikipedia.org/wiki/Alan_Turing" target="_blank">Turing</a>'s stay at Bell Labs from January 1943, consulting on the <a href="https://en.wikipedia.org/wiki/SIGSALY" target="_blank">SIGSALY</a> speech-encryption system and taking tea with Shannon: the wartime link between the <a href="https://en.wikipedia.org/wiki/Bletchley_Park" target="_blank">Bletchley Park</a> codebreaking effort and Bell Labs.</li>
<li>Polish Cipher Bureau — <a href="https://en.wikipedia.org/wiki/Marian_Rejewski" target="_blank">Rejewski</a>, <a href="https://en.wikipedia.org/wiki/Henryk_Zygalski" target="_blank">Zygalski</a>, <a href="https://en.wikipedia.org/wiki/Jerzy_R%C3%B3%C5%BCycki" target="_blank">Różycki</a>; <a href="https://en.wikipedia.org/wiki/AVA_Radio_Company" target="_blank">AVA Radio Company</a>; the <a href="https://www.gchq.gov.uk/information/the-pyry-forest-meeting" target="_blank">Pyry forest meeting</a>, 25 Jul 1939.</li>
<li>N. Chomsky, <i>Syntactic Structures</i> (1957) — the example sentence <a href="https://en.wikipedia.org/wiki/Colorless_green_ideas_sleep_furiously" target="_blank">"colorless green ideas sleep furiously"</a>.</li>
<li>R. Brautigan, <i>All Watched Over by Machines of Loving Grace</i> (1967). <a href="https://en.wikipedia.org/wiki/Richard_Brautigan" target="_blank">author</a></li>
<li>The 1955 proposal for the <a href="https://en.wikipedia.org/wiki/Dartmouth_workshop" target="_blank">Dartmouth Summer Research Project on Artificial Intelligence</a> (McCarthy, Minsky, Rochester, Shannon).</li>
<li>J. McCarthy, <i>Automata Studies</i> (co-edited with C. E. Shannon; Princeton University Press, 1956), and McCarthy's account of coining "artificial intelligence" after their 1952 Bell Labs collaboration, from the <a href="https://en.wikipedia.org/wiki/Lighthill_report" target="_blank">Lighthill debate</a>, 1973 (<a href="https://www.youtube.com/watch?v=pyU9pm1hmYs&t=153s" target="_blank">video, from 2:33</a>).</li>
<li>"Daisy Bell" (Harry Dacre, 1892), sung by an IBM mainframe at Bell Labs, 1961. <a href="https://en.wikipedia.org/wiki/Daisy_Bell" target="_blank">Wikipedia</a></li>
<li>J. Weizenbaum, <i>Computer Power and Human Reason</i> (1976); <a href="https://en.wikipedia.org/wiki/Joseph_Weizenbaum" target="_blank">Weizenbaum</a>, <a href="https://en.wikipedia.org/wiki/ELIZA" target="_blank">ELIZA</a>.</li>
<li>M. Kranzberg, "Technology and History: Kranzberg's Laws," <i>Technology and Culture</i> (1986). <a href="https://en.wikipedia.org/wiki/Melvin_Kranzberg" target="_blank">Kranzberg</a></li>
</ul>
</div>
</div>
<div class="wrap">
<!-- graph-above-text layout: the bigram graph and the generative output sit at
the top, where the reader watches. The control knobs move to the bottom so
they do not compete for attention while words are being generated. The
keyboard shortcuts live in each panel's heading, not a separate strip. -->
<section class="panel full" id="graphpanel">
<h2>Trained language model <span id="graphHeadDesigned">(<kbd>T</kbd> to randomize); each column is a part of speech</span></h2>
<div id="graphwrap"></div>
<div class="legend">
<span><i style="background:var(--accent)"></i>current word</span>
<span><i style="background:var(--opt0)"></i>choice 0</span>
<span><i style="background:var(--opt1)"></i>choice 1</span>
<span><i style="background:var(--stop)"></i>STOP (hidden token)</span>
</div>
</section>
<section class="panel">
<h2>Generated language (<kbd class="keytap" data-act="step" role="button" tabindex="0" title="Next word">↵</kbd> for next, <kbd class="keytap" data-act="play" role="button" tabindex="0" title="Play / pause">space</kbd> to play/pause, <kbd class="keytap" data-act="slower" role="button" tabindex="0" title="Slower">←</kbd><kbd class="keytap" data-act="faster" role="button" tabindex="0" title="Faster">→</kbd> for slower, faster)</h2>
<div id="output"></div>
<h2 style="margin-top:16px">Next-word choice</h2>
<div id="branch"></div>
<div class="note">Bright word = where we are. The chips are its choices in the graph; one is sampled.</div>
</section>
<section class="panel">
<h2>Training text<span id="trainKeys"> (<kbd>T</kbd> to randomize, <kbd>↑</kbd><kbd>↓</kbd> tokens: fewer, more)</span></h2>
<div id="training"></div>
<div class="note" id="trnote"></div>
</section>
<section class="panel full">
<h2>Self-check — out-degrees recomputed from the displayed text</h2>
<p class="note" style="margin-top:0">A property of the <b>whole training text above</b>, computed once when the text
is generated. It does not change as the walk steps; it is checking the text, not your current position.
<b>Out-degree</b> = how many different words follow a given word. The check rebuilds the bigram graph straight from
the displayed tokens and confirms every word has the out-degree the design promises (in the Designed tabs, two).</p>
<div id="verdict"></div>
<div class="histwrap">
<span class="histaxis histaxis-y">how many<br>words</span>
<div class="hist" id="hist"></div>
</div>
<div class="histaxis histaxis-x">out-degree (number of distinct next-words) →</div>
<div id="vtable"></div>
</section>
<section class="panel full" id="ctrlpanel">
<div id="controls">
<button id="play" class="primary" title="Play / pause (Space)">Play the walk</button>
<button id="step" title="Step one word (Enter)">Step one word</button>
<button id="reset" title="Reset the walk (R)">Reset</button>
<button id="regen" title="New training text (T)">Randomize text</button>
<label>Strategy
<select id="strategy">
<option value="A">lattice (strict k=2)</option>
<option value="M">mixed (k = 2 or 3)</option>
<option value="P">prose (objects + conjunctions)</option>
<option value="N" selected>natural (optional adjectives + prepositions)</option>
<option value="F">free function words</option>
</select>
</label>
<!-- Speed and token-count are driven by the arrow keys; these on-screen
buttons are the click/touch fallback (they call the same nudge fns).
Values live in hidden inputs so existing reads keep working. -->
<input type="hidden" id="lenSlider" value="2">
<input type="hidden" id="speed" value="650">
<span class="nudgegroup" id="tokenNudge"><span class="nudgelabel">tokens</span><button id="tokDown" title="Fewer tokens (Down arrow)">−</button><button id="tokUp" title="More tokens (Up arrow)">+</button></span>
<span class="nudgegroup"><span class="nudgelabel">speed</span><button id="spdDown" title="Slower (Left arrow)">−</button><button id="spdUp" title="Faster (Right arrow)">+</button></span>
</div>
</section>
</div>
<script>
/* Password gate disabled: the site is public, so the page is never locked.
(The gate was client-side obfuscation only. Left as a no-op rather than
deleted so it is easy to restore if the site ever needs to be sealed again.) */
</script>
<script>
"use strict";
/* =====================================================================
Deterministic PRNG (so a given "New training text" is reproducible
within a session, and Date.now is avoided per environment rules).
===================================================================== */
function mulberry32(a) {
return function () {
a |= 0; a = (a + 0x6D2B79F5) | 0;
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
/* =====================================================================
POS POOLS (disjoint -> each surface string lives in one slot only,
which is what kills the out-degree aggregation trap)
===================================================================== */
// Vocabulary chosen to echo two touchstones in the history of language and
// machines: Chomsky's "colorless green ideas sleep furiously" (Syntactic
// Structures, 1957 -- a sentence that parses but means nothing) and Brautigan's
// poem "All Watched Over by Machines of Loving Grace" (1967), whose imagery of
// machines and nature in harmony the noun pool nods to. The lattice cycles
// DET -> ADJ -> NOUN -> VERB, so the generated text reads as grammatical but
// surreal lines in that spirit, e.g. "the colorless meadow dreams."
// Word pools, slotted by true part of speech so the lattice (DET -> ADJ -> NOUN
// -> VERB, cycling) composes into sentences that PARSE: "the green machine
// dreams. then this tender daisy sleeps." The part-of-speech grouping is only an
// authoring device for writing a training text that is both grammatical AND
// exactly k=2 per word; the bigram model itself knows nothing of grammar. The
// determiners all read before any adjective (no bare "a", so no a/an agreement
// to handle); the verbs are intransitive and third-person singular, agreeing
// with the singular noun. Vocabulary keeps the Chomsky/Brautigan/Strachey
// register (see the Word sources tab).
// Word pools drawn from the full set of touchstones in the Word sources tab, not
// just Chomsky/Brautigan. Each entry is a generic English word evoking a source:
// EVERY word below is verbatim in a named source text (verified against the
// actual texts; see ref/word-sources/ in the repo). No made-up filler.
// Chomsky, "colorless green ideas sleep furiously": colorless, green, idea, sleeps
// Brautigan, "All Watched Over...": cybernetic, meadow, loving, the, and
// White (quoting Orwell's Ecclesiastes parody): objective, machine, this, every,
// that, yet -- and the conjunctions
// Dartmouth 1955 proposal: intelligent, abstract, intelligence, conjecture,
// concept, language, simulates, reasons, some, each, then
// Weizenbaum (the ELIZA "delusional thinking" quote): delusional, program
// Searle (Chinese Room): formal, syntax, semantics
// Strachey's love-letter word lists (gingerbeardman/loveletter): tender, wistful,
// passionate, darling, heart, yearns, adores, loves, treasures, woos
// Slotted by true part of speech so the lattice still composes into grammatical
// clauses; verbs are third-person singular.
const POS_POOLS = {
DET: ["the", "this", "every", "some", "each", "that"],
ADJ: ["colorless", "green", "cybernetic", "objective", "intelligent", "abstract",
"formal", "delusional", "tender", "loving", "wistful", "passionate"],
NOUN: ["machine", "meadow", "idea", "language", "intelligence", "conjecture",
"program", "syntax", "semantics", "concept", "darling", "heart"],
VERB: ["sleeps", "simulates", "reasons", "yearns", "adores", "loves", "treasures", "woos"],
// sentence openers (successors of the period) and the period token itself
OPEN: ["then", "and", "yet"],
// prepositions for the "natural" strategy's optional prepositional phrase. Each is
// verbatim in a saved source (in: Dartmouth/White/Brautigan; of: same; with:
// White/Brautigan) -- see ref/word-sources/. No invented function words.
PREP: ["in", "of", "with"],
END_PUNCT: "."
};
const PERIOD = POS_POOLS.END_PUNCT;
const STOP = "␃"; // internal STOP marker (Symbol-for-end-of-text), never displayed as a word
/* =====================================================================
STRATEGY A: cyclic grammatical lattice with unique vocab.
Returns { tokens, designed } where
tokens = array of emitted training tokens (the displayed text)
designed = Map word -> [successors...] (the intended graph; the
verifier re-derives the empirical one independently)
===================================================================== */
function buildStrategyA(rng, width) {
const TEMPLATE = ["DET", "ADJ", "NOUN", "VERB"]; // one clause; cycles back to DET
// WIDTH = words per grammar slot. More words per column => bigger vocabulary,
// more edges, and a longer covering walk (the "Length" slider). Pools cap it
// at the smallest content pool (DET/VERB have 8), so 2..8 is the safe range.
const WIDTH = Math.max(2, Math.min(width || 4, 8));
const C = TEMPLATE.length;
// --- fill columns with globally-unique words ---
const used = new Set();
function drawUnique(pos, n) {
const pool = POS_POOLS[pos].filter(w => !used.has(w));
shuffle(pool, rng);
const picked = pool.slice(0, n);
picked.forEach(w => used.add(w));
return picked;
}
const columns = TEMPLATE.map(pos => drawUnique(pos, WIDTH)); // C columns x WIDTH words
const openers = (function () { const o = POS_POOLS.OPEN.slice(); shuffle(o, rng); return o.slice(0, 2); })();
openers.forEach(w => used.add(w));
// --- 2-out index map S_k -> S_{(k+1) mod C} : succ(i) = {2i, 2i+1} mod m ---
const designed = new Map();
for (let k = 0; k < C; k++) {
const cur = columns[k];
const nxt = columns[(k + 1) % C];
const m = nxt.length;
cur.forEach((w, i) => {
designed.set(w, [ nxt[(2 * i) % m], nxt[(2 * i + 1) % m] ]);
});
}
// --- terminating set: the VERB column (last slot of a clause). The PERIOD
// "." is the VISIBLE end-of-sequence token (the model's EOS). A verb can
// end a sentence, so each verb's successor set is exactly its 2 real
// DET successors PLUS the period: out-degree 3. This is the "k=3 for the
// pre-image of END" structure -- the period plays the role of END, shown
// in the text rather than hidden. Every NON-terminating word stays at
// exactly 2. The period itself is a normal k=2 node pointing to the two
// sentence openers, which point back into the first DET column, closing
// the cycle so the graph is strongly connected and edge-coverable. */
const verbs = columns[C - 1];
verbs.forEach(v => {
const real = designed.get(v).slice(0, 2); // 2 real successors (next-clause DETs)
designed.set(v, [ real[0], real[1], PERIOD ]); // verbs are k=3: 2 real + period
});
// period: k=2, points to the two openers (this is the EOS->next-sentence map)
designed.set(PERIOD, openers.slice());
// openers: k=2, point into the first DET column (indices 0,1)
openers.forEach((op, i) => {
designed.set(op, [ columns[0][(2 * i) % columns[0].length], columns[0][(2 * i + 1) % columns[0].length] ]);
});
// --- emit the displayed training text: a covering walk over the designed graph
// that traverses every edge at least once (Guan-route augmentation +
// Eulerian circuit; see coveringWalkEulerian). A verb->period step emits ".",
// and period->opener starts a fresh sentence, so the text reads as sentences.
const tokens = emitCoveringText_A(columns, openers, designed, rng);
const meta = {
terminating: new Set(verbs),
openers, columns, period: PERIOD, template: TEMPLATE,
startWord: columns[0][0]
};
return { tokens, designed, meta };
}
// =====================================================================
// STRATEGY F: FREE FUNCTION WORDS. Content words (ADJ/NOUN/VERB) keep out-degree
// 2; the function words -- determiners, the period, the openers -- are allowed to
// branch to MANY successors, which is what gives real English its connective
// tissue. This reads the most naturally and is the most honest about how real
// bigram graphs look (function words are high out-degree, content words low).
// The verifier reports the true distribution rather than asserting a flat k=2.
// =====================================================================
function buildStrategyF(rng, width) {
const WIDTH = Math.max(3, Math.min((width || 4) + 1, 8));
const used = new Set();