Skip to content

Repository files navigation

A Partition Cover Approach to Tokenization


NeurIPS 2025 | arXiv


In this work, we formulate tokenization as an optimization objective, show that it is NP-hard via a simple reduction from vertex cover, and propose a polynomial-time greedy algorithm GreedTok. Our formulation naturally relaxes to the well-studied weighted maximum coverage problem which has a simple $(1 - 1/e)$-approximation greedy algorithm.

Dataset$k$#uniq words#candidatesTimeGain from lazy updates
UN5K105,505884,630~6 secondsx23
arXiv5K881,2337,625,530~63 secondsx26
Wiki10K8,769,94393,243,449~11 minutesx68
PubMed10K6,527,61497,870,366~11 minutesx133
Wiki-chinese10K7,035,54469,728,860~8.5 minutesx90
Wiki-japanese10K2,737,55560,410,961~8.5 minutesx74
Wiki-korean10K5,459,833130,927,124~18 minutesx86

Table results shows time to solve (obtain a $k$-sized token set) from word counts. Since most of the compute is front-heavy, solving for larger $k$ size is trivial. For detailed logs, compare cpp_logs/{$data}/{$data}.log versus cpp_logs/{$data}/{$data}_fast.log.

Huggingface AutoTokenizer interface

Install the v0.15 version (for transformers >= 4), for Linux-based:

wget "https://github.com/PreferredAI/pcatt/archive/refs/tags/v0.15.zip"
unzip v0.15.zip -d pcatt
cd pcatt
pip install -r requirements.txt
pip install .

or pip install greedtok

For "training" either:

from pcatt.hf.greedtok import GreedTok
greedtok = GreedTok().train_new_from_iterator(word_iterator, 100, max_token_length=5, min_word_count=1)

or

from pcatt.hf.greedtok import GreedTok
greedtok = GreedTok().train_new_from_counts(word_count_dict, 100, max_token_length=5, min_word_count=1)

To use either:

from pcatt.hf.greedtok import GreedTok
greedtok = GreedTok.from_pretrained(greedtok_file_directory)

or

import pcatt.hf
greedtok = AutoTokenizer.from_pretrained("greedtok_file_directory")

Refer to eval_hf.ipynb for examples and tips. Note that the code in pcatt.hf is Apache 2.0 (following Huggingface Tokenizers).

Evaluations in eval_notebook.ipynb.

Citation

@inproceedings{lim2025partitioncoverapproachtokenization,
title={A Partition Cover Approach to Tokenization},
author={Jia Peng Lim and Shawn Tan and Davin Choo and Hady W. Lauw},
year={2025}
booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems},
}

About

GreedTok - aiming to be your preferred greedy tokenizer

Topics

Resources

Stars

2 stars

Watchers

4 watching

Forks

Releases

Packages

Contributors

Languages