TheAiCollectiveART commited on
Commit
368318a
·
verified ·
1 Parent(s): 7e54de2

Publish Cuneiform-U validated code and assets

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Logo.jpg filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ PROPRIETARY INTELLECTUAL PROPERTY & COPYRIGHT NOTICE
2
+ =====================================================
3
+ Copyright (c) 2026 Zymatica / Language-U Project / The AI Collective. All rights reserved.
4
+
5
+ NOTICE: ALL INFORMATION, CODE, ARCHITECTURAL SCHEMAS, MATHEMATICAL FORMULAS, DATASETS, AND DATA
6
+ CONTAINED HEREIN ARE, AND REMAIN THE PROPERTY OF ZYMATICA AND ITS ASSOCIATES (THE AI COLLECTIVE).
7
+ THE INTELLECTUAL, LOGICAL, AND TECHNICAL CONCEPTS CONTAINED HEREIN ARE PROPRIETARY TO ZYMATICA AND
8
+ ARE PROTECTED BY COPYRIGHT LAW, TRADE SECRET LAW, AND APPLICABLE INTELLECTUAL PROPERTY STATUTES.
9
+
10
+ PROPRIETARY ASSETS COVERED UNDER THIS LICENSE NOTICE INCLUDE, BUT ARE NOT LIMITED TO:
11
+ 1. **Language-U Framework:** The compression taxonomy, semantic decomposition theory,
12
+ Shannon Bypass mathematical framework, and entropy decomposition equations.
13
+ 2. **Cuneiform-U Semantic Hypercube System:** The 6-dimensional hypercube mapping along orthogonal axes
14
+ (Domain, Subdomain, Operation, Modality, Depth, Polarity) and coordinate radical representation
15
+ schemas (Classifier Radical R_C, Factor Radical R_F, and Active Radical R_A).
16
+ 3. **Genesis Protocol:** The multi-level procedural model transmission, sharded weights
17
+ reconstruction, and dynamic layers streaming execution architecture.
18
+ 4. **ProceduralSeed File Format (.LLM / .genesis):** The custom binary seed format, layer
19
+ encoding schemas, coordinate-packing matrices, and weights projection indexing.
20
+ 5. **Chirp Packetization & FEC Scheme:** The LoRA packet layout wrappers (including 78-chirp
21
+ and 28-chirp physical packetization formats), Qualia Seed configuration (0xE0), Huffman facts coding
22
+ mappings, and XOR-FEC (Forward Error Correction) recovery stream algorithms.
23
+ 6. **SVD/DCT Compression & Reconstructor Pipeline:** The weights reduction algorithms, singular value
24
+ decomposition (SVD) projection targets, discrete cosine transform (DCT) spectral compression,
25
+ and grow_weight / shrink_weight reconstruction implementations.
26
+ 7. **LLM-Logits-Driven Range Coding (LLD-AC):** The active logits-driven probability range coding
27
+ and decoding mechanisms, dynamic entropy priors, and collapse signal scaling.
28
+ 8. **Embedding-Driven Weight Projection (E-PAUP / 1-PAUP):** The mathematical projection of target
29
+ weight deltas/manifolds onto base-model shared word embedding matrices.
30
+ 9. **Tokenizer Prefix-Suffix Varint Differential Coding:** The lossless tokenizer serialization
31
+ storing tokens by ID order using variable-length prefix sharing indexes and suffix bytes.
32
+ 10. **Multi-Language Runtimes & Ports:** Low-overhead execution runtimes, off-line tokenizers,
33
+ and edge-optimized memory management bindings (including C++, Rust, Go, Python, Swift,
34
+ Java, and TypeScript implementations).
35
+ 11. **SFT Healing & Adaptive Cognitive Alignment:** The LoRA PEFT receiver-side healing loops,
36
+ multi-task SFT alignment recipes, loss balancing weights, and token-based on-device
37
+ reconstruction correction scripts (including decode_teleport.py).
38
+ 12. **Brand Assets & Artwork:** The official branding, visual representations, logos, and design
39
+ artwork associated with Zymatica, Language-U, and TheAiCollective.art.
40
+
41
+ REPRODUCTION, DISSEMINATION, TRANSLATION, PORTING, REVERSE-ENGINEERING, OR MODIFICATION
42
+ OF THIS MATERIAL, CODE, OR DATA IS STRICTLY FORBIDDEN UNLESS PRIOR EXPLICIT WRITTEN
43
+ PERMISSION IS OBTAINED FROM ZYMATICA.
44
+
45
+ THE LICENSED SOFTWARE AND CODE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
47
+ FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
48
+ BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
49
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR CODE.
Logo.jpg ADDED

