code wiki / (root) / nx_embfeat_lib.nx

nx_embfeat_lib.nx

buildroot/runtime/nx_embfeat_lib.nx

6957 B160 linesdepth 5pulls 9 transitivereach 4 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_embfeat_lib.nx -- DENSE EMBEDDING FEATURES for a hashed linear sequence model: the ONE library reader of the estate's trained word embeddings (knowledge/index/embed_v1.bin, written by nx_embed_train: a 24-byte header [NXEMB1, nv, dim] then nv x dim Q10 integers, row index shared with the PPMI vocabulary that nx_ppmi_lib resolves) turned into discrete features a perceptron or CRF can weight. Each coordinate is quantised to a signed bucket at half-RMS steps and clamped at +-EF_BUCKET_MAX; the step is DERIVED from the table itself at load (the RMS over every coordinate), never typed, so the buckets follow the model's own scale. A word the vocabulary does not know reads EF_NONE at every coordinate and its feature spells a single byte, degrading to the base features rather than to garbage. Two gates already read this file inline (the reader gates); this is the copy both can import. license_tier: ORIGINAL No hw writes (Rule 26). LIB.

dependencies 3 imports · 2 importers

nx_syscalls.nx nx_reviewmine_lib.nx nx_ppmi_lib.nx nx_embfeat_lib.nx nx_absa_seq.nx nx_embfeat_gate.nx

imports: nx_syscalls.nxnx_reviewmine_lib.nxnx_ppmi_lib.nx

imported by: nx_absa_seq.nxnx_embfeat_gate.nx

structs

none

consts

13const EF_G_BYTES: i64 = 1024 // the PPMI lib's g-block (its contract: a zeroed block of at least 632 bytes)
14const EF_HDR: i64 = 24 // magic 8 + nv 8 + dim 8
15const EF_I64_BYTES: i64 = 8
16const EF_MAGIC_N: i64 = 78
17const EF_MAGIC_X: i64 = 88
18const EF_MAGIC_E: i64 = 69
19const EF_MAGIC_M: i64 = 77
20const EF_MAGIC_B: i64 = 66
21const EF_MAGIC_1: i64 = 49
22const EF_BUCKET_MAX: i64 = 4 // buckets -4..4: nine cells at half-RMS steps resolve a bell-shaped coordinate
23const EF_STEP_DIV: i64 = 2 // step = rms / 2
24const EF_NONE: i64 = 0 - 1
25const EF_CH_ZERO: i64 = 48
26const EF_CH_AT: i64 = 64

functions

38func ef_reset() -> i64
called by 2: sp_evalef_load calls 1: sys_mmap
50func ef_load(ppmi_path: *u8, emb_path: *u8) -> i64
85func ef_ok() -> i64 { return ef_ready }
86func ef_dim_of() -> i64 { return ef_dim }
called by 2: sp_evalmain
87func ef_nv_of() -> i64 { return ef_nv }
called by 1: main
88func ef_step_of() -> i64 { return ef_step }
called by 1: main
89func ef_rms_of() -> i64 { return ef_rms }
called by 1: main
90func ef_lookup_count() -> i64 { return ef_lookups }
called by 2: sp_evalmain
91func ef_hit_count() -> i64 { return ef_hits }
called by 2: sp_evalmain
93func ef_wid(s: *u8, n: i64) -> i64
called by 2: sp_featsmain calls 1: ppl_wid_range
103func ef_coord(wid: i64, d: i64) -> i64 { return ef_tab[wid * ef_dim + d] }
called by 2: mainef_spell
105func ef_bucket(v: i64) -> i64
called by 2: mainef_spell
112func ef_spell(wid: i64, d: i64, out: *u8) -> i64
called by 2: sp_featsmain calls 2: ef_bucketef_coord
121func ef_plant(path: *u8, buf: *u8, offs: *i64, lens: *i64, vecs: *i64, nw: i64, dim: i64) -> i64