SPIRA / python /scripts /correction_sparse_probe.py
thefinalboss's picture
SPIRA v2: entropy-patch tokenization + hierarchical dopamine-gated spiking cortex + hippocampal one-shot memory with replay consolidation
032a961 verified
Raw History Blame Contribute Delete
1.88 kB
#!/usr/bin/env python3
"""Corrupted-cue completion with a SPARSE hippocampus (book only, no corpus load).
The main correction metrics are measured with the full corpus AM (46% load
factor) — the deployed state. This probe measures the capacity-to-spare
regime (fresh AM + only the taught book) that v1 accidentally measured via
its broken AM checkpoint format. Both are honest numbers for different
memory loads; the paper reports both.
"""
import sys
sys.path.insert(0, "/home/z/my-project/download/spira")
import numpy as np
from spira import SPIRA
from spira.hippocampus import Hippocampus
BASE = "/home/z/my-project"
m = SPIRA.load(f"{BASE}/download/spira/artifacts/spira_model.npz")
m.am = Hippocampus(m=m.cfg.am_m, size=m.cfg.am_size, min_lanes=m.cfg.am_min_lanes)
oneshot = open(f"{BASE}/data/oneshot.bin", "rb").read()
book = oneshot[:60_000]
taught = m.teach_bytes(book)
print(f"taught {taught['tokens']} tokens into a fresh AM "
f"({m.am.stats()['load_factor']:.4f} load)")
out = {}
for k in (0, 1, 2, 3):
r = m.eval_stream(book, corrupt_lanes=k, max_positions=8_000)
out[f"corrupt_{k}_of_4"] = {kk: r[kk] for kk in ("am_acc", "am_acc_invocab", "fused_acc")}
print(f" corrupt {k}/4 lanes (sparse AM): am={r['am_acc']:.4f} fused={r['fused_acc']:.4f}")
import json
mp = f"{BASE}/download/spira/artifacts/metrics.json"
metrics = json.load(open(mp))
metrics["correction_sparse_am"] = {
**out,
"note": "corrupted-cue completion with a fresh hippocampus (book only, ~0 load); "
"the main 'correction' section reports the deployed state (corpus AM at "
"46% load). v1's 92% was measured in this sparse regime by accident "
"(broken checkpoint format emptied the loaded corpus AM).",
}
json.dump(metrics, open(mp, "w"), indent=2, ensure_ascii=False)
print("saved -> metrics['correction_sparse_am']")