README: add Gemma-4, Qwen3.6, Kimi-K2.6 benchmarks + head-to-head vs flagships
Browse files
README.md
CHANGED
|
@@ -20,18 +20,21 @@ A bilingual Arabic/English tokenizer at 65k vocab built on HuggingFace's Unigram
|
|
| 20 |
|
| 21 |
## The headline
|
| 22 |
|
| 23 |
-
**v0.2 is the first bilingual tokenizer tested to beat GPT-5
|
| 24 |
|
| 25 |
| Tokenizer | Vocab | AR CpT | EN CpT | Parity |
|
| 26 |
|---|--:|--:|--:|--:|
|
| 27 |
| **SARFTokenizer v0.2** | **65,000** | **3.683** | **3.522** | **1.046** |
|
|
|
|
| 28 |
| tiktoken/o200k_base (GPT-4o, GPT-5) | 200,019 | 3.087 | 3.409 | 0.906 |
|
| 29 |
| ALLaM-7B | 64,000 | 2.854 | 2.518 | 1.133 |
|
| 30 |
-
| gemma-
|
|
|
|
| 31 |
| Qwen2.5-0.5B | 151,665 | 2.583 | 2.923 | 0.884 |
|
| 32 |
| SARFTokenizer v0.1 (BPE) | 62,912 | 3.262 | 2.729 | 1.196 |
|
|
|
|
| 33 |
|
| 34 |
-
Full comparison: [`BENCHMARK.md`](./BENCHMARK.md). Deep-dive writeup:
|
| 35 |
|
| 36 |
---
|
| 37 |
|
|
@@ -122,7 +125,7 @@ batch = tok(
|
|
| 122 |
|
| 123 |
## Benchmark
|
| 124 |
|
| 125 |
-
###
|
| 126 |
|
| 127 |
Protocol: 300 AR + 300 EN documents from `deeplatent-hq-bilingual` validation shards, 2000 chars each. `add_special_tokens=False`. Each tokenizer's own normalizer/pre-tokenizer runs (no external preprocessing). Metrics:
|
| 128 |
- **AR CpT** = Arabic chars / tokens (higher = more compression)
|
|
@@ -134,15 +137,30 @@ Protocol: 300 AR + 300 EN documents from `deeplatent-hq-bilingual` validation sh
|
|
| 134 |
|---:|---|--:|--:|--:|--:|--:|--:|
|
| 135 |
| 1 | **SARFTokenizer v0.2** (Unigram) | **65,000** | **3.683** | **3.522** | **1.046** | **1.57** | **2.01** |
|
| 136 |
| 2 | SARFTokenizer v0.1 (MYTE + BPE) | 62,912 | 3.262 | 2.729 | 1.196 | 1.77 | 2.59 |
|
| 137 |
-
| 3 |
|
| 138 |
-
| 4 |
|
| 139 |
-
| 5 |
|
| 140 |
-
| 6 | google/gemma-
|
| 141 |
-
|
|
| 142 |
-
| 8 |
|
| 143 |
-
| 9 |
|
| 144 |
-
| 10 |
|
| 145 |
-
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
### v0.2 vs v0.1 (same vocab tier)
|
| 148 |
|
|
@@ -171,10 +189,10 @@ Clean-room test, fresh venv, 1M samples streamed from each of:
|
|
| 171 |
- `HuggingFaceFW/fineweb-edu` config `sample-10BT` (English)
|
| 172 |
|
| 173 |
| Stream | Samples | Chars | Tokens | CpT | T/W |
|
| 174 |
-
|---|--:|--:|--:|--:|--:|
|
| 175 |
| AR (FineWeb-2) | 1,000,000 | 3,045,017,883 | 829,621,672 | **3.670** | 1.60 |
|
| 176 |
| EN (FineWeb-Edu) | 1,000,000 | 4,685,926,211 | 1,041,078,482 | **4.501** | 1.37 |
|
| 177 |
-
| **Total** | **2,000,000** | **7.73 GB** | **1.87 B** | | |
|
| 178 |
|
| 179 |
**AR matches the internal benchmark within 0.4%** (3.683 β 3.670) β the tokenizer generalizes across corpora.
|
| 180 |
**EN is 27.8% higher on FineWeb-Edu** (3.522 β 4.501) because FineWeb-Edu is a quality-filtered educational corpus (Wikipedia/textbook-heavy), structurally easier than mixed web text.
|
|
@@ -184,10 +202,10 @@ Raw per-stream results: `benchmark_results.json`.
|
|
| 184 |
### Run the benchmark yourself
|
| 185 |
|
| 186 |
```python
|
| 187 |
-
import
|
| 188 |
-
|
|
|
|
| 189 |
|
| 190 |
-
# Quick sanity check: count tokens on some text you own
|
| 191 |
from transformers import AutoTokenizer
|
| 192 |
tok = AutoTokenizer.from_pretrained("almaghrabima/SARFTokenizer")
|
| 193 |
|
|
@@ -197,7 +215,24 @@ print(f"AR: {len(ar)} chars -> {len(tok.encode(ar))} tokens = {len(ar)/len(tok.e
|
|
| 197 |
print(f"EN: {len(en)} chars -> {len(tok.encode(en))} tokens = {len(en)/len(tok.encode(en)):.3f} CpT")
|
| 198 |
```
|
| 199 |
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
---
|
| 203 |
|
|
@@ -279,7 +314,7 @@ Your token is valid but `AutoConfig` is not forwarding it. Use `login()` to set
|
|
| 279 |
|
| 280 |
## Version history
|
| 281 |
|
| 282 |
-
- **v0.2** β Unigram LM at 65k vocab with AraToken normalizer. First sub-100k-vocab tokenizer to beat GPT-5 on both AR and EN simultaneously. E2E-validated on 2M FineWeb samples.
|
| 283 |
- **v0.1** β MYTE + parity-aware BPE at 62,912 vocab with 14k Arabic morpheme atomic tokens.
|
| 284 |
|
| 285 |
---
|
|
|
|
| 20 |
|
| 21 |
## The headline
|
| 22 |
|
| 23 |
+
**v0.2 is the first bilingual tokenizer tested to beat GPT-5 (o200k_base), GPT-4o, Gemma-4, Qwen 3.6, and Kimi K2.6 on both Arabic AND English chars-per-token β at 25β32.5% of their vocabulary sizes.**
|
| 24 |
|
| 25 |
| Tokenizer | Vocab | AR CpT | EN CpT | Parity |
|
| 26 |
|---|--:|--:|--:|--:|
|
| 27 |
| **SARFTokenizer v0.2** | **65,000** | **3.683** | **3.522** | **1.046** |
|
| 28 |
+
| Qwen/Qwen3.6-35B-A3B | 248,077 | 3.129 | 2.985 | 1.048 |
|
| 29 |
| tiktoken/o200k_base (GPT-4o, GPT-5) | 200,019 | 3.087 | 3.409 | 0.906 |
|
| 30 |
| ALLaM-7B | 64,000 | 2.854 | 2.518 | 1.133 |
|
| 31 |
+
| google/gemma-4-31B-it | 262,144 | 2.833 | 3.069 | 0.923 |
|
| 32 |
+
| google/gemma-3-1b-pt | 262,145 | 2.833 | 3.069 | 0.923 |
|
| 33 |
| Qwen2.5-0.5B | 151,665 | 2.583 | 2.923 | 0.884 |
|
| 34 |
| SARFTokenizer v0.1 (BPE) | 62,912 | 3.262 | 2.729 | 1.196 |
|
| 35 |
+
| moonshotai/Kimi-K2.6 | 163,840 | 2.074 | 3.239 | 0.640 |
|
| 36 |
|
| 37 |
+
Full comparison: [`BENCHMARK.md`](./BENCHMARK.md). Deep-dive writeup: `docs/V6_REPORT.md` in the [GitHub repo](https://github.com/almaghrabima/smctm).
|
| 38 |
|
| 39 |
---
|
| 40 |
|
|
|
|
| 125 |
|
| 126 |
## Benchmark
|
| 127 |
|
| 128 |
+
### Full table (sorted by Arabic CpT)
|
| 129 |
|
| 130 |
Protocol: 300 AR + 300 EN documents from `deeplatent-hq-bilingual` validation shards, 2000 chars each. `add_special_tokens=False`. Each tokenizer's own normalizer/pre-tokenizer runs (no external preprocessing). Metrics:
|
| 131 |
- **AR CpT** = Arabic chars / tokens (higher = more compression)
|
|
|
|
| 137 |
|---:|---|--:|--:|--:|--:|--:|--:|
|
| 138 |
| 1 | **SARFTokenizer v0.2** (Unigram) | **65,000** | **3.683** | **3.522** | **1.046** | **1.57** | **2.01** |
|
| 139 |
| 2 | SARFTokenizer v0.1 (MYTE + BPE) | 62,912 | 3.262 | 2.729 | 1.196 | 1.77 | 2.59 |
|
| 140 |
+
| 3 | Qwen/Qwen3.6-35B-A3B | 248,077 | 3.129 | 2.985 | 1.048 | 1.85 | 2.38 |
|
| 141 |
+
| 4 | tiktoken/o200k_base (GPT-4o, GPT-5) | 200,019 | 3.087 | 3.409 | 0.906 | 1.87 | 2.07 |
|
| 142 |
+
| 5 | ALLaM-AI/ALLaM-7B-Instruct-preview | 64,000 | 2.854 | 2.518 | 1.133 | 2.03 | 2.81 |
|
| 143 |
+
| 6 | google/gemma-3-1b-pt | 262,145 | 2.833 | 3.069 | 0.923 | 2.04 | 2.30 |
|
| 144 |
+
| 6t | google/gemma-4-31B-it | 262,144 | 2.833 | 3.069 | 0.923 | 2.04 | 2.30 |
|
| 145 |
+
| 8 | google/gemma-2-2b | 256,000 | 2.779 | 3.117 | 0.892 | 2.08 | 2.27 |
|
| 146 |
+
| 9 | QCRI/Fanar-1-9B-Instruct | 128,256 | 2.778 | 3.047 | 0.911 | 2.08 | 2.32 |
|
| 147 |
+
| 10 | Qwen/Qwen2.5-0.5B | 151,665 | 2.583 | 2.923 | 0.884 | 2.24 | 2.42 |
|
| 148 |
+
| 11 | hammh0a/Hala-350M | 64,400 | 2.219 | 3.220 | 0.689 | 2.61 | 2.20 |
|
| 149 |
+
| 12 | moonshotai/Kimi-K2.6 | 163,840 | 2.074 | 3.239 | 0.640 | 2.79 | 2.20 |
|
| 150 |
+
| 13 | tiktoken/cl100k_base (GPT-4) | 100,277 | 1.429 | 3.066 | 0.466 | 4.05 | 2.31 |
|
| 151 |
+
| 14 | tiiuae/falcon-7b | 65,024 | 0.991 | 2.720 | 0.364 | 5.84 | 2.60 |
|
| 152 |
+
|
| 153 |
+
### Head-to-head: v0.2 vs flagship 2025/2026 tokenizers
|
| 154 |
+
|
| 155 |
+
| Competitor | Vocab | Their AR CpT | **Our AR CpT** | Ξ AR | Their EN CpT | **Our EN CpT** | Ξ EN |
|
| 156 |
+
|---|--:|--:|--:|--:|--:|--:|--:|
|
| 157 |
+
| **GPT-5 / GPT-4o** (o200k_base) | 200,019 | 3.087 | **3.683** | **+19.3%** | 3.409 | **3.522** | +3.3% |
|
| 158 |
+
| **Gemma-4-31B-it** | 262,144 | 2.833 | **3.683** | **+30.0%** | 3.069 | **3.522** | +14.8% |
|
| 159 |
+
| **Qwen3.6-35B-A3B** | 248,077 | 3.129 | **3.683** | **+17.7%** | 2.985 | **3.522** | +18.0% |
|
| 160 |
+
| **Kimi-K2.6** | 163,840 | 2.074 | **3.683** | **+77.6%** | 3.239 | **3.522** | +8.7% |
|
| 161 |
+
| **ALLaM-7B** | 64,000 | 2.854 | **3.683** | **+29.0%** | 2.518 | **3.522** | +39.9% |
|
| 162 |
+
|
| 163 |
+
At 65k vocab β **25β32.5%** the vocabulary size of these flagships β SARFTokenizer v0.2 wins on both Arabic and English, simultaneously.
|
| 164 |
|
| 165 |
### v0.2 vs v0.1 (same vocab tier)
|
| 166 |
|
|
|
|
| 189 |
- `HuggingFaceFW/fineweb-edu` config `sample-10BT` (English)
|
| 190 |
|
| 191 |
| Stream | Samples | Chars | Tokens | CpT | T/W |
|
| 192 |
+
|---|--:|--:|--:|--:|--:|
|
| 193 |
| AR (FineWeb-2) | 1,000,000 | 3,045,017,883 | 829,621,672 | **3.670** | 1.60 |
|
| 194 |
| EN (FineWeb-Edu) | 1,000,000 | 4,685,926,211 | 1,041,078,482 | **4.501** | 1.37 |
|
| 195 |
+
| **Total** | **2,000,000** | **7.73 GB** | **1.87 B** | | |
|
| 196 |
|
| 197 |
**AR matches the internal benchmark within 0.4%** (3.683 β 3.670) β the tokenizer generalizes across corpora.
|
| 198 |
**EN is 27.8% higher on FineWeb-Edu** (3.522 β 4.501) because FineWeb-Edu is a quality-filtered educational corpus (Wikipedia/textbook-heavy), structurally easier than mixed web text.
|
|
|
|
| 202 |
### Run the benchmark yourself
|
| 203 |
|
| 204 |
```python
|
| 205 |
+
from google.colab import userdata
|
| 206 |
+
from huggingface_hub import login
|
| 207 |
+
login(token=userdata.get("HF-Token"), add_to_git_credential=False)
|
| 208 |
|
|
|
|
| 209 |
from transformers import AutoTokenizer
|
| 210 |
tok = AutoTokenizer.from_pretrained("almaghrabima/SARFTokenizer")
|
| 211 |
|
|
|
|
| 215 |
print(f"EN: {len(en)} chars -> {len(tok.encode(en))} tokens = {len(en)/len(tok.encode(en)):.3f} CpT")
|
| 216 |
```
|
| 217 |
|
| 218 |
+
### Head-to-head your own corpus vs any flagship tokenizer
|
| 219 |
+
|
| 220 |
+
```python
|
| 221 |
+
from transformers import AutoTokenizer
|
| 222 |
+
|
| 223 |
+
sarf = AutoTokenizer.from_pretrained("almaghrabima/SARFTokenizer")
|
| 224 |
+
gemma = AutoTokenizer.from_pretrained("google/gemma-4-31B-it")
|
| 225 |
+
qwen = AutoTokenizer.from_pretrained("Qwen/Qwen3.6-35B-A3B")
|
| 226 |
+
kimi = AutoTokenizer.from_pretrained("moonshotai/Kimi-K2.6", trust_remote_code=True)
|
| 227 |
+
|
| 228 |
+
text = "your Arabic or English text here"
|
| 229 |
+
for name, t in [("SARF v0.2", sarf), ("Gemma-4", gemma),
|
| 230 |
+
("Qwen3.6", qwen), ("Kimi-K2.6", kimi)]:
|
| 231 |
+
ids = t.encode(text, add_special_tokens=False)
|
| 232 |
+
print(f"{name:<14} vocab={len(t):>7,} tokens={len(ids):>5} CpT={len(text)/len(ids):.3f}")
|
| 233 |
+
```
|
| 234 |
+
|
| 235 |
+
Full reproducibility (all 14 tokenizer peers + E2E FineWeb run) via `scripts/bench_tokenizers.py` and `scripts/e2e_test_fineweb.py` on [GitHub](https://github.com/almaghrabima/smctm).
|
| 236 |
|
| 237 |
---
|
| 238 |
|
|
|
|
| 314 |
|
| 315 |
## Version history
|
| 316 |
|
| 317 |
+
- **v0.2** β Unigram LM at 65k vocab with AraToken normalizer. First sub-100k-vocab tokenizer to beat GPT-5, Gemma-4, Qwen3.6, and Kimi-K2.6 on both AR and EN simultaneously. E2E-validated on 2M FineWeb samples.
|
| 318 |
- **v0.1** β MYTE + parity-aware BPE at 62,912 vocab with 14k Arabic morpheme atomic tokens.
|
| 319 |
|
| 320 |
---
|