QuatronTokenizer
QuatronTokenizer combines KoktenV2 (Turkish morphological root/suffix segmentation, 19 UD causal channels), CodexTokenizer (22-language source code, shell, and LaTeX-Math with single-digit arithmetic preservation, 14 causal channels), and EnglishTokenizer (en-seg-v1 root/affix-aware BPE, 11 causal channels) into a single zero-copy, causal, 100% byte-lossless Rust + Python tokenizer.
- Unified 128-Aligned Vocabularies:
65,536,81,920(default), and97,920tokens. - 20 Unified Causal Channels (
available_at <= t): Deterministic multi-domain conditioning vector (core.*+dom.c0..c13) with zero future leakage for FiLM-conditioned LLM pretraining and inference. - Zero-Copy Python API (
PyO3+abi3): Directnumpy.asarray(...)memory views via Python Buffer Protocol and GIL-releasedrayonbatch encoding. - Native Training Format (
KOKTEN2S): Atomic 64-byte aligned shard writer, SHA-256 verification (verify --replay), resume support, andShardSampler.
Installation
Python (pip)
# Once published on PyPI:
pip install quatron-tokenizer
# Or directly from GitHub:
pip install "git+https://github.com/muhamedsahin/Quatron_Tokenizer.git"
Rust (Cargo)
# Add core library to a Rust project:
cargo add quatron-core
# Install CLI binary (`quatron`):
cargo install quatron-cli
Build from Source
git clone https://github.com/muhamedsahin/Quatron_Tokenizer.git
cd Quatron_Tokenizer
# Build & test Rust workspace + CLI
cargo test --release --workspace --exclude quatron-py
cargo build --release -p quatron-cli
# Build & install Python wheel (requires Python >= 3.11 and maturin)
pip install maturin numpy
maturin build --release -o dist
pip install dist/quatron_tokenizer-*.whl
Unified Vocabulary & Control Contract
- Targets (
128-aligned):65,536,81,920(default),97,920. - Shared control slots
[0, 16):PAD=0,UNK=1,BOS=2,EOS=3,<mask>=4,<sep>=5,<cls>=6,<|endoftext|>=7,<|user|>=8,<|assistant|>=9,<|system|>=10,<fim_prefix>=11,<fim_middle>=12,<fim_suffix>=13,<fim_pad>=14,<extra_7>=15. - Byte fallback
[16, 272): Full 256-byte fallback ensuring 100% byte-level lossless roundtrip on arbitrary UTF-8 and binary-like text. - Reasoning boundaries:
<think>and</think>are guaranteed single-token entries in every unified vocabulary (decode([think_open_id]) == b"<think>").
Quick Usage
Python
import numpy as np
import quatron_tokenizer as qt
tok = qt.QuatronTokenizer(target=81920) # or 65536 / 97920
text = "<think>Plan</think>\nMerhaba! ```python\ndef f(x): return x + 1\n``` $$123$$"
ids = tok.encode(text)
assert tok.decode(ids) == text.encode("utf-8")
# Zero-copy read-only NumPy view
arr = np.asarray(tok.encode_np("Türkiye'deki geliştiriciler"))
# 20-channel causal vectors for FiLM conditioning
vec = qt.numpy(tok.encode_vectors("let x = foo(1);", domain="rust"))
print(vec["value"].shape, vec["status"].shape) # (T, 20), (T, 20)
# Causal streaming with checkpoint/restore
st = qt.Stream(tok, domain="auto")
out = st.push_bytes(b"Merhaba ")
ckpt = st.checkpoint()
st2 = qt.Stream.restore(tok, ckpt)
out += st2.push_bytes(b"d\xc3\xbcnya!") + st2.finish_document()
Rust
use quatron_core::{DomainHint, QuatronTokenizer, VectorOptions};
fn main() -> quatron_core::Result<()> {
let tok = QuatronTokenizer::from_builtin_target(65536)?;
let vec = tok.encode_vectors(
b"Merhaba! def add(a, b): return a + b",
DomainHint::Auto,
VectorOptions { bos: true, eos: true },
);
assert_eq!(tok.decode(&vec.ids[1..vec.ids.len() - 1])?, b"Merhaba! def add(a, b): return a + b");
Ok(())
}
CLI (quatron)
quatron build-unified --target 65536 --out vocab-65536.json
quatron encode --vocab vocab-65536.json --ids-only sample.txt
quatron vectors --vocab vocab-65536.json --bos --eos sample.txt
quatron encode-corpus --vocab vocab-65536.json --input docs.jsonl --out shards/ --domain auto --bos --resume
quatron verify shards/ --vocab vocab-65536.json --replay
quatron bench --target 81920 --domain auto --repeat 5
Performance Summary (quatron-unified-81920)
Detailed benchmark tables are recorded in bench/quatron-report.md:
- Parallel 16T Encoding:
151.1 MB/s(Mixed TR+EN+Code+Math),419.7 MB/s(Turkish),301.6 MB/s(English),174.1 MB/s(Rust),164.9 MB/s(LaTeX Math). - Decode:
1,268 MB/s(mixed) —1,591 MB/s(Rust source code), 100% lossless. - Memory Footprint:
61.7 MBloaded RSS /99.5 MBpeak RSS (all three engines shared viaArc).
Workspace Structure
crates/quatron-kokten: Bundledkokten2Turkish morphological engine (quatron-koktenon crates.io).crates/quatron-codex: Bundledcodex_core22-language code/LaTeX-Math engine (quatron-codexon crates.io).crates/quatron-english: Bundledenglish_coreEnglish engine (quatron-englishon crates.io).crates/quatron-core: Unified vocabulary,O(1)LUT, causal multi-domain router, 20-channel adapter,Stream,KOKTEN2S.crates/quatron-cli:quatronCLI binary.crates/quatron-py:PyO3+maturin(abi3) Python bindings (quatron-tokenizeron PyPI).
License & Citation
Licensed under the Apache License 2.0. If you use QuatronTokenizer in research or training, please cite via CITATION.cff.
Metadata
Release files for quatron-tokenizer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quatron_tokenizer-0.1.0.tar.gz | 2.4 MB | Without provenance | Details for quatron_tokenizer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quatron_tokenizer-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for quatron_tokenizer-0.1.0-cp311-abi3-win_amd64.whl |
Total release size: 5.5 MB
Release files / quatron_tokenizer-0.1.0.tar.gz
| Download URL | quatron_tokenizer-0.1.0.tar.gz |
|---|---|
| Size | 2.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d27585589340ed0c027b73f5b1a2f13ffa932f6bb10e848fad8c00c386ef4dca
|
|
BLAKE2b-256 checksum How to use checksums |
ab2db06eb2e6a669c26fc7a05cf8ad5ffb8eff9e981fdc5bc9aa50e83c232a47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Release files / quatron_tokenizer-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | quatron_tokenizer-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bd91f2b44e14bdb84b1b6a9be218a80276da24d00c465188dffbfeb139d727d4
|
|
BLAKE2b-256 checksum How to use checksums |
25f3a86b4d9d59200d0e10abbae70cbc4173c5a76bae2e2ec2e8553de02f8956
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.16.0
|
Security for quatron-tokenizer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.