almaghrabima commited on
Commit
e489970
·
verified ·
1 Parent(s): fedd19e

Add README.md: 600-sample SARFTokenizer benchmark eval

Browse files
Files changed (1) hide show
  1. README.md +155 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - ar
5
+ - en
6
+ tags:
7
+ - tokenizer
8
+ - benchmark
9
+ - eval
10
+ - arabic
11
+ - english
12
+ - chars-per-token
13
+ pretty_name: SARFTokenizer Benchmark Eval (600)
14
+ size_categories:
15
+ - n<1K
16
+ task_categories:
17
+ - text-classification
18
+ dataset_info:
19
+ features:
20
+ - name: idx
21
+ dtype: int64
22
+ - name: language
23
+ dtype: string
24
+ - name: text
25
+ dtype: string
26
+ - name: source
27
+ dtype: string
28
+ splits:
29
+ - name: test
30
+ num_bytes: 574100
31
+ num_examples: 600
32
+ configs:
33
+ - config_name: default
34
+ data_files:
35
+ - split: test
36
+ path: eval.parquet
37
+ ---
38
+
39
+ # SARFTokenizer Benchmark Eval (600 docs)
40
+
41
+ The exact 300 Arabic + 300 English documents used to benchmark [`almaghrabima/SARFTokenizer`](https://huggingface.co/almaghrabima/SARFTokenizer) against GPT-5, GPT-4o, Gemma-4, Qwen3.6, Kimi-K2.6, ALLaM, and 8 other tokenizers.
42
+
43
+ Publishing this dataset makes the benchmark in [SARFTokenizer/BENCHMARK.md](https://huggingface.co/almaghrabima/SARFTokenizer/blob/main/BENCHMARK.md) **fully reproducible** — anyone can compute the exact same chars-per-token numbers on the exact same samples.
44
+
45
+ ## Statistics
46
+
47
+ | | AR | EN | Total |
48
+ |---|--:|--:|--:|
49
+ | Documents | 300 | 300 | 600 |
50
+ | Characters | 479,808 | 69,308 | 549,116 |
51
+ | Words | 82,964 | 9,805 | 92,769 |
52
+ | Max chars/sample | 2,000 | 2,000 | — |
53
+
54
+ ## Schema
55
+
56
+ | Field | Type | Description |
57
+ |---|---|---|
58
+ | `idx` | int64 | Index within the per-language subset (0–299) |
59
+ | `language` | string | `"ar"` or `"en"` |
60
+ | `text` | string | Document text, truncated to 2000 characters |
61
+ | `source` | string | Always `"deeplatent-hq-bilingual"` |
62
+
63
+ Sampled from the first 5 `ar_*.parquet` and first 5 `en_*.parquet` files of the `deeplatent-hq-bilingual` validation shards, with a 10% Arabic-character threshold for AR filtering (matching `scripts/bench_tokenizers.py`).
64
+
65
+ ## Reproduce the headline benchmark
66
+
67
+ ```bash
68
+ pip install transformers tokenizers datasets
69
+ ```
70
+
71
+ ```python
72
+ from datasets import load_dataset
73
+ from transformers import AutoTokenizer
74
+
75
+ # Our eval corpus
76
+ ds = load_dataset("almaghrabima/SARFTokenizer-benchmark-eval", split="test")
77
+ ar_texts = [r["text"] for r in ds if r["language"] == "ar"]
78
+ en_texts = [r["text"] for r in ds if r["language"] == "en"]
79
+
80
+ # Load any tokenizer
81
+ from huggingface_hub import login
82
+ login(token="your_hf_token") # needed for private SARFTokenizer; skip if public
83
+ tok = AutoTokenizer.from_pretrained("almaghrabima/SARFTokenizer")
84
+
85
+ def stats(texts):
86
+ chars = sum(len(t) for t in texts)
87
+ words = sum(len(t.split()) for t in texts)
88
+ tokens = sum(len(tok.encode(t, add_special_tokens=False)) for t in texts)
89
+ return chars, words, tokens
90
+
91
+ ar_c, ar_w, ar_t = stats(ar_texts)
92
+ en_c, en_w, en_t = stats(en_texts)
93
+ print(f"AR: {ar_c:,}c / {ar_t:,}t → CpT={ar_c/ar_t:.3f} T/W={ar_t/ar_w:.2f}")
94
+ print(f"EN: {en_c:,}c / {en_t:,}t → CpT={en_c/en_t:.3f} T/W={en_t/en_w:.2f}")
95
+ print(f"Parity = {(ar_c/ar_t)/(en_c/en_t):.3f}")
96
+ ```
97
+
98
+ Expected output for SARFTokenizer v0.2:
99
+
100
+ ```
101
+ AR: 479,808c / 130,253t → CpT=3.683 T/W=1.57
102
+ EN: 69,308c / 19,680t → CpT=3.522 T/W=2.01
103
+ Parity = 1.046
104
+ ```
105
+
106
+ ## Compare multiple tokenizers in one shot
107
+
108
+ ```python
109
+ from datasets import load_dataset
110
+ from transformers import AutoTokenizer
111
+ from huggingface_hub import login
112
+
113
+ login(token="your_hf_token") # needed for private SARFTokenizer
114
+
115
+ ds = load_dataset("almaghrabima/SARFTokenizer-benchmark-eval", split="test")
116
+ ar_texts = [r["text"] for r in ds if r["language"] == "ar"]
117
+ en_texts = [r["text"] for r in ds if r["language"] == "en"]
118
+ ar_chars = sum(len(t) for t in ar_texts)
119
+ en_chars = sum(len(t) for t in en_texts)
120
+
121
+ peers = {
122
+ "SARFTokenizer-v0.2": ("almaghrabima/SARFTokenizer", False),
123
+ "gemma-4-31B-it": ("google/gemma-4-31B-it", False),
124
+ "Qwen3.6-35B-A3B": ("Qwen/Qwen3.6-35B-A3B", False),
125
+ "Kimi-K2.6": ("moonshotai/Kimi-K2.6", True),
126
+ "ALLaM-7B": ("ALLaM-AI/ALLaM-7B-Instruct-preview", False),
127
+ "Qwen2.5-0.5B": ("Qwen/Qwen2.5-0.5B", False),
128
+ "Falcon-7B": ("tiiuae/falcon-7b", False),
129
+ }
130
+
131
+ print(f"{'Tokenizer':<22} {'Vocab':>10} {'AR CpT':>8} {'EN CpT':>8} {'Parity':>8}")
132
+ print("=" * 60)
133
+ for name, (repo, trc) in peers.items():
134
+ try:
135
+ t = AutoTokenizer.from_pretrained(repo, trust_remote_code=trc)
136
+ ar_t = sum(len(t.encode(x, add_special_tokens=False)) for x in ar_texts)
137
+ en_t = sum(len(t.encode(x, add_special_tokens=False)) for x in en_texts)
138
+ ar_cpt = ar_chars / ar_t
139
+ en_cpt = en_chars / en_t
140
+ print(f"{name:<22} {len(t):>10,} {ar_cpt:>8.3f} {en_cpt:>8.3f} {ar_cpt/en_cpt:>8.3f}")
141
+ except Exception as e:
142
+ print(f"{name:<22} SKIP: {e.__class__.__name__}")
143
+ ```
144
+
145
+ Expected numbers are the [headline benchmark](https://huggingface.co/almaghrabima/SARFTokenizer/blob/main/BENCHMARK.md) — any divergence means a tokenizer changed upstream.
146
+
147
+ ## Files
148
+
149
+ - `eval.parquet` �� 600 documents, schema above, ~540 KB
150
+ - `summary.json` — aggregate stats
151
+ - `README.md` — this file
152
+
153
+ ## License
154
+
155
+ Apache 2.0. Underlying text is from the `deeplatent-hq-bilingual` curated corpus; individual documents retain their original web-sourced licenses.