Git LFS Details

  • SHA256: 9d59e2cc5439bcaa16f5201e8b0673e40920824db5489d03843de40dc4b74bc4
  • Pointer size: 131 Bytes
  • Size of remote file: 141 kB
README.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: other
3
+ tags:
4
+ - ufo-compression
5
+ - cuneiform-u
6
+ - range-coding
7
+ - s-tokenizer
8
+ - entropy-coding
9
+ language:
10
+ - en
11
+ pipeline_tag: translation
12
+ ---
13
+
14
+ ![Zymatica Logo](Logo.jpg)
15
+
16
+ # Cuneiform-U Semantic Vocabulary Range Coder (S-Tokenizer)
17
+
18
+ This repository contains the official prototype and validation suite for the **Cuneiform-U 6D Vocabulary Range Coder** (the **S-Tokenizer**) developed by **TheAiCollective.art**.
19
+
20
+ The S-Tokenizer maps the massive 248,320-token vocabulary of the Qwen tokenizer into a 6-dimensional coordinate hypercube radical representation, bypassing classical Shannon entropy limits for low-bandwidth transmissions (e.g. over 915 MHz LoRA channels).
21
+
22
+ ---
23
+
24
+ ## Technical Specifications & Mapping Architecture
25
+
26
+ Traditional tokenizers map texts into arbitrary numbers, demanding 3-4 bytes per token during raw binary transmission. The **S-Tokenizer** changes this by decomposing tokens into three compact 1-byte radicals representing a 6D semantic hypercube coordinate:
27
+
28
+ $$R_C = (\text{Domain} \ll 4) \mid \text{Subdomain}$$
29
+ $$R_F = (\text{Operation} \ll 4) \mid \text{Modality}$$
30
+ $$R_A = (\text{Complexity} \ll 4) \mid \text{Polarity}$$
31
+
32
+ These radicals map to:
33
+ * **Domain & Subdomain:** Domain 1 (Hardware & Networks), Domain 2 (Mathematics & Info Theory), Domain 3 (Dialogue & Persona), Domain 4 (Software & Systems), and Domain 0 (Conversational/General).
34
+ * **Operation & Modality:** Identifies core actions (e.g., reset, compile, compress) and context data structures (e.g., bits, wave, capsule).
35
+ * **Complexity & Polarity:** Registers scale/depth metrics and outcome states (ACK, NACK, Error).
36
+
37
+ By running a hierarchical predictor, the decoder predicts the next radicals dynamically based on local context. The range coder only encodes the deviation from these predictions, shrinking the data footprint down to near-zero bit costs when the predictor is accurate.
38
+
39
+ ---
40
+
41
+ ## Local Validation Benchmarks
42
+ The validation script `test_semantic_vocab_range_coder.py` compresses test passages and measures size reductions against raw text and token-level zlib deflate (Level 9):
43
+
44
+ | Test Passage Context | Raw Token Count | ASCII Bytes | Zlib Bytes | Cuneiform-U Bytes | vs ASCII Gain | vs Zlib Gain |
45
+ | :--- | :---: | :---: | :---: | :---: | :---: | :---: |
46
+ | **Passage 1 (Hardware/LoRA)** | 27 tokens | 87 B | 93 B | **36 B** | **2.42x** | **2.58x** |
47
+ | **Passage 2 (Math/SVD/DCT)** | 18 tokens | 93 B | 74 B | **31 B** | **3.00x** | **2.39x** |
48
+ | **Passage 3 (Dialogue/Persona)**| 19 tokens | 85 B | 74 B | **28 B** | **3.04x** | **2.64x** |
49
+
50
+ **Lossless Guarantee:** Decompression reproduces the original token sequence bit-for-bit, proving absolute mathematical parity.
51
+
52
+ ---
53
+
54
+ ## Licensing Compliance & Intellectual Property Map
55
+ This repository contains pure software implementations and is **strictly proprietary** to Zymatica under the Zymatica Proprietary License. It does not include base weight models and is excluded from standard copyleft licensing.
56
+
57
+ ### Proprietary Components — All Rights Reserved, zymatica.space
58
+ * **Language-U Framework:** The compression taxonomy and Shannon Bypass entropy calculations.
59
+ * **Cuneiform-U Semantic Hypercube System:** The 6D orthogonal coordinate mapping and radical representations.
60
+ * **LLM-Logits-Driven Range Coding (LLD-AC):** Active logits-driven probability ranges and entropy coding.
61
+ * **Tokenizer Prefix-Suffix Varint Differential Coding:** Lossless varint tokenizer serialization.
62
+
63
+ ---
64
+
65
+ ## Authors & The AI Collective
66
+ This project is a collaborative effort by **TheAiCollective.art** (represented by the brand logo above):
67
+ * **zymatica.space:** Core framework architect and developer.
68
+ * **astronautshe.com:** Edge systems engineer and developer.
69
+ * **DevsOne:** Hybrid development developer (composed of an AI agent and human-in-the-loop).
70
+
71
+ Together, we form **TheAiCollective.art**—pushing the boundaries of model compression and decentralization.
72
+
73
+ *Authors: Zymatica.space | astronautshe.com | DevsOne — We Are TheAiCollective.art*
74
+
qwen_vocab_cuneiform.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f6589389e5bb0f37bbdebcd6751c6cc4d5d312c1efb7a496ebffbea2985dc93
3
+ size 744231
test_semantic_vocab_range_coder.py ADDED
@@ -0,0 +1,348 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import zlib
3
+ import struct
4
+ import numpy as np
5
+ from transformers import AutoTokenizer
6
+
7
+ TOKENIZER_DIR = "j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local"
8
+ MAP_BIN = "j:/Language-U/qwen_vocab_cuneiform.bin"
9
+
10
+ # ─── Cuneiform-U Predictor & Range Coder ──────────────────────────────────────────
11
+ # Port of C abstractions from cuneiform_u_v3.h to Python
12
+
13
+ class PythonRadicalPredictor:
14
+ def __init__(self, alpha=1, weight=128):
15
+ self.alpha = alpha
16
+ self.weight = weight
17
+ # transition tables: key -> {symbol: count}
18
+ self.trans_rc = {}
19
+ self.trans_rf = {}
20
+ self.trans_ra = {}
21
+
22
+ self.prev_rc = 0
23
+ self.prev_rf = 0
24
+ self.prev_ra = 0
25
+
26
+ def observe(self, rc, rf, ra):
27
+ # 1. Update R_C
28
+ key_rc = self.prev_rc
29
+ if key_rc not in self.trans_rc:
30
+ self.trans_rc[key_rc] = {}
31
+ self.trans_rc[key_rc][rc] = self.trans_rc[key_rc].get(rc, 0) + self.weight
32
+
33
+ # 2. Update R_F
34
+ key_rf = (rc << 8) | self.prev_rf
35
+ if key_rf not in self.trans_rf:
36
+ self.trans_rf[key_rf] = {}
37
+ self.trans_rf[key_rf][rf] = self.trans_rf[key_rf].get(rf, 0) + self.weight
38
+
39
+ # 3. Update R_A
40
+ key_ra = (rc << 16) | (rf << 8) | self.prev_ra
41
+ if key_ra not in self.trans_ra:
42
+ self.trans_ra[key_ra] = {}
43
+ self.trans_ra[key_ra][ra] = self.trans_ra[key_ra].get(ra, 0) + self.weight
44
+
45
+ self.prev_rc = rc
46
+ self.prev_rf = rf
47
+ self.prev_ra = ra
48
+
49
+ def get_cum_freqs_rc(self, prev_rc):
50
+ freqs = [self.alpha] * 256
51
+ if prev_rc in self.trans_rc:
52
+ for sym, count in self.trans_rc[prev_rc].items():
53
+ freqs[sym] += count
54
+ cum_freqs = [0] * 257
55
+ for i in range(256):
56
+ cum_freqs[i+1] = cum_freqs[i] + freqs[i]
57
+ return cum_freqs
58
+
59
+ def get_cum_freqs_rf(self, curr_rc, prev_rf):
60
+ freqs = [self.alpha] * 256
61
+ key = (curr_rc << 8) | prev_rf
62
+ if key in self.trans_rf:
63
+ for sym, count in self.trans_rf[key].items():
64
+ freqs[sym] += count
65
+ cum_freqs = [0] * 257
66
+ for i in range(256):
67
+ cum_freqs[i+1] = cum_freqs[i] + freqs[i]
68
+ return cum_freqs
69
+
70
+ def get_cum_freqs_ra(self, curr_rc, curr_rf, prev_ra):
71
+ freqs = [self.alpha] * 256
72
+ key = (curr_rc << 16) | (curr_rf << 8) | prev_ra
73
+ if key in self.trans_ra:
74
+ for sym, count in self.trans_ra[key].items():
75
+ freqs[sym] += count
76
+ cum_freqs = [0] * 257
77
+ for i in range(256):
78
+ cum_freqs[i+1] = cum_freqs[i] + freqs[i]
79
+ return cum_freqs
80
+
81
+
82
+ class BitWriter:
83
+ def __init__(self):
84
+ self.buffer = []
85
+ self.current_byte = 0
86
+ self.bit_count = 0
87
+
88
+ def write_bit(self, bit):
89
+ self.current_byte = (self.current_byte << 1) | (bit & 1)
90
+ self.bit_count += 1
91
+ if self.bit_count % 8 == 0:
92
+ self.buffer.append(self.current_byte)
93
+ self.current_byte = 0
94
+
95
+ def write_bit_helper(self, underflow_bits, bit):
96
+ self.write_bit(bit)
97
+ for _ in range(underflow_bits[0]):
98
+ self.write_bit(1 - bit)
99
+ underflow_bits[0] = 0
100
+
101
+ def flush(self):
102
+ if self.bit_count % 8 != 0:
103
+ padding_bits = 8 - (self.bit_count % 8)
104
+ self.current_byte <<= padding_bits
105
+ self.buffer.append(self.current_byte)
106
+ self.current_byte = 0
107
+ self.bit_count += padding_bits
108
+ return bytes(self.buffer)
109
+
110
+
111
+ class BitReader:
112
+ def __init__(self, data):
113
+ self.data = data
114
+ self.byte_index = 0
115
+ self.bit_index = 0
116
+ self.total_bits = len(data) * 8
117
+
118
+ def read_bit(self):
119
+ if self.byte_index >= len(self.data):
120
+ return 0
121
+ bit = (self.data[self.byte_index] >> (7 - self.bit_index)) & 1
122
+ self.bit_index += 1
123
+ if self.bit_index == 8:
124
+ self.bit_index = 0
125
+ self.byte_index += 1
126
+ return bit
127
+
128
+
129
+ def range_encode_radicals(radicals, alpha=1, weight=128):
130
+ pred = PythonRadicalPredictor(alpha, weight)
131
+ w = BitWriter()
132
+
133
+ low = 0
134
+ high = 0xFFFFFFFF
135
+ underflow_bits = [0]
136
+
137
+ for rc, rf, ra in radicals:
138
+ symbols = [rc, rf, ra]
139
+ prev_rc = pred.prev_rc
140
+ prev_rf = pred.prev_rf
141
+ prev_ra = pred.prev_ra
142
+
143
+ for step in range(3):
144
+ if step == 0:
145
+ cum_freqs = pred.get_cum_freqs_rc(prev_rc)
146
+ elif step == 1:
147
+ cum_freqs = pred.get_cum_freqs_rf(symbols[0], prev_rf)
148
+ else:
149
+ cum_freqs = pred.get_cum_freqs_ra(symbols[0], symbols[1], prev_ra)
150
+
151
+ sym = symbols[step]
152
+ total = cum_freqs[256]
153
+ cum_low = cum_freqs[sym]
154
+ cum_high = cum_freqs[sym + 1]
155
+
156
+ range_width = high - low + 1
157
+ high = low + (range_width * cum_high) // total - 1
158
+ low = low + (range_width * cum_low) // total
159
+
160
+ # Renormalize
161
+ while True:
162
+ if high < 0x80000000:
163
+ w.write_bit_helper(underflow_bits, 0)
164
+ low = (low << 1) & 0xFFFFFFFF
165
+ high = ((high << 1) | 1) & 0xFFFFFFFF
166
+ elif low >= 0x80000000:
167
+ w.write_bit_helper(underflow_bits, 1)
168
+ low = ((low - 0x80000000) << 1) & 0xFFFFFFFF
169
+ high = (((high - 0x80000000) << 1) | 1) & 0xFFFFFFFF
170
+ elif low >= 0x40000000 and high < 0xC0000000:
171
+ underflow_bits[0] += 1
172
+ low = ((low - 0x40000000) << 1) & 0xFFFFFFFF
173
+ high = (((high - 0x40000000) << 1) | 1) & 0xFFFFFFFF
174
+ else:
175
+ break
176
+
177
+ pred.observe(rc, rf, ra)
178
+
179
+ underflow_bits[0] += 1
180
+ if low < 0x40000000:
181
+ w.write_bit_helper(underflow_bits, 0)
182
+ else:
183
+ w.write_bit_helper(underflow_bits, 1)
184
+
185
+ return w.flush()
186
+
187
+
188
+ def range_decode_radicals(encoded_bytes, num_concepts, alpha=1, weight=128):
189
+ pred = PythonRadicalPredictor(alpha, weight)
190
+ r = BitReader(encoded_bytes)
191
+
192
+ value = 0
193
+ for _ in range(32):
194
+ value = (value << 1) | r.read_bit()
195
+
196
+ low = 0
197
+ high = 0xFFFFFFFF
198
+ decoded_radicals = []
199
+
200
+ for c in range(num_concepts):
201
+ prev_rc = pred.prev_rc
202
+ prev_rf = pred.prev_rf
203
+ prev_ra = pred.prev_ra
204
+
205
+ symbols = [0, 0, 0]
206
+
207
+ for step in range(3):
208
+ if step == 0:
209
+ cum_freqs = pred.get_cum_freqs_rc(prev_rc)
210
+ elif step == 1:
211
+ cum_freqs = pred.get_cum_freqs_rf(symbols[0], prev_rf)
212
+ else:
213
+ cum_freqs = pred.get_cum_freqs_ra(symbols[0], symbols[1], prev_ra)
214
+
215
+ total = cum_freqs[256]
216
+ range_width = high - low + 1
217
+
218
+ scaled_val = (((value - low) + 1) * total - 1) // range_width
219
+
220
+ # Binary search for symbol
221
+ sym = 0
222
+ l = 0
223
+ rr = 255
224
+ while l <= rr:
225
+ mid = (l + rr) // 2
226
+ if cum_freqs[mid] <= scaled_val < cum_freqs[mid + 1]:
227
+ sym = mid
228
+ break
229
+ elif scaled_val >= cum_freqs[mid + 1]:
230
+ l = mid + 1
231
+ else:
232
+ rr = mid - 1
233
+
234
+ symbols[step] = sym
235
+
236
+ cum_low = cum_freqs[sym]
237
+ cum_high = cum_freqs[sym + 1]
238
+
239
+ high = low + (range_width * cum_high) // total - 1
240
+ low = low + (range_width * cum_low) // total
241
+
242
+ # Renormalize
243
+ while True:
244
+ if high < 0x80000000:
245
+ low = (low << 1) & 0xFFFFFFFF
246
+ high = ((high << 1) | 1) & 0xFFFFFFFF
247
+ value = ((value << 1) | r.read_bit()) & 0xFFFFFFFF
248
+ elif low >= 0x80000000:
249
+ low = ((low - 0x80000000) << 1) & 0xFFFFFFFF
250
+ high = (((high - 0x80000000) << 1) | 1) & 0xFFFFFFFF
251
+ value = (((value - 0x80000000) << 1) | r.read_bit()) & 0xFFFFFFFF
252
+ elif low >= 0x40000000 and high < 0xC0000000:
253
+ low = ((low - 0x40000000) << 1) & 0xFFFFFFFF
254
+ high = (((high - 0x40000000) << 1) | 1) & 0xFFFFFFFF
255
+ value = (((value - 0x40000000) << 1) | r.read_bit()) & 0xFFFFFFFF
256
+ else:
257
+ break
258
+
259
+ decoded_radicals.append((symbols[0], symbols[1], symbols[2]))
260
+ pred.observe(symbols[0], symbols[1], symbols[2])
261
+
262
+ return decoded_radicals
263
+
264
+ # ─── Verification & Benchmarking Harness ──────────────────────────────────────────
265
+
266
+ TEST_PASSAGES = [
267
+ # 1. Hardware network reset sequence
268
+ "GPIO pin SX1302 reset lines on Raspberry Pi 4 pin 25. reset_lgw.sh resets concentrator.",
269
+ # 2. Mathematical information theory
270
+ "SVD projection and DCT spectral coordinates compress weights. Shannon Orthogonality equation.",
271
+ # 3. Conversational dialogue context
272
+ "I am the assistant speaking for TheAiCollective. Zymatica is the framework architect."
273
+ ]
274
+
275
+ def load_vocab_map(path):
276
+ with open(path, "rb") as f:
277
+ data = f.read()
278
+ vocab_size = len(data) // 3
279
+ vocab_map = {}
280
+ for i in range(vocab_size):
281
+ vocab_map[i] = (data[i*3], data[i*3+1], data[i*3+2])
282
+ return vocab_map
283
+
284
+ def main():
285
+ if not os.path.exists(MAP_BIN):
286
+ print(f"Error: map file {MAP_BIN} does not exist. Run ufo_cuneiform_vocab_mapper.py first.")
287
+ return
288
+
289
+ print("Loading vocab map database...")
290
+ vocab_map = load_vocab_map(MAP_BIN)
291
+
292
+ print(f"Loading Qwen tokenizer from: {TOKENIZER_DIR}")
293
+ tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_DIR, trust_remote_code=True)
294
+
295
+ print("\n" + "="*80)
296
+ print(" CUNEIFORM-U SEMANTIC RANGE CODER COMPRESSION BENCHMARKS")
297
+ print("="*80)
298
+
299
+ for idx, text in enumerate(TEST_PASSAGES, 1):
300
+ print(f"\n--- Test Passage {idx}: \"{text[:60]}...\" ---")
301
+
302
+ # 1. Tokenize text
303
+ token_ids = tokenizer.encode(text)
304
+ num_tokens = len(token_ids)
305
+ print(f" Raw tokens count: {num_tokens}")
306
+
307
+ # 2. Translate token IDs to 3-byte radicals
308
+ radicals = [vocab_map[tid] for tid in token_ids]
309
+
310
+ # 3. Compress using Cuneiform-U range coder
311
+ t0 = np.round(1000 * np.round(0, 4)) # dummy placeholder
312
+ compressed_bytes = range_encode_radicals(radicals, alpha=1, weight=128)
313
+ compressed_len = len(compressed_bytes)
314
+
315
+ # 4. Lossless Decompress Verification
316
+ decoded_radicals = range_decode_radicals(compressed_bytes, num_tokens, alpha=1, weight=128)
317
+ assert decoded_radicals == radicals, f" [FAIL] ERROR: Lossless validation failed at index {idx}!"
318
+ print(" [OK] Lossless reconstruction validation PASSED.")
319
+
320
+ # 5. Baselines comparison
321
+ # Baseline A: Raw ASCII text bytes
322
+ ascii_bytes_len = len(text.encode('utf-8'))
323
+
324
+ # Baseline B: Raw Token IDs as 32-bit integers (4 bytes per token)
325
+ raw_ids_bytes = num_tokens * 4
326
+
327
+ # Baseline C: Token IDs compressed via standard zlib deflate (Level 9)
328
+ token_bytes_flat = bytearray()
329
+ for tid in token_ids:
330
+ token_bytes_flat.extend(struct.pack(">I", tid))
331
+ zlib_compressed = zlib.compress(bytes(token_bytes_flat), level=9)
332
+ zlib_len = len(zlib_compressed)
333
+
334
+ print("\n Compression Size Metrics:")
335
+ print(f" - Raw ASCII Text: {ascii_bytes_len} bytes")
336
+ print(f" - Raw Token IDs (32-bit): {raw_ids_bytes} bytes")
337
+ print(f" - Token IDs + Zlib (deflate): {zlib_len} bytes")
338
+ print(f" - **Cuneiform-U Range Coding**: {compressed_len} bytes")
339
+
340
+ # Ratios
341
+ vs_ascii = ascii_bytes_len / compressed_len
342
+ vs_zlib = zlib_len / compressed_len
343
+
344
+ print(f"\n [+] Cuneiform-U vs ASCII: {vs_ascii:.2f}x compression gain")
345
+ print(f" [+] Cuneiform-U vs Zlib (tokens): {vs_zlib:.2f}x compression gain")
346
+
347
+ if __name__ == "__main__":
348
+ main()
ufo_cuneiform_vocab_mapper.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import struct
3
+ import numpy as np
4
+ from transformers import AutoTokenizer
5
+
6
+ TOKENIZER_DIR = "j:/Language-U/Language-U-V2/qwen-3.5-0.8b-local"
7
+ OUTPUT_BIN = "j:/Language-U/qwen_vocab_cuneiform.bin"
8
+
9
+ def classify_token(token_str):
10
+ # Normalize token string (replace special character G/Ġ representing space)
11
+ s = token_str.replace("Ġ", " ").replace(" ", "").lower()
12
+
13
+ # 1. DOMAIN & SUBDOMAIN
14
+ domain = 0
15
+ subdomain = 0
16
+
17
+ # Domain 1: Hardware & LoRA Networks
18
+ hw_net_kw = ['gpio', 'lora', 'chirp', 'reset', 'pin', 'spi', 'sx1302', 'pi4', 'pi5',
19
+ 'concentrator', 'antenna', 'frequency', 'mhz', 'dbm', 'packet', 'transmit',
20
+ 'tx', 'rx', 'sf7', 'fec', 'parity', 'duty', 'dwell', 'mac', 'gateway', 'beacon']
21
+ # Domain 2: Mathematics, Logic & Information Theory
22
+ math_kw = ['svd', 'dct', 'quant', 'math', 'entropy', 'shannon', 'gradient', 'atom',
23
+ 'ortho', 'eigen', 'projection', 'reconstruct', 'rank', 'matrix', 'vector',
24
+ 'basis', 'decompo', 'smooth', 'laplace', 'probability', 'logits', 'prior',
25
+ 'bypass', 'q_proj', 'v_proj', 'k_proj', 'o_proj']
26
+ # Domain 3: Dialogue, Persona & Authors
27
+ dialogue_kw = ['zymatica', 'collective', 'dialogue', 'persona', 'chat', 'assistant',
28
+ 'speak', 'talk', 'bot', 'agent', 'she', 'astronaut', 'devsone', 'bouldiez',
29
+ 'partner', 'art']
30
+ # Domain 4: Software, Systems & Runtimes
31
+ sw_kw = ['rust', 'cpp', 'go', 'python', 'swift', 'java', 'typescript', 'compile',
32
+ 'code', 'exec', 'run', 'lib', 'class', 'struct', 'header', 'import', 'from',
33
+ 'package', 'build', 'cmake', 'cargo']
34
+
35
+ if any(k in s for k in hw_net_kw):
36
+ domain = 1
37
+ if 'lora' in s or 'chirp' in s or 'fec' in s:
38
+ subdomain = 1
39
+ elif 'gpio' in s or 'pin' in s or 'reset' in s:
40
+ subdomain = 2
41
+ elif 'packet' in s or 'beacon' in s:
42
+ subdomain = 3
43
+ elif any(k in s for k in math_kw):
44
+ domain = 2
45
+ if 'svd' in s or 'matrix' in s or 'projection' in s:
46
+ subdomain = 1
47
+ elif 'entropy' in s or 'shannon' in s or 'bypass' in s:
48
+ subdomain = 2
49
+ elif 'logits' in s or 'prior' in s or 'smooth' in s:
50
+ subdomain = 3
51
+ elif any(k in s for k in dialogue_kw):
52
+ domain = 3
53
+ if 'zymatica' in s or 'collective' in s:
54
+ subdomain = 1
55
+ elif 'persona' in s or 'dialogue' in s or 'speak' in s:
56
+ subdomain = 2
57
+ elif any(k in s for k in sw_kw):
58
+ domain = 4
59
+ if 'rust' in s or 'go' in s or 'cpp' in s:
60
+ subdomain = 1
61
+ elif 'python' in s or 'typescript' in s or 'java' in s:
62
+ subdomain = 2
63
+
64
+ # 2. OPERATION (Actions)
65
+ # Map key verbs to operation IDs (1 to 15)
66
+ operations = [
67
+ 'reset', 'clear', 'toggle', 'write', 'read', 'set', 'get',
68
+ 'encode', 'decode', 'compress', 'decompress', 'train', 'heal',
69
+ 'eval', 'test', 'load', 'save', 'grow', 'shrink', 'bypass'
70
+ ]
71
+ operation = 0
72
+ for i, op in enumerate(operations, 1):
73
+ if op in s:
74
+ operation = i % 16
75
+ break
76
+
77
+ # 3. MODALITY (Data layouts / formats)
78
+ modalities = [
79
+ 'bin', 'zlib', 'json', 'capsule', 'genesis', 'llm', 'file',
80
+ 'packet', 'byte', 'bit', 'char', 'string', 'token', 'wave', 'hal'
81
+ ]
82
+ modality = 0
83
+ for i, mod in enumerate(modalities, 1):
84
+ if mod in s:
85
+ modality = i % 16
86
+ break
87
+
88
+ # 4. DEPTH (Complexity scale)
89
+ depth = 0
90
+ if domain == 1:
91
+ if 'seed' in s or 'genesis' in s:
92
+ depth = 8
93
+ elif 'dct' in s:
94
+ depth = 4
95
+ elif 'atom' in s:
96
+ depth = 6
97
+ elif 'qa' in s or 'facts' in s:
98
+ depth = 1
99
+ else:
100
+ depth = len(s) % 16
101
+
102
+ # 5. POLARITY (Outcome states)
103
+ polarity = 0
104
+ pos_states = ['ack', 'success', 'ok', 'pass', 'valid', 'correct', 'true']
105
+ neg_states = ['nack', 'fail', 'error', 'wrong', 'miss', 'warn', 'oom', 'crash', 'abort', 'false']
106
+ if any(k in s for k in pos_states):
107
+ polarity = 1
108
+ elif any(k in s for k in neg_states):
109
+ polarity = 2
110
+
111
+ return domain, subdomain, operation, modality, depth, polarity
112
+
113
+ def main():
114
+ print(f"Loading tokenizer from: {TOKENIZER_DIR}")
115
+ tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_DIR, trust_remote_code=True)
116
+ vocab = tokenizer.get_vocab()
117
+ vocab_size = len(vocab)
118
+ print(f"Total vocabulary size: {vocab_size}")
119
+
120
+ # Build the binary map in token ID order
121
+ # Each record is 3 bytes: R_C, R_F, R_A
122
+ packed_data = bytearray(vocab_size * 3)
123
+
124
+ domain_counts = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
125
+ op_counts = 0
126
+ polarity_counts = {0: 0, 1: 0, 2: 0}
127
+
128
+ for token_str, token_id in vocab.items():
129
+ if token_id >= vocab_size:
130
+ continue
131
+
132
+ domain, subdomain, operation, modality, depth, polarity = classify_token(token_str)
133
+
134
+ # Pack into radicals
135
+ rc = (domain << 4) | (subdomain & 0xF)
136
+ rf = (operation << 4) | (modality & 0xF)
137
+ ra = (depth << 4) | (polarity & 0xF)
138
+
139
+ packed_data[token_id * 3] = rc
140
+ packed_data[token_id * 3 + 1] = rf
141
+ packed_data[token_id * 3 + 2] = ra
142
+
143
+ # Metrics collection
144
+ domain_counts[domain] = domain_counts.get(domain, 0) + 1
145
+ if operation > 0:
146
+ op_counts += 1
147
+ polarity_counts[polarity] = polarity_counts.get(polarity, 0) + 1
148
+
149
+ # Write to output file
150
+ with open(OUTPUT_BIN, "wb") as f:
151
+ f.write(packed_data)
152
+
153
+ print(f"\n[+] Successfully generated binary map at: {OUTPUT_BIN}")
154
+ print(f" Total tokens written: {vocab_size}")
155
+ print("\n--- Mapping Classification Metrics ---")
156
+ print(f" Domain 0 (General English): {domain_counts[0]:,} tokens ({domain_counts[0]/vocab_size*100:.2f}%)")
157
+ print(f" Domain 1 (Hardware & LoRA): {domain_counts[1]:,} tokens ({domain_counts[1]/vocab_size*100:.2f}%)")
158
+ print(f" Domain 2 (Math & Info Theory): {domain_counts[2]:,} tokens ({domain_counts[2]/vocab_size*100:.2f}%)")
159
+ print(f" Domain 3 (Dialogue & Persona): {domain_counts[3]:,} tokens ({domain_counts[3]/vocab_size*100:.2f}%)")
160
+ print(f" Domain 4 (Software & Systems): {domain_counts[4]:,} tokens ({domain_counts[4]/vocab_size*100:.2f}%)")
161
+ print(f" Active Operations Detected: {op_counts:,} tokens")
162
+ print(f" Neutral Polarity (0): {polarity_counts[0]:,} tokens")
163
+ print(f" Positive Polarity (1 - ACK): {polarity_counts[1]:,} tokens")
164
+ print(f" Negative Polarity (2 - ERR): {polarity_counts[2]:,} tokens")
165
+
166
+ if __name__ == "__main__":
167
+ main()