code wiki / _hdl_build / nx_mt_r2_gate.nx

nx_mt_r2_gate.nx

buildroot/runtime/_hdl_build/nx_mt_r2_gate.nx

12205 B282 linesdepth 6pulls 8 transitivereach 0 importersview sourcekind gate/prooftopic mt
docsdependenciesstructsconstsfunctions

about

nx_mt_r2_gate.nx -- GATE for MT-R2: CROSS-TOKEN CONTEXT enables REORDERING. The first genuinely "machine translation" phenomenon: an output token that depends on MORE than its own aligned input token. Task = REVERSE+map: source [a,b] -> target [tmap[b], tmap[a]] (the canonical MT reordering, e.g. EN adjective-noun "red house" -> ES noun-adjective "casa roja"). A per-token aligned map (MT-R1 / nx_mt_core) provably CANNOT do this; a cross-token model can. This rung proves the CAPABILITY + the measured necessity contrast; the parameter-free fnet_mix and attention are the SCALABLE realizations of this same cross-token mixing, wired at R3+ when we move to real arrays/vocab. MODEL (cross-token, tape-trainable -- linear, so pure add/mul through nx_autograd): two learned heads W[h] (h=0,1), each [T x 2S], over the CONCATENATED one-hot input [onehot(a) ; onehot(b)]. head h, output j logit = W[h,j,a] + W[h,j,S+b] (the two active concat dims) ; argmax_j. head 0 target = onehot(tmap[b]) (reordered!), head 1 target = onehot(tmap[a]). Full-batch GD, MSE, zero-init. The loss is convex; lr chosen for the bipartite Hessian (degree ~ pairs/token). Vocab S=T=4 (small -> clean convex convergence + fast): EN 0 hello 1 family 2 love 3 good ; ES 0 familia 1 bueno 2 hola 3 amor ; tmap=[2,0,3,1]. TRAIN = 13 of the 16 (a,b) pairs; HELD-OUT = 3 pairs {(0,3),(3,0),(1,2)} (combinations never trained). FOUR GATES: A LEARNS reordering: per-token acc == 2*train_pairs, loss decreased to < half. B GENERALIZES: per-token acc == 2*held_pairs on pairs NEVER trained. C BIT-EXACT: retrain -> identical W bits. D PER-TOKEN MODEL CANNOT (measured necessity contrast + liar-kill): train MT-R1's per-token shared map (nx_mt_core) on the SAME reverse task -> its acc < 2*train_pairs. Proves the cross-token capacity is NECESSARY, not decorative. genealogy_id: rumelhart_1986_backprop (realized_in nx_autograd) + lee_2021_fnet (the mixing motive) lineage_id: sovereign_neural_mt_r2_crosstoken_reorder_v1 license_tier: ORIGINAL

dependencies 3 imports · 0 importers

nx_mt_core.nx nx_autograd.nx nx_syscalls.nx nx_mt_r2_gate.nx

imports: nx_mt_core.nxnx_autograd.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap m2_train sys_mmap ↻ ag_leaf ag_add ag_mk nx_f32_add nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ m2_idx ag_sub ag_mk ↻ nx_f32_sub nx_f32_add ↻ nx_f32_neg ag_mul ag_mk ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ag_backward nx_f32_add ↻ nx_f32_mul ↻ nx_f32_neg ↻ nx_f32_gt nx_f32_lt nx_f32_is_nan nx_f32_classify ↻ nx_f32_is_zero nx_f32_classify ↻ ag_val nx_f32_sub ↻ nx_f32_mul ↻

structs

none

consts

35const M2_LOG: *u8 = "knowledge/status/mt_r2.log"
36const M2_S: i64 = 4
37const M2_T: i64 = 4
39const EN0: *u8 = "hello" as *u8
40const EN1: *u8 = "family" as *u8
41const EN2: *u8 = "love" as *u8
42const EN3: *u8 = "good" as *u8
43const ES0: *u8 = "familia" as *u8
44const ES1: *u8 = "bueno" as *u8
45const ES2: *u8 = "hola" as *u8
46const ES3: *u8 = "amor" as *u8
47const ESQ: *u8 = "?" as *u8

functions

49func m2_en(i: i64) -> *u8
called by 1: m2_demo
56func m2_es(j: i64) -> *u8
called by 1: m2_demo
64func m2_w(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
called by 2: m2_demom2_emit calls 1: sys_write
65func m2_wn(fd: i64, v: i64) -> i64
called by 1: m2_emit calls 2: sys_mmapsys_write
75func m2_f32_to_milli(v: i64) -> i64
91func m2_idx(h: i64, j: i64, d: i64) -> i64 { return h * M2_T * (2 * M2_S) + j * (2 * M2_S) + d }
called by 2: m2_predm2_train
94func m2_pred(W: *i64, h: i64, a: i64, b: i64) -> i64
107func m2_acc(W: *i64, pa: *i64, pb: *i64, npair: i64, tmap: *i64) -> i64
called by 1: main calls 1: m2_pred
119func m2_train(W: *i64, pa: *i64, pb: *i64, npair: i64, tmap: *i64, epochs: i64, lr: i64, lfirst: *i64, llast: *i64) -> i64
170func m2_demo(fd: i64, W: *i64, a: i64, b: i64) -> i64
called by 1: main calls 4: m2_wm2_enm2_esm2_pred
177func m2_emit(fd: i64, r: *i64) -> i64
called by 1: main calls 2: m2_wm2_wn
189func main() -> i64