Spaces:
Running
Running
deploy(hf): sync szl-holdings/a11oy@main derived COPY set
Browse filesReusable Dockerfile-COPY-derived deploy from szl-holdings/a11oy main.
Files: 863 Pruned: 0
Derived from Dockerfile COPY sources (NO hand-maintained allowlist).
Signed-off-by: SZL Holdings <noreply@szlholdings.ai>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- static/3d/holographic.html +4 -0
- static/3d/surfaces/inplacettt.js +572 -0
- static/3d/surfaces/nested.js +545 -0
- static/3d/surfaces/sement.js +456 -0
- static/3d/surfaces/ternary.js +468 -0
static/3d/holographic.html
CHANGED
|
@@ -99,6 +99,10 @@ const SURFACES = [
|
|
| 99 |
{ id: "pfield", title: "Pressure-Field Coordination", mod: "/static/3d/surfaces/pfield.js" },
|
| 100 |
{ id: "qhall", title: "Quantum-Inspired Hallucination UQ", mod: "/static/3d/surfaces/qhall.js" },
|
| 101 |
{ id: "aimc", title: "Analog In-Memory Attention", mod: "/static/3d/surfaces/aimc.js" },
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 103 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 104 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },
|
|
|
|
| 99 |
{ id: "pfield", title: "Pressure-Field Coordination", mod: "/static/3d/surfaces/pfield.js" },
|
| 100 |
{ id: "qhall", title: "Quantum-Inspired Hallucination UQ", mod: "/static/3d/surfaces/qhall.js" },
|
| 101 |
{ id: "aimc", title: "Analog In-Memory Attention", mod: "/static/3d/surfaces/aimc.js" },
|
| 102 |
+
{ id: "ternary", title: "Ternary 1.58-bit Weights", mod: "/static/3d/surfaces/ternary.js" },
|
| 103 |
+
{ id: "sement", title: "Semantic-Entropy Uncertainty", mod: "/static/3d/surfaces/sement.js" },
|
| 104 |
+
{ id: "inplacettt", title: "In-Place Test-Time Training", mod: "/static/3d/surfaces/inplacettt.js" },
|
| 105 |
+
{ id: "nested", title: "Nested Learning (multi-timescale)", mod: "/static/3d/surfaces/nested.js" },
|
| 106 |
{ id: "energy", title: "Energy", mod: "/static/3d/surfaces/energy.js" },
|
| 107 |
{ id: "fabric", title: "Fabric", mod: "/static/3d/surfaces/fabric.js" },
|
| 108 |
{ id: "pnt", title: "PNT", mod: "/static/3d/surfaces/pnt.js" },
|
static/3d/surfaces/inplacettt.js
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/inplacettt.js — IN-PLACE TEST-TIME TRAINING (InPlaceTTT) organ for
|
| 5 |
+
// the holographic frontier ring (Feng et al. 2026, ByteDance Seed + Peking
|
| 6 |
+
// University — "In-Place Test-Time Training", ICLR 2026 Oral). Renders a stock
|
| 7 |
+
// gated-MLP block whose EXISTING down-projection matrix W_down is re-purposed as
|
| 8 |
+
// FAST WEIGHTS (updated at inference time) while W_up and W_gate stay FROZEN as
|
| 9 |
+
// slow weights. A stream of token chunks flows past the block; a strictly-causal
|
| 10 |
+
// 1-D convolution builds the next-token-prediction target (no future leakage),
|
| 11 |
+
// and ONE gradient step per chunk mutates W_down. Two ribbons contrast the
|
| 12 |
+
// running next-token loss of the ADAPTING run (W_down mutates, proof-teal —
|
| 13 |
+
// FALLS) against the FROZEN-W_down control (lattice-blue — stays FLAT). A HUD
|
| 14 |
+
// reads the live snapshot at /api/killinchu/v1/inplacettt/adapt. Honesty label
|
| 15 |
+
// "MODELED" is read VERBATIM from the JSON and displayed as-is; never upgraded.
|
| 16 |
+
//
|
| 17 |
+
// Surface export shape (mirrors titans.js / kla.js exactly):
|
| 18 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 19 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 20 |
+
//
|
| 21 |
+
// DATA SHOWN (all from live endpoint, inside payload):
|
| 22 |
+
// d_model, d_ff, vocab, chunk_size, num_chunks, learning_rate, freeze_up,
|
| 23 |
+
// freeze_gate, fast_matrix, causal_kernel, causal_offsets, causal_guard_ok,
|
| 24 |
+
// adapt_loss_start, adapt_loss_end, frozen_loss_start, frozen_loss_end,
|
| 25 |
+
// adapt_loss_drop, frozen_loss_drop, improvement, loss_curve[], w_down_delta_norm
|
| 26 |
+
//
|
| 27 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 28 |
+
// In-Place Test-Time Training (mechanism simulated here):
|
| 29 |
+
// Feng, Luo, Hua, Zhang, He, Huang, Cai 2026, ByteDance Seed + Peking Univ,
|
| 30 |
+
// arXiv:2604.06169 (ICLR 2026 Oral)
|
| 31 |
+
// https://arxiv.org/abs/2604.06169
|
| 32 |
+
// Official code:
|
| 33 |
+
// https://github.com/ByteDance-Seed/In-Place-TTT
|
| 34 |
+
//
|
| 35 |
+
// DISTINCTNESS (scope-sensitive): vs titans (ADDS a separate memory module +
|
| 36 |
+
// params, surprise-driven) — inplacettt ADDS NO PARAMETERS, hijacks the
|
| 37 |
+
// existing W_down, and its update signal is an NTP-aligned loss. vs testtime
|
| 38 |
+
// (spends more inference COMPUTE against FROZEN weights) — inplacettt MUTATES
|
| 39 |
+
// weights (W_down is no longer frozen). Compute-allocation vs weight-mutation.
|
| 40 |
+
//
|
| 41 |
+
// HONESTY LABELS: MODELED (deterministic toy analytic simulation of the
|
| 42 |
+
// down-projection-as-fast-weights / NTP-aligned / causal-chunk-update
|
| 43 |
+
// mechanism; inspired-not-real; NOT the ByteDance model; toy 8-dim weights;
|
| 44 |
+
// NO 128k-context / 4B-parameter claim). Read verbatim from JSON; never
|
| 45 |
+
// upgraded here. The endpoint nests fields under `payload` and the label at
|
| 46 |
+
// the top level — this surface handles the label at top-level OR inside
|
| 47 |
+
// payload.label defensively.
|
| 48 |
+
// COLOURS: lattice-blue 0x5b8dee (frozen slow weights / frozen control / spine),
|
| 49 |
+
// violet-blue 0x8a6bff (chunk stream / W_down fast-weight lattice), proof-teal
|
| 50 |
+
// 0x3af4c8 (adapting run / falling loss / HUD accent), greys (frozen-flat /
|
| 51 |
+
// degraded). Purple BANNED.
|
| 52 |
+
// 0 RUNTIME CDN. three.js via ctx.THREE (vendored by the page importmap).
|
| 53 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 54 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 55 |
+
|
| 56 |
+
const ID = "inplacettt";
|
| 57 |
+
const TITLE = "In-Place Test-Time Training · W_down as Fast Weights (live)";
|
| 58 |
+
|
| 59 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 60 |
+
// cross-origin (killinchu returns access-control-allow-origin: https://a-11-oy.com).
|
| 61 |
+
// This keeps the inplacettt organ's rebuilds/faults isolated from the flagship.
|
| 62 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/inplacettt/adapt?seed=42&chunk_size=16&learning_rate=0.2&num_chunks=24";
|
| 63 |
+
|
| 64 |
+
// data-viz hues — purple BANNED
|
| 65 |
+
const C_FROZEN = 0x5b8dee; // lattice-blue (frozen slow weights / frozen control / spine)
|
| 66 |
+
const C_FAST = 0x8a6bff; // violet-blue (W_down fast-weight lattice / chunk stream)
|
| 67 |
+
const C_ADAPT = 0x3af4c8; // proof-teal (adapting run / falling loss / HUD accent)
|
| 68 |
+
const C_FLAT = 0x5a6570; // grey (flat frozen loss / low activity)
|
| 69 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 70 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 71 |
+
|
| 72 |
+
// layout geometry
|
| 73 |
+
const FF_COLS = 16; // W_down columns rendered (d_ff fast-weight cells)
|
| 74 |
+
const DM_ROWS = 8; // W_down rows rendered (d_model)
|
| 75 |
+
const LATTICE_W = 6.0; // world-units the W_down lattice spans along X
|
| 76 |
+
const LATTICE_H = 3.2; // world-units the W_down lattice spans along Y
|
| 77 |
+
const MAX_CURVE = 96; // cap on loss-curve points rendered (== payload cap)
|
| 78 |
+
const CURVE_SPAN = 12.0; // world-units the loss ribbons span along X
|
| 79 |
+
const CURVE_Y = 4.2; // baseline height of the loss ribbons
|
| 80 |
+
|
| 81 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 82 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 83 |
+
let _plain = false;
|
| 84 |
+
|
| 85 |
+
// geometry handles
|
| 86 |
+
let _floor = null;
|
| 87 |
+
let _lattice = []; // Array<THREE.Mesh> — W_down fast-weight cells
|
| 88 |
+
let _upBar = null; // THREE.Mesh — frozen W_up slab
|
| 89 |
+
let _gateBar = null; // THREE.Mesh — frozen W_gate slab
|
| 90 |
+
let _adaptLine = null; // THREE.Line — adapting-run loss ribbon
|
| 91 |
+
let _frozenLine = null; // THREE.Line — frozen-control loss ribbon
|
| 92 |
+
let _core = null; // THREE.Mesh — central "improvement" core
|
| 93 |
+
|
| 94 |
+
// live state
|
| 95 |
+
const S = {
|
| 96 |
+
label: null,
|
| 97 |
+
dModel: null, // d_model
|
| 98 |
+
dFf: null, // d_ff
|
| 99 |
+
vocab: null, // vocab
|
| 100 |
+
chunkSize: null, // chunk_size
|
| 101 |
+
numChunks: null, // num_chunks
|
| 102 |
+
learningRate: null, // learning_rate
|
| 103 |
+
freezeUp: null, // freeze_up
|
| 104 |
+
freezeGate: null, // freeze_gate
|
| 105 |
+
fastMatrix: null, // fast_matrix
|
| 106 |
+
causalKernel: null, // causal_kernel[]
|
| 107 |
+
causalGuard: null, // causal_guard_ok
|
| 108 |
+
adaptStart: null, // adapt_loss_start
|
| 109 |
+
adaptEnd: null, // adapt_loss_end
|
| 110 |
+
frozenStart: null, // frozen_loss_start
|
| 111 |
+
frozenEnd: null, // frozen_loss_end
|
| 112 |
+
adaptDrop: null, // adapt_loss_drop
|
| 113 |
+
frozenDrop: null, // frozen_loss_drop
|
| 114 |
+
improvement: null, // improvement
|
| 115 |
+
curve: null, // loss_curve[]
|
| 116 |
+
deltaNorm: null, // w_down_delta_norm
|
| 117 |
+
state: "init",
|
| 118 |
+
};
|
| 119 |
+
|
| 120 |
+
// =============================================================================
|
| 121 |
+
// mount(ctx)
|
| 122 |
+
// =============================================================================
|
| 123 |
+
export function mount(ctx) {
|
| 124 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 125 |
+
_group = new _THREE.Group();
|
| 126 |
+
_stage.scene.add(_group);
|
| 127 |
+
_stage.camera.position.set(0, 8, 20);
|
| 128 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 2.0, 0); _stage.controls.update(); } } catch (_) {}
|
| 129 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 130 |
+
|
| 131 |
+
_buildFloor();
|
| 132 |
+
_buildFrozenSlabs();
|
| 133 |
+
_buildLattice();
|
| 134 |
+
_buildLossRibbons();
|
| 135 |
+
_buildCore();
|
| 136 |
+
|
| 137 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 138 |
+
|
| 139 |
+
_badge = ctx.live.createBadge();
|
| 140 |
+
_polls.push(ctx.live.poll(EP, 5000, _onAdapt, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 141 |
+
|
| 142 |
+
_buildOverlay();
|
| 143 |
+
return { id: ID, started: true };
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// =============================================================================
|
| 147 |
+
// builders
|
| 148 |
+
// =============================================================================
|
| 149 |
+
function _buildFloor() {
|
| 150 |
+
const THREE = _THREE;
|
| 151 |
+
const grid = new THREE.GridHelper(44, 44, C_GRID, 0x0f2027);
|
| 152 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 153 |
+
_group.add(grid);
|
| 154 |
+
_floor = grid;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// Two FROZEN slow-weight slabs (W_up, W_gate) — rendered lattice-blue and held
|
| 158 |
+
// static: they never change colour or scale from live data (they are frozen).
|
| 159 |
+
function _buildFrozenSlabs() {
|
| 160 |
+
const THREE = _THREE;
|
| 161 |
+
const geo = new THREE.BoxGeometry(1.4, 2.4, 0.35);
|
| 162 |
+
_upBar = new THREE.Mesh(
|
| 163 |
+
geo,
|
| 164 |
+
new THREE.MeshStandardMaterial({ color: C_FROZEN, emissive: C_FROZEN, emissiveIntensity: 0.14, transparent: true, opacity: 0.55 }),
|
| 165 |
+
);
|
| 166 |
+
_upBar.position.set(-4.8, 1.4, 0);
|
| 167 |
+
_group.add(_upBar);
|
| 168 |
+
|
| 169 |
+
_gateBar = new THREE.Mesh(
|
| 170 |
+
geo,
|
| 171 |
+
new THREE.MeshStandardMaterial({ color: C_FROZEN, emissive: C_FROZEN, emissiveIntensity: 0.14, transparent: true, opacity: 0.55 }),
|
| 172 |
+
);
|
| 173 |
+
_gateBar.position.set(-4.8, 1.4, -1.1);
|
| 174 |
+
_group.add(_gateBar);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
// The W_down FAST-WEIGHT lattice: a d_model x d_ff grid of cells. Pre-allocated;
|
| 178 |
+
// cell brightness/scale animate as W_down "adapts" (driven by w_down_delta_norm
|
| 179 |
+
// and the adapting-run loss drop). Violet-blue at rest, warms to proof-teal as
|
| 180 |
+
// the fast weights move.
|
| 181 |
+
function _buildLattice() {
|
| 182 |
+
const THREE = _THREE;
|
| 183 |
+
const cellGeo = new THREE.BoxGeometry(0.26, 0.26, 0.26);
|
| 184 |
+
for (let r = 0; r < DM_ROWS; r++) {
|
| 185 |
+
for (let c = 0; c < FF_COLS; c++) {
|
| 186 |
+
const x = -LATTICE_W / 2 + (c / (FF_COLS - 1)) * LATTICE_W;
|
| 187 |
+
const y = 0.6 + (r / (DM_ROWS - 1)) * LATTICE_H;
|
| 188 |
+
const mesh = new THREE.Mesh(
|
| 189 |
+
cellGeo,
|
| 190 |
+
new THREE.MeshStandardMaterial({ color: C_FAST, emissive: C_FAST, emissiveIntensity: 0.18, transparent: true, opacity: 0.0 }),
|
| 191 |
+
);
|
| 192 |
+
mesh.position.set(x, y, 1.4);
|
| 193 |
+
mesh.visible = false;
|
| 194 |
+
_group.add(mesh);
|
| 195 |
+
_lattice.push(mesh);
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
// Two loss ribbons over the chunk axis: adapting (proof-teal, should FALL) and
|
| 201 |
+
// frozen control (grey/lattice-blue, should stay FLAT). Pre-allocated as Lines
|
| 202 |
+
// with MAX_CURVE points; positions rewritten in-place from live loss_curve.
|
| 203 |
+
function _buildLossRibbons() {
|
| 204 |
+
const THREE = _THREE;
|
| 205 |
+
|
| 206 |
+
function mkLine(color) {
|
| 207 |
+
const pts = [];
|
| 208 |
+
for (let i = 0; i < MAX_CURVE; i++) {
|
| 209 |
+
const x = -CURVE_SPAN / 2 + (i / (MAX_CURVE - 1)) * CURVE_SPAN;
|
| 210 |
+
pts.push(new THREE.Vector3(x, CURVE_Y, -3.0));
|
| 211 |
+
}
|
| 212 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 213 |
+
const mat = new THREE.LineBasicMaterial({ color: color, transparent: true, opacity: 0.85 });
|
| 214 |
+
const line = new THREE.Line(geo, mat);
|
| 215 |
+
line.visible = false;
|
| 216 |
+
_group.add(line);
|
| 217 |
+
return line;
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
_adaptLine = mkLine(C_ADAPT);
|
| 221 |
+
_frozenLine = mkLine(C_FLAT);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
function _buildCore() {
|
| 225 |
+
const THREE = _THREE;
|
| 226 |
+
_core = new THREE.Mesh(
|
| 227 |
+
new THREE.IcosahedronGeometry(0.7, 1),
|
| 228 |
+
new THREE.MeshStandardMaterial({ color: C_ADAPT, emissive: C_ADAPT, emissiveIntensity: 0.45, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 229 |
+
);
|
| 230 |
+
_core.position.set(0, 0.6, 0);
|
| 231 |
+
_group.add(_core);
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
// =============================================================================
|
| 235 |
+
// live data handler
|
| 236 |
+
// =============================================================================
|
| 237 |
+
function _onAdapt(j) {
|
| 238 |
+
// The endpoint nests its metrics under `payload`; the honesty label may sit
|
| 239 |
+
// at the TOP LEVEL or (defensively) inside payload.label. Read it VERBATIM
|
| 240 |
+
// from wherever it is — never upgrade.
|
| 241 |
+
const p = (j && typeof j.payload === "object" && j.payload) ? j.payload : j;
|
| 242 |
+
const rawLabel = (j && j.label) || (p && p.label) || "MODELED";
|
| 243 |
+
S.label = String(rawLabel).toUpperCase();
|
| 244 |
+
|
| 245 |
+
S.dModel = typeof p.d_model === "number" ? p.d_model : null;
|
| 246 |
+
S.dFf = typeof p.d_ff === "number" ? p.d_ff : null;
|
| 247 |
+
S.vocab = typeof p.vocab === "number" ? p.vocab : null;
|
| 248 |
+
S.chunkSize = typeof p.chunk_size === "number" ? p.chunk_size : null;
|
| 249 |
+
S.numChunks = typeof p.num_chunks === "number" ? p.num_chunks : null;
|
| 250 |
+
S.learningRate = typeof p.learning_rate === "number" ? p.learning_rate : null;
|
| 251 |
+
S.freezeUp = typeof p.freeze_up === "boolean" ? p.freeze_up : null;
|
| 252 |
+
S.freezeGate = typeof p.freeze_gate === "boolean" ? p.freeze_gate : null;
|
| 253 |
+
S.fastMatrix = typeof p.fast_matrix === "string" ? p.fast_matrix : null;
|
| 254 |
+
S.causalKernel = Array.isArray(p.causal_kernel) ? p.causal_kernel : null;
|
| 255 |
+
S.causalGuard = typeof p.causal_guard_ok === "boolean" ? p.causal_guard_ok : null;
|
| 256 |
+
S.adaptStart = typeof p.adapt_loss_start === "number" ? p.adapt_loss_start : null;
|
| 257 |
+
S.adaptEnd = typeof p.adapt_loss_end === "number" ? p.adapt_loss_end : null;
|
| 258 |
+
S.frozenStart = typeof p.frozen_loss_start === "number" ? p.frozen_loss_start : null;
|
| 259 |
+
S.frozenEnd = typeof p.frozen_loss_end === "number" ? p.frozen_loss_end : null;
|
| 260 |
+
S.adaptDrop = typeof p.adapt_loss_drop === "number" ? p.adapt_loss_drop : null;
|
| 261 |
+
S.frozenDrop = typeof p.frozen_loss_drop === "number" ? p.frozen_loss_drop : null;
|
| 262 |
+
S.improvement = typeof p.improvement === "number" ? p.improvement : null;
|
| 263 |
+
S.curve = Array.isArray(p.loss_curve) ? p.loss_curve : null;
|
| 264 |
+
S.deltaNorm = typeof p.w_down_delta_norm === "number" ? p.w_down_delta_norm : null;
|
| 265 |
+
|
| 266 |
+
_updateGeometry();
|
| 267 |
+
_paintOverlay();
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
// =============================================================================
|
| 271 |
+
// geometry updater — drives the lattice + ribbons from live data
|
| 272 |
+
// =============================================================================
|
| 273 |
+
function _updateGeometry() {
|
| 274 |
+
const live = S.state === "live";
|
| 275 |
+
|
| 276 |
+
// frozen slow-weight slabs: always lattice-blue when live, grey when not —
|
| 277 |
+
// and NEVER animated (they are frozen; that is the point).
|
| 278 |
+
[_upBar, _gateBar].forEach((bar) => {
|
| 279 |
+
if (!bar) return;
|
| 280 |
+
const col = live ? C_FROZEN : C_DIM;
|
| 281 |
+
bar.material.color.setHex(col);
|
| 282 |
+
bar.material.emissive.setHex(col);
|
| 283 |
+
bar.material.opacity = live ? 0.55 : 0.22;
|
| 284 |
+
});
|
| 285 |
+
|
| 286 |
+
// W_down fast-weight lattice: activity scales with the total weight movement
|
| 287 |
+
// (w_down_delta_norm) and the adapting-run loss drop. Cells warm from
|
| 288 |
+
// violet-blue toward proof-teal as the fast weights adapt.
|
| 289 |
+
const delta = live && S.deltaNorm != null ? S.deltaNorm : 0;
|
| 290 |
+
const drop = live && S.adaptDrop != null ? Math.max(0, S.adaptDrop) : 0;
|
| 291 |
+
const warm = Math.min(1, drop * 60); // how "teal" (adapted) the lattice looks
|
| 292 |
+
const act = Math.min(1, delta / 2.0); // overall movement intensity
|
| 293 |
+
for (let i = 0; i < _lattice.length; i++) {
|
| 294 |
+
const mesh = _lattice[i];
|
| 295 |
+
if (!live) { mesh.visible = false; continue; }
|
| 296 |
+
mesh.visible = true;
|
| 297 |
+
// deterministic per-cell phase so the lattice shimmers coherently
|
| 298 |
+
const adapted = ((i * 2654435761) % 1000) / 1000 < warm;
|
| 299 |
+
const col = adapted ? C_ADAPT : C_FAST;
|
| 300 |
+
mesh.material.color.setHex(col);
|
| 301 |
+
mesh.material.emissive.setHex(col);
|
| 302 |
+
mesh.material.emissiveIntensity = 0.18 + 0.5 * act + (adapted ? 0.25 : 0);
|
| 303 |
+
mesh.material.opacity = 0.35 + 0.5 * act;
|
| 304 |
+
mesh.scale.setScalar(0.8 + 0.5 * act + (adapted ? 0.25 : 0));
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
// loss ribbons: map the live loss_curve onto the two Lines. Adapting should
|
| 308 |
+
// slope DOWN; frozen should be FLAT. We normalise both against a shared range.
|
| 309 |
+
const curve = live && S.curve && S.curve.length ? S.curve.slice(0, MAX_CURVE) : [];
|
| 310 |
+
if (curve.length && _adaptLine && _frozenLine) {
|
| 311 |
+
let lo = Infinity, hi = -Infinity;
|
| 312 |
+
for (const c of curve) {
|
| 313 |
+
const a = typeof c.adapt_loss === "number" ? c.adapt_loss : 0;
|
| 314 |
+
const f = typeof c.frozen_loss === "number" ? c.frozen_loss : 0;
|
| 315 |
+
lo = Math.min(lo, a, f); hi = Math.max(hi, a, f);
|
| 316 |
+
}
|
| 317 |
+
const rng = hi - lo || 1;
|
| 318 |
+
_writeRibbon(_adaptLine, curve, "adapt_loss", lo, rng, -2.6);
|
| 319 |
+
_writeRibbon(_frozenLine, curve, "frozen_loss", lo, rng, -3.4);
|
| 320 |
+
_adaptLine.visible = true;
|
| 321 |
+
_frozenLine.visible = true;
|
| 322 |
+
_adaptLine.material.color.setHex(C_ADAPT);
|
| 323 |
+
_frozenLine.material.color.setHex(C_FLAT);
|
| 324 |
+
} else {
|
| 325 |
+
if (_adaptLine) _adaptLine.visible = false;
|
| 326 |
+
if (_frozenLine) _frozenLine.visible = false;
|
| 327 |
+
}
|
| 328 |
+
|
| 329 |
+
// central core: size/colour reflect the adapting advantage (improvement)
|
| 330 |
+
if (_core) {
|
| 331 |
+
if (live && S.improvement != null) {
|
| 332 |
+
_core.material.color.setHex(C_ADAPT);
|
| 333 |
+
_core.material.emissive.setHex(C_ADAPT);
|
| 334 |
+
_core.material.opacity = 0.85;
|
| 335 |
+
_core.scale.setScalar(0.8 + Math.max(0, S.improvement) * 40);
|
| 336 |
+
} else {
|
| 337 |
+
_core.material.color.setHex(C_DIM);
|
| 338 |
+
_core.material.emissive.setHex(C_DIM);
|
| 339 |
+
_core.material.opacity = 0.3;
|
| 340 |
+
_core.scale.setScalar(0.8);
|
| 341 |
+
}
|
| 342 |
+
}
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
function _writeRibbon(line, curve, key, lo, rng, z) {
|
| 346 |
+
const pos = line.geometry.attributes.position;
|
| 347 |
+
const n = Math.min(curve.length, MAX_CURVE);
|
| 348 |
+
for (let i = 0; i < MAX_CURVE; i++) {
|
| 349 |
+
const src = i < n ? curve[i] : curve[n - 1];
|
| 350 |
+
const v = src && typeof src[key] === "number" ? src[key] : lo;
|
| 351 |
+
const norm = (v - lo) / rng; // 0 (best) .. 1 (worst)
|
| 352 |
+
const x = -CURVE_SPAN / 2 + (i / (MAX_CURVE - 1)) * CURVE_SPAN;
|
| 353 |
+
const y = CURVE_Y + (1 - norm) * 2.2; // lower loss -> higher ribbon
|
| 354 |
+
pos.setXYZ(i, x, y, z);
|
| 355 |
+
}
|
| 356 |
+
pos.needsUpdate = true;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
// =============================================================================
|
| 360 |
+
// per-frame animation
|
| 361 |
+
// =============================================================================
|
| 362 |
+
function _onFrame() {
|
| 363 |
+
const t = performance.now();
|
| 364 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00008) * 0.14;
|
| 365 |
+
if (_core) {
|
| 366 |
+
_core.rotation.y += 0.02;
|
| 367 |
+
_core.rotation.x += 0.009;
|
| 368 |
+
const pulse = 1.0 + 0.12 * Math.sin(t * 0.0035);
|
| 369 |
+
const base = (S.state === "live" && S.improvement != null) ? (0.8 + Math.max(0, S.improvement) * 40) : 0.8;
|
| 370 |
+
_core.scale.setScalar(base * pulse);
|
| 371 |
+
}
|
| 372 |
+
// gentle shimmer on the fast-weight lattice (the weights are "moving")
|
| 373 |
+
if (_lattice.length && S.state === "live") {
|
| 374 |
+
const a = 0.5 + 0.5 * Math.sin(t * 0.002);
|
| 375 |
+
for (let i = 0; i < _lattice.length; i += 7) {
|
| 376 |
+
const m = _lattice[i];
|
| 377 |
+
if (m && m.visible) m.material.emissiveIntensity = 0.2 + 0.4 * a;
|
| 378 |
+
}
|
| 379 |
+
}
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
// =============================================================================
|
| 383 |
+
// overlay
|
| 384 |
+
// =============================================================================
|
| 385 |
+
function _buildOverlay() {
|
| 386 |
+
const ctx = _ctx;
|
| 387 |
+
_overlay = document.createElement("div");
|
| 388 |
+
Object.assign(_overlay.style, {
|
| 389 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 390 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 391 |
+
maxWidth: "min(94%,460px)",
|
| 392 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 393 |
+
color: "#eef3f6",
|
| 394 |
+
});
|
| 395 |
+
|
| 396 |
+
const h = document.createElement("div");
|
| 397 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 398 |
+
h.textContent = TITLE;
|
| 399 |
+
_overlay.appendChild(h);
|
| 400 |
+
|
| 401 |
+
const sub = document.createElement("div");
|
| 402 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 403 |
+
sub.innerHTML =
|
| 404 |
+
'Test-time adaptation with <b>no new module</b>: a stock MLP block\u2019s existing ' +
|
| 405 |
+
'<b>down-projection W_down</b> is re-purposed as <b>fast weights</b> (updated at inference), ' +
|
| 406 |
+
'while <b>W_up / W_gate stay frozen</b>. The update target is built by a <b>strictly-causal</b> ' +
|
| 407 |
+
'1-D convolution over past tokens (no future leakage), and one gradient step runs <b>per chunk</b>. ' +
|
| 408 |
+
'The <b>adapting</b> run\u2019s next-token loss <b>falls</b>; the <b>frozen-W_down control</b> stays <b>flat</b>. ' +
|
| 409 |
+
'Honesty label <b>MODELED</b> (inspired-not-real toy simulation; NOT the ByteDance model). 0 runtime CDN.';
|
| 410 |
+
_overlay.appendChild(sub);
|
| 411 |
+
|
| 412 |
+
const brow = document.createElement("div");
|
| 413 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 414 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 415 |
+
_overlay.appendChild(brow);
|
| 416 |
+
|
| 417 |
+
const card = document.createElement("div");
|
| 418 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 419 |
+
|
| 420 |
+
const chead = document.createElement("div");
|
| 421 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 422 |
+
const dot = document.createElement("span");
|
| 423 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 424 |
+
const nm = document.createElement("b");
|
| 425 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 426 |
+
nm.textContent = "in-place test-time training";
|
| 427 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 428 |
+
card.appendChild(chead);
|
| 429 |
+
|
| 430 |
+
const grid = document.createElement("div");
|
| 431 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 432 |
+
|
| 433 |
+
function kpiRow(id, label) {
|
| 434 |
+
const r = document.createElement("div");
|
| 435 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 436 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 437 |
+
const v = document.createElement("b");
|
| 438 |
+
v.id = id;
|
| 439 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:58%";
|
| 440 |
+
v.textContent = "\u2014";
|
| 441 |
+
_el[id] = v;
|
| 442 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
grid.appendChild(kpiRow("ip-fast", "fast weights (mutated)"));
|
| 446 |
+
grid.appendChild(kpiRow("ip-frozen", "frozen slow weights"));
|
| 447 |
+
grid.appendChild(kpiRow("ip-chunks", "chunks \u00d7 chunk_size"));
|
| 448 |
+
grid.appendChild(kpiRow("ip-lr", "learning_rate (per chunk)"));
|
| 449 |
+
grid.appendChild(kpiRow("ip-causal", "causal guard (no future leak)"));
|
| 450 |
+
grid.appendChild(kpiRow("ip-adapt", "adapt loss (start \u2192 end) \u2014 MODELED"));
|
| 451 |
+
grid.appendChild(kpiRow("ip-frozenl","frozen-control loss (flat)"));
|
| 452 |
+
grid.appendChild(kpiRow("ip-improve","improvement (adapting advantage)"));
|
| 453 |
+
grid.appendChild(kpiRow("ip-delta", "W_down movement (L1)"));
|
| 454 |
+
grid.appendChild(kpiRow("ip-label", "honesty label"));
|
| 455 |
+
card.appendChild(grid);
|
| 456 |
+
|
| 457 |
+
const fn = document.createElement("div");
|
| 458 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 459 |
+
fn.textContent = "Feng et al. 2026 (ByteDance Seed + Peking Univ) \u00b7 In-Place Test-Time Training \u00b7 arXiv:2604.06169 (ICLR 2026 Oral) \u00b7 github.com/ByteDance-Seed/In-Place-TTT. MODELED \u00b7 inspired-not-real \u00b7 not claimed-as.";
|
| 460 |
+
card.appendChild(fn);
|
| 461 |
+
_overlay.appendChild(card);
|
| 462 |
+
|
| 463 |
+
const pl = document.createElement("button");
|
| 464 |
+
pl.textContent = "\u25d1 what this means";
|
| 465 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 466 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 467 |
+
pl.addEventListener("click", () => {
|
| 468 |
+
_plain = !_plain;
|
| 469 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 470 |
+
_applyPlain();
|
| 471 |
+
});
|
| 472 |
+
_overlay.appendChild(pl);
|
| 473 |
+
|
| 474 |
+
const pd = document.createElement("div");
|
| 475 |
+
pd.id = "ip-plain";
|
| 476 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 477 |
+
_el["plain"] = pd;
|
| 478 |
+
_overlay.appendChild(pd);
|
| 479 |
+
|
| 480 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 481 |
+
_paintOverlay();
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
function _applyPlain() {
|
| 485 |
+
const pd = _el["plain"];
|
| 486 |
+
if (!pd) return;
|
| 487 |
+
pd.style.display = _plain ? "block" : "none";
|
| 488 |
+
if (!_plain) return;
|
| 489 |
+
const chunks = S.numChunks != null ? String(S.numChunks) : "loading\u2026";
|
| 490 |
+
const aS = S.adaptStart != null ? S.adaptStart.toFixed(4) : "loading\u2026";
|
| 491 |
+
const aE = S.adaptEnd != null ? S.adaptEnd.toFixed(4) : "loading\u2026";
|
| 492 |
+
const fE = S.frozenEnd != null ? S.frozenEnd.toFixed(4) : "loading\u2026";
|
| 493 |
+
pd.innerHTML =
|
| 494 |
+
"<b>What this means:</b> Normally an AI model\u2019s weights are <b>frozen</b> once training ends \u2014 " +
|
| 495 |
+
"it can\u2019t learn anything new while it answers you. In-Place Test-Time Training lets the model " +
|
| 496 |
+
"keep learning <i>as it reads</i>, <b>without bolting on any new part</b>: it quietly re-uses one " +
|
| 497 |
+
"matrix it already has (the <b>down-projection W_down</b>) as a scratchpad it\u2019s allowed to nudge, " +
|
| 498 |
+
"while the rest of the block stays fixed. To decide how to nudge it, the model looks only at what " +
|
| 499 |
+
"it has <b>already seen</b> (a strict <b>no-peeking-at-the-future</b> rule) and takes one small step " +
|
| 500 |
+
"per chunk of text. Over <b>" + chunks + "</b> chunks its next-word error <b>drops from " + aS + " to " + aE + "</b>, " +
|
| 501 |
+
"while an identical copy whose W_down is <b>kept frozen</b> stays flat at <b>" + fE + "</b>. " +
|
| 502 |
+
"<br><br><b>Inspired-not-real:</b> this view is a <b>MODELED</b> toy simulation of that mechanism " +
|
| 503 |
+
"\u2014 random toy weights, an 8-dimension hidden state and a tiny synthetic sequence. It is <b>NOT the " +
|
| 504 |
+
"ByteDance model</b> and does <b>NOT</b> reproduce the paper\u2019s 128k-context or 4B-parameter results; " +
|
| 505 |
+
"the loss drop is a qualitative demonstration on a controlled stream, not a benchmark claim. " +
|
| 506 |
+
"(Different from <b>titans</b>, which adds a whole new memory module, and from <b>testtime</b>, which " +
|
| 507 |
+
"just spends more compute without changing any weights \u2014 here an existing weight actually moves.)";
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
function _tok(s) {
|
| 511 |
+
if (s === "live") return null;
|
| 512 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 513 |
+
if (s === "degraded") return "DEGRADED";
|
| 514 |
+
if (s === "error") return "OFFLINE";
|
| 515 |
+
return "\u2026";
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 519 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 520 |
+
|
| 521 |
+
function _paintOverlay() {
|
| 522 |
+
const t = _tok(S.state);
|
| 523 |
+
_set("ip-fast", t || (S.fastMatrix ? S.fastMatrix + " (fast)" : "W_down (fast)"));
|
| 524 |
+
_set("ip-frozen", t || ((S.freezeUp || S.freezeGate) ? "W_up + W_gate \u2014 frozen" : "\u2014"));
|
| 525 |
+
_set("ip-chunks", t || (S.numChunks != null && S.chunkSize != null ? S.numChunks + " \u00d7 " + S.chunkSize : "\u2014"));
|
| 526 |
+
_set("ip-lr", t || fx(S.learningRate, 3));
|
| 527 |
+
_set("ip-causal", t || (S.causalGuard === true ? "OK \u2014 past-only" : (S.causalGuard === false ? "VIOLATION" : "\u2014")));
|
| 528 |
+
_set("ip-adapt", t || (S.adaptStart != null && S.adaptEnd != null
|
| 529 |
+
? fx(S.adaptStart, 4) + " \u2192 " + fx(S.adaptEnd, 4)
|
| 530 |
+
: "\u2014"));
|
| 531 |
+
_set("ip-frozenl", t || (S.frozenEnd != null
|
| 532 |
+
? fx(S.frozenEnd, 4) + (S.frozenDrop != null ? " (\u0394 " + fx(S.frozenDrop, 4) + ")" : "")
|
| 533 |
+
: "\u2014"));
|
| 534 |
+
_set("ip-improve", t || (S.improvement != null ? "+" + fx(S.improvement, 4) : "\u2014"));
|
| 535 |
+
_set("ip-delta", t || fx(S.deltaNorm, 3));
|
| 536 |
+
// honesty label verbatim — never upgraded
|
| 537 |
+
_set("ip-label", t || (S.label || "MODELED"));
|
| 538 |
+
if (_plain) _applyPlain();
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
// =============================================================================
|
| 542 |
+
// unmount — clean up everything; must not affect other organs
|
| 543 |
+
// =============================================================================
|
| 544 |
+
export function unmount() {
|
| 545 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 546 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 547 |
+
try {
|
| 548 |
+
if (_group && _stage) {
|
| 549 |
+
_group.traverse((o) => {
|
| 550 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 551 |
+
if (o.material) {
|
| 552 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 553 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 554 |
+
}
|
| 555 |
+
});
|
| 556 |
+
_stage.scene.remove(_group);
|
| 557 |
+
}
|
| 558 |
+
} catch (_) {}
|
| 559 |
+
_group = _overlay = null;
|
| 560 |
+
_floor = null; _lattice = []; _upBar = null; _gateBar = null;
|
| 561 |
+
_adaptLine = null; _frozenLine = null; _core = null;
|
| 562 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 563 |
+
_stage = _THREE = _ctx = null;
|
| 564 |
+
S.label = S.dModel = S.dFf = S.vocab = null;
|
| 565 |
+
S.chunkSize = S.numChunks = S.learningRate = null;
|
| 566 |
+
S.freezeUp = S.freezeGate = S.fastMatrix = S.causalKernel = S.causalGuard = null;
|
| 567 |
+
S.adaptStart = S.adaptEnd = S.frozenStart = S.frozenEnd = null;
|
| 568 |
+
S.adaptDrop = S.frozenDrop = S.improvement = S.curve = S.deltaNorm = null;
|
| 569 |
+
S.state = "init";
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/nested.js — NESTED LEARNING / CONTINUUM MEMORY SYSTEM ("Hope")
|
| 5 |
+
// organ for the holographic frontier ring (Behrouz, Razaviyayn, Zhong &
|
| 6 |
+
// Mirrokni, Google Research, NeurIPS 2025 — "the illusion of deep learning
|
| 7 |
+
// architectures"). Renders a THREE-TIER PLASTICITY LADDER of memory levels at
|
| 8 |
+
// different update clocks (fast k=1, medium k=8, slow k=64), fed by a streaming
|
| 9 |
+
// toy continual-learning task-block sequence. A HUD contrasts the FORGETTING
|
| 10 |
+
// CURVE of task A for a single-clock baseline vs the multi-timescale CMS
|
| 11 |
+
// schedule from the live snapshot at /api/killinchu/v1/nested/schedule. The
|
| 12 |
+
// slow "core" (protected by a surprise gate) glows proof-teal as it retains
|
| 13 |
+
// early tasks; the always-on baseline overwrites and forgets (grey). Honesty
|
| 14 |
+
// label "MODELED" is read VERBATIM from the JSON and displayed as-is; never
|
| 15 |
+
// upgraded.
|
| 16 |
+
//
|
| 17 |
+
// Surface export shape (mirrors titans.js / episodic.js exactly):
|
| 18 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 19 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 20 |
+
//
|
| 21 |
+
// DATA SHOWN (all from live endpoint, inside payload):
|
| 22 |
+
// num_tasks, block_len, n_tokens, k_fast, k_med, k_slow, gate, levels[],
|
| 23 |
+
// taskA_baseline[], taskA_cms[], retainedA_baseline, retainedA_cms,
|
| 24 |
+
// retention_delta, mean_retention_delta, slow_writes_cms,
|
| 25 |
+
// slow_writes_baseline, mean_surprise, peak_surprise, momentum, forget_curve[]
|
| 26 |
+
//
|
| 27 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 28 |
+
// Nested Learning: The Illusion of Deep Learning Architectures (the paradigm,
|
| 29 |
+
// Continuum Memory System, and "Hope" proof-of-concept simulated here):
|
| 30 |
+
// Behrouz, Razaviyayn, Zhong & Mirrokni 2025, Google Research, NeurIPS 2025
|
| 31 |
+
// https://arxiv.org/abs/2512.24695
|
| 32 |
+
// Google Research blog — Introducing Nested Learning (official announcement):
|
| 33 |
+
// https://research.google/blog/introducing-nested-learning-a-new-ml-paradigm-for-continual-learning/
|
| 34 |
+
//
|
| 35 |
+
// HONESTY LABELS: MODELED (deterministic re-implementation of the multi-
|
| 36 |
+
// timescale update-scheduling + optimizer-as-memory arithmetic; NOT the Hope
|
| 37 |
+
// architecture; NEVER-CLAIMED-AS a trained model). Independent-ablation
|
| 38 |
+
// nuance: the NeurIPS paper was noted in public commentary to lack full
|
| 39 |
+
// ablations in its first version, so this demonstrates the SCHEDULING
|
| 40 |
+
// MECHANISM reduces forgetting on a controlled toy stream — NOT reproducing
|
| 41 |
+
// Hope's benchmark wins. Read verbatim from JSON; never upgraded here. The
|
| 42 |
+
// endpoint nests its fields under `payload`, with the label at the top level —
|
| 43 |
+
// this surface handles the label at top-level OR inside payload.label
|
| 44 |
+
// defensively.
|
| 45 |
+
// COLOURS: lattice-blue 0x5b8dee (fast level / task stream / spine), violet-blue
|
| 46 |
+
// 0x8a6bff (medium level / clock ring), proof-teal 0x3af4c8 (protected slow
|
| 47 |
+
// core / retention / HUD accent), greys (forgotten / degraded state). Purple
|
| 48 |
+
// BANNED.
|
| 49 |
+
// 0 RUNTIME CDN. three.js via ctx.THREE (vendored by the page importmap).
|
| 50 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 51 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 52 |
+
|
| 53 |
+
const ID = "nested";
|
| 54 |
+
const TITLE = "Nested Learning · Continuum Memory System (live)";
|
| 55 |
+
|
| 56 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 57 |
+
// cross-origin (killinchu returns access-control-allow-origin: https://a-11-oy.com).
|
| 58 |
+
// This keeps the nested organ's rebuilds/faults isolated from the flagship.
|
| 59 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/nested/schedule?seed=42&num_tasks=6&k_fast=1&k_med=8&k_slow=64&gate=0.15";
|
| 60 |
+
|
| 61 |
+
// data-viz hues — purple BANNED
|
| 62 |
+
const C_FAST = 0x5b8dee; // lattice-blue (fast level / task stream / spine)
|
| 63 |
+
const C_MED = 0x8a6bff; // violet-blue (medium level / clock ring)
|
| 64 |
+
const C_SLOW = 0x3af4c8; // proof-teal (protected slow core / retention / HUD accent)
|
| 65 |
+
const C_FORGET = 0x5a6570; // grey (forgotten / overwritten baseline point)
|
| 66 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 67 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 68 |
+
|
| 69 |
+
// layout geometry
|
| 70 |
+
const LEVEL_Y = [0.7, 2.2, 3.7]; // y of fast / med / slow tiers (bottom -> top)
|
| 71 |
+
const LEVEL_R = [1.4, 2.6, 3.8]; // ring radius of each tier
|
| 72 |
+
const RING_SEG = 64; // ring outline segments
|
| 73 |
+
const MAX_BLOCKS = 96; // cap on forgetting-curve markers rendered
|
| 74 |
+
const CURVE_SPAN = 12.0; // world-units the forgetting curve spans along X
|
| 75 |
+
|
| 76 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 77 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 78 |
+
let _plain = false;
|
| 79 |
+
|
| 80 |
+
// geometry handles
|
| 81 |
+
let _floor = null;
|
| 82 |
+
let _rings = []; // Array<THREE.LineLoop> — one clock ring per level
|
| 83 |
+
let _tiers = []; // Array<THREE.Mesh> — the three memory-level nodes
|
| 84 |
+
let _baseMarks = []; // Array<THREE.Mesh> — baseline forgetting-curve markers
|
| 85 |
+
let _cmsMarks = []; // Array<THREE.Mesh> — CMS forgetting-curve markers
|
| 86 |
+
let _core = null; // THREE.Mesh — central slow-core "retention" node
|
| 87 |
+
|
| 88 |
+
// live state
|
| 89 |
+
const S = {
|
| 90 |
+
label: null,
|
| 91 |
+
numTasks: null, // num_tasks
|
| 92 |
+
blockLen: null, // block_len
|
| 93 |
+
nTokens: null, // n_tokens
|
| 94 |
+
kFast: null, // k_fast
|
| 95 |
+
kMed: null, // k_med
|
| 96 |
+
kSlow: null, // k_slow
|
| 97 |
+
gate: null, // gate
|
| 98 |
+
taskABase: null, // taskA_baseline[]
|
| 99 |
+
taskACms: null, // taskA_cms[]
|
| 100 |
+
retainBase: null, // retainedA_baseline
|
| 101 |
+
retainCms: null, // retainedA_cms
|
| 102 |
+
retDelta: null, // retention_delta
|
| 103 |
+
meanDelta: null, // mean_retention_delta
|
| 104 |
+
slowWritesCms: null, // slow_writes_cms
|
| 105 |
+
slowWritesBase: null, // slow_writes_baseline
|
| 106 |
+
meanSurprise: null, // mean_surprise
|
| 107 |
+
peakSurprise: null, // peak_surprise
|
| 108 |
+
momentum: null, // momentum
|
| 109 |
+
curve: null, // forget_curve[]
|
| 110 |
+
state: "init",
|
| 111 |
+
};
|
| 112 |
+
|
| 113 |
+
// =============================================================================
|
| 114 |
+
// mount(ctx)
|
| 115 |
+
// =============================================================================
|
| 116 |
+
export function mount(ctx) {
|
| 117 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 118 |
+
_group = new _THREE.Group();
|
| 119 |
+
_stage.scene.add(_group);
|
| 120 |
+
_stage.camera.position.set(0, 8, 20);
|
| 121 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 2.0, 0); _stage.controls.update(); } } catch (_) {}
|
| 122 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 123 |
+
|
| 124 |
+
_buildFloor();
|
| 125 |
+
_buildLadder();
|
| 126 |
+
_buildCurve();
|
| 127 |
+
_buildCore();
|
| 128 |
+
|
| 129 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 130 |
+
|
| 131 |
+
_badge = ctx.live.createBadge();
|
| 132 |
+
_polls.push(ctx.live.poll(EP, 5000, _onNested, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 133 |
+
|
| 134 |
+
_buildOverlay();
|
| 135 |
+
return { id: ID, started: true };
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
// =============================================================================
|
| 139 |
+
// builders
|
| 140 |
+
// =============================================================================
|
| 141 |
+
function _buildFloor() {
|
| 142 |
+
const THREE = _THREE;
|
| 143 |
+
const grid = new THREE.GridHelper(44, 44, C_GRID, 0x0f2027);
|
| 144 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 145 |
+
_group.add(grid);
|
| 146 |
+
_floor = grid;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
// The plasticity LADDER: three stacked clock rings (fast/med/slow) each with a
|
| 150 |
+
// central level node. Higher rings = slower clocks = more protected memory.
|
| 151 |
+
function _buildLadder() {
|
| 152 |
+
const THREE = _THREE;
|
| 153 |
+
const cols = [C_FAST, C_MED, C_SLOW];
|
| 154 |
+
|
| 155 |
+
for (let lvl = 0; lvl < 3; lvl++) {
|
| 156 |
+
const r = LEVEL_R[lvl];
|
| 157 |
+
const y = LEVEL_Y[lvl];
|
| 158 |
+
|
| 159 |
+
// clock ring outline
|
| 160 |
+
const pts = [];
|
| 161 |
+
for (let i = 0; i <= RING_SEG; i++) {
|
| 162 |
+
const a = (i / RING_SEG) * Math.PI * 2;
|
| 163 |
+
pts.push(new THREE.Vector3(Math.cos(a) * r, y, Math.sin(a) * r));
|
| 164 |
+
}
|
| 165 |
+
const geo = new THREE.BufferGeometry().setFromPoints(pts);
|
| 166 |
+
const mat = new THREE.LineBasicMaterial({ color: cols[lvl], transparent: true, opacity: 0.4 });
|
| 167 |
+
const ring = new THREE.LineLoop(geo, mat);
|
| 168 |
+
_group.add(ring);
|
| 169 |
+
_rings.push(ring);
|
| 170 |
+
|
| 171 |
+
// level node (the memory level itself)
|
| 172 |
+
const node = new THREE.Mesh(
|
| 173 |
+
new THREE.OctahedronGeometry(0.34, 0),
|
| 174 |
+
new THREE.MeshStandardMaterial({ color: cols[lvl], emissive: cols[lvl], emissiveIntensity: 0.3, transparent: true, opacity: 0.85 }),
|
| 175 |
+
);
|
| 176 |
+
node.position.set(0, y, 0);
|
| 177 |
+
_group.add(node);
|
| 178 |
+
_tiers.push(node);
|
| 179 |
+
}
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
// Two rows of forgetting-curve markers streaming along X: task-A accuracy after
|
| 183 |
+
// each task block for the single-clock baseline (front row) and the multi-
|
| 184 |
+
// timescale CMS schedule (back row). Height encodes retained accuracy.
|
| 185 |
+
function _buildCurve() {
|
| 186 |
+
const THREE = _THREE;
|
| 187 |
+
const mGeo = new THREE.SphereGeometry(0.13, 8, 8);
|
| 188 |
+
for (let i = 0; i < MAX_BLOCKS; i++) {
|
| 189 |
+
const x = -CURVE_SPAN / 2 + (i / (MAX_BLOCKS - 1)) * CURVE_SPAN;
|
| 190 |
+
|
| 191 |
+
const b = new THREE.Mesh(
|
| 192 |
+
mGeo,
|
| 193 |
+
new THREE.MeshStandardMaterial({ color: C_FORGET, emissive: C_FORGET, emissiveIntensity: 0.2, transparent: true, opacity: 0.0 }),
|
| 194 |
+
);
|
| 195 |
+
b.position.set(x, 0.2, 2.4);
|
| 196 |
+
b.visible = false;
|
| 197 |
+
_group.add(b);
|
| 198 |
+
_baseMarks.push(b);
|
| 199 |
+
|
| 200 |
+
const c = new THREE.Mesh(
|
| 201 |
+
mGeo,
|
| 202 |
+
new THREE.MeshStandardMaterial({ color: C_SLOW, emissive: C_SLOW, emissiveIntensity: 0.2, transparent: true, opacity: 0.0 }),
|
| 203 |
+
);
|
| 204 |
+
c.position.set(x, 0.2, -2.4);
|
| 205 |
+
c.visible = false;
|
| 206 |
+
_group.add(c);
|
| 207 |
+
_cmsMarks.push(c);
|
| 208 |
+
}
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
function _buildCore() {
|
| 212 |
+
const THREE = _THREE;
|
| 213 |
+
_core = new THREE.Mesh(
|
| 214 |
+
new THREE.IcosahedronGeometry(0.6, 1),
|
| 215 |
+
new THREE.MeshStandardMaterial({ color: C_SLOW, emissive: C_SLOW, emissiveIntensity: 0.45, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 216 |
+
);
|
| 217 |
+
_core.position.set(0, LEVEL_Y[2], 0);
|
| 218 |
+
_group.add(_core);
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
// =============================================================================
|
| 222 |
+
// live data handler
|
| 223 |
+
// =============================================================================
|
| 224 |
+
function _onNested(j) {
|
| 225 |
+
// The endpoint nests its metrics under `payload`; the honesty label may sit at
|
| 226 |
+
// the TOP LEVEL or (defensively) inside payload.label. Read it VERBATIM from
|
| 227 |
+
// wherever it is — never upgrade.
|
| 228 |
+
const p = (j && typeof j.payload === "object" && j.payload) ? j.payload : j;
|
| 229 |
+
const rawLabel = (j && j.label) || (p && p.label) || "MODELED";
|
| 230 |
+
S.label = String(rawLabel).toUpperCase();
|
| 231 |
+
|
| 232 |
+
S.numTasks = typeof p.num_tasks === "number" ? p.num_tasks : null;
|
| 233 |
+
S.blockLen = typeof p.block_len === "number" ? p.block_len : null;
|
| 234 |
+
S.nTokens = typeof p.n_tokens === "number" ? p.n_tokens : null;
|
| 235 |
+
S.kFast = typeof p.k_fast === "number" ? p.k_fast : null;
|
| 236 |
+
S.kMed = typeof p.k_med === "number" ? p.k_med : null;
|
| 237 |
+
S.kSlow = typeof p.k_slow === "number" ? p.k_slow : null;
|
| 238 |
+
S.gate = typeof p.gate === "number" ? p.gate : null;
|
| 239 |
+
S.retainBase = typeof p.retainedA_baseline === "number" ? p.retainedA_baseline : null;
|
| 240 |
+
S.retainCms = typeof p.retainedA_cms === "number" ? p.retainedA_cms : null;
|
| 241 |
+
S.retDelta = typeof p.retention_delta === "number" ? p.retention_delta : null;
|
| 242 |
+
S.meanDelta = typeof p.mean_retention_delta === "number" ? p.mean_retention_delta : null;
|
| 243 |
+
S.slowWritesCms = typeof p.slow_writes_cms === "number" ? p.slow_writes_cms : null;
|
| 244 |
+
S.slowWritesBase = typeof p.slow_writes_baseline === "number" ? p.slow_writes_baseline : null;
|
| 245 |
+
S.meanSurprise = typeof p.mean_surprise === "number" ? p.mean_surprise : null;
|
| 246 |
+
S.peakSurprise = typeof p.peak_surprise === "number" ? p.peak_surprise : null;
|
| 247 |
+
S.momentum = typeof p.momentum === "number" ? p.momentum : null;
|
| 248 |
+
S.taskABase = Array.isArray(p.taskA_baseline) ? p.taskA_baseline : null;
|
| 249 |
+
S.taskACms = Array.isArray(p.taskA_cms) ? p.taskA_cms : null;
|
| 250 |
+
S.curve = Array.isArray(p.forget_curve) ? p.forget_curve : null;
|
| 251 |
+
|
| 252 |
+
_updateScene();
|
| 253 |
+
_paintOverlay();
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
// =============================================================================
|
| 257 |
+
// geometry updater — drives the ladder + forgetting curve from live data
|
| 258 |
+
// =============================================================================
|
| 259 |
+
function _updateScene() {
|
| 260 |
+
const live = S.state === "live";
|
| 261 |
+
const cols = [C_FAST, C_MED, C_SLOW];
|
| 262 |
+
|
| 263 |
+
// clock rings + level nodes degrade to grey when not live
|
| 264 |
+
for (let lvl = 0; lvl < 3; lvl++) {
|
| 265 |
+
const ring = _rings[lvl];
|
| 266 |
+
if (ring) {
|
| 267 |
+
ring.material.color.setHex(live ? cols[lvl] : C_DIM);
|
| 268 |
+
ring.material.opacity = live ? 0.4 : 0.12;
|
| 269 |
+
}
|
| 270 |
+
const node = _tiers[lvl];
|
| 271 |
+
if (node) {
|
| 272 |
+
const c = live ? cols[lvl] : C_FORGET;
|
| 273 |
+
node.material.color.setHex(c);
|
| 274 |
+
node.material.emissive.setHex(c);
|
| 275 |
+
node.material.emissiveIntensity = live ? 0.35 : 0.08;
|
| 276 |
+
node.material.opacity = live ? 0.9 : 0.25;
|
| 277 |
+
}
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
// forgetting-curve markers: height = retained task-A accuracy per block.
|
| 281 |
+
const base = live && S.taskABase && S.taskABase.length ? S.taskABase.slice(0, MAX_BLOCKS) : [];
|
| 282 |
+
const cms = live && S.taskACms && S.taskACms.length ? S.taskACms.slice(0, MAX_BLOCKS) : [];
|
| 283 |
+
const n = Math.max(base.length, cms.length);
|
| 284 |
+
for (let i = 0; i < MAX_BLOCKS; i++) {
|
| 285 |
+
const bm = _baseMarks[i];
|
| 286 |
+
const cm = _cmsMarks[i];
|
| 287 |
+
if (!live || i >= n) { bm.visible = false; cm.visible = false; continue; }
|
| 288 |
+
|
| 289 |
+
if (i < base.length) {
|
| 290 |
+
const a = base[i];
|
| 291 |
+
bm.visible = true;
|
| 292 |
+
bm.position.y = 0.2 + a * 3.2;
|
| 293 |
+
// baseline that has forgotten (low retention) fades to grey
|
| 294 |
+
const c = a >= 0.5 ? C_FAST : C_FORGET;
|
| 295 |
+
bm.material.color.setHex(c);
|
| 296 |
+
bm.material.emissive.setHex(c);
|
| 297 |
+
bm.material.emissiveIntensity = 0.2 + 0.5 * a;
|
| 298 |
+
bm.material.opacity = 0.35 + 0.55 * a;
|
| 299 |
+
bm.scale.setScalar(0.7 + 0.7 * a);
|
| 300 |
+
} else { bm.visible = false; }
|
| 301 |
+
|
| 302 |
+
if (i < cms.length) {
|
| 303 |
+
const a = cms[i];
|
| 304 |
+
cm.visible = true;
|
| 305 |
+
cm.position.y = 0.2 + a * 3.2;
|
| 306 |
+
cm.material.color.setHex(C_SLOW);
|
| 307 |
+
cm.material.emissive.setHex(C_SLOW);
|
| 308 |
+
cm.material.emissiveIntensity = 0.25 + 0.6 * a;
|
| 309 |
+
cm.material.opacity = 0.4 + 0.55 * a;
|
| 310 |
+
cm.scale.setScalar(0.7 + 0.7 * a);
|
| 311 |
+
} else { cm.visible = false; }
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// slow core: size/brightness reflect how much of task A the protected core
|
| 315 |
+
// retains (retainedA_cms), and pulse brighter with the retention advantage.
|
| 316 |
+
if (_core) {
|
| 317 |
+
if (live && S.retainCms != null) {
|
| 318 |
+
_core.material.color.setHex(C_SLOW);
|
| 319 |
+
_core.material.emissive.setHex(C_SLOW);
|
| 320 |
+
_core.material.opacity = 0.85;
|
| 321 |
+
_core.scale.setScalar(0.6 + S.retainCms * 1.0);
|
| 322 |
+
} else {
|
| 323 |
+
_core.material.color.setHex(C_DIM);
|
| 324 |
+
_core.material.emissive.setHex(C_DIM);
|
| 325 |
+
_core.material.opacity = 0.3;
|
| 326 |
+
_core.scale.setScalar(0.6);
|
| 327 |
+
}
|
| 328 |
+
}
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// =============================================================================
|
| 332 |
+
// per-frame animation
|
| 333 |
+
// =============================================================================
|
| 334 |
+
function _onFrame() {
|
| 335 |
+
const t = performance.now();
|
| 336 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00008) * 0.14;
|
| 337 |
+
// rings spin at their own clock rate — fast ring spins fastest
|
| 338 |
+
if (_rings[0]) _rings[0].rotation.y += 0.010;
|
| 339 |
+
if (_rings[1]) _rings[1].rotation.y += 0.0035;
|
| 340 |
+
if (_rings[2]) _rings[2].rotation.y += 0.0009;
|
| 341 |
+
if (_core) {
|
| 342 |
+
_core.rotation.y += 0.02;
|
| 343 |
+
_core.rotation.x += 0.009;
|
| 344 |
+
const pulse = 1.0 + 0.12 * Math.sin(t * 0.0035);
|
| 345 |
+
const base = (S.state === "live" && S.retainCms != null) ? (0.6 + S.retainCms * 1.0) : 0.6;
|
| 346 |
+
_core.scale.setScalar(base * pulse);
|
| 347 |
+
}
|
| 348 |
+
}
|
| 349 |
+
|
| 350 |
+
// =============================================================================
|
| 351 |
+
// overlay
|
| 352 |
+
// =============================================================================
|
| 353 |
+
function _buildOverlay() {
|
| 354 |
+
const ctx = _ctx;
|
| 355 |
+
_overlay = document.createElement("div");
|
| 356 |
+
Object.assign(_overlay.style, {
|
| 357 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 358 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 359 |
+
maxWidth: "min(94%,460px)",
|
| 360 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 361 |
+
color: "#eef3f6",
|
| 362 |
+
});
|
| 363 |
+
|
| 364 |
+
const h = document.createElement("div");
|
| 365 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 366 |
+
h.textContent = TITLE;
|
| 367 |
+
_overlay.appendChild(h);
|
| 368 |
+
|
| 369 |
+
const sub = document.createElement("div");
|
| 370 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 371 |
+
sub.innerHTML =
|
| 372 |
+
'A model as a stack of memory levels updating at <b>different clocks</b> (fast/medium/slow), with ' +
|
| 373 |
+
'the <b>optimizer itself as associative memory</b>. On a toy continual-learning stream, the slow ' +
|
| 374 |
+
'<b>protected core</b> (a surprise-gated timescale) <b>retains earlier tasks</b> where a single-clock ' +
|
| 375 |
+
'baseline overwrites and <b>forgets</b> them. ' +
|
| 376 |
+
'Honesty label <b>MODELED</b> (deterministic scheduling simulation; NOT the Hope architecture). 0 runtime CDN.';
|
| 377 |
+
_overlay.appendChild(sub);
|
| 378 |
+
|
| 379 |
+
const brow = document.createElement("div");
|
| 380 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 381 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 382 |
+
_overlay.appendChild(brow);
|
| 383 |
+
|
| 384 |
+
const card = document.createElement("div");
|
| 385 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 386 |
+
|
| 387 |
+
const chead = document.createElement("div");
|
| 388 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 389 |
+
const dot = document.createElement("span");
|
| 390 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 391 |
+
const nm = document.createElement("b");
|
| 392 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 393 |
+
nm.textContent = "nested learning / continuum memory system";
|
| 394 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 395 |
+
card.appendChild(chead);
|
| 396 |
+
|
| 397 |
+
const grid = document.createElement("div");
|
| 398 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 399 |
+
|
| 400 |
+
function kpiRow(id, label) {
|
| 401 |
+
const r = document.createElement("div");
|
| 402 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 403 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 404 |
+
const v = document.createElement("b");
|
| 405 |
+
v.id = id;
|
| 406 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:58%";
|
| 407 |
+
v.textContent = "\u2014";
|
| 408 |
+
_el[id] = v;
|
| 409 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 410 |
+
}
|
| 411 |
+
|
| 412 |
+
grid.appendChild(kpiRow("ne-tasks", "continual-learning tasks"));
|
| 413 |
+
grid.appendChild(kpiRow("ne-clocks", "clocks k_fast / k_med / k_slow"));
|
| 414 |
+
grid.appendChild(kpiRow("ne-gate", "slow-core surprise gate"));
|
| 415 |
+
grid.appendChild(kpiRow("ne-retbase", "task-A retained \u2014 single-clock"));
|
| 416 |
+
grid.appendChild(kpiRow("ne-retcms", "task-A retained \u2014 CMS (MODELED)"));
|
| 417 |
+
grid.appendChild(kpiRow("ne-delta", "retention gain (CMS \u2212 baseline)"));
|
| 418 |
+
grid.appendChild(kpiRow("ne-writes", "slow-core writes CMS / baseline"));
|
| 419 |
+
grid.appendChild(kpiRow("ne-surprise","mean / peak surprise"));
|
| 420 |
+
grid.appendChild(kpiRow("ne-momentum","momentum (optimizer-as-memory)"));
|
| 421 |
+
grid.appendChild(kpiRow("ne-label", "honesty label"));
|
| 422 |
+
card.appendChild(grid);
|
| 423 |
+
|
| 424 |
+
const fn = document.createElement("div");
|
| 425 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 426 |
+
fn.textContent = "Behrouz, Razaviyayn, Zhong & Mirrokni 2025 (Google Research) \u00b7 Nested Learning: The Illusion of Deep Learning Architectures \u00b7 NeurIPS 2025 \u00b7 arXiv:2512.24695 \u00b7 research.google/blog Nested Learning. MODELED \u00b7 not claimed-as.";
|
| 427 |
+
card.appendChild(fn);
|
| 428 |
+
_overlay.appendChild(card);
|
| 429 |
+
|
| 430 |
+
const pl = document.createElement("button");
|
| 431 |
+
pl.textContent = "\u25d1 what this means";
|
| 432 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 433 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 434 |
+
pl.addEventListener("click", () => {
|
| 435 |
+
_plain = !_plain;
|
| 436 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 437 |
+
_applyPlain();
|
| 438 |
+
});
|
| 439 |
+
_overlay.appendChild(pl);
|
| 440 |
+
|
| 441 |
+
const pd = document.createElement("div");
|
| 442 |
+
pd.id = "ne-plain";
|
| 443 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 444 |
+
_el["plain"] = pd;
|
| 445 |
+
_overlay.appendChild(pd);
|
| 446 |
+
|
| 447 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 448 |
+
_paintOverlay();
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
function _applyPlain() {
|
| 452 |
+
const pd = _el["plain"];
|
| 453 |
+
if (!pd) return;
|
| 454 |
+
pd.style.display = _plain ? "block" : "none";
|
| 455 |
+
if (!_plain) return;
|
| 456 |
+
const rBase = S.retainBase != null ? (S.retainBase * 100).toFixed(0) + "%" : "loading\u2026";
|
| 457 |
+
const rCms = S.retainCms != null ? (S.retainCms * 100).toFixed(0) + "%" : "loading\u2026";
|
| 458 |
+
const dPct = S.retDelta != null ? "+" + (S.retDelta * 100).toFixed(0) + " points" : "loading\u2026";
|
| 459 |
+
pd.innerHTML =
|
| 460 |
+
"<b>What this means:</b> When an AI learns a new skill it often <b>forgets the old one</b> " +
|
| 461 |
+
"(\u201ccatastrophic forgetting\u201d). Nested Learning treats the model as a <b>stack of memories that " +
|
| 462 |
+
"update at different speeds</b> \u2014 a fast one that chases whatever it is learning right now, and " +
|
| 463 |
+
"slower ones that only commit knowledge once it has <b>settled</b>. The slowest \u201ccore\u201d is " +
|
| 464 |
+
"<b>protected</b>: it refuses to overwrite itself during the noisy middle of learning something new. " +
|
| 465 |
+
"Here we teach it several small tasks in a row and then check how much of the <b>first</b> task it still " +
|
| 466 |
+
"remembers. A plain single-speed model keeps only about <b>" + rBase + "</b> of task A, while the " +
|
| 467 |
+
"multi-speed schedule keeps about <b>" + rCms + "</b> \u2014 a gain of roughly <b>" + dPct + "</b> less " +
|
| 468 |
+
"forgetting on this toy stream. " +
|
| 469 |
+
"<b>Honest caveat:</b> this is a <b>MODELED</b> toy simulation of the scheduling idea (tiny linear " +
|
| 470 |
+
"tasks, hand-set clocks), <b>not the \u201cHope\u201d model</b>. The paper was noted publicly to lack full " +
|
| 471 |
+
"ablations in its first version, so this only shows the <b>scheduling mechanism</b> reduces forgetting " +
|
| 472 |
+
"on a controlled stream \u2014 it does <b>not</b> reproduce Hope's language-modeling or needle-in-haystack " +
|
| 473 |
+
"results or its claimed wins over Titans / Transformers.";
|
| 474 |
+
}
|
| 475 |
+
|
| 476 |
+
function _tok(s) {
|
| 477 |
+
if (s === "live") return null;
|
| 478 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 479 |
+
if (s === "degraded") return "DEGRADED";
|
| 480 |
+
if (s === "error") return "OFFLINE";
|
| 481 |
+
return "\u2026";
|
| 482 |
+
}
|
| 483 |
+
|
| 484 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 485 |
+
function pct(v, d) { return typeof v === "number" ? (v * 100).toFixed(d) + "%" : "\u2014"; }
|
| 486 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 487 |
+
|
| 488 |
+
function _paintOverlay() {
|
| 489 |
+
const t = _tok(S.state);
|
| 490 |
+
_set("ne-tasks", t || (S.numTasks != null ? String(S.numTasks) : "\u2014"));
|
| 491 |
+
_set("ne-clocks", t || (S.kFast != null || S.kMed != null || S.kSlow != null
|
| 492 |
+
? (S.kFast != null ? String(S.kFast) : "\u2014") + " / " +
|
| 493 |
+
(S.kMed != null ? String(S.kMed) : "\u2014") + " / " +
|
| 494 |
+
(S.kSlow != null ? String(S.kSlow) : "\u2014")
|
| 495 |
+
: "\u2014"));
|
| 496 |
+
_set("ne-gate", t || fx(S.gate, 3));
|
| 497 |
+
_set("ne-retbase", t || pct(S.retainBase, 1));
|
| 498 |
+
_set("ne-retcms", t || pct(S.retainCms, 1));
|
| 499 |
+
_set("ne-delta", t || (S.retDelta != null ? "+" + (S.retDelta * 100).toFixed(1) + "%" : "\u2014"));
|
| 500 |
+
_set("ne-writes", t || (S.slowWritesCms != null || S.slowWritesBase != null
|
| 501 |
+
? (S.slowWritesCms != null ? String(S.slowWritesCms) : "\u2014") + " / " +
|
| 502 |
+
(S.slowWritesBase != null ? String(S.slowWritesBase) : "\u2014")
|
| 503 |
+
: "\u2014"));
|
| 504 |
+
_set("ne-surprise", t || (S.meanSurprise != null || S.peakSurprise != null
|
| 505 |
+
? fx(S.meanSurprise, 3) + " / " + fx(S.peakSurprise, 3)
|
| 506 |
+
: "\u2014"));
|
| 507 |
+
_set("ne-momentum", t || fx(S.momentum, 2));
|
| 508 |
+
// honesty label verbatim — never upgraded
|
| 509 |
+
_set("ne-label", t || (S.label || "MODELED"));
|
| 510 |
+
if (_plain) _applyPlain();
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
// =============================================================================
|
| 514 |
+
// unmount — clean up everything; must not affect other organs
|
| 515 |
+
// =============================================================================
|
| 516 |
+
export function unmount() {
|
| 517 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 518 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 519 |
+
try {
|
| 520 |
+
if (_group && _stage) {
|
| 521 |
+
_group.traverse((o) => {
|
| 522 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 523 |
+
if (o.material) {
|
| 524 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 525 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 526 |
+
}
|
| 527 |
+
});
|
| 528 |
+
_stage.scene.remove(_group);
|
| 529 |
+
}
|
| 530 |
+
} catch (_) {}
|
| 531 |
+
_group = _overlay = null;
|
| 532 |
+
_floor = null; _rings = []; _tiers = []; _baseMarks = []; _cmsMarks = []; _core = null;
|
| 533 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 534 |
+
_stage = _THREE = _ctx = null;
|
| 535 |
+
S.label = S.numTasks = S.blockLen = S.nTokens = null;
|
| 536 |
+
S.kFast = S.kMed = S.kSlow = S.gate = null;
|
| 537 |
+
S.taskABase = S.taskACms = null;
|
| 538 |
+
S.retainBase = S.retainCms = S.retDelta = S.meanDelta = null;
|
| 539 |
+
S.slowWritesCms = S.slowWritesBase = null;
|
| 540 |
+
S.meanSurprise = S.peakSurprise = S.momentum = null;
|
| 541 |
+
S.curve = null;
|
| 542 |
+
S.state = "init";
|
| 543 |
+
}
|
| 544 |
+
|
| 545 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|
static/3d/surfaces/sement.js
ADDED
|
@@ -0,0 +1,456 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/sement.js — SEMANTIC-ENTROPY / EFFECTIVE-RANK EPISTEMIC-UNCERTAINTY
|
| 5 |
+
// hallucination-detection organ for the holographic frontier ring.
|
| 6 |
+
//
|
| 7 |
+
// Renders two side-by-side "regime" pylons — a CONFIDENT regime and a CONFABULATING regime —
|
| 8 |
+
// driven by a live snapshot from /api/killinchu/v1/sement/estimate. For each regime the organ
|
| 9 |
+
// samples K candidate generations for one fixed prompt, clusters them into semantic-equivalence
|
| 10 |
+
// classes, and shows three bars: NAIVE (surface-string) entropy, SEMANTIC (meaning-cluster)
|
| 11 |
+
// entropy, and spectral EFFECTIVE RANK — plus a threshold-driven answer/abstain verdict. The
|
| 12 |
+
// honest signal it visualizes: semantic entropy AND effective rank both RISE on the confabulating
|
| 13 |
+
// regime while naive entropy can be misleadingly low. Honesty label "MODELED" is read VERBATIM
|
| 14 |
+
// from the JSON and displayed as-is; never upgraded.
|
| 15 |
+
//
|
| 16 |
+
// IMPORTANT — MODELED, NOT A REAL LLM:
|
| 17 |
+
// This organ simulates the uncertainty-estimation METHOD on synthetic toy data. The
|
| 18 |
+
// semantic-equivalence clustering is a HAND-SPECIFIED lookup table (real semantic entropy
|
| 19 |
+
// uses a bidirectional-entailment model); the "hidden states" behind the effective rank are
|
| 20 |
+
// SYNTHETIC seeded matrices. It demonstrates the ORDERING (uncertain > confident) that the
|
| 21 |
+
// published methods exploit; it does NOT reproduce AUROC or benchmark numbers and makes no
|
| 22 |
+
// claim about real-model calibration. This is stated plainly in the "what this means" copy
|
| 23 |
+
// and echoed in the endpoint's own JSON payload (honest_note).
|
| 24 |
+
//
|
| 25 |
+
// Surface export shape (mirrors qhall.js / interpretability.js exactly):
|
| 26 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 27 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 28 |
+
//
|
| 29 |
+
// DATA SHOWN (all from live endpoint):
|
| 30 |
+
// K — candidate generations sampled per regime
|
| 31 |
+
// naive_entropy — Shannon entropy over SURFACE strings (nats)
|
| 32 |
+
// semantic_entropy — Shannon entropy over MEANING clusters (nats)
|
| 33 |
+
// effective_rank — exp(entropy of normalized singular values) of synthetic hidden states
|
| 34 |
+
// decision — "answer" | "abstain" (threshold on semantic entropy)
|
| 35 |
+
// n_clusters — semantic-equivalence classes recovered
|
| 36 |
+
// ordering_holds — semantic entropy & effective rank both rise on confabulating
|
| 37 |
+
//
|
| 38 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own):
|
| 39 |
+
// Farquhar, Kossen, Kuhn & Gal (2024) "Detecting hallucinations in large language models
|
| 40 |
+
// using semantic entropy". Nature 630, 625-630. DOI 10.1038/s41586-024-07421-0.
|
| 41 |
+
// https://www.nature.com/articles/s41586-024-07421-0
|
| 42 |
+
// Wang, Wei, Yue & Sun (2025) "Revisiting Hallucination Detection with Effective
|
| 43 |
+
// Rank-based Uncertainty". arXiv:2510.08389. https://arxiv.org/abs/2510.08389
|
| 44 |
+
//
|
| 45 |
+
// HONESTY LABELS: MODELED (simulation of the METHOD on synthetic toy data; hand-specified
|
| 46 |
+
// clustering, synthetic hidden states, NO real LLM). Read verbatim from JSON.
|
| 47 |
+
// COLOURS: lattice-blue 0x5b8dee (confident regime / naive-entropy bar), violet-blue 0x8a6bff
|
| 48 |
+
// (confabulating regime / semantic-entropy bar — data-viz only), proof-teal 0x3af4c8
|
| 49 |
+
// (effective-rank accent), greys for dim/idle. Purple BANNED as UI/background.
|
| 50 |
+
// 0 RUNTIME CDN. Vendored three.js via page importmap (ctx.THREE).
|
| 51 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 52 |
+
// This organ adds NOTHING to SZL's own locked-8 / Λ-Conjecture-1.
|
| 53 |
+
|
| 54 |
+
const ID = "sement";
|
| 55 |
+
const TITLE = "Semantic-Entropy · Effective-Rank Epistemic Uncertainty (live)";
|
| 56 |
+
|
| 57 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 58 |
+
// cross-origin (killinchu returns access-control-allow-origin for the flagship origin).
|
| 59 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/sement/estimate?seed=42&K=40&n_clusters=5&threshold=0.6";
|
| 60 |
+
|
| 61 |
+
// data-viz hues — purple BANNED
|
| 62 |
+
const C_CONF = 0x5b8dee; // lattice-blue (confident regime / naive-entropy bar)
|
| 63 |
+
const C_CONFAB = 0x8a6bff; // violet-blue (confabulating regime / semantic-entropy bar — data-viz only)
|
| 64 |
+
const C_ACCENT = 0x3af4c8; // proof-teal accent (effective-rank bar + verdict ring)
|
| 65 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data / idle)
|
| 66 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 67 |
+
|
| 68 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 69 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 70 |
+
let _plain = false;
|
| 71 |
+
|
| 72 |
+
// geometry handles — two regime clusters, each with three metric bars
|
| 73 |
+
let _bars = []; // Array<THREE.Mesh> — 2 regimes x 3 metrics
|
| 74 |
+
let _rings = []; // Array<THREE.Mesh> — one verdict ring per regime
|
| 75 |
+
const _MAX_BARS = 6;
|
| 76 |
+
const _pulse = new Float32Array(_MAX_BARS);
|
| 77 |
+
let _built = false;
|
| 78 |
+
|
| 79 |
+
// live state
|
| 80 |
+
const S = {
|
| 81 |
+
label: null,
|
| 82 |
+
K: null, // K samples per regime
|
| 83 |
+
threshold: null, // abstain/answer threshold (nats)
|
| 84 |
+
ordering: null, // ordering_holds
|
| 85 |
+
// per-regime metrics: index 0 = confident, 1 = confabulating
|
| 86 |
+
reg: [
|
| 87 |
+
{ name: "confident", naive: null, sem: null, effr: null, decision: null, nclus: null },
|
| 88 |
+
{ name: "confabulating", naive: null, sem: null, effr: null, decision: null, nclus: null },
|
| 89 |
+
],
|
| 90 |
+
state: "init",
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
// =============================================================================
|
| 94 |
+
// mount(ctx)
|
| 95 |
+
// =============================================================================
|
| 96 |
+
export function mount(ctx) {
|
| 97 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 98 |
+
_group = new _THREE.Group();
|
| 99 |
+
_stage.scene.add(_group);
|
| 100 |
+
_stage.camera.position.set(0, 7, 20);
|
| 101 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 2.0, 0); _stage.controls.update(); } } catch (_) {}
|
| 102 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 103 |
+
|
| 104 |
+
_buildFloor();
|
| 105 |
+
_buildBars();
|
| 106 |
+
|
| 107 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 108 |
+
|
| 109 |
+
_badge = ctx.live.createBadge();
|
| 110 |
+
_polls.push(ctx.live.poll(EP, 5000, _onEstimate, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); _updateBars(); } }));
|
| 111 |
+
|
| 112 |
+
_buildOverlay();
|
| 113 |
+
return { id: ID, started: true };
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
// =============================================================================
|
| 117 |
+
// builders
|
| 118 |
+
// =============================================================================
|
| 119 |
+
function _buildFloor() {
|
| 120 |
+
const THREE = _THREE;
|
| 121 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 122 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 123 |
+
_group.add(grid);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// Two regime clusters, each with three metric bars (naive / semantic / effective-rank),
|
| 127 |
+
// plus a verdict ring above each cluster. Heights are set from live data in _updateBars().
|
| 128 |
+
function _buildBars() {
|
| 129 |
+
const THREE = _THREE;
|
| 130 |
+
if (_built) return;
|
| 131 |
+
_built = true;
|
| 132 |
+
|
| 133 |
+
const barGeo = new THREE.BoxGeometry(0.9, 1.0, 0.9);
|
| 134 |
+
const cols = [C_CONF, C_CONFAB, C_ACCENT]; // naive, semantic, effective-rank
|
| 135 |
+
// regime cluster centres (confident left, confabulating right)
|
| 136 |
+
const centres = [-5.0, 5.0];
|
| 137 |
+
const spread = 1.4;
|
| 138 |
+
|
| 139 |
+
_bars = [];
|
| 140 |
+
for (let r = 0; r < 2; r++) {
|
| 141 |
+
for (let m = 0; m < 3; m++) {
|
| 142 |
+
const mat = new THREE.MeshStandardMaterial({
|
| 143 |
+
color: C_DIM, emissive: C_DIM, emissiveIntensity: 0.15, metalness: 0.25, roughness: 0.55,
|
| 144 |
+
});
|
| 145 |
+
const mesh = new THREE.Mesh(barGeo, mat);
|
| 146 |
+
const x = centres[r] + (m - 1) * spread;
|
| 147 |
+
mesh.position.set(x, 0.5, 0);
|
| 148 |
+
mesh.userData.baseCol = cols[m];
|
| 149 |
+
mesh.userData.x = x;
|
| 150 |
+
_group.add(mesh);
|
| 151 |
+
_bars.push(mesh);
|
| 152 |
+
}
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
// verdict rings, one above each regime cluster
|
| 156 |
+
_rings = [];
|
| 157 |
+
for (let r = 0; r < 2; r++) {
|
| 158 |
+
const ring = new THREE.Mesh(
|
| 159 |
+
new THREE.TorusGeometry(1.6, 0.05, 10, 48),
|
| 160 |
+
new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.4, transparent: true, opacity: 0.5 }),
|
| 161 |
+
);
|
| 162 |
+
ring.position.set(centres[r], 6.4, 0);
|
| 163 |
+
ring.rotation.x = Math.PI / 2;
|
| 164 |
+
_group.add(ring);
|
| 165 |
+
_rings.push(ring);
|
| 166 |
+
}
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// =============================================================================
|
| 170 |
+
// live data handler — reads label VERBATIM (top-level 'label' OR nested 'payload.label')
|
| 171 |
+
// =============================================================================
|
| 172 |
+
function _onEstimate(j) {
|
| 173 |
+
const p = (j && typeof j.payload === "object" && j.payload) ? j.payload : j;
|
| 174 |
+
const rawLabel = (p && p.label != null) ? p.label : (j && j.label != null ? j.label : "MODELED");
|
| 175 |
+
S.label = String(rawLabel).toUpperCase();
|
| 176 |
+
|
| 177 |
+
S.K = typeof p.K === "number" ? p.K : null;
|
| 178 |
+
S.threshold = typeof p.threshold === "number" ? p.threshold : null;
|
| 179 |
+
S.ordering = typeof p.ordering_holds === "boolean" ? p.ordering_holds : null;
|
| 180 |
+
|
| 181 |
+
if (Array.isArray(p.regimes)) {
|
| 182 |
+
p.regimes.forEach((rr) => {
|
| 183 |
+
const idx = rr && rr.regime === "confabulating" ? 1 : (rr && rr.regime === "confident" ? 0 : -1);
|
| 184 |
+
if (idx < 0) return;
|
| 185 |
+
const slot = S.reg[idx];
|
| 186 |
+
slot.naive = typeof rr.naive_entropy === "number" ? rr.naive_entropy : null;
|
| 187 |
+
slot.sem = typeof rr.semantic_entropy === "number" ? rr.semantic_entropy : null;
|
| 188 |
+
slot.effr = typeof rr.effective_rank === "number" ? rr.effective_rank : null;
|
| 189 |
+
slot.decision = typeof rr.decision === "string" ? rr.decision : null;
|
| 190 |
+
slot.nclus = typeof rr.n_clusters === "number" ? rr.n_clusters : null;
|
| 191 |
+
});
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
_updateBars();
|
| 195 |
+
_paintOverlay();
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
// =============================================================================
|
| 199 |
+
// geometry updater — bar heights from metrics, colours by regime/metric, verdict rings
|
| 200 |
+
// =============================================================================
|
| 201 |
+
function _updateBars() {
|
| 202 |
+
const live = S.state === "live";
|
| 203 |
+
// normalization so bars stay on-screen: entropies in nats (~0..2), eff-rank (~1..8)
|
| 204 |
+
const entScale = 1.6; // world units per nat
|
| 205 |
+
const rankScale = 0.5; // world units per rank unit
|
| 206 |
+
for (let r = 0; r < 2; r++) {
|
| 207 |
+
const slot = S.reg[r];
|
| 208 |
+
const vals = [slot.naive, slot.sem, slot.effr];
|
| 209 |
+
for (let m = 0; m < 3; m++) {
|
| 210 |
+
const mesh = _bars[r * 3 + m];
|
| 211 |
+
if (!mesh) continue;
|
| 212 |
+
let v = vals[m];
|
| 213 |
+
let h = 0.4;
|
| 214 |
+
if (live && typeof v === "number") {
|
| 215 |
+
h = (m === 2 ? v * rankScale : v * entScale);
|
| 216 |
+
h = Math.max(0.4, Math.min(h, 9.0));
|
| 217 |
+
}
|
| 218 |
+
mesh.scale.y = h;
|
| 219 |
+
mesh.position.y = h / 2;
|
| 220 |
+
const col = live ? mesh.userData.baseCol : C_DIM;
|
| 221 |
+
mesh.material.color.setHex(col);
|
| 222 |
+
mesh.material.emissive.setHex(col);
|
| 223 |
+
mesh.material.emissiveIntensity = live ? 0.35 : 0.12;
|
| 224 |
+
if (live) _pulse[r * 3 + m] = 60;
|
| 225 |
+
}
|
| 226 |
+
// verdict ring: abstain burns violet-blue + bright; answer stays calm teal
|
| 227 |
+
const ring = _rings[r];
|
| 228 |
+
if (ring) {
|
| 229 |
+
const abstain = slot.decision === "abstain";
|
| 230 |
+
const rcol = live ? (abstain ? C_CONFAB : C_ACCENT) : C_DIM;
|
| 231 |
+
ring.material.color.setHex(rcol);
|
| 232 |
+
ring.material.emissive.setHex(rcol);
|
| 233 |
+
ring.material.emissiveIntensity = live ? (abstain ? 0.85 : 0.3) : 0.12;
|
| 234 |
+
ring.material.opacity = live ? 0.6 : 0.2;
|
| 235 |
+
ring.scale.setScalar(live ? (abstain ? 1.15 : 0.85) : 0.8);
|
| 236 |
+
}
|
| 237 |
+
}
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
// =============================================================================
|
| 241 |
+
// per-frame animation
|
| 242 |
+
// =============================================================================
|
| 243 |
+
function _onFrame() {
|
| 244 |
+
const t = performance.now();
|
| 245 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.0001) * 0.12;
|
| 246 |
+
_rings.forEach((ring) => { if (ring) ring.rotation.z += 0.004; });
|
| 247 |
+
|
| 248 |
+
const live = S.state === "live";
|
| 249 |
+
_bars.forEach((mesh, i) => {
|
| 250 |
+
if (_pulse[i] > 0) {
|
| 251 |
+
_pulse[i] -= 1;
|
| 252 |
+
const f = _pulse[i] / 60;
|
| 253 |
+
mesh.material.emissiveIntensity = Math.max(mesh.material.emissiveIntensity, 0.2 + 0.7 * f);
|
| 254 |
+
}
|
| 255 |
+
if (live) mesh.position.x = mesh.userData.x + Math.sin(t * 0.0011 + i) * 0.02;
|
| 256 |
+
});
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
// =============================================================================
|
| 260 |
+
// overlay
|
| 261 |
+
// =============================================================================
|
| 262 |
+
function _buildOverlay() {
|
| 263 |
+
const ctx = _ctx;
|
| 264 |
+
_overlay = document.createElement("div");
|
| 265 |
+
Object.assign(_overlay.style, {
|
| 266 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 267 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 268 |
+
maxWidth: "min(94%,480px)",
|
| 269 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 270 |
+
color: "#eef3f6",
|
| 271 |
+
});
|
| 272 |
+
|
| 273 |
+
const h = document.createElement("div");
|
| 274 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 275 |
+
h.textContent = TITLE;
|
| 276 |
+
_overlay.appendChild(h);
|
| 277 |
+
|
| 278 |
+
const sub = document.createElement("div");
|
| 279 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 280 |
+
sub.innerHTML =
|
| 281 |
+
'For one prompt we sample <b>K</b> candidate answers, group answers that <b>mean the same ' +
|
| 282 |
+
'thing</b> into semantic clusters, and score the <b>entropy</b> over those clusters ' +
|
| 283 |
+
'(<b>semantic entropy</b>). We compare a <b>confident</b> regime against a ' +
|
| 284 |
+
'<b>confabulating</b> one, and add the 2025 <b>spectral effective rank</b> of the ' +
|
| 285 |
+
'hidden states. Semantic entropy and effective rank both <b>rise</b> when the model ' +
|
| 286 |
+
'confabulates \\u2014 even when naive surface entropy stays misleadingly low \\u2014 so we ' +
|
| 287 |
+
'<b>abstain</b>. Honesty label <b>MODELED</b> \\u2014 a simulation of the method on ' +
|
| 288 |
+
'synthetic toy data, <b>not</b> a real LLM. 0 runtime CDN.';
|
| 289 |
+
_overlay.appendChild(sub);
|
| 290 |
+
|
| 291 |
+
const brow = document.createElement("div");
|
| 292 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 293 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 294 |
+
_overlay.appendChild(brow);
|
| 295 |
+
|
| 296 |
+
const card = document.createElement("div");
|
| 297 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 298 |
+
|
| 299 |
+
const chead = document.createElement("div");
|
| 300 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 301 |
+
const dot = document.createElement("span");
|
| 302 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#5b8dee;box-shadow:0 0 7px #5b8dee";
|
| 303 |
+
const nm = document.createElement("b");
|
| 304 |
+
nm.style.cssText = "font-size:12px;color:#5b8dee;letter-spacing:.3px";
|
| 305 |
+
nm.textContent = "sement \\u00b7 epistemic uncertainty";
|
| 306 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 307 |
+
card.appendChild(chead);
|
| 308 |
+
|
| 309 |
+
const grid = document.createElement("div");
|
| 310 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 311 |
+
|
| 312 |
+
function kpiRow(id, label) {
|
| 313 |
+
const r = document.createElement("div");
|
| 314 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 315 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 316 |
+
const v = document.createElement("b");
|
| 317 |
+
v.id = id;
|
| 318 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:60%";
|
| 319 |
+
v.textContent = "\\u2014";
|
| 320 |
+
_el[id] = v;
|
| 321 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
grid.appendChild(kpiRow("se-K", "candidate generations K"));
|
| 325 |
+
grid.appendChild(kpiRow("se-thr", "abstain threshold (nats)"));
|
| 326 |
+
grid.appendChild(kpiRow("se-cn", "confident \\u00b7 naive / semantic H"));
|
| 327 |
+
grid.appendChild(kpiRow("se-cr", "confident \\u00b7 effective rank"));
|
| 328 |
+
grid.appendChild(kpiRow("se-cd", "confident \\u00b7 decision"));
|
| 329 |
+
grid.appendChild(kpiRow("se-bn", "confabulating \\u00b7 naive / semantic H"));
|
| 330 |
+
grid.appendChild(kpiRow("se-br", "confabulating \\u00b7 effective rank"));
|
| 331 |
+
grid.appendChild(kpiRow("se-bd", "confabulating \\u00b7 decision"));
|
| 332 |
+
grid.appendChild(kpiRow("se-ord", "ordering holds (uncertain > confident)"));
|
| 333 |
+
grid.appendChild(kpiRow("se-label", "honesty label"));
|
| 334 |
+
card.appendChild(grid);
|
| 335 |
+
|
| 336 |
+
const fn = document.createElement("div");
|
| 337 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 338 |
+
fn.textContent = "Farquhar, Kossen, Kuhn & Gal, Nature 2024 (DOI 10.1038/s41586-024-07421-0) \\u00b7 " +
|
| 339 |
+
"Wang, Wei, Yue & Sun arXiv:2510.08389 (2025) \\u00b7 MODELED \\u00b7 hand-specified clustering, " +
|
| 340 |
+
"synthetic hidden states, no real LLM \\u00b7 not claimed-as.";
|
| 341 |
+
card.appendChild(fn);
|
| 342 |
+
_overlay.appendChild(card);
|
| 343 |
+
|
| 344 |
+
const pl = document.createElement("button");
|
| 345 |
+
pl.textContent = "\\u25d1 what this means";
|
| 346 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 347 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 348 |
+
pl.addEventListener("click", () => {
|
| 349 |
+
_plain = !_plain;
|
| 350 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 351 |
+
_applyPlain();
|
| 352 |
+
});
|
| 353 |
+
_overlay.appendChild(pl);
|
| 354 |
+
|
| 355 |
+
const pd = document.createElement("div");
|
| 356 |
+
pd.id = "sement-plain";
|
| 357 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 358 |
+
_el["plain"] = pd;
|
| 359 |
+
_overlay.appendChild(pd);
|
| 360 |
+
|
| 361 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 362 |
+
_paintOverlay();
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
function _applyPlain() {
|
| 366 |
+
const pd = _el["plain"];
|
| 367 |
+
if (!pd) return;
|
| 368 |
+
pd.style.display = _plain ? "block" : "none";
|
| 369 |
+
if (!_plain) return;
|
| 370 |
+
const K = S.K != null ? String(S.K) : "loading\\u2026";
|
| 371 |
+
const conf = S.reg[0], bad = S.reg[1];
|
| 372 |
+
const cSem = conf.sem != null ? conf.sem.toFixed(3) : "loading\\u2026";
|
| 373 |
+
const bSem = bad.sem != null ? bad.sem.toFixed(3) : "loading\\u2026";
|
| 374 |
+
const bNaive = bad.naive != null ? bad.naive.toFixed(3) : "loading\\u2026";
|
| 375 |
+
const bRank = bad.effr != null ? bad.effr.toFixed(2) : "loading\\u2026";
|
| 376 |
+
const bDec = bad.decision || "loading\\u2026";
|
| 377 |
+
pd.innerHTML =
|
| 378 |
+
"<b>What this means:</b> We ask the model the same question <b>" + K + "</b> times and collect " +
|
| 379 |
+
"its candidate answers. We group answers that <b>mean the same thing</b> together, then measure " +
|
| 380 |
+
"how scattered the meanings are (<b>semantic entropy</b>). When the model is <b>confident</b>, " +
|
| 381 |
+
"almost every answer means the same thing, so semantic entropy is low (here <b>" + cSem + "</b>) " +
|
| 382 |
+
"and we <b>answer</b>. When the model is <b>confabulating</b>, its answers scatter across many " +
|
| 383 |
+
"contradictory meanings, so semantic entropy jumps to <b>" + bSem + "</b> and a second, spectral " +
|
| 384 |
+
"signal \\u2014 the <b>effective rank</b> of its hidden states (\\u2248 <b>" + bRank + "</b>) \\u2014 " +
|
| 385 |
+
"rises too, so we <b>" + bDec + "</b>. Crucially, plain surface-word entropy on the confabulating " +
|
| 386 |
+
"case can look misleadingly modest (\\u2248 <b>" + bNaive + "</b>), which is exactly why " +
|
| 387 |
+
"meaning-level and spectral uncertainty beat surface uncertainty." +
|
| 388 |
+
"<br><br><b>Important honesty note:</b> this is a <b>MODELED</b> toy simulation of the " +
|
| 389 |
+
"<b>uncertainty estimator</b>, <b>not a real language model</b>. The step that decides which " +
|
| 390 |
+
"answers \\u201cmean the same thing\\u201d is a <b>hand-specified lookup table</b> (real semantic " +
|
| 391 |
+
"entropy uses a trained entailment model), and the <b>hidden states are synthetic seeded " +
|
| 392 |
+
"matrices</b>. It faithfully demonstrates the <b>ordering</b> (uncertain > confident) that the " +
|
| 393 |
+
"published methods exploit, but it does <b>not</b> reproduce the Nature paper\\u2019s AUROC or the " +
|
| 394 |
+
"effective-rank paper\\u2019s benchmark numbers, and makes no claim about real-model calibration " +
|
| 395 |
+
"(Farquhar et al., Nature 2024; Wang et al., arXiv:2510.08389, 2025).";
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
function _tok(s) {
|
| 399 |
+
if (s === "live") return null;
|
| 400 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 401 |
+
if (s === "degraded") return "DEGRADED";
|
| 402 |
+
if (s === "error") return "OFFLINE";
|
| 403 |
+
return "\\u2026";
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\\u2014"; }
|
| 407 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 408 |
+
|
| 409 |
+
function _paintOverlay() {
|
| 410 |
+
const t = _tok(S.state);
|
| 411 |
+
const conf = S.reg[0], bad = S.reg[1];
|
| 412 |
+
_set("se-K", t || (S.K != null ? String(S.K) : "\\u2014"));
|
| 413 |
+
_set("se-thr", t || fx(S.threshold, 2));
|
| 414 |
+
_set("se-cn", t || (conf.naive != null && conf.sem != null ? fx(conf.naive, 3) + " / " + fx(conf.sem, 3) : "\\u2014"));
|
| 415 |
+
_set("se-cr", t || fx(conf.effr, 3));
|
| 416 |
+
_set("se-cd", t || (conf.decision ? conf.decision.toUpperCase() : "\\u2014"));
|
| 417 |
+
_set("se-bn", t || (bad.naive != null && bad.sem != null ? fx(bad.naive, 3) + " / " + fx(bad.sem, 3) : "\\u2014"));
|
| 418 |
+
_set("se-br", t || fx(bad.effr, 3));
|
| 419 |
+
_set("se-bd", t || (bad.decision ? bad.decision.toUpperCase() : "\\u2014"));
|
| 420 |
+
_set("se-ord", t || (S.ordering == null ? "\\u2014" : (S.ordering ? "YES \\u2014 semantic H & eff-rank both rise" : "no")));
|
| 421 |
+
// honesty label verbatim — never upgraded
|
| 422 |
+
_set("se-label", t || (S.label || "MODELED"));
|
| 423 |
+
if (_plain) _applyPlain();
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
// =============================================================================
|
| 427 |
+
// unmount — clean up everything; must not affect other organs
|
| 428 |
+
// =============================================================================
|
| 429 |
+
export function unmount() {
|
| 430 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 431 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 432 |
+
try {
|
| 433 |
+
if (_group && _stage) {
|
| 434 |
+
_group.traverse((o) => {
|
| 435 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 436 |
+
if (o.material) {
|
| 437 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 438 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 439 |
+
}
|
| 440 |
+
});
|
| 441 |
+
_stage.scene.remove(_group);
|
| 442 |
+
}
|
| 443 |
+
} catch (_) {}
|
| 444 |
+
_group = _overlay = null;
|
| 445 |
+
_bars = []; _rings = [];
|
| 446 |
+
_built = false;
|
| 447 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 448 |
+
_stage = _THREE = _ctx = null;
|
| 449 |
+
S.label = S.K = S.threshold = S.ordering = null;
|
| 450 |
+
S.reg[0] = { name: "confident", naive: null, sem: null, effr: null, decision: null, nclus: null };
|
| 451 |
+
S.reg[1] = { name: "confabulating", naive: null, sem: null, effr: null, decision: null, nclus: null };
|
| 452 |
+
S.state = "init";
|
| 453 |
+
_pulse.fill(0);
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|
static/3d/surfaces/ternary.js
ADDED
|
@@ -0,0 +1,468 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// SPDX-License-Identifier: Apache-2.0
|
| 2 |
+
// © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11
|
| 3 |
+
//
|
| 4 |
+
// surfaces/ternary.js — NATIVE 1.58-BIT TERNARY-WEIGHT LM organ for the
|
| 5 |
+
// holographic frontier ring (BitNet b1.58 BitLinear ternarization + multiply-
|
| 6 |
+
// free integer arithmetic, Microsoft Research-style). Renders a synthetic
|
| 7 |
+
// weight matrix as a 3D lattice of ternary cells: weights that ternarize to +1
|
| 8 |
+
// glow proof-teal (add), -1 glow lattice-blue (subtract), and 0 fade to grey
|
| 9 |
+
// (skip / structured sparsity). A HUD shows the three MEASURED metrics from the
|
| 10 |
+
// live snapshot at /api/killinchu/v1/ternary/quantize:
|
| 11 |
+
// (1) COMPRESSION (bits/weight + x-shrink), (2) FIDELITY (the MEASURED,
|
| 12 |
+
// non-zero rel_l2 / cosine error — reported, NOT hidden), (3) ARITHMETIC
|
| 13 |
+
// PROFILE (float multiplies eliminated). Honesty label "MODELED" is read
|
| 14 |
+
// VERBATIM from the JSON and displayed as-is; it is never upgraded.
|
| 15 |
+
//
|
| 16 |
+
// Surface export shape (mirrors kvcache.js / aimc.js exactly):
|
| 17 |
+
// export default { id, title, endpoints, mount(ctx), unmount() }
|
| 18 |
+
// ctx = { stage, container, live, label, THREE, szl3d }
|
| 19 |
+
//
|
| 20 |
+
// DATA SHOWN (all from live endpoint):
|
| 21 |
+
// rows, cols, batch, act_bits, beta, sparsity, ternary_counts{neg,zero,pos},
|
| 22 |
+
// bits_per_weight_ternary, compression_vs_fp16, compression_vs_fp32,
|
| 23 |
+
// rel_l2_error, cosine_error, float_muls_full, float_muls_ternary,
|
| 24 |
+
// muls_eliminated, muls_eliminated_frac, int_ops_ternary
|
| 25 |
+
//
|
| 26 |
+
// LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own; VERIFY real):
|
| 27 |
+
// BitNet b1.58 2B4T Technical Report (mechanism simulated here):
|
| 28 |
+
// Ma, Wang, Huang, Zhang, Hu, Song, Xia, Wei et al. (Microsoft Research)
|
| 29 |
+
// arXiv:2504.12285 https://arxiv.org/abs/2504.12285
|
| 30 |
+
// Official open weights: https://huggingface.co/microsoft/bitnet-b1.58-2B-4T
|
| 31 |
+
// Official inference stack: https://github.com/microsoft/BitNet
|
| 32 |
+
// Genealogy "The Era of 1-bit LLMs": arXiv:2402.17764
|
| 33 |
+
// https://arxiv.org/abs/2402.17764
|
| 34 |
+
//
|
| 35 |
+
// HONESTY LABELS: MODELED (deterministic reproduction of the BitNet b1.58
|
| 36 |
+
// ternary-quantization + integer-arithmetic MECHANISM on a toy synthetic
|
| 37 |
+
// matrix; NOT the trained model; error is MEASURED and displayed;
|
| 38 |
+
// NEVER-CLAIMED-AS a production inference engine). Read verbatim from JSON;
|
| 39 |
+
// never upgraded here.
|
| 40 |
+
// COLOURS: proof-teal 0x3af4c8 (+1 -> add / HUD accent), lattice-blue 0x5b8dee
|
| 41 |
+
// (-1 -> subtract), violet-blue 0x8a6bff (rescale/β accent), greys (0 -> skip /
|
| 42 |
+
// degraded state). Purple BANNED as UI/background.
|
| 43 |
+
// 0 RUNTIME CDN. Vendored three.js via ctx.THREE (page importmap).
|
| 44 |
+
// DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown.
|
| 45 |
+
// Nothing here is in the locked-8. Λ stays Conjecture 1. Trust never 100%.
|
| 46 |
+
|
| 47 |
+
const ID = "ternary";
|
| 48 |
+
const TITLE = "Native 1.58-bit Ternary-Weight LM · BitNet b1.58 (live)";
|
| 49 |
+
|
| 50 |
+
// Endpoint is hosted on the dedicated killinchu Space (isolated compute), reached
|
| 51 |
+
// cross-origin (killinchu returns access-control-allow-origin for the flagship).
|
| 52 |
+
// This keeps the ternary organ's rebuilds/faults isolated from the flagship.
|
| 53 |
+
const EP = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/ternary/quantize?seed=42&rows=32&cols=32&batch=16&act_bits=8";
|
| 54 |
+
|
| 55 |
+
// data-viz hues — purple BANNED
|
| 56 |
+
const C_POS = 0x3af4c8; // proof-teal (+1 weight -> add)
|
| 57 |
+
const C_NEG = 0x5b8dee; // lattice-blue (-1 weight -> subtract)
|
| 58 |
+
const C_RESCALE = 0x8a6bff; // violet-blue (β rescale / accent marker)
|
| 59 |
+
const C_ZERO = 0x5a6570; // grey (0 weight -> skip / structured sparsity)
|
| 60 |
+
const C_DIM = 0x42505d; // grey (degraded / no-live-data)
|
| 61 |
+
const C_GRID = 0x1b3a44; // floor / link colour
|
| 62 |
+
|
| 63 |
+
// lattice layout geometry
|
| 64 |
+
const CELL_GAP = 0.44; // world-units between weight cells
|
| 65 |
+
const MAX_SIDE = 24; // cap on cells rendered per axis (perf): MAX_SIDE^2 max
|
| 66 |
+
const CELL_Y = 0.4; // resting height of a weight cell
|
| 67 |
+
|
| 68 |
+
let _stage = null, _THREE = null, _ctx = null, _group = null, _overlay = null;
|
| 69 |
+
let _frameReg = false, _polls = [], _el = {}, _badge = null;
|
| 70 |
+
let _plain = false;
|
| 71 |
+
|
| 72 |
+
// geometry handles
|
| 73 |
+
let _floor = null;
|
| 74 |
+
let _cellMesh = []; // Array<THREE.Mesh> — flattened lattice cells
|
| 75 |
+
let _marker = null; // THREE.Mesh — β-rescale HUD marker
|
| 76 |
+
|
| 77 |
+
// live state
|
| 78 |
+
const S = {
|
| 79 |
+
label: null,
|
| 80 |
+
rows: null,
|
| 81 |
+
cols: null,
|
| 82 |
+
batch: null,
|
| 83 |
+
actBits: null, // act_bits
|
| 84 |
+
beta: null,
|
| 85 |
+
sparsity: null,
|
| 86 |
+
tcNeg: null, // ternary_counts.neg
|
| 87 |
+
tcZero: null, // ternary_counts.zero
|
| 88 |
+
tcPos: null, // ternary_counts.pos
|
| 89 |
+
bitsPerWeight: null, // bits_per_weight_ternary
|
| 90 |
+
compVsFp16: null, // compression_vs_fp16
|
| 91 |
+
compVsFp32: null, // compression_vs_fp32
|
| 92 |
+
relL2Error: null, // rel_l2_error (MEASURED)
|
| 93 |
+
cosineError: null, // cosine_error (MEASURED)
|
| 94 |
+
floatMulsFull: null, // float_muls_full
|
| 95 |
+
floatMulsTernary: null, // float_muls_ternary
|
| 96 |
+
mulsEliminated: null, // muls_eliminated
|
| 97 |
+
mulsElimFrac: null, // muls_eliminated_frac
|
| 98 |
+
intOps: null, // int_ops_ternary
|
| 99 |
+
state: "init",
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
// =============================================================================
|
| 103 |
+
// mount(ctx)
|
| 104 |
+
// =============================================================================
|
| 105 |
+
export function mount(ctx) {
|
| 106 |
+
_ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE;
|
| 107 |
+
_group = new _THREE.Group();
|
| 108 |
+
_stage.scene.add(_group);
|
| 109 |
+
_stage.camera.position.set(6, 8, 16);
|
| 110 |
+
try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(5, 1, 5); _stage.controls.update(); } } catch (_) {}
|
| 111 |
+
try { _stage.setBloom(true); } catch (_) {}
|
| 112 |
+
|
| 113 |
+
_buildFloor();
|
| 114 |
+
_buildLattice();
|
| 115 |
+
_buildMarker();
|
| 116 |
+
|
| 117 |
+
if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; }
|
| 118 |
+
|
| 119 |
+
_badge = ctx.live.createBadge();
|
| 120 |
+
_polls.push(ctx.live.poll(EP, 5000, _onTernary, { badge: _badge, onState: (m) => { S.state = m.state; _paintOverlay(); } }));
|
| 121 |
+
|
| 122 |
+
_buildOverlay();
|
| 123 |
+
return { id: ID, started: true };
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
// =============================================================================
|
| 127 |
+
// builders
|
| 128 |
+
// =============================================================================
|
| 129 |
+
function _buildFloor() {
|
| 130 |
+
const THREE = _THREE;
|
| 131 |
+
const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027);
|
| 132 |
+
grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01;
|
| 133 |
+
_group.add(grid);
|
| 134 |
+
_floor = grid;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
// Pre-allocate a fixed MAX_SIDE x MAX_SIDE lattice of weight-cell meshes. We
|
| 138 |
+
// toggle visibility / color / height in-place as live data arrives (no per-poll
|
| 139 |
+
// geometry churn). Each cell = one ternary weight; we colour by a deterministic
|
| 140 |
+
// sign pattern derived from live ternary_counts (client never invents weights it
|
| 141 |
+
// cannot see — it colours proportionally to the reported neg/zero/pos mix).
|
| 142 |
+
function _buildLattice() {
|
| 143 |
+
const THREE = _THREE;
|
| 144 |
+
const cellGeo = new THREE.BoxGeometry(0.26, 0.26, 0.26);
|
| 145 |
+
for (let r = 0; r < MAX_SIDE; r++) {
|
| 146 |
+
for (let c = 0; c < MAX_SIDE; c++) {
|
| 147 |
+
const mesh = new THREE.Mesh(
|
| 148 |
+
cellGeo,
|
| 149 |
+
new THREE.MeshStandardMaterial({ color: C_ZERO, emissive: C_ZERO, emissiveIntensity: 0.2, transparent: true, opacity: 0.0 }),
|
| 150 |
+
);
|
| 151 |
+
mesh.position.set(c * CELL_GAP, CELL_Y, r * CELL_GAP);
|
| 152 |
+
mesh.visible = false;
|
| 153 |
+
_group.add(mesh);
|
| 154 |
+
_cellMesh.push(mesh);
|
| 155 |
+
}
|
| 156 |
+
}
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function _buildMarker() {
|
| 160 |
+
const THREE = _THREE;
|
| 161 |
+
_marker = new THREE.Mesh(
|
| 162 |
+
new THREE.IcosahedronGeometry(0.3, 1),
|
| 163 |
+
new THREE.MeshStandardMaterial({ color: C_RESCALE, emissive: C_RESCALE, emissiveIntensity: 0.5, wireframe: true, transparent: true, opacity: 0.85 }),
|
| 164 |
+
);
|
| 165 |
+
_marker.position.set(-1.2, 1.4, -1.2);
|
| 166 |
+
_group.add(_marker);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
// =============================================================================
|
| 170 |
+
// live data handler
|
| 171 |
+
// =============================================================================
|
| 172 |
+
function _onTernary(j) {
|
| 173 |
+
// read honesty label VERBATIM — never upgrade. handle top-level 'label' OR
|
| 174 |
+
// nested 'payload.label' to match our own module's shape.
|
| 175 |
+
const lbl = (j && j.label != null) ? j.label
|
| 176 |
+
: (j && j.payload && j.payload.label != null) ? j.payload.label
|
| 177 |
+
: "MODELED";
|
| 178 |
+
const src = (j && j.payload && typeof j.payload === "object") ? j.payload : j;
|
| 179 |
+
S.label = String(lbl).toUpperCase();
|
| 180 |
+
|
| 181 |
+
S.rows = typeof src.rows === "number" ? src.rows : null;
|
| 182 |
+
S.cols = typeof src.cols === "number" ? src.cols : null;
|
| 183 |
+
S.batch = typeof src.batch === "number" ? src.batch : null;
|
| 184 |
+
S.actBits = typeof src.act_bits === "number" ? src.act_bits : null;
|
| 185 |
+
S.beta = typeof src.beta === "number" ? src.beta : null;
|
| 186 |
+
S.sparsity = typeof src.sparsity === "number" ? src.sparsity : null;
|
| 187 |
+
S.bitsPerWeight = typeof src.bits_per_weight_ternary === "number" ? src.bits_per_weight_ternary : null;
|
| 188 |
+
S.compVsFp16 = typeof src.compression_vs_fp16 === "number" ? src.compression_vs_fp16 : null;
|
| 189 |
+
S.compVsFp32 = typeof src.compression_vs_fp32 === "number" ? src.compression_vs_fp32 : null;
|
| 190 |
+
S.relL2Error = typeof src.rel_l2_error === "number" ? src.rel_l2_error : null;
|
| 191 |
+
S.cosineError = typeof src.cosine_error === "number" ? src.cosine_error : null;
|
| 192 |
+
S.floatMulsFull = typeof src.float_muls_full === "number" ? src.float_muls_full : null;
|
| 193 |
+
S.floatMulsTernary = typeof src.float_muls_ternary === "number" ? src.float_muls_ternary : null;
|
| 194 |
+
S.mulsEliminated = typeof src.muls_eliminated === "number" ? src.muls_eliminated : null;
|
| 195 |
+
S.mulsElimFrac = typeof src.muls_eliminated_frac === "number" ? src.muls_eliminated_frac : null;
|
| 196 |
+
S.intOps = typeof src.int_ops_ternary === "number" ? src.int_ops_ternary : null;
|
| 197 |
+
|
| 198 |
+
if (src.ternary_counts && typeof src.ternary_counts === "object") {
|
| 199 |
+
S.tcNeg = typeof src.ternary_counts.neg === "number" ? src.ternary_counts.neg : null;
|
| 200 |
+
S.tcZero = typeof src.ternary_counts.zero === "number" ? src.ternary_counts.zero : null;
|
| 201 |
+
S.tcPos = typeof src.ternary_counts.pos === "number" ? src.ternary_counts.pos : null;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
_updateLattice();
|
| 205 |
+
_paintOverlay();
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// =============================================================================
|
| 209 |
+
// geometry updater — colours the lattice from the live ternary mix
|
| 210 |
+
// =============================================================================
|
| 211 |
+
// Deterministic per-cell PRNG (LCG, mirrors the module's family) so the lattice
|
| 212 |
+
// pattern is stable across polls and never fabricated beyond the reported mix.
|
| 213 |
+
function _cellSign(idx, pNeg, pZero) {
|
| 214 |
+
let s = ((idx + 1) * 2654435761) >>> 0;
|
| 215 |
+
s = (1664525 * s + 1013904223) >>> 0;
|
| 216 |
+
const u = s / 4294967295;
|
| 217 |
+
if (u < pZero) return 0;
|
| 218 |
+
if (u < pZero + pNeg) return -1;
|
| 219 |
+
return 1;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
function _updateLattice() {
|
| 223 |
+
const live = S.state === "live";
|
| 224 |
+
const rows = live && S.rows ? Math.min(S.rows, MAX_SIDE) : 0;
|
| 225 |
+
const cols = live && S.cols ? Math.min(S.cols, MAX_SIDE) : 0;
|
| 226 |
+
|
| 227 |
+
const total = (S.tcNeg || 0) + (S.tcZero || 0) + (S.tcPos || 0);
|
| 228 |
+
const pNeg = total > 0 ? (S.tcNeg || 0) / total : 0.33;
|
| 229 |
+
const pZero = total > 0 ? (S.tcZero || 0) / total : 0.34;
|
| 230 |
+
|
| 231 |
+
for (let r = 0; r < MAX_SIDE; r++) {
|
| 232 |
+
for (let c = 0; c < MAX_SIDE; c++) {
|
| 233 |
+
const mesh = _cellMesh[r * MAX_SIDE + c];
|
| 234 |
+
if (!live || r >= rows || c >= cols) {
|
| 235 |
+
mesh.visible = false;
|
| 236 |
+
continue;
|
| 237 |
+
}
|
| 238 |
+
mesh.visible = true;
|
| 239 |
+
const sign = _cellSign(r * MAX_SIDE + c, pNeg, pZero);
|
| 240 |
+
let color;
|
| 241 |
+
if (sign === 1) color = C_POS; // +1 -> add -> proof-teal
|
| 242 |
+
else if (sign === -1) color = C_NEG; // -1 -> subtract -> lattice-blue
|
| 243 |
+
else color = C_ZERO; // 0 -> skip -> grey
|
| 244 |
+
mesh.material.color.setHex(color);
|
| 245 |
+
mesh.material.emissive.setHex(color);
|
| 246 |
+
mesh.material.emissiveIntensity = sign === 0 ? 0.12 : 0.55;
|
| 247 |
+
mesh.material.opacity = sign === 0 ? 0.3 : 0.95;
|
| 248 |
+
mesh.position.y = sign === 0 ? CELL_Y - 0.28 : CELL_Y; // zeros sink (skipped)
|
| 249 |
+
}
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
if (_marker) {
|
| 253 |
+
if (live) {
|
| 254 |
+
_marker.material.color.setHex(C_RESCALE);
|
| 255 |
+
_marker.material.emissive.setHex(C_RESCALE);
|
| 256 |
+
_marker.material.opacity = 0.85;
|
| 257 |
+
} else {
|
| 258 |
+
_marker.material.color.setHex(C_DIM);
|
| 259 |
+
_marker.material.emissive.setHex(C_DIM);
|
| 260 |
+
_marker.material.opacity = 0.3;
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
}
|
| 264 |
+
|
| 265 |
+
// =============================================================================
|
| 266 |
+
// per-frame animation
|
| 267 |
+
// =============================================================================
|
| 268 |
+
function _onFrame() {
|
| 269 |
+
const t = performance.now();
|
| 270 |
+
if (_group) _group.rotation.y = Math.sin(t * 0.00009) * 0.14;
|
| 271 |
+
if (_marker) {
|
| 272 |
+
_marker.rotation.y += 0.025;
|
| 273 |
+
_marker.rotation.x += 0.012;
|
| 274 |
+
const pulse = 1.0 + 0.15 * Math.sin(t * 0.004);
|
| 275 |
+
_marker.scale.setScalar(pulse);
|
| 276 |
+
}
|
| 277 |
+
}
|
| 278 |
+
|
| 279 |
+
// =============================================================================
|
| 280 |
+
// overlay
|
| 281 |
+
// =============================================================================
|
| 282 |
+
function _buildOverlay() {
|
| 283 |
+
const ctx = _ctx;
|
| 284 |
+
_overlay = document.createElement("div");
|
| 285 |
+
Object.assign(_overlay.style, {
|
| 286 |
+
position: "absolute", left: "14px", top: "14px", zIndex: "6",
|
| 287 |
+
display: "flex", flexDirection: "column", gap: "8px",
|
| 288 |
+
maxWidth: "min(94%,460px)",
|
| 289 |
+
font: "12px ui-sans-serif,system-ui,Segoe UI,Roboto,Arial",
|
| 290 |
+
color: "#eef3f6",
|
| 291 |
+
});
|
| 292 |
+
|
| 293 |
+
const h = document.createElement("div");
|
| 294 |
+
h.style.cssText = "font:600 13px ui-sans-serif,system-ui;letter-spacing:.4px";
|
| 295 |
+
h.textContent = TITLE;
|
| 296 |
+
_overlay.appendChild(h);
|
| 297 |
+
|
| 298 |
+
const sub = document.createElement("div");
|
| 299 |
+
sub.style.cssText = "color:#9fb1bf;font-size:11px;line-height:1.55";
|
| 300 |
+
sub.innerHTML =
|
| 301 |
+
'Every weight is constrained to a ternary code <b>{\u22121, 0, +1}</b> (~1.58 bits/weight) via ' +
|
| 302 |
+
'<b>BitLinear</b>: scale \u03b2 = mean(|W|), then W<sub>t</sub> = round-clip(W/\u03b2). Because weights are ' +
|
| 303 |
+
'ternary, the float matmul collapses into integer <b>add</b> (+1) / <b>subtract</b> (\u22121) / ' +
|
| 304 |
+
'<b>skip</b> (0) \u2014 no per-weight multiply. HUD reports three MEASURED metrics: compression, ' +
|
| 305 |
+
'fidelity error (shown, NOT hidden), and multiplies eliminated. Honesty label <b>MODELED</b> ' +
|
| 306 |
+
'(deterministic mechanism reproduction on a toy matrix; NOT the trained BitNet model). 0 runtime CDN.';
|
| 307 |
+
_overlay.appendChild(sub);
|
| 308 |
+
|
| 309 |
+
const brow = document.createElement("div");
|
| 310 |
+
brow.style.cssText = "display:flex;gap:8px;align-items:center;flex-wrap:wrap";
|
| 311 |
+
if (_badge && _badge.el) brow.appendChild(_badge.el);
|
| 312 |
+
_overlay.appendChild(brow);
|
| 313 |
+
|
| 314 |
+
const card = document.createElement("div");
|
| 315 |
+
card.style.cssText = "background:#0a1117;border:1px solid #1d2a36;border-radius:9px;padding:9px 10px;display:flex;flex-direction:column;gap:6px";
|
| 316 |
+
|
| 317 |
+
const chead = document.createElement("div");
|
| 318 |
+
chead.style.cssText = "display:flex;align-items:center;gap:8px;flex-wrap:wrap";
|
| 319 |
+
const dot = document.createElement("span");
|
| 320 |
+
dot.style.cssText = "width:9px;height:9px;border-radius:50%;background:#3af4c8;box-shadow:0 0 7px #3af4c8";
|
| 321 |
+
const nm = document.createElement("b");
|
| 322 |
+
nm.style.cssText = "font-size:12px;color:#3af4c8;letter-spacing:.3px";
|
| 323 |
+
nm.textContent = "native 1.58-bit ternary-weight lm";
|
| 324 |
+
chead.appendChild(dot); chead.appendChild(nm);
|
| 325 |
+
card.appendChild(chead);
|
| 326 |
+
|
| 327 |
+
const grid = document.createElement("div");
|
| 328 |
+
grid.style.cssText = "display:grid;grid-template-columns:1fr;gap:4px";
|
| 329 |
+
|
| 330 |
+
function kpiRow(id, label) {
|
| 331 |
+
const r = document.createElement("div");
|
| 332 |
+
r.style.cssText = "display:flex;justify-content:space-between;gap:10px;font-size:11px";
|
| 333 |
+
const l = document.createElement("span"); l.style.cssText = "color:#9fb1bf"; l.textContent = label;
|
| 334 |
+
const v = document.createElement("b");
|
| 335 |
+
v.id = id;
|
| 336 |
+
v.style.cssText = "font-variant-numeric:tabular-nums;color:#eef3f6;text-align:right;max-width:56%";
|
| 337 |
+
v.textContent = "\u2014";
|
| 338 |
+
_el[id] = v;
|
| 339 |
+
r.appendChild(l); r.appendChild(v); return r;
|
| 340 |
+
}
|
| 341 |
+
|
| 342 |
+
grid.appendChild(kpiRow("tn-dims", "matrix (rows \u00d7 cols)"));
|
| 343 |
+
grid.appendChild(kpiRow("tn-actbits", "activation bit-width (absmax)"));
|
| 344 |
+
grid.appendChild(kpiRow("tn-beta", "\u03b2 = mean(|W|) (absmean scale)"));
|
| 345 |
+
grid.appendChild(kpiRow("tn-mix", "ternary mix (\u22121 / 0 / +1)"));
|
| 346 |
+
grid.appendChild(kpiRow("tn-sparsity", "sparsity (weights \u2192 0, skipped)"));
|
| 347 |
+
grid.appendChild(kpiRow("tn-bpw", "bits/weight (ternary) \u2014 MODELED"));
|
| 348 |
+
grid.appendChild(kpiRow("tn-comp16", "COMPRESSION vs fp16"));
|
| 349 |
+
grid.appendChild(kpiRow("tn-comp32", "COMPRESSION vs fp32"));
|
| 350 |
+
grid.appendChild(kpiRow("tn-rell2", "FIDELITY \u2014 rel L2 error (MEASURED)"));
|
| 351 |
+
grid.appendChild(kpiRow("tn-cos", "FIDELITY \u2014 cosine error (MEASURED)"));
|
| 352 |
+
grid.appendChild(kpiRow("tn-muls", "float-muls ELIMINATED"));
|
| 353 |
+
grid.appendChild(kpiRow("tn-mulsfrac", "multiply-free fraction"));
|
| 354 |
+
grid.appendChild(kpiRow("tn-intops", "integer add/sub ops"));
|
| 355 |
+
grid.appendChild(kpiRow("tn-label", "honesty label"));
|
| 356 |
+
card.appendChild(grid);
|
| 357 |
+
|
| 358 |
+
const fn = document.createElement("div");
|
| 359 |
+
fn.style.cssText = "font-size:9.5px;color:#6b7a86;line-height:1.5";
|
| 360 |
+
fn.textContent = "BitNet b1.58 \u2014 Ma, Wang, Huang, Zhang, Hu, Song, Xia, Wei et al. (Microsoft Research) arXiv:2504.12285 \u00b7 genealogy arXiv:2402.17764. MODELED \u00b7 not claimed-as.";
|
| 361 |
+
card.appendChild(fn);
|
| 362 |
+
_overlay.appendChild(card);
|
| 363 |
+
|
| 364 |
+
const pl = document.createElement("button");
|
| 365 |
+
pl.textContent = "\u25d1 what this means";
|
| 366 |
+
pl.title = "Toggle plain-language explanation for investors & consumers.";
|
| 367 |
+
pl.style.cssText = "font:11px ui-monospace,monospace;padding:5px 11px;border-radius:7px;border:1px solid #3af4c8;background:#08140f;color:#3af4c8;cursor:pointer;width:fit-content";
|
| 368 |
+
pl.addEventListener("click", () => {
|
| 369 |
+
_plain = !_plain;
|
| 370 |
+
pl.style.background = _plain ? "#0f2a20" : "#08140f";
|
| 371 |
+
_applyPlain();
|
| 372 |
+
});
|
| 373 |
+
_overlay.appendChild(pl);
|
| 374 |
+
|
| 375 |
+
const pd = document.createElement("div");
|
| 376 |
+
pd.id = "tn-plain";
|
| 377 |
+
pd.style.cssText = "font-size:10.5px;color:#c9d6df;line-height:1.55;border:1px dashed #26333f;border-radius:7px;padding:7px 9px;display:none";
|
| 378 |
+
_el["plain"] = pd;
|
| 379 |
+
_overlay.appendChild(pd);
|
| 380 |
+
|
| 381 |
+
(ctx.container || document.body).appendChild(_overlay);
|
| 382 |
+
_paintOverlay();
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
function _applyPlain() {
|
| 386 |
+
const pd = _el["plain"];
|
| 387 |
+
if (!pd) return;
|
| 388 |
+
pd.style.display = _plain ? "block" : "none";
|
| 389 |
+
if (!_plain) return;
|
| 390 |
+
const comp = S.compVsFp16 != null ? S.compVsFp16.toFixed(1) + "\u00d7" : "loading\u2026";
|
| 391 |
+
const relPct = S.relL2Error != null ? (S.relL2Error * 100).toFixed(1) + "%" : "loading\u2026";
|
| 392 |
+
const mulPct = S.mulsElimFrac != null ? (S.mulsElimFrac * 100).toFixed(1) + "%" : "loading\u2026";
|
| 393 |
+
pd.innerHTML =
|
| 394 |
+
"<b>What this means:</b> Ordinary language models store each number (\u201cweight\u201d) using 16 or 32 " +
|
| 395 |
+
"bits and multiply by it billions of times. This approach instead snaps every weight to just three " +
|
| 396 |
+
"values \u2014 minus one, zero, or plus one \u2014 which needs only about 1.58 bits each. That shrinks storage " +
|
| 397 |
+
"by roughly <b>" + comp + "</b>, and the big multiplications turn into simple add / subtract / skip \u2014 here " +
|
| 398 |
+
"<b>" + mulPct + "</b> of the multiplies disappear. The catch, shown honestly, is a <b>MEASURED</b> " +
|
| 399 |
+
"approximation error of about <b>" + relPct + "</b> on this toy matrix \u2014 we display it rather than hide it. " +
|
| 400 |
+
"This view is a <b>MODELED</b> deterministic reproduction of the ternary-quantization and multiply-free " +
|
| 401 |
+
"arithmetic MECHANISM on a small synthetic matrix, NOT the trained BitNet model. It does not reproduce " +
|
| 402 |
+
"downstream accuracy, the 2B-parameter / 4T-token training, or the paper's energy figures. \u201cMatches " +
|
| 403 |
+
"full precision\u201d is <b>Microsoft's claim</b> about their trained model \u2014 the estate does not independently " +
|
| 404 |
+
"verify it.";
|
| 405 |
+
}
|
| 406 |
+
|
| 407 |
+
function _tok(s) {
|
| 408 |
+
if (s === "live") return null;
|
| 409 |
+
if (s === "missing") return "NO-LIVE-DATA";
|
| 410 |
+
if (s === "degraded") return "DEGRADED";
|
| 411 |
+
if (s === "error") return "OFFLINE";
|
| 412 |
+
return "\u2026";
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; }
|
| 416 |
+
function pct(v, d) { return typeof v === "number" ? (v * 100).toFixed(d) + "%" : "\u2014"; }
|
| 417 |
+
function _set(id, v) { if (_el[id]) _el[id].textContent = v; }
|
| 418 |
+
|
| 419 |
+
function _paintOverlay() {
|
| 420 |
+
const t = _tok(S.state);
|
| 421 |
+
_set("tn-dims", t || ((S.rows != null && S.cols != null) ? (S.rows + " \u00d7 " + S.cols) : "\u2014"));
|
| 422 |
+
_set("tn-actbits", t || (S.actBits != null ? (S.actBits + "-bit") : "\u2014"));
|
| 423 |
+
_set("tn-beta", t || fx(S.beta, 4));
|
| 424 |
+
_set("tn-mix", t || ((S.tcNeg != null) ? (S.tcNeg + " / " + S.tcZero + " / " + S.tcPos) : "\u2014"));
|
| 425 |
+
_set("tn-sparsity", t || pct(S.sparsity, 2));
|
| 426 |
+
_set("tn-bpw", t || fx(S.bitsPerWeight, 4));
|
| 427 |
+
_set("tn-comp16", t || (S.compVsFp16 != null ? S.compVsFp16.toFixed(2) + "\u00d7" : "\u2014"));
|
| 428 |
+
_set("tn-comp32", t || (S.compVsFp32 != null ? S.compVsFp32.toFixed(2) + "\u00d7" : "\u2014"));
|
| 429 |
+
_set("tn-rell2", t || pct(S.relL2Error, 2));
|
| 430 |
+
_set("tn-cos", t || pct(S.cosineError, 2));
|
| 431 |
+
_set("tn-muls", t || ((S.mulsEliminated != null && S.floatMulsFull != null) ? (S.mulsEliminated + " / " + S.floatMulsFull) : "\u2014"));
|
| 432 |
+
_set("tn-mulsfrac", t || pct(S.mulsElimFrac, 2));
|
| 433 |
+
_set("tn-intops", t || (S.intOps != null ? String(S.intOps) : "\u2014"));
|
| 434 |
+
// honesty label verbatim — never upgraded
|
| 435 |
+
_set("tn-label", t || (S.label || "MODELED"));
|
| 436 |
+
if (_plain) _applyPlain();
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
// =============================================================================
|
| 440 |
+
// unmount — clean up everything; must not affect other organs
|
| 441 |
+
// =============================================================================
|
| 442 |
+
export function unmount() {
|
| 443 |
+
_polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = [];
|
| 444 |
+
try { if (_overlay && _overlay.parentNode) _overlay.parentNode.removeChild(_overlay); } catch (_) {}
|
| 445 |
+
try {
|
| 446 |
+
if (_group && _stage) {
|
| 447 |
+
_group.traverse((o) => {
|
| 448 |
+
if (o.geometry && o.geometry.dispose) o.geometry.dispose();
|
| 449 |
+
if (o.material) {
|
| 450 |
+
const ms = Array.isArray(o.material) ? o.material : [o.material];
|
| 451 |
+
ms.forEach((m) => { if (m.dispose) m.dispose(); });
|
| 452 |
+
}
|
| 453 |
+
});
|
| 454 |
+
_stage.scene.remove(_group);
|
| 455 |
+
}
|
| 456 |
+
} catch (_) {}
|
| 457 |
+
_group = _overlay = null;
|
| 458 |
+
_floor = null; _cellMesh = []; _marker = null;
|
| 459 |
+
_el = {}; _badge = null; _plain = false; _frameReg = false;
|
| 460 |
+
_stage = _THREE = _ctx = null;
|
| 461 |
+
S.label = S.rows = S.cols = S.batch = S.actBits = S.beta = S.sparsity = null;
|
| 462 |
+
S.tcNeg = S.tcZero = S.tcPos = S.bitsPerWeight = null;
|
| 463 |
+
S.compVsFp16 = S.compVsFp32 = S.relL2Error = S.cosineError = null;
|
| 464 |
+
S.floatMulsFull = S.floatMulsTernary = S.mulsEliminated = S.mulsElimFrac = S.intOps = null;
|
| 465 |
+
S.state = "init";
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
export default { id: ID, title: TITLE, endpoints: [EP], mount, unmount };
|