nx_wordpiece_lib.nx
buildroot/runtime/nx_wordpiece_lib.nx
about
nx_wordpiece_lib.nx -- SOVEREIGN WordPiece tokenizer over a BERT uncased vocab.txt, a library so the cross-encoder
arm of nx_beir_eval and its gate drive it in-process (search rung R0, 2026-09-14). ABSENT-PROVEN before writing
(nx_absent wordpiece buildroot/runtime nx: matches=0 coverage_complete=1). The vocab is read whole through
sys_read_file (no cap), every token is hashed into an open-addressing table sized from the token count, and every
hit is verified by bytes, so a hash collision can never return the wrong id. Basic tokenisation follows the HF
BertTokenizer with do_lower_case: ASCII lowercase, every byte below 33 splits, every ASCII punctuation byte is its
own token, a word longer than WP_MAX_WORD_CHARS is [UNK] whole, then greedy longest-match wordpiece with the
two-byte continuation prefix. DEVIATION, stated: bytes above 0x7f are kept as word characters (no NFD accent
stripping, no CJK isolation), so an accented word normally becomes [UNK] pieces. license_tier: ORIGINAL
dependencies 1 imports · 2 importers
imports: nx_syscalls.nx
imported by: nx_beir_eval.nxnx_bert_ce_gate.nx
structs
| none |
consts
| 13 | const WP_G_VBUF: i64 = 0 // vocab.txt bytes |
| 14 | const WP_G_VLEN: i64 = 1 |
| 15 | const WP_G_NTOK: i64 = 2 |
| 16 | const WP_G_TOFF: i64 = 3 // *i64 token start offset per id |
| 17 | const WP_G_TLEN: i64 = 4 // *i64 token byte length per id |
| 18 | const WP_G_HT: i64 = 5 // *i64 open-addressing table, 2 slots per bucket: hash, id+1 (0 = empty) |
| 19 | const WP_G_HCAP: i64 = 6 // bucket count, a power of two derived from the token count |
| 20 | const WP_G_UNK: i64 = 7 |
| 21 | const WP_G_CLS: i64 = 8 |
| 22 | const WP_G_SEP: i64 = 9 |
| 23 | const WP_G_PAD: i64 = 10 |
| 24 | const WP_G_LOADED: i64 = 11 |
| 25 | const WP_G_WSCR: i64 = 12 // *u8 lowercased-word scratch, WP_MAX_WORD_CHARS bytes |
| 26 | const WP_G_PSCR: i64 = 13 // *i64 piece scratch, WP_MAX_WORD_CHARS slots |
| 27 | const WP_G_SLOTS: i64 = 14 |
| 28 | const WP_G_BYTES: i64 = 112 // WP_G_SLOTS * 8 |
| 31 | const WP_MAX_WORD_CHARS: i64 = 100 |
| 33 | const WP_HASH_BYTE: i64 = 35 |
| 35 | const WP_DJB2_SEED: i64 = 5381 |
| 36 | const WP_DJB2_MUL: i64 = 33 |
| 37 | const WP_LF: i64 = 10 |
| 38 | const WP_CR: i64 = 13 |
| 39 | const WP_SPACE: i64 = 32 |
| 40 | const WP_UPPER_A: i64 = 65 |
| 41 | const WP_UPPER_Z: i64 = 90 |
| 42 | const WP_CASE_DELTA: i64 = 32 |
| 43 | const WP_DEL: i64 = 127 |
functions
| 45 | func wp_hash_run(h0: i64, buf: *u8, off: i64, len: i64) -> i64 |
| 53 | func wp_tok_eq(g: *i64, id: i64, pre: i64, buf: *u8, off: i64, len: i64) -> i64 |
| 72 | func wp_lookup(g: *i64, pre: i64, buf: *u8, off: i64, len: i64) -> i64 |
| 91 | func wp_load(g: *i64, path: *u8) -> i64 |
| 153 | func wp_is_punct(c: i64) -> i64 |
| 163 | func wp_word(g: *i64, buf: *u8, off: i64, len: i64, out: *i64, n: i64) -> i64 |
| 192 | func wp_tokenize(g: *i64, text: *u8, off: i64, len: i64, out: *i64) -> i64 |
| 227 | func wp_pair(g: *i64, qtok: *i64, nq0: i64, dtok: *i64, nd0: i64, maxlen: i64, ids: *i64, types: *i64) -> i64 |