code wiki / _hdl_build / _bpe_vocab_authored.nx
_bpe_vocab_authored.nx
buildroot/runtime/_hdl_build/_bpe_vocab_authored.nx
about
_bpe_vocab_authored.nx -- T2 rung 1 of the training-substrate ladder: TRAIN a BPE vocab
on the TEAM CORPUS (the read side existed: nx_f32_bpe_load; the TRAINING side was the
research-flagged gap -- this rung lands it at the smallest honest scale: greedy byte-pair,
deterministic tie-break = lowest-left-then-lowest-right, no regex pretokenization;
honest scope noted in the registry).
Corpus is conf-driven (law 11): knowledge/status/bpe_corpus.conf rows "C <path>".
GATES: K hand-computed merge oracle on the classic aaabdaaabac corpus (merges MUST come out
(97,97),(97,98),(256,257) -- construction-known, computed by hand in this header:
aa x4 wins; then tie Za=2 vs ab=2 -> ab by lowest-left; then Z,257 x2)
| D determinism (two trains -> identical merge tables)
| R LOSSLESS roundtrip (encode->decode == original bytes for EVERY corpus line)
| C compression MEASURED (tokens < bytes; permil reported, never asserted).
Vocab persisted durable + reloadable: knowledge/store/bpe_vocab_v1.txt BPEMERGE rows.
Evidence: MODELWRIGHT T2 rows -> modelwright.log. Tamper hook: argv[1] conf override.
LAWS: struct-free, flat ifs, no &&/||. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_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
| 18 | const BP_MERGES: i64 = 64 |
| 19 | const BP_VCAP: i64 = 320 |
| 20 | const BP_MAXB: i64 = 65536 |
functions
| 22 | func bp_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 } |
| 23 | func bp_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } |
| 24 | func bp_bp(fd: i64, s: *u8) -> i64 { bp_w(1, s); if fd >= 0 { bp_w(fd, s) } return 0 } |
| 25 | func bp_bn(fd: i64, v: i64) -> i64 { bp_wn(1, v); if fd >= 0 { bp_wn(fd, v) } return 0 } |
| 26 | func bp_match(b: *u8, i: i64, n: i64, lit: *u8) -> i64 called by 1: bp_load |
| 37 | func bp_load(conf: *u8, buf: *u8) -> i64 |
| 79 | func bp_train(bytes: *u8, n: i64, seq: *i64, counts: *i64, merges: *i64) -> i64 called by 1: main |
| 131 | func bp_encode(bytes: *u8, off: i64, n: i64, merges: *i64, mcount: i64, seq: *i64) -> i64 called by 1: main |
| 165 | func bp_decode_tok(tok: i64, merges: *i64, out: *u8, opos: i64) -> i64 |
| 188 | func main(argc: i64, argv: *i64) -> i64 |