code wiki / _hdl_build / nx_mt_r2_gate.nx
nx_mt_r2_gate.nx
buildroot/runtime/_hdl_build/nx_mt_r2_gate.nx
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
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
structs
| none |
consts
| 35 | const M2_LOG: *u8 = "knowledge/status/mt_r2.log" |
| 36 | const M2_S: i64 = 4 |
| 37 | const M2_T: i64 = 4 |
| 39 | const EN0: *u8 = "hello" as *u8 |
| 40 | const EN1: *u8 = "family" as *u8 |
| 41 | const EN2: *u8 = "love" as *u8 |
| 42 | const EN3: *u8 = "good" as *u8 |
| 43 | const ES0: *u8 = "familia" as *u8 |
| 44 | const ES1: *u8 = "bueno" as *u8 |
| 45 | const ES2: *u8 = "hola" as *u8 |
| 46 | const ES3: *u8 = "amor" as *u8 |
| 47 | const ESQ: *u8 = "?" as *u8 |
functions
| 49 | func m2_en(i: i64) -> *u8 called by 1: m2_demo |
| 56 | func m2_es(j: i64) -> *u8 called by 1: m2_demo |
| 64 | func 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 } |
| 65 | func m2_wn(fd: i64, v: i64) -> i64 |
| 75 | func m2_f32_to_milli(v: i64) -> i64 |
| 91 | func m2_idx(h: i64, j: i64, d: i64) -> i64 { return h * M2_T * (2 * M2_S) + j * (2 * M2_S) + d } |
| 94 | func m2_pred(W: *i64, h: i64, a: i64, b: i64) -> i64 |
| 107 | func m2_acc(W: *i64, pa: *i64, pb: *i64, npair: i64, tmap: *i64) -> i64 |
| 119 | func m2_train(W: *i64, pa: *i64, pb: *i64, npair: i64, tmap: *i64, epochs: i64, lr: i64, lfirst: *i64, llast: *i64) -> i64 |
| 170 | func m2_demo(fd: i64, W: *i64, a: i64, b: i64) -> i64 |
| 177 | func m2_emit(fd: i64, r: *i64) -> i64 |
| 189 | func main() -> i64 |