code wiki / _hdl_build / nx_semppmi_build.nx

nx_semppmi_build.nx source

↩ module page · 438 lines · 20030 B

1// nx_semppmi_build.nx -- EXPLICIT-VOCAB SPARSE PPMI embeddings = the CANONICAL count-based method at full 2// strength (Levy&Goldberg: full sparse PPMI rows rival trained embeddings on word similarity). This is the 3// last count-method rung before "trained-only" is airtight: v1 (nx_semcorpus_build) failed its probes with 4// HASHED rows (collisions) + a 256-dim PROJECTION (lossy) -- this build removes BOTH: every word gets its own 5// row; contexts are the full vocabulary; cells are PPMI (positive pointwise mutual information, log2 x16 6// fixed-point); rows stay SPARSE (sorted triples). Corpus = same banked benchmark prose (no gold leakage: 7// only JSON strings >= 48 chars). 8// PIPELINE (one corpus walk): tokens -> 61-bit djb2x hash stream (+ -1 markers at string ends) -> 9// vocab = sort(copy)+unique (explicit; 61-bit space => collisions ~0 at 60k words) -> 10// window +-4 pair emission as packed keys (aid<<20|bid, both directions) -> sort -> RLE -> triples(cnt>=2) -> 11// marginals -> PPMI16 -> row index + norms -> PROBES -> persist knowledge/index/semppmi_v1.bin. 12// PROBES decide (same discipline as v1): if won~defeated fails to order again, count methods are DEAD at 13// canonical strength and the R1 trained thread is the proven only door. TEETH structural + neg-controls. 14// expect_exit: 0 license_tier: ORIGINAL 15import "nx_qabench_engine.nx" 16import "nx_estate_path.nx" // ep_anchor: the CWD must not decide this organ verdict 17const SP_MAGIC_262144: i64 = 262144 18const SP_MAGIC_16777216: i64 = 16777216 19const SP_MAGIC_250000: i64 = 250000 20const SP_MAGIC_4000: i64 = 4000 21const SP_MAGIC_32768: i64 = 32768 22const SP_MAGIC_3500000: i64 = 3500000 23const SP_MAGIC_30000000: i64 = 30000000 24const SP_MAGIC_1048576: i64 = 1048576 25const SP_MAGIC_8000000: i64 = 8000000 26const SP_MAGIC_4096: i64 = 4096 27const SP_MAGIC_3000: i64 = 3000 28const SP_MAGIC_10000: i64 = 10000 29const SP_MAGIC_100000: i64 = 100000 30const SP_MAGIC_50000: i64 = 50000 31 32const SP_WIN: i64 = 4 33const SP_MINSTR: i64 = 48 34const SP_MAXV: i64 = 262144 35const SP_MINCNT: i64 = 2 36 37// 61-bit string hash: SHARED single-source db_semhash from the engine (nx_qabench resolves with the same fn) 38func sp_hash(buf: *u8, off: i64, len: i64) -> i64 { return db_semhash(buf, off, len) } 39 40// write n bytes to fd; 0 ok, 1 err 41func sp_wblock(fd: i64, buf: *u8, n: i64) -> i64 { 42 var off: i64 = 0 43 while off < n { 44 var chunk: i64 = SP_MAGIC_262144 45 if n - off < chunk { chunk = n - off } 46 let ww: i64 = sys_write(fd, (buf as i64 + off) as *u8, chunk) 47 if ww <= 0 { return 1 } 48 off = off + ww 49 } 50 return 0 51} 52 53func sp_isqrt(v: i64) -> i64 { 54 if v <= 0 { return 0 } 55 var x: i64 = v 56 var y: i64 = (x + 1) / 2 57 while y < x { x = y; let q: i64 = v / x; y = (x + q) / 2 } 58 return x 59} 60 61// log2 in 1/16ths of the ratio q (q >= 1); bitlen-based + 4-bit linear fraction 62func sp_ilog2x16(q: i64) -> i64 { 63 if q <= 1 { return 0 } 64 var bl: i64 = 0 65 var t: i64 = q 66 while t > 1 { t = t / 2; bl = bl + 1 } 67 var frac: i64 = 0 68 if bl >= 4 { frac = (q / (1 << (bl-4))) - 16 } 69 if bl < 4 { frac = (q << (4-bl)) - 16 } 70 if frac < 0 { frac = 0 } 71 if frac > 15 { frac = 15 } 72 return bl*16 + frac 73} 74 75// in-place quicksort of a[lo..hi] 76func sp_qsort(a: *i64, lo: i64, hi: i64) -> i64 { 77 if lo >= hi { return 0 } 78 let p: i64 = a[(lo+hi)/2] 79 var i: i64 = lo 80 var j: i64 = hi 81 while i <= j { 82 while a[i] < p { i = i + 1 } 83 while a[j] > p { j = j - 1 } 84 if i <= j { 85 let tmp: i64 = a[i] 86 a[i] = a[j] 87 a[j] = tmp 88 i = i + 1 89 j = j - 1 90 } 91 } 92 sp_qsort(a, lo, j) 93 sp_qsort(a, i, hi) 94 return 0 95} 96 97// binary search: SHARED db_bsearch_i64 from the engine 98func sp_bsearch(a: *i64, n: i64, v: i64) -> i64 { return db_bsearch_i64(a, n, v) } 99 100// walk one raw file's long JSON strings -> append token hashes to stream (marker -1 between strings). 101// c[0]=strings c[1]=tokens. stream cap slots in c[2] (bump in c[3]). 102func sp_walk(g: *i64, path: *u8, stream: *i64, c: *i64) -> i64 { 103 let total: i64 = db_read_raw(g, path, SP_MAGIC_16777216) 104 if total <= 0 { db_w(" [absent] "); db_w(path); db_w("\n" as *u8); return 0 } 105 if total == 0-2 { db_w(" [too big] "); db_w(path); db_w("\n" as *u8); return 0 } 106 g[2] = db_body_start(g, total) 107 g[1] = total - g[2] 108 let scr: *u8 = g[5] as *u8 109 let nrm: *u8 = g[6] as *u8 110 let toff: *i64 = g[7] as *i64 111 let tlen: *i64 = g[8] as *i64 112 g[3] = 0 113 while g[3] < g[1] { 114 let ch: i64 = db_b(g, g[3]) 115 if ch == 34 { 116 let sl: i64 = db_dec_str(g, scr, SP_MAGIC_250000) 117 if sl >= SP_MINSTR { 118 c[0] = c[0] + 1 119 let nl: i64 = qs_norm(scr, nrm) 120 let nt: i64 = qs_tok(nrm, nl, toff, tlen, SP_MAGIC_4000) 121 var j: i64 = 0 122 while j < nt { 123 if tlen[j] >= 2 { if db_is_stop(nrm, toff[j], tlen[j]) == 0 { 124 if c[3] < c[2] { 125 let hv: i64 = sp_hash(nrm, toff[j], tlen[j]) 126 stream[c[3]] = hv 127 c[3] = c[3] + 1 128 c[1] = c[1] + 1 129 } 130 } } 131 j = j + 1 132 } 133 if c[3] < c[2] { stream[c[3]] = 0-1; c[3] = c[3] + 1 } 134 } 135 } else { g[3] = g[3] + 1 } 136 } 137 db_w(" walked "); db_w(path); db_w(" strings="); db_n(c[0]); db_w(" tokens="); db_n(c[1]); db_w("\n" as *u8) 138 return 1 139} 140 141// cosine between sparse PPMI rows a and b: rows = triples[ridx[a]..ridx[a+1]) sorted by ctx id. 142// trip layout: tctx[i], tval[i]. norms nrm2[] precomputed (sum of val^2). 143func sp_cos(tctx: *i64, tval: *i64, ridx: *i64, nrm2: *i64, a: i64, b: i64) -> i64 { 144 var ia: i64 = ridx[a] 145 var ib: i64 = ridx[b] 146 let ea: i64 = ridx[a+1] 147 let eb: i64 = ridx[b+1] 148 var dot: i64 = 0 149 while ia < ea { 150 if ib >= eb { ia = ea } else { 151 if tctx[ia] == tctx[ib] { dot = dot + tval[ia]*tval[ib]; ia = ia + 1; ib = ib + 1 } 152 else { if tctx[ia] < tctx[ib] { ia = ia + 1 } else { ib = ib + 1 } } 153 } 154 } 155 if dot <= 0 { return 0 } 156 let d1: i64 = sp_isqrt(nrm2[a]) 157 let d2: i64 = sp_isqrt(nrm2[b]) 158 if d1 == 0 { return 0 } 159 if d2 == 0 { return 0 } 160 var cv: i64 = (dot*1000)/(d1*d2) 161 if cv > 1000 { cv = 1000 } 162 return cv 163} 164 165// probe helper: word -> vocab id (via sorted hash list) 166func sp_wid(vh: *i64, nv: i64, w: *u8) -> i64 { 167 var n: i64 = 0 168 while w[n] != (0 as u8) { n = n + 1 } 169 let hv: i64 = sp_hash(w, 0, n) 170 return sp_bsearch(vh, nv, hv) 171} 172 173func main() -> i64 { 174 // ANCHOR FIRST (2026-08-04, nx_cwdguard finding): this organ reads a RELATIVE 175 // knowledge/ path, so its answer depended on where it was launched. No-op when 176 // already at the estate root, so the cron/MCP context is unchanged. 177 ep_anchor() 178 db_w("=== nx_semppmi_build -- EXPLICIT-vocab sparse PPMI (canonical count method, the last pre-trained rung) ===\n" as *u8) 179 let g: *i64 = sys_mmap(256) as *i64 180 let m0: *u8 = sys_mmap(SP_MAGIC_16777216); g[0] = m0 as i64 181 let m5: *u8 = sys_mmap(SP_MAGIC_262144); g[5] = m5 as i64 182 let m6: *u8 = sys_mmap(SP_MAGIC_262144); g[6] = m6 as i64 183 let m7: *u8 = sys_mmap(SP_MAGIC_32768); g[7] = m7 as i64 184 let m8: *u8 = sys_mmap(SP_MAGIC_32768); g[8] = m8 as i64 185 186 let SCAP: i64 = SP_MAGIC_3500000 187 let stream: *i64 = sys_mmap(SCAP*8) as *i64 188 let c: *i64 = sys_mmap(64) as *i64 189 c[0]=0; c[1]=0; c[2]=SCAP; c[3]=0 190 191 sp_walk(g, "knowledge/fetched/qab_squad_big.raw" as *u8, stream, c) 192 sp_walk(g, "knowledge/fetched/qab_hotpot_big.raw" as *u8, stream, c) 193 sp_walk(g, "knowledge/fetched/qab_musique_big.raw" as *u8, stream, c) 194 // corpus-growth chunks (DISJOINT from the eval rows above; absent files skip cleanly) 195 sp_walk(g, "knowledge/fetched/qab_squad_c0.raw" as *u8, stream, c) 196 sp_walk(g, "knowledge/fetched/qab_squad_c1.raw" as *u8, stream, c) 197 sp_walk(g, "knowledge/fetched/qab_squad_c2.raw" as *u8, stream, c) 198 sp_walk(g, "knowledge/fetched/qab_hotpot_c0.raw" as *u8, stream, c) 199 sp_walk(g, "knowledge/fetched/qab_hotpot_c1.raw" as *u8, stream, c) 200 sp_walk(g, "knowledge/fetched/qab_hotpot_c2.raw" as *u8, stream, c) 201 sp_walk(g, "knowledge/fetched/qab_musique_c0.raw" as *u8, stream, c) 202 sp_walk(g, "knowledge/fetched/qab_musique_c1.raw" as *u8, stream, c) 203 let slen: i64 = c[3] 204 205 // ---- vocab: sort a copy of the hash stream, unique (markers filtered) ---- 206 let vs: *i64 = sys_mmap(SCAP*8) as *i64 207 var vn: i64 = 0 208 var i: i64 = 0 209 while i < slen { let sv: i64 = stream[i]; if sv >= 0 { vs[vn] = sv; vn = vn + 1 } i = i + 1 } 210 sp_qsort(vs, 0, vn-1) 211 let vh: *i64 = sys_mmap(SP_MAXV*8) as *i64 212 var nv: i64 = 0 213 i = 0 214 while i < vn { 215 var take: i64 = 1 216 if i > 0 { if vs[i] == vs[i-1] { take = 0 } } 217 if take == 1 { if nv < SP_MAXV { vh[nv] = vs[i]; nv = nv + 1 } } 218 i = i + 1 219 } 220 db_w("vocab (explicit, unique) = "); db_n(nv); db_w(" words from "); db_n(vn); db_w(" events\n" as *u8) 221 222 // ---- pair emission: packed key (aid<<20)|bid for window pairs, both directions ---- 223 let PCAP: i64 = SP_MAGIC_30000000 224 let pairs: *i64 = sys_mmap(PCAP*8) as *i64 225 var np: i64 = 0 226 i = 0 227 while i < slen { 228 if stream[i] >= 0 { 229 let av: i64 = sp_bsearch(vh, nv, stream[i]) 230 if av >= 0 { 231 var b: i64 = i + 1 232 var bend: i64 = i + SP_WIN 233 if bend > slen-1 { bend = slen-1 } 234 var stop: i64 = 0 235 while b <= bend { 236 if stop == 0 { 237 if stream[b] < 0 { stop = 1 } else { 238 let bv: i64 = sp_bsearch(vh, nv, stream[b]) 239 if bv >= 0 { if np < PCAP-2 { 240 pairs[np] = av*SP_MAGIC_1048576 + bv 241 pairs[np+1] = bv*SP_MAGIC_1048576 + av 242 np = np + 2 243 } } 244 } 245 } 246 b = b + 1 247 } 248 } 249 } 250 i = i + 1 251 } 252 db_w("window pair-events = "); db_n(np); db_w("\n" as *u8) 253 sp_qsort(pairs, 0, np-1) 254 255 // ---- RLE -> triples (cnt >= SP_MINCNT), marginals ---- 256 let TCAP: i64 = SP_MAGIC_8000000 257 let taid: *i64 = sys_mmap(TCAP*8) as *i64 258 let tctx: *i64 = sys_mmap(TCAP*8) as *i64 259 let tcnt: *i64 = sys_mmap(TCAP*8) as *i64 260 let marg: *i64 = sys_mmap(SP_MAXV*8) as *i64 261 var nt3: i64 = 0 262 var run: i64 = 1 263 i = 1 264 var dropped: i64 = 0 265 while i <= np { 266 var flush: i64 = 1 267 if i < np { if pairs[i] == pairs[i-1] { run = run + 1; flush = 0 } } 268 if flush == 1 { 269 let key: i64 = pairs[i-1] 270 let aid: i64 = key / SP_MAGIC_1048576 271 let bid: i64 = key % SP_MAGIC_1048576 272 marg[aid] = marg[aid] + run 273 if run >= SP_MINCNT { if nt3 < TCAP { 274 taid[nt3] = aid; tctx[nt3] = bid; tcnt[nt3] = run; nt3 = nt3 + 1 275 } } else { dropped = dropped + 1 } 276 run = 1 277 } 278 i = i + 1 279 } 280 db_w("triples cnt>="); db_n(SP_MINCNT); db_w(": "); db_n(nt3); db_w(" (singleton pairs dropped="); db_n(dropped); db_w(")\n" as *u8) 281 282 // total mass T for PMI 283 var TT: i64 = 0 284 i = 0 285 while i < nv { TT = TT + marg[i]; i = i + 1 } 286 287 // ---- PPMI16 transform in place on tcnt; row index + norms ---- 288 let ridx: *i64 = sys_mmap((SP_MAXV+2)*8) as *i64 289 let nrm2: *i64 = sys_mmap(SP_MAXV*8) as *i64 290 var cur: i64 = 0 291 i = 0 292 while i < nv { ridx[i] = 0; nrm2[i] = 0; i = i + 1 } 293 ridx[nv] = 0 294 // triples are sorted by (aid,ctx) already (pair sort). build ridx by counting then prefix. 295 i = 0 296 while i < nt3 { let ai: i64 = taid[i]; ridx[ai] = ridx[ai] + 1; i = i + 1 } 297 var pref: i64 = 0 298 i = 0 299 while i <= nv { let cnt0: i64 = ridx[i]; ridx[i] = pref; pref = pref + cnt0; i = i + 1 } 300 // transform + norms (triples already in row-major order; indices align with ridx layout) 301 i = 0 302 var kept: i64 = 0 303 while i < nt3 { 304 let aid2: i64 = taid[i] 305 let bid2: i64 = tctx[i] 306 let cc: i64 = tcnt[i] 307 let den: i64 = marg[aid2] * marg[bid2] 308 var pp: i64 = 0 309 if den > 0 { 310 let q: i64 = (cc * TT * 256) / den 311 let lg: i64 = sp_ilog2x16(q) 312 if lg > 128 { pp = lg - 128 } // subtract log2(256)*16 = 8*16 -> PPMI (positive part) 313 } 314 tcnt[i] = pp 315 if pp > 0 { kept = kept + 1 } 316 nrm2[aid2] = nrm2[aid2] + pp*pp 317 i = i + 1 318 } 319 db_w("PPMI-positive cells = "); db_n(kept); db_w("/"); db_n(nt3); db_w(" total-mass T="); db_n(TT); db_w("\n" as *u8) 320 321 // ---- PROBES (the verdict): explicit sparse PPMI on the wall pairs ---- 322 let w1: i64 = sp_wid(vh, nv, "won" as *u8) 323 let w2: i64 = sp_wid(vh, nv, "defeated" as *u8) 324 let w3: i64 = sp_wid(vh, nv, "purple" as *u8) 325 let w4: i64 = sp_wid(vh, nv, "city" as *u8) 326 let w5: i64 = sp_wid(vh, nv, "stadium" as *u8) 327 let w6: i64 = sp_wid(vh, nv, "january" as *u8) 328 var p1: i64 = 0-1 329 var p2: i64 = 0-1 330 var p3: i64 = 0-1 331 var p4: i64 = 0-1 332 if w1 >= 0 { if w2 >= 0 { p1 = sp_cos(tctx, tcnt, ridx, nrm2, w1, w2) } } 333 if w1 >= 0 { if w3 >= 0 { p2 = sp_cos(tctx, tcnt, ridx, nrm2, w1, w3) } } 334 if w4 >= 0 { if w5 >= 0 { p3 = sp_cos(tctx, tcnt, ridx, nrm2, w4, w5) } } 335 if w4 >= 0 { if w6 >= 0 { p4 = sp_cos(tctx, tcnt, ridx, nrm2, w4, w6) } } 336 db_w("PROBE cos(won,defeated)="); db_n(p1); db_w(" cos(won,purple)="); db_n(p2) 337 var ord1: i64 = 0 338 if p1 > p2 { ord1 = 1; db_w(" [orders CORRECTLY]\n" as *u8) } else { db_w(" [does NOT order]\n" as *u8) } 339 db_w("PROBE cos(city,stadium)="); db_n(p3); db_w(" cos(city,january)="); db_n(p4) 340 var ord2: i64 = 0 341 if p3 > p4 { ord2 = 1; db_w(" [orders CORRECTLY]\n" as *u8) } else { db_w(" [does NOT order]\n" as *u8) } 342 343 // NEG: identity + disjoint-row zero 344 var ident: i64 = 0 345 if w1 >= 0 { ident = sp_cos(tctx, tcnt, ridx, nrm2, w1, w1) } 346 db_w("NEG identity="); db_n(ident); db_w("\n" as *u8) 347 348 // ---- persist the QUERY-side structures -> knowledge/index/semppmi_v1.bin 349 // layout: 32B header [NXPPMI1\0][nv][nt3][reserved] then vh[nv] ridx[nv+1] nrm2[nv] tctx[nt3] tval[nt3] 350 let hdr: *u8 = sys_mmap(SP_MAGIC_4096) 351 hdr[0]=78 as u8; hdr[1]=88 as u8; hdr[2]=80 as u8; hdr[3]=80 as u8; hdr[4]=77 as u8; hdr[5]=73 as u8; hdr[6]=49 as u8; hdr[7]=0 as u8 352 let hi2: *i64 = (hdr as i64 + 8) as *i64 353 hi2[0] = nv 354 hi2[1] = nt3 355 hi2[2] = 0 356 var werr: i64 = 0 357 // OUTPUT PATH IS NO LONGER HARDCODED. 20 organs consume knowledge/index/semppmi_v1.bin 358 // (nx_qabench, nx_beir_eval, nx_dr_semjudge, nx_debtcluster, nx_recall_dense, nx_ppmi_lib_gate, 359 // nx_lawsearch ...), so rebuilding this on a different corpus SILENTLY changed every one of them -- 360 // a shared-artifact clobber, not an upgrade, and the reason no domain model was ever built. 361 // Note the asymmetry this fixes: ppl_load already takes the model path as a PARAMETER, its header 362 // says so callers can A/B the general model against a domain-augmented one. The READ side was 363 // parameterised for exactly this purpose; the WRITE side never was. 364 // If knowledge/index/semppmi_out.conf exists, its first token is the destination; otherwise the 365 // historic default. Rule 19: with no conf present this is byte-identical to the old behaviour, 366 // so every existing consumer is untouched unless someone deliberately opts out. 367 let opath: *u8 = sys_mmap(SP_MAGIC_4096) 368 var opl: i64 = 0 369 let cfd: i64 = sys_openat_rd("knowledge/index/semppmi_out.conf" as *u8) 370 if cfd >= 0 { 371 let cb: *u8 = sys_mmap(SP_MAGIC_4096) 372 let cn: i64 = sys_read(cfd, cb, 1000) 373 sys_close(cfd) 374 var ci: i64 = 0 375 while ci < cn { if cb[ci] > (32 as u8) { opath[opl] = cb[ci]; opl = opl + 1 } ci = ci + 1 } 376 } 377 if opl < 4 { 378 opl = 0 379 let dflt: *u8 = "knowledge/index/semppmi_v1.bin" as *u8 380 while dflt[opl] != (0 as u8) { opath[opl] = dflt[opl]; opl = opl + 1 } 381 } 382 opath[opl] = 0 as u8 383 db_w("persist target: " as *u8); db_w(opath); db_w("\n" as *u8) 384 // FAIL-CLOSED PERSIST. This organ used to write its output UNCONDITIONALLY, even when its own 385 // teeth reported 0/5. On 2026-08-01 that destroyed the shared 43MB model twenty organs read: the 386 // corpus was absent, the build produced vocab=0 from 0 events, went RED, and PERSISTED THE EMPTY 387 // RESULT over the good file. A build that fails its own teeth must NOT ship its output -- writing 388 // after RED converts a DETECTED failure into a DESTROYED artefact, which is strictly worse than 389 // crashing. Refuse instead, and leave the previous artefact untouched. 390 // nv>0 is the minimum bar: an empty vocabulary can never be a usable model, and no legitimate 391 // corpus produces one. The caller keeps whatever was there before, which is always recoverable. 392 var may_write: i64 = 1 393 if nv <= 0 { may_write = 0 } 394 if nt3 <= 0 { may_write = 0 } 395 if may_write == 0 { 396 db_w("PERSIST REFUSED -- empty model (nv=" as *u8); db_n(nv); db_w(" nt=" as *u8); db_n(nt3) 397 db_w("). Refusing to overwrite " as *u8); db_w(opath); db_w(" with a build that failed its own teeth.\n" as *u8) 398 db_w("(fix the corpus, then re-run; the previous artefact is UNTOUCHED)\n" as *u8) 399 return 1 400 } 401 let fd: i64 = sys_openat_wr(opath, 0x1a4) 402 if fd < 0 { werr = 1 } else { 403 var hw: i64 = 0 404 while hw < 32 { let w0: i64 = sys_write(fd, (hdr as i64 + hw) as *u8, 32 - hw); if w0 <= 0 { werr = 1; hw = 32 } else { hw = hw + w0 } } 405 werr = werr + sp_wblock(fd, vh as *u8, nv*8) 406 werr = werr + sp_wblock(fd, ridx as *u8, (nv+1)*8) 407 werr = werr + sp_wblock(fd, nrm2 as *u8, nv*8) 408 werr = werr + sp_wblock(fd, tctx as *u8, nt3*8) 409 werr = werr + sp_wblock(fd, tcnt as *u8, nt3*8) 410 sys_close(fd) 411 } 412 // Report the path we ACTUALLY wrote, not a literal. The first cut of this parameterisation moved 413 // the WRITE to opath but left this message hardcoded, so a verification run printed 414 // "persisted knowledge/index/semppmi_v1.bin" while the bytes went to semppmi_scratch.bin. 415 // A write that moves while its log stays put is WORSE than a hardcoded write: the log is now 416 // confidently wrong, and every reader downstream inherits that wrongness. 417 if werr == 0 { db_w("persisted " as *u8); db_w(opath); db_w(" (query-side sparse PPMI)\n" as *u8) } else { db_w("PERSIST FAILED for " as *u8); db_w(opath); db_w("\n" as *u8) } 418 419 var pass: i64 = 0 420 if c[0] >= SP_MAGIC_3000 { pass = pass + 1 } 421 if nv >= SP_MAGIC_10000 { pass = pass + 1 } 422 if nt3 >= SP_MAGIC_100000 { pass = pass + 1 } 423 if kept >= SP_MAGIC_50000 { pass = pass + 1 } 424 if ident == 1000 { if werr == 0 { pass = pass + 1 } } 425 db_w("TEETH T1(strings)+T2(vocab)+T3(triples)+T4(ppmi-cells)+T5(identity) = "); db_n(pass); db_w("/5\n" as *u8) 426 db_w("PROBE-GATE (decides MODE2 wiring): ord(won-defeated)="); db_n(ord1); db_w(" ord(city-stadium)="); db_n(ord2); db_w("\n" as *u8) 427 if pass == 5 { 428 if ord1 == 1 { if ord2 == 1 { 429 db_w("GREEN + PROBES ORDER -- explicit sparse PPMI carries the signal; wire MODE2-soft next.\n" as *u8) 430 return 0 431 } } 432 db_w("GREEN (structure) but PROBES INSUFFICIENT -- count methods now exhausted at CANONICAL strength\n" as *u8) 433 db_w("(explicit vocab, no projection, full PPMI). The semantic wall is TRAINED-MODEL-BOUND, airtight.\n" as *u8) 434 return 0 435 } 436 db_w("RED -- build integrity failed\n" as *u8) 437 return 1 438}