CoolFace
Datasetpublic

Abzalbek89/kk-tokenizer-fertility-baseline

Kazakh Tokenizer Fertility Baseline Reproducible fertility benchmark of subword tokenizers on the Kazakh language. Companion artifact for the paper "Tokenizer Optimization for Kazakh Small Language Models" (in preparation, target: ACM TALLIP). Headline numbers Tokenizer Fertility ๐Ÿฅ‡ Best overall kk-bpe-32k 1.679 ๐Ÿšจ Worst GPT-4 (cl100k) 5.895 GPT-4 penalty GPT-4 (cl100k) is 3.51ร— worse than the best Kazakh-trained tokenizer โ†’ The custom Kazakhโ€ฆ See the full description on the dataset page: https://huggingface.co/datasets/Abzalbek89/kk-tokenizer-fertility-baseline.

sourceHugging Faceapache-2.0updated 3mo agoView on Hugging Face
0likes601downloads
Dataset Card

Kazakh Tokenizer Fertility Baseline

Reproducible fertility benchmark of subword tokenizers on the Kazakh language. Companion artifact for the paper "Tokenizer Optimization for Kazakh Small Language Models" (in preparation, target: ACM TALLIP).

Headline numbers

TokenizerFertility
๐Ÿฅ‡ Best overallkk-bpe-32k1.679
๐Ÿšจ WorstGPT-4 (cl100k)5.895
GPT-4 penaltyGPT-4 (cl100k) is 3.51ร— worse than the best Kazakh-trained tokenizer

โ†’ The custom Kazakh BPE tokenizer is 3.51ร— more efficient than GPT-4 for Kazakh text, which translates to ~72% lower API cost and ~3.5ร— longer effective context window.

Full ranking (13 tokenizers)

Ours โ€” Kazakh-trained, no morphology pre-segmentation

TokenizerVocabFertility โ†“Chars/Token โ†‘
kk-bpe-32k32,0001.6794.672
kk-sp-bpe-32k32,0001.7584.463
kk-sp-unigram-32k32,0001.7624.454
kk-hf-unigram-32k32,0002.0263.872

Ours โ€” Kazakh-trained, morphology-aware (Morfessor โ†’ tokenizer)

TokenizerVocabFertility โ†“Chars/Token โ†‘
kk-morph-hf-bpe-32k32,0001.7614.456
kk-morph-sp-unigram-32k32,0001.9454.034
kk-morph-hf-unigram-32k32,0002.3463.345

Reference โ€” multilingual / industry tokenizers

TokenizerVocabFertility โ†“Chars/Token โ†‘
XLM-R250,0022.1813.597
GPT-4o (o200k)200,0192.5993.020
mBERT119,5472.9292.679
Qwen2.5151,6434.7861.639
Llama-3128,0004.8031.634
GPT-4 (cl100k)100,2775.8951.331

Methodology

Held-out evaluation set: 2,966,207 whitespace-words (โ‰ˆ15K documents) from the validation split of `Abzalbek89/corpus_clean`.

Metrics:

  • โ€”Fertility = total tokens / total whitespace-words (lower is better).
  • โ€”Compression (chars/token) = total characters / total tokens (higher is better).
  • โ€”Compression (bytes/token) = total UTF-8 bytes / total tokens (higher is better).

Trained tokenizers (vocab = 32,000, all share the same training corpus):

  • โ€”kk-bpe-32k โ€” HF tokenizers ByteLevel BPE
  • โ€”kk-sp-bpe-32k โ€” SentencePiece BPE (character_coverage=1.0, NFKC)
  • โ€”kk-sp-unigram-32k โ€” SentencePiece Unigram
  • โ€”kk-hf-unigram-32k โ€” HF tokenizers Unigram with ByteLevel pre-tok
  • โ€”kk-morph-hf-bpe-32k โ€” HF BPE on Morfessor-segmented corpus
  • โ€”kk-morph-hf-unigram-32k โ€” HF Unigram on Morfessor-segmented corpus
  • โ€”kk-morph-sp-unigram-32k โ€” SentencePiece Unigram on Morfessor-segmented corpus

Reference tokenizers: mBERT, XLM-R, Llama-3, Qwen 2.5, GPT-4 (cl100k_base), GPT-4o (o200k_base).

Files

PathDescription
experiment.pyv1 โ€” single Unigram baseline
experiment_v2.pyv2 โ€” extended (BPE/Unigram across libraries)
experiment_v3_fix.pyv2 fix โ€” re-measure SentencePiece tokenizers via raw SentencePieceProcessor
experiment_morph.pyExperiment 2 โ€” morphology-aware variants
morfessor.bintrained Morfessor segmentation model (top-1M Kazakh words)
v2/fertility_v2.csv, .json, .pngfixed v2 numbers
v3/fertility_v3.csv, .json, .pngextended v3 numbers (with morph-aware)
v3/RESULTS_V3.mdhuman-readable v3 report

Reproducing

On a vast.ai / RunPod / Colab instance with โ‰ฅ30GB disk and โ‰ฅ16GB RAM:

bash
pip install 'datasets>=2.14' 'transformers>=4.45' 'tokenizers>=0.20' \
            'sentencepiece>=0.2.0' 'huggingface_hub>=0.25' \
            tiktoken matplotlib morfessor

export HF_TOKEN=hf_...   # write access
export HF_USER=Abzalbek89

curl -fsSL -o experiment_morph.py \
  https://huggingface.co/datasets/Abzalbek89/kk-tokenizer-fertility-baseline/resolve/main/experiment_morph.py
python experiment_morph.py

Total runtime: ~30 min on cached Morfessor model, ~70 min cold start.

Companion tokenizer repos

ยน Morphology-aware variants โ€” apply Morfessor (morfessor.bin in this repo) before encoding.

Citation

bibtex
@misc{kk_tokenizer_fertility_2026,
  title        = {Kazakh Tokenizer Fertility Baseline},
  author       = {Abzalbek Ulasbek},
  year         = {2026},
  howpublished = {\url{https://huggingface.co/datasets/Abzalbek89/kk-tokenizer-fertility-baseline}},
}

License

Apache 2.0


Last updated: fertilityv3.csv (13 tokenizers)_