code wiki / _hdl_build / nx_semppmi_build.nx

nx_semppmi_build.nx

buildroot/runtime/_hdl_build/nx_semppmi_build.nx

20030 B438 linesdepth 4pulls 6 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_semppmi_build.nx -- EXPLICIT-VOCAB SPARSE PPMI embeddings = the CANONICAL count-based method at full strength (Levy&Goldberg: full sparse PPMI rows rival trained embeddings on word similarity). This is the last count-method rung before "trained-only" is airtight: v1 (nx_semcorpus_build) failed its probes with HASHED rows (collisions) + a 256-dim PROJECTION (lossy) -- this build removes BOTH: every word gets its own row; contexts are the full vocabulary; cells are PPMI (positive pointwise mutual information, log2 x16 fixed-point); rows stay SPARSE (sorted triples). Corpus = same banked benchmark prose (no gold leakage: only JSON strings >= 48 chars). PIPELINE (one corpus walk): tokens -> 61-bit djb2x hash stream (+ -1 markers at string ends) -> vocab = sort(copy)+unique (explicit; 61-bit space => collisions ~0 at 60k words) -> window +-4 pair emission as packed keys (aid<<20|bid, both directions) -> sort -> RLE -> triples(cnt>=2) -> marginals -> PPMI16 -> row index + norms -> PROBES -> persist knowledge/index/semppmi_v1.bin. PROBES decide (same discipline as v1): if won~defeated fails to order again, count methods are DEAD at canonical strength and the R1 trained thread is the proven only door. TEETH structural + neg-controls. expect_exit: 0 license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_qabench_engine.nx nx_estate_path.nx nx_semppmi_build.nx

imports: nx_qabench_engine.nxnx_estate_path.nx

imported by: nobody (leaf or entry point)

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

main ep_anchor sys_openat_rd sys_close sys_chdir sys_mmap db_w sp_walk db_read_raw sys_read db_w ↻ db_body_start db_b db_dec_str db_skip_ws db_b ↻ db_b ↻ qs_norm qs_tok qs_is_article db_is_stop db_tok_is sp_hash db_semhash db_n nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write sys_munmap sp_qsort sp_qsort ↻ db_n ↻ sp_bsearch db_bsearch_i64 sp_ilog2x16 sp_wid sp_hash ↻ sp_bsearch ↻

structs

none

consts

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
32const SP_WIN: i64 = 4
33const SP_MINSTR: i64 = 48
34const SP_MAXV: i64 = 262144
35const SP_MINCNT: i64 = 2

functions

38func sp_hash(buf: *u8, off: i64, len: i64) -> i64 { return db_semhash(buf, off, len) }
called by 2: sp_walksp_wid calls 1: db_semhash
41func sp_wblock(fd: i64, buf: *u8, n: i64) -> i64
called by 1: main
53func sp_isqrt(v: i64) -> i64
called by 1: sp_cos
62func sp_ilog2x16(q: i64) -> i64
called by 1: main
76func sp_qsort(a: *i64, lo: i64, hi: i64) -> i64
called by 2: sp_qsortmain calls 1: sp_qsort
98func sp_bsearch(a: *i64, n: i64, v: i64) -> i64 { return db_bsearch_i64(a, n, v) }
called by 2: sp_widmain calls 1: db_bsearch_i64
102func sp_walk(g: *i64, path: *u8, stream: *i64, c: *i64) -> i64
143func sp_cos(tctx: *i64, tval: *i64, ridx: *i64, nrm2: *i64, a: i64, b: i64) -> i64
called by 1: main calls 1: sp_isqrt
166func sp_wid(vh: *i64, nv: i64, w: *u8) -> i64
called by 1: main calls 2: sp_hashsp_bsearch
173func main() -> i64