-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsilk-codec.html
More file actions
657 lines (618 loc) · 43.3 KB
/
silk-codec.html
File metadata and controls
657 lines (618 loc) · 43.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latent Space Learning — Silk Docs</title>
<link rel="stylesheet" href="css/shared.css">
<style>
.chapter-num{font-family:'Fragment Mono',monospace;font-size:0.7rem;letter-spacing:0.15em;color:var(--text-muted);margin-bottom:0.5rem;display:block;}
.visual-break{height:2px;background:linear-gradient(90deg,var(--border),transparent);margin:3rem 0;}
.arch-step{display:grid;grid-template-columns:80px 1fr;gap:1.5rem;margin:2rem 0;align-items:start;}
.arch-num{width:56px;height:56px;border-radius:50%;background:#f2f0ed;display:flex;align-items:center;justify-content:center;font-family:'Fragment Mono',monospace;font-size:1.2rem;font-weight:700;color:var(--text);flex-shrink:0;}
.arch-content h4{font-size:1.05rem;margin-bottom:0.5rem;margin-top:0;}
.arch-content p{font-size:0.9rem;color:var(--text-muted);}
.mae-grid{display:grid;grid-template-columns:repeat(20,1fr);gap:4px;margin:1rem 0;}
.mae-cell{aspect-ratio:1;border-radius:4px;transition:all 0.4s ease;font-family:'Fragment Mono',monospace;font-size:0.7rem;display:flex;align-items:center;justify-content:center;color:rgba(255,255,255,0.7);}
.mae-cell.visible{background:rgba(45,138,78,0.4);border:1px solid rgba(45,138,78,0.6);}
.mae-cell.masked{background:rgba(100,100,120,0.2);border:1px solid rgba(100,100,120,0.3);}
.mae-cell.predicted{background:rgba(45,138,78,0.4);border:1px solid rgba(45,138,78,0.6);animation:popIn 0.3s ease;}
@keyframes popIn{0%{transform:scale(0.5);opacity:0;}100%{transform:scale(1);opacity:1;}}
</style>
</head>
<body>
<aside class="sidebar">
<div class="sidebar-progress"><div class="sidebar-progress-fill"></div></div>
<div class="sidebar-rail">
<div class="sidebar-brand">S</div>
<nav>
<a href="index.html" data-page="index.html" data-num="01" title="How Voice AI Works"><span class="pip-tooltip">How Voice AI Works</span></a>
<a href="how-codecs-work.html" data-page="how-codecs-work.html" data-num="02" title="How Codecs Work"><span class="pip-tooltip">How Codecs Work</span></a>
<a href="silk-codec.html" data-page="silk-codec.html" data-num="03" title="Latent Space Learning"><span class="pip-tooltip">Latent Space Learning</span></a>
<a href="voice-ai-pipeline.html" data-page="voice-ai-pipeline.html" data-num="04" title="Voice AI Pipeline"><span class="pip-tooltip">Voice AI Pipeline</span></a>
<a href="comparison.html" data-page="comparison.html" data-num="05" title="Silk vs The World"><span class="pip-tooltip">Silk vs The World</span></a>
<a href="geometry.html" data-page="geometry.html" data-num="06" title="Why It Works"><span class="pip-tooltip">Why It Works</span></a>
<div class="quiz-pip"><a href="quiz.html" data-page="quiz.html" data-num="?" title="Test Yourself"><span class="pip-tooltip">Test Yourself</span></a></div>
</nav>
</div>
<div class="sidebar-panel">
<div class="sidebar-logo"><h2>Silk</h2><span>internal briefing</span></div>
<nav>
<a href="index.html" data-page="index.html"><span class="nav-num">01</span> How Voice AI Works</a>
<a href="how-codecs-work.html" data-page="how-codecs-work.html"><span class="nav-num">02</span> How Codecs Work</a>
<a href="silk-codec.html" data-page="silk-codec.html"><span class="nav-num">03</span> Latent Space Learning</a>
<a href="voice-ai-pipeline.html" data-page="voice-ai-pipeline.html"><span class="nav-num">04</span> Voice AI Pipeline</a>
<a href="comparison.html" data-page="comparison.html"><span class="nav-num">05</span> Silk vs The World</a>
<a href="geometry.html" data-page="geometry.html"><span class="nav-num">06</span> Why It Works</a>
<div class="quiz-link"><a href="quiz.html" data-page="quiz.html"><span class="nav-num">?</span> Test Yourself</a></div>
</nav>
</div>
</aside>
<main class="main-content">
<div class="page-content">
<span class="chapter-num">rmk-silk-003 · page 02</span>
<h1>latent space learning</h1>
<p class="subtitle">silk rests on three breakthroughs: <strong>latent space learning (LSL)</strong> — a network that discovers the physics of sound on its own. a <strong>codec architecture</strong> built on that continuous space instead of a fixed codebook. and a <strong>2.5 Hz frame rate</strong> that produces 47.5 tokens/sec — 12× fewer than the next best codec.</p>
<!-- ============ WHAT IS LSL ============ -->
<h2>what is latent space learning?</h2>
<p>every other codec starts with a fixed vocabulary of sounds and tries to make it bigger or faster. LSL takes the opposite approach: let the network discover its own representation. the encoder and 8 Conformer blocks learn a 128-dimensional continuous space where volume, pitch, and timbre emerge as geometric structure. no codebook. no fixed vocabulary. just physics.</p>
<!-- LATENT SPACE VISUAL EXPLAINER -->
<div class="interactive-block fade-in">
<h3 style="margin-bottom:0.5rem;">what does a latent space look like?</h3>
<p class="description" style="font-size:0.95rem;max-width:660px;">a latent space is a map the network builds internally. every sound gets a position. similar sounds end up nearby. the network figures out this organization on its own — nobody designs it.</p>
<div style="background:var(--bg);border-radius:var(--radius-md);padding:1.5rem;margin:1.5rem 0;">
<div style="font-family:'Fragment Mono',monospace;font-size:0.85rem;font-weight:600;color:var(--text);margin-bottom:1rem;">how the space organizes itself:</div>
<div style="display:grid;grid-template-columns:repeat(3,1fr);gap:1rem;">
<div style="text-align:center;">
<div style="background:#1a1a2e;border-radius:var(--radius-md);padding:1rem;margin-bottom:0.5rem;aspect-ratio:1;display:flex;align-items:center;justify-content:center;">
<svg viewBox="0 0 180 180" style="width:100%;height:auto;max-width:160px;">
<circle cx="90" cy="90" r="80" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
<circle cx="90" cy="90" r="52" fill="none" stroke="rgba(255,255,255,0.08)" stroke-width="1"/>
<circle cx="90" cy="90" r="24" fill="none" stroke="rgba(255,255,255,0.06)" stroke-width="1"/>
<circle cx="82" cy="86" r="7" fill="#2d8a4e" opacity="0.8"/>
<text x="82" y="76" text-anchor="middle" fill="rgba(255,255,255,0.7)" font-size="12" font-weight="600" font-family="Fragment Mono">quiet</text>
<circle cx="148" cy="40" r="9" fill="#888" opacity="0.8"/>
<text x="148" y="28" text-anchor="middle" fill="rgba(255,255,255,0.7)" font-size="12" font-weight="600" font-family="Fragment Mono">LOUD</text>
<line x1="90" y1="90" x2="140" y2="45" stroke="rgba(255,255,255,0.2)" stroke-width="1" stroke-dasharray="4,3"/>
</svg>
</div>
<div style="font-weight:600;font-size:0.8rem;margin-bottom:0.2rem;">distance = volume</div>
<div style="font-size:0.75rem;color:var(--text-muted);line-height:1.5;">louder sounds are farther from the center. whispers are close to the origin.</div>
</div>
<div style="text-align:center;">
<div style="background:#1a1a2e;border-radius:var(--radius-md);padding:1rem;margin-bottom:0.5rem;aspect-ratio:1;display:flex;align-items:center;justify-content:center;">
<svg viewBox="0 0 180 180" style="width:100%;height:auto;max-width:160px;">
<line x1="90" y1="90" x2="90" y2="15" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
<line x1="90" y1="90" x2="165" y2="90" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
<line x1="90" y1="90" x2="90" y2="165" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
<line x1="90" y1="90" x2="15" y2="90" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
<circle cx="90" cy="28" r="7" fill="#e88a6a" opacity="0.8"/>
<text x="110" y="32" fill="rgba(255,255,255,0.7)" font-size="12" font-weight="600" font-family="Fragment Mono">high ↑</text>
<circle cx="90" cy="152" r="7" fill="#5b7fb5" opacity="0.8"/>
<text x="110" y="156" fill="rgba(255,255,255,0.7)" font-size="12" font-weight="600" font-family="Fragment Mono">low ↓</text>
<circle cx="145" cy="58" r="7" fill="#d4a053" opacity="0.8"/>
<text x="145" y="80" text-anchor="middle" fill="rgba(255,255,255,0.7)" font-size="12" font-weight="600" font-family="Fragment Mono">mid →</text>
</svg>
</div>
<div style="font-weight:600;font-size:0.8rem;margin-bottom:0.2rem;">direction = pitch</div>
<div style="font-size:0.75rem;color:var(--text-muted);line-height:1.5;">different pitches point in different directions. soprano vs bass = different angles in the space.</div>
</div>
<div style="text-align:center;">
<div style="background:#1a1a2e;border-radius:var(--radius-md);padding:1rem;margin-bottom:0.5rem;aspect-ratio:1;display:flex;align-items:center;justify-content:center;">
<svg viewBox="0 0 180 180" style="width:100%;height:auto;max-width:160px;">
<circle cx="55" cy="60" r="28" fill="rgba(136,136,136,0.15)" stroke="rgba(136,136,136,0.3)" stroke-width="1"/>
<circle cx="48" cy="56" r="6" fill="#888" opacity="0.7"/>
<circle cx="62" cy="64" r="5" fill="#888" opacity="0.5"/>
<circle cx="52" cy="52" r="5" fill="#888" opacity="0.6"/>
<text x="55" y="96" text-anchor="middle" fill="rgba(255,255,255,0.7)" font-size="13" font-weight="600" font-family="Fragment Mono">violin</text>
<circle cx="128" cy="115" r="28" fill="rgba(45,138,78,0.15)" stroke="rgba(45,138,78,0.3)" stroke-width="1"/>
<circle cx="124" cy="112" r="6" fill="#2d8a4e" opacity="0.7"/>
<circle cx="136" cy="118" r="5" fill="#2d8a4e" opacity="0.5"/>
<circle cx="126" cy="122" r="5" fill="#2d8a4e" opacity="0.6"/>
<text x="128" y="150" text-anchor="middle" fill="rgba(255,255,255,0.7)" font-size="13" font-weight="600" font-family="Fragment Mono">voice</text>
<line x1="75" y1="78" x2="108" y2="98" stroke="rgba(255,255,255,0.15)" stroke-width="1" stroke-dasharray="4,3"/>
<text x="98" y="82" fill="rgba(255,255,255,0.35)" font-size="10" font-family="Fragment Mono">different</text>
</svg>
</div>
<div style="font-weight:600;font-size:0.8rem;margin-bottom:0.2rem;">region = timbre</div>
<div style="font-size:0.75rem;color:var(--text-muted);line-height:1.5;">different instruments/voices live in different neighborhoods. similar timbres cluster together.</div>
</div>
</div>
</div>
<div style="padding:1rem 1.5rem;background:var(--accent-light);border-radius:var(--radius-md);border-left:3px solid var(--accent);margin-top:1rem;">
<p style="font-size:0.95rem;margin:0;line-height:1.6;">these mappings aren't designed. the network discovers that volume, pitch, and timbre are the most efficient way to organize sound — so it converges on the physics of audio production.</p>
</div>
</div>
<!-- Discrete vs Continuous — large animated comparison -->
<div class="interactive-block fade-in">
<h3 style="margin-bottom:0.5rem;">discrete codebook vs continuous latent space</h3>
<p class="description" style="font-size:0.95rem;">this is the fundamental difference between every other codec and Silk.</p>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:2rem;margin:1.5rem 0;">
<div>
<div style="font-family:'Fragment Mono',monospace;font-size:0.85rem;font-weight:600;color:var(--error);margin-bottom:0.75rem;text-align:center;">discrete codebook (every other codec)</div>
<div style="background:#1a1a2e;border-radius:var(--radius-md);overflow:hidden;border:2px solid rgba(196,64,64,0.3);">
<canvas id="viz-discrete" height="280" style="display:block;width:100%;"></canvas>
</div>
<div style="font-size:0.85rem;color:var(--text-muted);margin-top:0.75rem;line-height:1.6;text-align:center;">fixed pins in space. sounds snap to nearest pin. <strong style="color:var(--error);">anything between pins is lost.</strong></div>
</div>
<div>
<div style="font-family:'Fragment Mono',monospace;font-size:0.85rem;font-weight:600;color:var(--success);margin-bottom:0.75rem;text-align:center;">continuous latent space (Silk)</div>
<div style="background:#1a1a2e;border-radius:var(--radius-md);overflow:hidden;border:2px solid rgba(45,138,78,0.3);">
<canvas id="viz-continuous" height="280" style="display:block;width:100%;"></canvas>
</div>
<div style="font-size:0.85rem;color:var(--text-muted);margin-top:0.75rem;line-height:1.6;text-align:center;">smooth gradient field. every point is valid. <strong style="color:var(--success);">sounds land exactly where they belong.</strong></div>
</div>
</div>
</div>
<p>the network organizes this space during training. what emerges:</p>
<ul style="margin:1rem 0 1rem 1.5rem;line-height:2;">
<li><strong>volume</strong> maps to magnitude (distance from origin)</li>
<li><strong>pitch</strong> maps to direction (angle in latent space)</li>
<li><strong>timbre</strong> maps to subspace structure (which dimensions are active)</li>
</ul>
<p>these patterns show up because they reflect how sound actually works physically. the network doesn't memorize english sounds — it picks up on the geometry of audio production.</p>
<!-- Interactive latent space -->
<div class="interactive-block fade-in">
<h3>interactive: the latent space in action</h3>
<p class="description" style="font-size:0.9rem;">each dot is a sound encoded by Silk. hover to see what it represents. similar sounds cluster by physics, not language.</p>
<div style="background:#1a1a2e;border-radius:var(--radius-md);position:relative;overflow:hidden;">
<canvas id="latent-field" height="400" style="display:block;width:100%;cursor:crosshair;"></canvas>
<div id="field-tooltip" style="display:none;position:absolute;background:rgba(0,0,0,0.9);color:#fff;padding:0.6rem 1rem;border-radius:8px;font-family:'Fragment Mono',monospace;font-size:0.8rem;pointer-events:none;z-index:10;white-space:nowrap;"></div>
</div>
<div style="display:flex;justify-content:center;gap:2rem;margin-top:1rem;font-size:0.85rem;">
<span style="color:#888;">● vowels</span>
<span style="color:#5b7fb5;">● consonants</span>
<span style="color:#2d8a4e;">● mandarin tones</span>
<span style="color:#d4a053;">● arabic pharyngeals</span>
</div>
</div>
<div class="visual-break"></div>
<!-- ============ THE SILK CODEC ============ -->
<span class="chapter-num">the implementation</span>
<h2 style="border:none;padding:0;margin-top:0;">the Silk Codec</h2>
<p>LSL is the insight. the Silk Codec is the architecture built on top of it. here's how the learned latent space becomes a working codec.</p>
<div class="interactive-block fade-in">
<h3>data flow: audio → latent space → tokens</h3>
<p class="description">the encoder compresses audio into the learned latent space (128 continuous dimensions). Conformer blocks refine it. only then does FSQ quantize to 19 token groups per frame.</p>
<div class="process-flow" id="silk-pipeline">
<div class="pf-node"><div class="pf-box">audio</div><div class="pf-sub">24kHz waveform</div></div>
<div class="pf-arrow">→</div>
<div class="pf-data">[T samples]</div>
<div class="pf-arrow">→</div>
<div class="pf-node"><div class="pf-box highlight">encoder</div><div class="pf-sub">conv + 8 conformer</div></div>
<div class="pf-arrow">→</div>
<div class="pf-node"><div class="pf-box green">latent space</div><div class="pf-sub">128D continuous</div></div>
<div class="pf-arrow">→</div>
<div class="pf-data">[T' × 128]</div>
<div class="pf-arrow">→</div>
<div class="pf-node"><div class="pf-box green">FSQ</div><div class="pf-sub">quantization</div></div>
<div class="pf-arrow">→</div>
<div class="pf-data">[T' × 19 groups]</div>
<div class="pf-arrow">→</div>
<div class="pf-node"><div class="pf-box highlight">decoder</div><div class="pf-sub">conv + iSTFT</div></div>
<div class="pf-arrow">→</div>
<div class="pf-data">[T samples]</div>
<div class="pf-arrow">→</div>
<div class="pf-node"><div class="pf-box">audio</div><div class="pf-sub">reconstructed</div></div>
</div>
</div>
<!-- Step-by-step architecture -->
<div class="arch-step fade-in">
<div class="arch-num">1</div>
<div class="arch-content">
<h4>raw audio → encoder → continuous latent space</h4>
<p>the encoder takes raw waveform directly — <strong>[B, 1, T_wav]</strong>. Conv1d layers with strided downsampling compress raw audio into the continuous latent space — 128-dimensional vectors where every value is a smooth floating-point number. output: <strong>[T' × 128]</strong>.</p>
</div>
</div>
<div class="arch-step fade-in">
<div class="arch-num">2</div>
<div class="arch-content">
<h4>8 Conformer blocks</h4>
<p>the 128-dimensional continuous vectors are processed by <strong>8 <span class="term" data-term="conformer">Conformer</span> blocks</strong>. during Stage 1 training, <strong><span class="term" data-term="masking">latent space learning</span></strong> masks ~50% of frames and predicts them in latent space (not input space). this is what forces the network to learn deep audio structure rather than memorize patterns.</p>
<div style="background:#1a1a2e;border-radius:var(--radius-lg);padding:2rem 1.5rem;margin:1rem 0;">
<svg id="silk-nn-svg" viewBox="0 0 700 260" style="width:100%;height:auto;display:block;">
<text x="60" y="20" text-anchor="middle" fill="rgba(100,100,100,0.6)" font-size="11" font-weight="600" font-family="Fragment Mono">128 dims in</text>
<text x="350" y="20" text-anchor="middle" fill="rgba(255,255,255,0.4)" font-size="11" font-family="Fragment Mono">8 conformer blocks</text>
<text x="640" y="20" text-anchor="middle" fill="rgba(45,138,78,0.6)" font-size="11" font-weight="600" font-family="Fragment Mono">128 dims out</text>
</svg>
</div>
<div style="display:flex;justify-content:space-between;font-family:'Fragment Mono',monospace;font-size:0.85rem;color:var(--text-light);margin-top:0.75rem;">
<span>128 continuous dims in</span>
<span style="color:var(--text-muted);">→ 8 conformer blocks →</span>
<span style="color:var(--text);">128 continuous dims out</span>
</div>
</div>
</div>
<div class="arch-step fade-in">
<div class="arch-num">3</div>
<div class="arch-content">
<h4>latent space → FSQ (Finite Scalar Quantization)</h4>
<p>this is where the continuous latent space becomes discrete tokens. <span class="term" data-term="fsq">FSQ</span> rounds each of the 128 latent dimensions to one of <strong>8 levels</strong>, producing <strong>19 packed token groups per frame</strong>. unlike <span class="term" data-term="rvq">RVQ</span> which snaps entire vectors to codebook entries, FSQ quantizes each dimension independently — preserving far more of the learned latent structure.</p>
</div>
</div>
<div class="arch-step fade-in">
<div class="arch-num">4</div>
<div class="arch-content">
<h4>decoder → reconstructed audio</h4>
<p>the decoder mirrors the encoder, reconstructing the waveform from quantized representations. output should sound identical to the input.</p>
</div>
</div>
<div class="callout insight fade-in">
<div class="callout-title">FSQ vs RVQ</div>
<p>in every other codec, <span class="term" data-term="rvq">RVQ</span> snaps entire vectors to codebook entries. Silk uses <strong><span class="term" data-term="fsq">FSQ</span></strong> — the latent space is learned first through LSL, then FSQ quantizes each dimension independently to 8 levels. this preserves far more information because the continuous structure is learned <strong>before</strong> quantization happens.</p>
</div>
<div class="visual-break"></div>
<!-- ============ HOW IT TRAINS ============ -->
<span class="chapter-num">training</span>
<h2 style="border:none;padding:0;margin-top:0;">how LSL trains</h2>
<p>the Silk Codec's core training approach: take a sequence of latent frames, randomly hide ~50% of them, and ask the network to predict the hidden ones <strong>in latent space</strong> (not input space). this is what makes the Silk Codec learn the physics of sound rather than memorizing patterns.</p>
<p>this forces the network to learn deep relationships between audio frames — it can't just memorize, it has to <strong>understand the structure of sound.</strong></p>
<div class="interactive-block fade-in">
<h3>interactive: latent space learning — masking simulation</h3>
<p class="description">click "mask & predict" to see the training process. green = visible frames. gray = masked (hidden). orange = predicted by the network.</p>
<div style="text-align:center;margin-bottom:1rem;">
<button id="mae-run" style="padding:0.5rem 1.5rem;background:var(--accent);color:#fff;border:none;border-radius:var(--radius-sm);font-family:'Fragment Mono',monospace;font-size:0.8rem;cursor:pointer;">▶ mask & predict</button>
<button id="mae-reset" style="padding:0.5rem 1.5rem;background:var(--bg-alt);color:var(--text-muted);border:1px solid var(--border);border-radius:var(--radius-sm);font-family:'Fragment Mono',monospace;font-size:0.8rem;cursor:pointer;margin-left:0.5rem;">reset</button>
</div>
<div style="background:var(--code-bg);border-radius:var(--radius-md);padding:1.5rem;">
<div style="font-family:'Fragment Mono',monospace;font-size:0.8rem;color:rgba(255,255,255,0.5);margin-bottom:0.75rem;">latent frames (each = 128 continuous numbers)</div>
<div class="mae-grid" id="mae-grid"></div>
<div style="display:flex;justify-content:space-between;margin-top:0.75rem;">
<span id="mae-status" style="font-family:'Fragment Mono',monospace;font-size:0.8rem;color:rgba(255,255,255,0.5);">20 frames • all visible</span>
<span id="mae-loss" style="font-family:'Fragment Mono',monospace;font-size:0.8rem;color:var(--accent);display:none;">reconstruction loss: 0.003</span>
</div>
</div>
</div>
<!-- ============ END-TO-END TRAINING ============ -->
<h2>end-to-end gradient flow</h2>
<p>the Silk Codec uses <strong><span class="term" data-term="multi-stage training">multi-stage training</span></strong>. Stage 1 (latent space learning): encoder and conformer blocks train with MSE loss in latent space. Stage 2: full system fine-tuned with STFT loss, L1 loss, GAN adversarial loss, feature matching loss, and optional WavLM perceptual loss.</p>
<div class="side-by-side fade-in">
<div class="side" style="border-color:var(--error);background:#fffbfb;">
<h4 style="color:var(--error);">discrete codecs: broken gradient</h4>
<p style="font-size:0.85rem;">quantization creates a "wall" that blocks gradients. encoder and decoder can't communicate precisely during training.</p>
<div style="text-align:center;margin:1rem 0;">
<svg viewBox="0 0 320 80" style="width:100%;height:auto;max-width:320px;">
<line x1="20" y1="36" x2="110" y2="36" stroke="#2d8a4e" stroke-width="3" marker-end="url(#arrowG)"/>
<rect x="118" y="16" width="84" height="40" rx="6" fill="#fef2f2" stroke="#d32f2f" stroke-width="2.5"/>
<text x="160" y="41" text-anchor="middle" fill="#d32f2f" font-size="14" font-weight="700" font-family="Fragment Mono">WALL</text>
<line x1="208" y1="36" x2="300" y2="36" stroke="#d4cfc7" stroke-width="2.5" stroke-dasharray="5,5"/>
<defs><marker id="arrowG" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><polygon points="0,0 8,3 0,6" fill="#2d8a4e"/></marker></defs>
<text x="60" y="66" text-anchor="middle" fill="#2d8a4e" font-size="12" font-weight="600" font-family="Fragment Mono">gradients flow</text>
<text x="255" y="66" text-anchor="middle" fill="#d32f2f" font-size="12" font-weight="600" font-family="Fragment Mono">blocked!</text>
<text x="255" y="28" fill="#d4cfc7" font-size="18" text-anchor="middle">✕</text>
</svg>
</div>
</div>
<div class="side" style="border-color:var(--success);background:#f9fefb;">
<h4 style="color:var(--success);">Silk: smooth gradient flow</h4>
<p style="font-size:0.85rem;">FSQ has smooth gradients. unlike codebook lookup, scalar quantization allows gradient flow with straight-through estimation at the individual dimension level — much more precise than RVQ's vector-level estimation.</p>
<div style="text-align:center;margin:1rem 0;">
<svg viewBox="0 0 320 80" style="width:100%;height:auto;max-width:320px;">
<line x1="20" y1="36" x2="295" y2="36" stroke="#2d8a4e" stroke-width="3" marker-end="url(#arrowG2)"/>
<defs><marker id="arrowG2" markerWidth="8" markerHeight="6" refX="8" refY="3" orient="auto"><polygon points="0,0 8,3 0,6" fill="#2d8a4e"/></marker></defs>
<text x="160" y="64" text-anchor="middle" fill="#2d8a4e" font-size="12" font-weight="600" font-family="Fragment Mono">smooth gradient flow end-to-end</text>
<text x="160" y="26" fill="#2d8a4e" font-size="16" text-anchor="middle">✓</text>
</svg>
</div>
</div>
</div>
<!-- ============ TRAINING VIZ ============ -->
<div class="interactive-block fade-in">
<h3>the training loop visualized</h3>
<p class="description">watch how the network improves over training epochs. the spectrogram on the right should converge toward the input on the left.</p>
<div style="display:grid;grid-template-columns:1fr 60px 1fr;align-items:center;gap:0;">
<div style="background:#0f0f1a;border-radius:var(--radius-md);overflow:hidden;text-align:center;">
<canvas id="spec-input" height="140" style="display:block;width:100%;"></canvas>
<div style="padding:0.5rem;font-family:'Fragment Mono',monospace;font-size:0.75rem;color:rgba(255,255,255,0.5);">target spectrogram</div>
</div>
<div style="text-align:center;">
<div style="font-family:'Fragment Mono',monospace;font-size:0.75rem;color:var(--text-light);">loss</div>
<div id="spec-loss" style="font-family:'Fragment Mono',monospace;font-size:0.9rem;color:var(--accent);font-weight:600;">—</div>
</div>
<div style="background:#0f0f1a;border-radius:var(--radius-md);overflow:hidden;text-align:center;">
<canvas id="spec-output" height="140" style="display:block;width:100%;"></canvas>
<div style="padding:0.5rem;font-family:'Fragment Mono',monospace;font-size:0.75rem;color:rgba(255,255,255,0.5);">reconstructed (improving...)</div>
</div>
</div>
</div>
<!-- Go Deeper -->
<div class="depth-section fade-in">
<button class="depth-toggle" data-target="depth-mae"><span class="arrow">▸</span> go deeper: why masking works</button>
<div class="depth-content" id="depth-mae">
<div class="depth-inner">
<h4>self-supervised learning through prediction</h4>
<p>the Silk Codec's latent space learning is a form of self-supervised learning — the network generates its own training signal by predicting masked frames in latent space (not input space). by masking ~50% of frames, it must learn:</p>
<p>1. <strong>Temporal patterns</strong> — what comes after what in speech<br>2. <strong>Spectral consistency</strong> — which frequency patterns co-occur<br>3. <strong>Long-range dependencies</strong> — how sounds relate across time</p>
<p>8 Conformer blocks give the network enough depth to capture all of these patterns simultaneously.</p>
</div>
</div>
</div>
<div class="depth-section fade-in">
<button class="depth-toggle" data-target="depth-loss"><span class="arrow">▸</span> go deeper: the loss function</button>
<div class="depth-content" id="depth-loss">
<div class="depth-inner">
<h4>multi-stage training losses</h4>
<p>the Silk Codec uses multi-stage training. <strong>Stage 1 (latent space learning):</strong> MSE loss in latent space — the network predicts masked frames. <strong>Stage 2:</strong> multiple reconstruction losses including STFT loss, L1 waveform loss, GAN adversarial loss, and feature matching loss. this multi-stage approach first builds understanding of audio structure, then refines reconstruction quality.</p>
<p>unlike RVQ codecs, Silk doesn't need:<br>• commitment loss (to prevent codebook collapse)<br>• codebook update rules (EMA or gradient-based)<br>FSQ's per-dimension quantization is simpler and more stable.</p>
</div>
</div>
</div>
<!-- Summary -->
<div class="callout insight fade-in">
<div class="callout-title">the chain: LSL → codec → 2.5 Hz</div>
<p><strong>latent space learning</strong> is the foundation. because LSL discovers a physics-first continuous representation, <strong>(1)</strong> the codec can use FSQ instead of RVQ — preserving far more information, <strong>(2)</strong> the representation generalizes across languages without retraining, <strong>(3)</strong> the downstream LLM works with just 47.5 tokens/sec (19 groups at 2.5 Hz) — the lowest token rate of any codec. every advantage traces back to LSL.</p>
</div>
<!-- Nav -->
<div style="display:flex;justify-content:space-between;margin-top:4rem;padding-top:1.5rem;border-top:1px solid var(--border-light);">
<a href="how-codecs-work.html" style="color:var(--accent);text-decoration:none;font-size:0.9rem;">← how codecs work</a>
<a href="voice-ai-pipeline.html" style="color:var(--accent);text-decoration:none;font-size:0.9rem;">voice AI pipeline →</a>
</div>
</div>
</main>
<script src="js/shared.js"></script>
<script>
// === SILK PIPELINE ANIMATION ===
(function(){
const c=document.getElementById('silk-pipeline');if(!c)return;
const arrows=c.querySelectorAll('.pf-arrow');const data=c.querySelectorAll('.pf-data');
let i=0;function step(){if(i<arrows.length){arrows[i].classList.add('show');if(data[Math.floor(i/2)])data[Math.floor(i/2)].classList.add('show');i++;setTimeout(step,150);}}
const obs=new IntersectionObserver(e=>{if(e[0].isIntersecting){step();obs.unobserve(c);}},{threshold:0.3});obs.observe(c);
})();
// === MEL SPECTROGRAM ===
(function(){
const c=document.getElementById('mel-spec');if(!c)return;
const ctx=c.getContext('2d');c.width=c.parentElement.offsetWidth*2;c.height=160;let t=0;
const data=[];for(let i=0;i<120;i++){const col=[];for(let j=0;j<40;j++)col.push(Math.random()*0.5);data.push(col);}
function draw(){data.shift();const col=[];for(let j=0;j<40;j++){col.push(0.2*Math.sin(j*0.12+t*0.05)+0.3+Math.random()*0.15+(j<10?0.25:0)*(0.5+0.5*Math.sin(t*0.03)));}data.push(col);
ctx.clearRect(0,0,c.width,c.height);const cw=c.width/120,ch=c.height/40;
data.forEach((col,x)=>{col.forEach((v,y)=>{ctx.fillStyle=`hsl(${240-v*200},70%,${20+v*40}%)`;ctx.fillRect(x*cw,(39-y)*ch,cw+1,ch+1);});});t++;requestAnimationFrame(draw);}draw();
})();
// === CONFORMER BLOCKS NN (SVG-based) ===
(function(){
const svg=document.getElementById('silk-nn-svg');if(!svg)return;
const layers=[8,10,10,8,6,4];
const layerX=[60,190,310,430,540,640];
function getY(l,i){const n=layers[l];const h=n*24;const start=(260-h)/2+10;return start+i*24;}
let html='';
// connections
for(let l=0;l<layers.length-1;l++){
for(let i=0;i<layers[l];i++){
for(let j=0;j<layers[l+1];j++){
html+=`<line x1="${layerX[l]}" y1="${getY(l,i)}" x2="${layerX[l+1]}" y2="${getY(l+1,j)}" stroke="rgba(100,100,100,0.1)" stroke-width="0.5"/>`;
}
}
}
// nodes
for(let l=0;l<layers.length;l++){
const isLast=l===layers.length-1;
for(let i=0;i<layers[l];i++){
html+=`<circle cx="${layerX[l]}" cy="${getY(l,i)}" r="8" fill="${isLast?'rgba(45,138,78,0.3)':'rgba(100,100,100,0.2)'}" stroke="${isLast?'rgba(45,138,78,0.5)':'rgba(100,100,100,0.35)'}" stroke-width="1.5"/>`;
}
}
// particles
for(let p=0;p<10;p++){
html+=`<circle class="silk-nn-particle" cx="0" cy="0" r="3.5" fill="#555" opacity="0.7" style="display:none;"/>`;
}
svg.innerHTML+=html;
const particles=svg.querySelectorAll('.silk-nn-particle');
let t=0;
function animate(){
particles.forEach((p,idx)=>{
const layer=Math.floor((t*0.008+idx*0.22)%(layers.length-1));
const prog=((t*0.008+idx*0.22)%(layers.length-1))-layer;
const s=idx%layers[layer],d=idx%layers[layer+1];
p.setAttribute('cx',layerX[layer]+(layerX[layer+1]-layerX[layer])*prog);
p.setAttribute('cy',getY(layer,s)+(getY(layer+1,d)-getY(layer,s))*prog);
p.style.display='';
});
t++;requestAnimationFrame(animate);
}
const obs=new IntersectionObserver(e=>{if(e[0].isIntersecting){animate();obs.unobserve(svg);}},{threshold:0.3});
obs.observe(svg);
})();
// === DISCRETE vs CONTINUOUS ANIMATED COMPARISON ===
(function(){
// DISCRETE codebook visualization
const cd=document.getElementById('viz-discrete');if(!cd)return;
const ctxD=cd.getContext('2d');cd.width=cd.parentElement.offsetWidth*2;cd.height=560;
const Wd=cd.width,Hd=cd.height;
// Fixed codebook entries (grid)
const cbEntries=[];
for(let r=0;r<5;r++)for(let c=0;c<6;c++){
cbEntries.push({x:Wd*0.12+c*(Wd*0.76/5),y:Hd*0.12+r*(Hd*0.76/4)});
}
// Floating input sounds
const dInputs=[];
for(let i=0;i<8;i++){dInputs.push({x:Wd*0.15+Math.random()*Wd*0.7,y:Hd*0.15+Math.random()*Hd*0.7,vx:(Math.random()-0.5)*0.4,vy:(Math.random()-0.5)*0.4});}
let td=0;
function drawDiscrete(){
ctxD.clearRect(0,0,Wd,Hd);
// Voronoi-like grid lines
ctxD.strokeStyle='rgba(255,255,255,0.04)';ctxD.lineWidth=1;
for(let r=0;r<5;r++){ctxD.beginPath();ctxD.moveTo(0,Hd*0.12+r*(Hd*0.76/4));ctxD.lineTo(Wd,Hd*0.12+r*(Hd*0.76/4));ctxD.stroke();}
for(let c=0;c<6;c++){ctxD.beginPath();ctxD.moveTo(Wd*0.12+c*(Wd*0.76/5),0);ctxD.lineTo(Wd*0.12+c*(Wd*0.76/5),Hd);ctxD.stroke();}
// Codebook entries
cbEntries.forEach(e=>{ctxD.beginPath();ctxD.arc(e.x,e.y,8,0,Math.PI*2);ctxD.fillStyle='rgba(212,207,199,0.4)';ctxD.fill();ctxD.strokeStyle='rgba(212,207,199,0.6)';ctxD.lineWidth=1.5;ctxD.stroke();});
// On-canvas label
ctxD.fillStyle='rgba(196,64,64,0.5)';ctxD.font='bold 14px Fragment Mono';ctxD.textAlign='center';
ctxD.fillText('sounds snap to nearest pin',Wd/2,Hd-20);
ctxD.fillStyle='rgba(212,207,199,0.35)';ctxD.font='12px Fragment Mono';
ctxD.fillText('□ = fixed codebook entries',Wd/2,28);
// Input sounds with snap lines
dInputs.forEach(p=>{
p.x+=p.vx;p.y+=p.vy;
if(p.x<Wd*0.08||p.x>Wd*0.92)p.vx*=-1;if(p.y<Hd*0.08||p.y>Hd*0.92)p.vy*=-1;
// Find nearest
let md=Infinity,best=cbEntries[0];cbEntries.forEach(e=>{const d=Math.hypot(p.x-e.x,p.y-e.y);if(d<md){md=d;best=e;}});
// Snap line
ctxD.setLineDash([4,4]);ctxD.strokeStyle='rgba(196,64,64,0.5)';ctxD.lineWidth=1.5;
ctxD.beginPath();ctxD.moveTo(p.x,p.y);ctxD.lineTo(best.x,best.y);ctxD.stroke();ctxD.setLineDash([]);
// Error circle
ctxD.beginPath();ctxD.arc(best.x,best.y,8,0,Math.PI*2);ctxD.strokeStyle='rgba(196,64,64,0.6)';ctxD.lineWidth=2;ctxD.stroke();
// Input dot
ctxD.beginPath();ctxD.arc(p.x,p.y,8,0,Math.PI*2);ctxD.fillStyle='#555';ctxD.fill();
});
td++;requestAnimationFrame(drawDiscrete);
}
drawDiscrete();
// CONTINUOUS latent space visualization
const cc=document.getElementById('viz-continuous');if(!cc)return;
const ctxC=cc.getContext('2d');cc.width=cc.parentElement.offsetWidth*2;cc.height=560;
const Wc=cc.width,Hc=cc.height;
// Floating sounds in smooth gradient field
const cInputs=[];
for(let i=0;i<8;i++){cInputs.push({x:Wc*0.15+Math.random()*Wc*0.7,y:Hc*0.15+Math.random()*Hc*0.7,vx:(Math.random()-0.5)*0.4,vy:(Math.random()-0.5)*0.4});}
let tc=0;
function drawContinuous(){
ctxC.clearRect(0,0,Wc,Hc);
// Smooth gradient background
const grd1=ctxC.createRadialGradient(Wc*0.3,Hc*0.3,0,Wc*0.3,Hc*0.3,Wc*0.4);
grd1.addColorStop(0,'rgba(45,138,78,0.15)');grd1.addColorStop(1,'transparent');ctxC.fillStyle=grd1;ctxC.fillRect(0,0,Wc,Hc);
const grd2=ctxC.createRadialGradient(Wc*0.7,Hc*0.6,0,Wc*0.7,Hc*0.6,Wc*0.35);
grd2.addColorStop(0,'rgba(91,127,181,0.12)');grd2.addColorStop(1,'transparent');ctxC.fillStyle=grd2;ctxC.fillRect(0,0,Wc,Hc);
const grd3=ctxC.createRadialGradient(Wc*0.5,Hc*0.8,0,Wc*0.5,Hc*0.8,Wc*0.3);
grd3.addColorStop(0,'rgba(100,100,100,0.1)');grd3.addColorStop(1,'transparent');ctxC.fillStyle=grd3;ctxC.fillRect(0,0,Wc,Hc);
// On-canvas labels
ctxC.fillStyle='rgba(45,138,78,0.35)';ctxC.font='12px Fragment Mono';ctxC.textAlign='center';
ctxC.fillText('smooth gradient — no fixed pins',Wc/2,28);
ctxC.fillStyle='rgba(45,138,78,0.5)';ctxC.font='bold 14px Fragment Mono';
ctxC.fillText('sounds land exactly where they belong',Wc/2,Hc-20);
// Input sounds with glow (no snap!)
cInputs.forEach(p=>{
p.x+=p.vx+Math.sin(tc*0.02+p.y*0.005)*0.3;
p.y+=p.vy+Math.cos(tc*0.02+p.x*0.005)*0.3;
if(p.x<Wc*0.08||p.x>Wc*0.92)p.vx*=-1;if(p.y<Hc*0.08||p.y>Hc*0.92)p.vy*=-1;
// Glow
const glow=ctxC.createRadialGradient(p.x,p.y,0,p.x,p.y,25);
glow.addColorStop(0,'rgba(45,138,78,0.4)');glow.addColorStop(1,'transparent');
ctxC.fillStyle=glow;ctxC.fillRect(p.x-25,p.y-25,50,50);
// Dot
ctxC.beginPath();ctxC.arc(p.x,p.y,8,0,Math.PI*2);ctxC.fillStyle='#2d8a4e';ctxC.fill();
ctxC.strokeStyle='rgba(45,138,78,0.6)';ctxC.lineWidth=1.5;ctxC.stroke();
});
tc++;requestAnimationFrame(drawContinuous);
}
drawContinuous();
})();
// === LATENT FIELD VIZ ===
(function(){
const c=document.getElementById('latent-field');if(!c)return;
const ctx=c.getContext('2d');c.width=c.parentElement.offsetWidth*2;c.height=800;
const W=c.width,H=c.height;
const tooltip=document.getElementById('field-tooltip');
// Generate clusters with descriptive labels
const points=[];
const clusters=[
{cx:0.22,cy:0.3,r:0.09,color:'#888888',group:'vowels',labels:['ah (father)','ee (beat)','oo (boot)','eh (bed)','ih (bit)']},
{cx:0.6,cy:0.25,r:0.11,color:'#5b7fb5',group:'consonants',labels:['s (sun)','t (top)','k (cat)','p (pat)','f (fun)','sh (ship)','th (think)']},
{cx:0.38,cy:0.7,r:0.07,color:'#2d8a4e',group:'mandarin tones',labels:['tone1 mā (flat)','tone2 má (rising)','tone3 mǎ (dip)','tone4 mà (falling)']},
{cx:0.78,cy:0.65,r:0.06,color:'#d4a053',group:'arabic sounds',labels:['ʕ (ain)','ħ (heavy h)','ʔ (glottal)','q (deep k)']},
{cx:0.13,cy:0.6,r:0.08,color:'#888888',group:'diphthongs',labels:['aw (cow)','oi (boy)','ey (day)','ow (go)']},
{cx:0.85,cy:0.4,r:0.07,color:'#5b7fb5',group:'nasals/liquids',labels:['m (mom)','n (noon)','ng (sing)','l (leaf)','r (red)']},
];
clusters.forEach(cl=>{
cl.labels.forEach(label=>{
points.push({x:W*(cl.cx+(Math.random()-0.5)*cl.r*2),y:H*(cl.cy+(Math.random()-0.5)*cl.r*2),color:cl.color,label:label,group:cl.group});
});
});
let hovered=null;
function draw(){
ctx.clearRect(0,0,W,H);
// Draw soft clusters with labels
clusters.forEach(cl=>{
const grd=ctx.createRadialGradient(W*cl.cx,H*cl.cy,0,W*cl.cx,H*cl.cy,W*cl.r*3);
grd.addColorStop(0,cl.color+'20');grd.addColorStop(1,'transparent');
ctx.fillStyle=grd;ctx.fillRect(0,0,W,H);
// Cluster label
ctx.fillStyle=cl.color+'70';ctx.font='bold 14px Fragment Mono';ctx.textAlign='center';
ctx.fillText(cl.group.toUpperCase(),W*cl.cx,H*cl.cy-W*cl.r*1.2);
});
points.forEach((p,i)=>{
const isHov=hovered===i;
ctx.beginPath();ctx.arc(p.x,p.y,isHov?12:9,0,Math.PI*2);
ctx.fillStyle=p.color+(isHov?'':'aa');ctx.fill();
if(isHov){ctx.strokeStyle='#fff';ctx.lineWidth=2;ctx.stroke();}
});
}
draw();
c.addEventListener('mousemove',e=>{
const rect=c.getBoundingClientRect();const mx=(e.clientX-rect.left)/rect.width*W;const my=(e.clientY-rect.top)/rect.height*H;
hovered=null;
points.forEach((p,i)=>{if(Math.hypot(p.x-mx,p.y-my)<25)hovered=i;});
if(hovered!==null){
tooltip.style.display='block';tooltip.innerHTML='<strong>'+points[hovered].label+'</strong><br><span style="opacity:0.6;">'+points[hovered].group+'</span>';
tooltip.style.left=(e.clientX-c.parentElement.getBoundingClientRect().left+12)+'px';
tooltip.style.top=(e.clientY-c.parentElement.getBoundingClientRect().top-40)+'px';
}else{tooltip.style.display='none';}
draw();
});
c.addEventListener('mouseleave',()=>{hovered=null;tooltip.style.display='none';draw();});
})();
// === MAE GRID ===
(function(){
const grid=document.getElementById('mae-grid');
const runBtn=document.getElementById('mae-run');
const resetBtn=document.getElementById('mae-reset');
const status=document.getElementById('mae-status');
const lossEl=document.getElementById('mae-loss');
const cells=[];
for(let i=0;i<20;i++){
const cell=document.createElement('div');
cell.className='mae-cell visible';cell.textContent=i+1;
grid.appendChild(cell);cells.push(cell);
}
runBtn.addEventListener('click',()=>{
// Phase 1: mask
const masked=[];
cells.forEach((cell,i)=>{
if(Math.random()<0.5){cell.className='mae-cell masked';cell.textContent='?';masked.push(i);}
else{cell.className='mae-cell visible';cell.textContent=i+1;}
});
status.textContent=`${20-masked.length} visible • ${masked.length} masked`;lossEl.style.display='none';
// Phase 2: predict
setTimeout(()=>{
masked.forEach((idx,j)=>{
setTimeout(()=>{cells[idx].className='mae-cell predicted';cells[idx].textContent=idx+1;},j*100);
});
setTimeout(()=>{status.textContent='all 20 frames reconstructed';lossEl.style.display='inline';},masked.length*100+200);
},1500);
});
resetBtn.addEventListener('click',()=>{
cells.forEach((cell,i)=>{cell.className='mae-cell visible';cell.textContent=i+1;});
status.textContent='20 frames • all visible';lossEl.style.display='none';
});
})();
// === TRAINING SPECTROGRAMS ===
(function(){
const cIn=document.getElementById('spec-input');const cOut=document.getElementById('spec-output');const lossEl=document.getElementById('spec-loss');
if(!cIn||!cOut)return;
const ctxIn=cIn.getContext('2d');const ctxOut=cOut.getContext('2d');
cIn.width=cIn.parentElement.offsetWidth*2;cIn.height=200;cOut.width=cOut.parentElement.offsetWidth*2;cOut.height=200;
const W=cIn.width,H=cIn.height;
// Generate "target" spectrogram
const target=[];for(let x=0;x<80;x++){const col=[];for(let y=0;y<40;y++){col.push(0.3+0.3*Math.sin(y*0.15+x*0.05)+0.1*Math.sin(y*0.4+x*0.1)+(y<10?0.2:0));}target.push(col);}
let epoch=0;const maxEpoch=150;
function drawSpec(ctx_,data,w,h){
ctx_.clearRect(0,0,w,h);const cw=w/80,ch=h/40;
data.forEach((col,x)=>{col.forEach((v,y)=>{ctx_.fillStyle=`hsl(${240-Math.max(0,Math.min(1,v))*200},70%,${20+Math.max(0,Math.min(1,v))*40}%)`;ctx_.fillRect(x*cw,(39-y)*ch,cw+1,ch+1);});});
}
// Draw target
drawSpec(ctxIn,target,W,H);
function tick(){
epoch++;const blend=1-Math.exp(-epoch*0.03);
const output=target.map(col=>col.map(v=>v*blend+(1-blend)*(Math.random()*0.5+0.2)));
drawSpec(ctxOut,output,W,H);
const loss=(1-blend)*0.8+0.02;
lossEl.textContent=loss.toFixed(3);
if(epoch<maxEpoch)setTimeout(tick,60);
}
const obs=new IntersectionObserver(e=>{if(e[0].isIntersecting){tick();obs.unobserve(cIn);}},{threshold:0.3});obs.observe(cIn);
})();
</script>
<nav class="mobile-nav">
<a href="#" class="mobile-prev">← prev</a>
<span class="current-page"></span>
<a href="#" class="mobile-next">next →</a>
</nav>
</body>
</html>