Upload benchmarks/gemma_baseline_summary.md with huggingface_hub
Browse files
benchmarks/gemma_baseline_summary.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gemma Baseline: OIM v0 vs the Actual Base-Model Tokenizer
|
| 2 |
+
|
| 3 |
+
Date: 2026-06-27
|
| 4 |
+
Status: decision-relevant baseline added. Closes the "compare Gemma" gap that
|
| 5 |
+
earlier pilots left open because Gemma was gated.
|
| 6 |
+
|
| 7 |
+
## Why This Matters
|
| 8 |
+
|
| 9 |
+
Every prior tokenizer audit compared OIM against XLM-R, GPT-2, and cl100k, but
|
| 10 |
+
**not** against Gemma β the tokenizer our own models (`google/gemma-4-E2B-it`)
|
| 11 |
+
actually ship with. That made the central decision ("is an OIM tokenizer worth
|
| 12 |
+
it for our Gemma fine-tunes?") unanswerable.
|
| 13 |
+
|
| 14 |
+
The Gemma tokenizer turned out to be loadable **without gated access** via the
|
| 15 |
+
non-gated Unsloth mirror `unsloth/gemma-4-E2B-it` (vocab 262,144 β identical to
|
| 16 |
+
our base). So we can now benchmark against the real baseline, no token required.
|
| 17 |
+
|
| 18 |
+
## Method
|
| 19 |
+
|
| 20 |
+
- Tokenizers: `unsloth/gemma-4-E2B-it` (our base), `tiktoken/cl100k_base`,
|
| 21 |
+
OIM `oim-script-equitable-regional-sp-bpe-32k-native-weighted-v0`.
|
| 22 |
+
- Held-out sets (same files used for the v0 audit):
|
| 23 |
+
- mixed: `script_equitable_v0_heldout.jsonl` (10,000 rows)
|
| 24 |
+
- Latin: `script_equitable_v0_latn_heldout.jsonl` (9,500 rows)
|
| 25 |
+
- native: derived from the mixed heldout, `script != Latn` (500 rows across
|
| 26 |
+
jawi, sunda, jawa, lampung, batak, bali, pegon, lontara)
|
| 27 |
+
- Metric: tokens/word, chars/token, fragmented-word rate over identical text.
|
| 28 |
+
|
| 29 |
+
## Result
|
| 30 |
+
|
| 31 |
+
| slice | tokenizer | tokens/word | chars/token | fragmented words |
|
| 32 |
+
|---|---|---:|---:|---:|
|
| 33 |
+
| mixed | gemma-4-E2B-it | 2.026 | 3.439 | 71.5% |
|
| 34 |
+
| mixed | cl100k_base | 2.409 | 2.892 | 80.5% |
|
| 35 |
+
| mixed | **OIM v0** | **1.526** | 4.567 | **22.4%** |
|
| 36 |
+
| Latin | gemma-4-E2B-it | 1.992 | 3.515 | 71.5% |
|
| 37 |
+
| Latin | cl100k_base | 2.377 | 2.946 | 80.4% |
|
| 38 |
+
| Latin | **OIM v0** | **1.527** | 4.585 | **22.2%** |
|
| 39 |
+
| native | gemma-4-E2B-it | 5.785 | 0.501 | 78.0% |
|
| 40 |
+
| native | cl100k_base | 5.972 | 0.485 | 82.6% |
|
| 41 |
+
| native | **OIM v0** | **1.313** | 2.206 | **36.9%** |
|
| 42 |
+
|
| 43 |
+
OIM reduction vs Gemma in tokens/word:
|
| 44 |
+
|
| 45 |
+
- mixed: **β24.7%** (2.026 β 1.526)
|
| 46 |
+
- Latin: **β23.3%** (1.992 β 1.527)
|
| 47 |
+
- native aksara: **β77.3%, i.e. 4.4Γ fewer tokens** (5.785 β 1.313)
|
| 48 |
+
|
| 49 |
+
## Interpretation
|
| 50 |
+
|
| 51 |
+
- **Gemma byte-fragments native aksara.** chars/token = 0.50 means Gemma emits
|
| 52 |
+
~2 tokens per character on Bali/Jawa/Sunda/Lontara/etc. β the Bengali-BPE
|
| 53 |
+
byte-fallback failure mode, now confirmed for our exact base model on
|
| 54 |
+
Indonesian scripts. cl100k is no better (0.49). OIM keeps real Unicode-aware
|
| 55 |
+
aksara sub-words (chars/token 2.21).
|
| 56 |
+
- **Even Latin regional text pays a Gemma tax.** OIM saves ~23% tokens/word and
|
| 57 |
+
cuts fragmented words from 71.5% to ~22% on Latin-script Indonesian/regional
|
| 58 |
+
text β not just aksara.
|
| 59 |
+
- **Decision gate cleared.** The strategy doc's threshold was "β₯25% tokens/word
|
| 60 |
+
reduction vs Gemma/XLM-R on held-out native script, plus downstream CPT win."
|
| 61 |
+
The native-script reduction vs Gemma is **77%**, far past the 25% gate. The
|
| 62 |
+
remaining gate condition is the downstream CPT validation win, which needs a
|
| 63 |
+
vocabulary-extension + CPT experiment (GPU).
|
| 64 |
+
|
| 65 |
+
## Caveats
|
| 66 |
+
|
| 67 |
+
- The native slice is 500 rows and mixes Brahmic (bali, jawa, sunda, lontara,
|
| 68 |
+
batak), Arabic-script (jawi, pegon), and Lampung proxy/Latin notation. The
|
| 69 |
+
aggregate native number is dominated by whichever scripts have the most rows;
|
| 70 |
+
per-script breakdown lives in
|
| 71 |
+
`tokenizer_benchmark_script_equitable_v0_by_native_script.md`.
|
| 72 |
+
- tokens/word for SentencePiece on aksara can be distorted by whitespace-based
|
| 73 |
+
word counting; the relative comparison on identical text is the valid signal,
|
| 74 |
+
and fragmented-word rate corroborates it.
|
| 75 |
+
- This measures compression only. It does **not** yet prove a modeling win β
|
| 76 |
+
that requires vocab-extension + CPT and a validation-loss comparison.
|
| 77 |
+
|
| 78 |
+
## Reproduce
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
OIM=artifacts/tokenizer_hf_preview/oim-script-equitable-regional-sp-bpe-32k-native-weighted-v0/oim-script-equitable-regional-v0-native-weighted-32k-sp-bpe.model
|
| 82 |
+
uv run python scripts/tokenizer_benchmark.py \
|
| 83 |
+
--input artifacts/tokenizer_corpora/scale_v0/script_equitable_v0_heldout.jsonl \
|
| 84 |
+
--language regional-mixed --field text \
|
| 85 |
+
--tokenizer unsloth/gemma-4-E2B-it \
|
| 86 |
+
--sentencepiece-model "$OIM" --tiktoken cl100k_base \
|
| 87 |
+
--output-md docs/data_audits/tokenizer_benchmark_gemma_vs_oim_mixed.md
|
| 88 |
+
# repeat with the latin and native-derived heldout files
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Next
|
| 92 |
+
|
| 93 |
+
1. Vocabulary-extension experiment: add OIM's high-value aksara tokens to the
|
| 94 |
+
Gemma vocab, initialize embeddings, run short CPT, measure validation loss.
|
| 95 |
+
This converts the compression win into a modeling claim.
|
| 96 |
+
2. Verify / re-upload the private HF artifact (blocked on a local HF token).
|
| 97 |
+
3. Per-script native heldouts with larger row counts once more native corpora
|
| 98 |
+
are sourced.
|