// SPDX-License-Identifier: Apache-2.0 // © 2026 Lutar, Stephen P. — SZL Holdings · ORCID 0009-0001-0110-4173 · Doctrine v11 // // surfaces/interpretability.js — MECHANISTIC-INTERPRETABILITY / SPARSE-AUTOENCODER // organ for the holographic frontier ring. // // Renders a 3D lattice of dictionary-feature nodes driven by a live JumpReLU sparse // autoencoder snapshot from /api/a11oy/v1/interpretability/features. The top-K FIRED // features light up; node brightness = SAE activation, node scale = causal-ablation KL // (how much the output distribution shifts when that feature is ablated). Honesty label // "MODELED" is read VERBATIM from the JSON and displayed as-is; it is never upgraded. // // Surface export shape (mirrors neuromorphic.js / frontier.js exactly): // export default { id, title, mount(ctx), unmount() } // ctx = { stage, container, live, label, THREE, szl3d } // // DATA SHOWN (all from live endpoint): // l0_sparsity — fraction of dictionary features active (interpretability ↑ as ↓) // active_features — count of features that fired (L0) // reconstruction_cos — MODELED SAE reconstruction fidelity (cosine) // top_features[] — {feature, activation, causal_ablation_kl, interpretation_confidence} // // LEADERS ADOPTED & CITED (clean-room; NOT claimed as SZL's own): // SAEs find interpretable features: Cunningham et al. arXiv:2309.08600 // https://arxiv.org/abs/2309.08600 // JumpReLU SAEs: Rajamanoharan et al. arXiv:2407.14435 // https://arxiv.org/abs/2407.14435 // Anthropic circuit tracing: https://transformer-circuits.pub/2025/january-update/index.html // Sparse feature circuits (causal): Marks et al. arXiv:2406.02395 // https://arxiv.org/abs/2406.02395 // // HONESTY LABELS: MODELED (simulation of the METHOD; no proprietary weights, no measured // logits). Read verbatim from JSON; never upgraded here. // COLOURS: lattice-blue 0x5b8dee (fired feature nodes), violet-blue 0x8a6bff (top causal // feature flash — data-viz only). Purple BANNED as UI/background. // 0 RUNTIME CDN. Vendored three.js r170 via page importmap. // DOCTRINE v11: degrades gracefully (grey) on 404/error; honesty label still shown. import { createShowcase } from "./_showcase.js"; const ID = "interpretability"; const TITLE = "Interpretability · Sparse-Autoencoder Features (live)"; // PRIMARY endpoint is the a11oy-NATIVE self-hosted SAE surface (same-origin, no CORS): // GET /api/a11oy/v1/interpretability/features (szl_a11oy_interpretability.py, MODELED). // FALLBACK stays the dedicated killinchu Space (isolated compute, reached cross-origin — // killinchu returns access-control-allow-origin: https://a-11-oy.com) so a rebuild/fault // on EITHER path never darkens the organ (fault isolation preserved). If the primary // reports missing/error we transparently swap to the Space fallback (see mount()). const EP = "/api/a11oy/v1/interpretability/features?seed=42&top_k=8&d_model=512&n_features=4096"; const EP_FALLBACK = "https://szlholdings-killinchu.hf.space/api/killinchu/v1/interpretability/features?seed=42&top_k=8&d_model=512&n_features=4096"; // data-viz hues — purple BANNED const C_NODE = 0x5b8dee; // lattice-blue (fired feature) const C_TOP = 0x8a6bff; // violet-blue (highest causal feature flash — data-viz only) const C_DIM = 0x42505d; // grey (degraded / no-live-data / unfired dictionary node) const C_ACCENT = 0x3af4c8; // proof-teal accent for the reconstruction ring const C_GRID = 0x1b3a44; // floor / link colour // dictionary lattice geometry: a ring of feature nodes (the fired dictionary features) const N_SLOTS = 16; // visual dictionary slots on the ring (matches endpoint feature bank) const RADIUS = 4.2; // world-unit ring radius let _stage = null, _THREE = null, _ctx = null, _group = null, _show = null; let _frameReg = false, _polls = [], _el = {}, _badge = null; // geometry handles let _slots = []; // Array — one per dictionary slot on the ring let _links = null; // THREE.LineSegments — slot→hub links let _hub = null; // THREE.Mesh — central reconstruction hub let _ring = null; // THREE.Mesh — reconstruction-fidelity ring // per-slot flash timers const _flash = new Float32Array(N_SLOTS); // live state const S = { label: null, l0: null, // l0_sparsity active: null, // active_features recon: null, // reconstruction_cos top: null, // Array<{feature,activation,causal_ablation_kl,interpretation_confidence}> state: "init", }; // ============================================================================= // mount(ctx) // ============================================================================= export function mount(ctx) { _ctx = ctx; _stage = ctx.stage; _THREE = ctx.THREE; _group = new _THREE.Group(); _stage.scene.add(_group); _stage.camera.position.set(0, 7, 20); try { if (_stage.controls && _stage.controls.target) { _stage.controls.target.set(0, 1.5, 0); _stage.controls.update(); } } catch (_) {} try { _stage.setBloom(true); } catch (_) {} _buildFloor(); _buildRing(); _buildHub(); if (!_frameReg) { _stage.onFrame(_onFrame); _frameReg = true; } _badge = ctx.live.createBadge(); // Guarded primary -> fallback: poll the a11oy-native endpoint; if it goes // missing/error, swap ONCE to the isolated killinchu Space (fault isolation). let _swapped = false; const _startPoll = (ep) => ctx.live.poll(ep, 5000, _onFeatures, { badge: _badge, onState: (m) => { S.state = m.state; if (!_swapped && (m.state === "missing" || m.state === "error")) { _swapped = true; try { _polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = []; } catch (_) {} _polls.push(_startPoll(EP_FALLBACK)); } _paintOverlay(); }, }); _polls.push(_startPoll(EP)); _buildOverlay(); return { id: ID, started: true }; } // ============================================================================= // builders // ============================================================================= function _buildFloor() { const THREE = _THREE; const grid = new THREE.GridHelper(40, 40, C_GRID, 0x0f2027); grid.material.opacity = 0.18; grid.material.transparent = true; grid.position.y = -0.01; _group.add(grid); } function _buildRing() { const THREE = _THREE; const geo = new THREE.SphereGeometry(0.24, 14, 10); _slots = []; const linkPts = []; const hubY = 2.2; for (let i = 0; i < N_SLOTS; i++) { const ang = (i / N_SLOTS) * Math.PI * 2; const x = Math.cos(ang) * RADIUS; const z = Math.sin(ang) * RADIUS; const mat = new THREE.MeshStandardMaterial({ color: C_DIM, emissive: C_DIM, emissiveIntensity: 0.15, metalness: 0.25, roughness: 0.55, }); const mesh = new THREE.Mesh(geo, mat); mesh.position.set(x, hubY, z); _group.add(mesh); _slots.push(mesh); // link each slot to the central hub linkPts.push(new THREE.Vector3(x, hubY, z), new THREE.Vector3(0, hubY, 0)); } const lg = new THREE.BufferGeometry().setFromPoints(linkPts); _links = new THREE.LineSegments(lg, new THREE.LineBasicMaterial({ color: C_GRID, transparent: true, opacity: 0.22 })); _group.add(_links); } function _buildHub() { const THREE = _THREE; // Central hub = the residual-stream activation being decomposed. _hub = new THREE.Mesh( new THREE.IcosahedronGeometry(0.6, 1), new THREE.MeshStandardMaterial({ color: C_NODE, emissive: C_NODE, emissiveIntensity: 0.3, wireframe: true, transparent: true, opacity: 0.55 }), ); _hub.position.set(0, 2.2, 0); _group.add(_hub); // Reconstruction-fidelity ring around the hub (radius scales with reconstruction_cos). _ring = new THREE.Mesh( new THREE.TorusGeometry(1.2, 0.03, 10, 64), new THREE.MeshStandardMaterial({ color: C_ACCENT, emissive: C_ACCENT, emissiveIntensity: 0.4, transparent: true, opacity: 0.5 }), ); _ring.position.set(0, 2.2, 0); _ring.rotation.x = Math.PI / 2; _group.add(_ring); } // ============================================================================= // live data handler // ============================================================================= function _onFeatures(j) { // read honesty label VERBATIM — never upgrade S.label = (j.label || "MODELED").toUpperCase(); S.l0 = typeof j.l0_sparsity === "number" ? j.l0_sparsity : null; S.active = typeof j.active_features === "number" ? j.active_features : null; S.recon = typeof j.reconstruction_cos === "number" ? j.reconstruction_cos : null; S.top = Array.isArray(j.top_features) ? j.top_features : null; _updateRing(); _paintOverlay(); } // ============================================================================= // geometry updater — drives slot colour/brightness from top features // ============================================================================= function _updateRing() { const live = S.state === "live"; const top = S.top || []; // maximum causal KL among top features (for scaling node size) const maxKL = top.reduce((m, f) => Math.max(m, (f && f.causal_ablation_kl) || 0), 0.0001); _slots.forEach((mesh, i) => { const f = top[i]; // first N_SLOTS top features light up; the rest stay dim if (live && f) { const act = typeof f.activation === "number" ? f.activation : 0; const kl = typeof f.causal_ablation_kl === "number" ? f.causal_ablation_kl : 0; const norm = kl / maxKL; // 0..1 relative causal effect const col = norm > 0.75 ? C_TOP : C_NODE; mesh.material.color.setHex(col); mesh.material.emissive.setHex(col); mesh.material.emissiveIntensity = 0.15 + 0.85 * act; mesh.scale.setScalar(0.7 + 0.9 * norm); // bigger = more causally important _flash[i] = Math.min(30 + norm * 60, 90); } else { mesh.material.color.setHex(C_DIM); mesh.material.emissive.setHex(C_DIM); mesh.material.emissiveIntensity = 0.1; mesh.scale.setScalar(0.55); } }); if (_hub) { const hcol = live ? C_NODE : C_DIM; _hub.material.color.setHex(hcol); _hub.material.emissive.setHex(hcol); _hub.material.emissiveIntensity = live ? 0.35 : 0.15; _hub.material.opacity = live ? 0.7 : 0.35; } if (_ring) { const cos = S.recon != null ? S.recon : 0.9; const rcol = live ? C_ACCENT : C_DIM; _ring.material.color.setHex(rcol); _ring.material.emissive.setHex(rcol); _ring.material.emissiveIntensity = live ? 0.2 + 0.6 * cos : 0.12; _ring.material.opacity = live ? 0.55 : 0.2; _ring.scale.setScalar(live ? (0.6 + cos) : 0.8); // fuller ring = better reconstruction } if (_links) { _links.material.opacity = live ? 0.3 : 0.14; _links.material.color.setHex(live ? C_GRID : C_DIM); } } // ============================================================================= // per-frame animation // ============================================================================= function _onFrame() { const t = performance.now(); if (_group) _group.rotation.y = Math.sin(t * 0.00012) * 0.2; if (_hub) { _hub.rotation.y += 0.006; _hub.rotation.x += 0.003; } if (_ring) { _ring.rotation.z += 0.004; } const live = S.state === "live"; _slots.forEach((mesh, i) => { if (_flash[i] > 0) { _flash[i] -= 1; const f = _flash[i] / 90; const col = live ? C_TOP : C_DIM; mesh.material.emissive.setHex(col); mesh.material.emissiveIntensity = Math.max(mesh.material.emissiveIntensity, 0.15 + 0.9 * f); } }); } // ============================================================================= // overlay // ============================================================================= function _buildOverlay() { _show = createShowcase(_ctx, { id: ID, title: TITLE, accent: "#5b8dee", badge: _badge, chips: [{ label: "MODELED", text: "interpretability", name: "hl" }], legend: ["MODELED"], description: 'A JumpReLU sparse autoencoder decomposes a model\u2019s internal activation into a ' + 'few human-readable features; each fired feature is a node on the ring, and we ' + 'causally ablate it to measure the output shift (KL). Honesty label MODELED ' + '(a simulation of the method \u2014 no proprietary weights, no measured logits). 0 runtime CDN.', citations: "Cunningham et al. arXiv:2309.08600 \u00b7 Rajamanoharan et al. arXiv:2407.14435 (JumpReLU) \u00b7 Marks et al. arXiv:2406.02395 (sparse feature circuits) \u00b7 Anthropic transformer-circuits.pub. MODELED \u00b7 not claimed-as.", plain: { html: _plainHtml }, }); _el["ip-l0"] = _show.addField("L0 sparsity (active / dict)"); _el["ip-active"] = _show.addField("active features"); _el["ip-recon"] = _show.addField("reconstruction cos \u2014 MODELED"); _el["ip-topf"] = _show.addField("top feature (by causal KL)"); _el["ip-label"] = _show.addField("honesty label"); _paintOverlay(); } function _plainHtml() { const act = S.active != null ? String(S.active) : "loading\u2026"; const l0 = S.l0 != null ? (S.l0 * 100).toFixed(3) + "% of the dictionary" : "loading\u2026"; const top = (S.top && S.top[0] && S.top[0].feature) ? S.top[0].feature : "loading\u2026"; return ( "What this means: Instead of treating the model as a black box, a sparse " + "autoencoder breaks one internal activation into a handful of named, human-readable " + "features \u2014 here " + act + " fired (only " + l0 + "). " + "The most causally important one right now is " + top + ": turning it off shifts " + "the model\u2019s output the most. " + "Plain: this is how you audit why an AI produced an answer and prove which internal " + "concept drove it \u2014 but this view is a MODELED simulation of the technique, not a " + "readout from a live production model."); } function _tok(s) { if (s === "live") return null; if (s === "missing") return "NO-LIVE-DATA"; if (s === "degraded") return "DEGRADED"; if (s === "error") return "OFFLINE"; return "\u2026"; } function fx(v, d) { return typeof v === "number" ? v.toFixed(d) : "\u2014"; } function _set(id, v) { if (_el[id]) _el[id].textContent = v; } function _paintOverlay() { const t = _tok(S.state); _set("ip-l0", t || fx(S.l0, 6)); _set("ip-active", t || (S.active != null ? String(S.active) : "\u2014")); _set("ip-recon", t || fx(S.recon, 4)); const top0 = (S.top && S.top[0]) ? S.top[0] : null; _set("ip-topf", t || (top0 ? (top0.feature + " (KL " + fx(top0.causal_ablation_kl, 3) + ")") : "\u2014")); // honesty label verbatim — never upgraded _set("ip-label", t || (S.label || "MODELED")); if (_show) { _show.setChip("hl", S.label || "MODELED", { text: "interpretability" }); _show.refreshPlain(); } } // ============================================================================= // unmount — clean up everything; must not affect other organs // ============================================================================= export function unmount() { _polls.forEach((p) => { try { p.stop(); } catch (_) {} }); _polls = []; try { if (_show) _show.destroy(); } catch (_) {} try { if (_group && _stage) { _group.traverse((o) => { if (o.geometry && o.geometry.dispose) o.geometry.dispose(); if (o.material) { const ms = Array.isArray(o.material) ? o.material : [o.material]; ms.forEach((m) => { if (m.dispose) m.dispose(); }); } }); _stage.scene.remove(_group); } } catch (_) {} _group = _show = null; _slots = []; _links = null; _hub = null; _ring = null; _el = {}; _badge = null; _frameReg = false; _stage = _THREE = _ctx = null; S.label = S.l0 = S.active = S.recon = S.top = null; S.state = "init"; _flash.fill(0); } export default { id: ID, title: TITLE, endpoints: [EP, EP_FALLBACK], mount, unmount };