TokenMonster: an ungreedy tokenizer that picks its own vocabulary
Ungreedy subword tokenizer and vocabulary trainer for Python, Go, C++ & Javascript
At a glance
- What is it?
- TokenMonster trains subword vocabularies and tokenizes text without the greedy merge behaviour of BPE style tokenizers. It ships pretrained vocabularies, a YAML import and export path, and implementations in Go, Python, C++ and JavaScript, but the project documentation disagrees with itself on how many vocabularies are actually ready.
- Who is it for?
- TokenMonster suits engineers who control their own training data and can retrain a vocabulary, or who want to reuse an existing GPT2 or LLaMa vocabulary while changing the tokenizer behaviour. It is a poor fit for teams that need one canonical tokenizer across many projects, since switching boundaries invalidates a previously trained model.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 106 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Ungreedy tokenization follows six branches at once
TokenMonster's central claim is about the tokenizer algorithm rather than the vocabulary. The project documentation describes an ungreedy scheme that "follows up to 6 parallel branches at a time" and that follows those six branches faster than other algorithms can follow one. Greedy tokenizers commit to the longest or highest scored merge as soon as they see it, which is cheap to implement and hard to improve on. TokenMonster keeps several candidate continuations alive and picks between them later, which costs more work per token in exchange for better token boundaries.
The encoding of case and of certain deletions leans on a separate mechanism called capcode. Capcode marker tokens are used to encode uppercasing and forward delete, which means a word that appears in both lowercase and uppercase form does not need two nearly identical vocabulary entries. The training process also claims to identify words, subwords, common phrases and figures of speech by itself, and the feature list says it works with HTML tags, sequential spaces and tabs without wasting context. Those properties are what separate it from a plain byte pair vocabulary builder, and they are the reason the project reports up to 7 characters per token depending on vocabulary size and optimization mode.
The documentation counts the pretrained vocabularies two different ways
The project ships vocabularies that you can download from Hugging Face, or request by name in the Python library, which fetches them automatically. The names encode four choices: a dataset from `code`, `english`, `englishcode` or `fiction`; a vocabulary size from `1024` up to `100256`; an optimization mode; and an optional `nocapcode` marker for vocabularies with capcode disabled, followed by a version number. Two example names are `fiction-24000-strict-v1` and `code-4096-clean-nocapcode-v1`.
Here is the problem. The opening paragraph says 442 vocabularies are provided. The feature list at the bottom says 422 pretrained vocabularies are ready for use. The vocabularies section says 442 are planned or have already been built, and warns that they are still being trained, with a note to check the Hugging Face listing to see which are currently available. So the number 442 is a plan and a partial delivery, while 422 is a claim of readiness, and neither is verifiable from the repository itself. If you are planning around a specific vocabulary name, treat the Hugging Face listing as the source of truth rather than either count. The project also has no GitHub releases, so there is no release history to cross check the vocabulary build against.
Loading a vocabulary by name in the Python library
The usage notes show the whole first run: load a vocabulary by name, then tokenize a string. No installation command is given, and the project points at the `python` directory of the repository for the Python binding. Vocabulary files themselves come from Hugging Face, or are downloaded on demand by the library when you name a vocabulary.
import tokenmonster
vocab = tokenmonster.load("englishcode-32000-consistent-v1")
tokens = vocab.tokenize("This is a test.")The name in that call has to exist in the published set. `englishcode` means the vocabulary was trained on a mix of English and code, `32000` is the vocabulary size, `consistent` is the third optimization mode, and `v1` is the version. If you want a vocabulary without capcode markers, the name carries a `nocapcode` segment instead, as in `code-4096-clean-nocapcode-v1`.
Two vocabularies are special cases. They are imports of the GPT2 Tokenizer and the LLaMa Tokenizer from Hugging Face Transformers:
vocab = tokenmonster.load("gpt2")The top level of the repository holds a `go` directory, a `python` directory, a `javascript` directory, a `training` directory, a `benchmark` directory, a `yaml_guide` directory and a `tokenmonster-cpp` directory, so the same vocabulary files are reachable from four language bindings. A browser demo is also linked, tokenizing live in native JavaScript.
Five optimization modes trade tokens against grammar complexity
Every optimization mode in TokenMonster is described as lossless, meaning the text can be reconstructed exactly from the tokens. What changes is the grammar the model has to learn. The stricter the mode, the more tokens are used for the same text, and the simpler the grammar becomes. The looser modes fit more text into fewer tokens and leave the model with a harder pattern to acquire.
`unfiltered` lets the training process choose tokens freely, and the project warns that it tends to overfit, especially on code, where it produces tokens for things like `\n\t\t\t\tif (`. That is the failure mode to fear, because such tokens memorise indentation rather than generalise. `clean` adds filters that force a vocabulary entry to begin a word with a space and limit how whitespace can be combined with other characters, and it is called the preferred choice in almost every case. `balanced` prioritizes whole words and tries to dissuade the vocabulary from things that are difficult to learn. `consistent` is described as a looser version of `strict`, aiming to limit the number of different tokens used.
The practical consequence is a budget decision. A smaller vocabulary with looser modes costs less memory and fewer tokens per inference, but the model must learn a more complicated grammar. A stricter vocabulary costs more tokens per document and buys a grammar that is easier to fit. A separate vocabulary selection guide is linked as well, so the recommended vocabulary for a given dataset and size is covered further than the mode list itself.
The gpt2 and llama imports keep token IDs but move the boundaries
The imported vocabularies are the sharpest limitation in the project, and the documentation states it plainly. The tokens and IDs of the GPT2 and LLaMa vocabularies are identical to the originals, but the tokenization of the same text is not always the same. The example given: the LLaMa Tokenizer on Hugging Face tokenizes " decoded" as ` dec` `oded`, while TokenMonster tokenizes it as ` decode` `d`.
This is the ungreedy behaviour showing its cost. If you load an existing vocabulary into TokenMonster, you inherit its token IDs, so any embedding table or model already trained on that vocabulary keeps working at the ID level. What changes is where the cuts fall between tokens. A model trained under the original tokenizer therefore sees a different segmentation of the same text at inference time, which is a mismatch you cannot detect from the vocabulary file alone.
The guidance is direct about when to use them: TokenMonster trained vocabularies are described as massively more efficient, so the instruction is to use `gpt2` and `llama` only if you have to. The practical reading is that these imports are a bridge for reusing an existing vocabulary while gaining the faster ungreedy tokenizer, and they are not a substitute for retraining.
Training cost and the shape of the repository
Training your own vocabulary is the expensive path. The project states that it can train and generate an optimal vocabulary on a 1 GB dataset within 24 hours on a typical desktop, and that vocabularies can be modified and resized after training. That last point matters for anyone who needs a specific vocabulary size for hardware reasons after the fact. The `training` directory holds the training files, and a datasets section is part of the documentation.
The repository also separates vocabulary storage from tokenizer implementations. Vocabularies can be imported and exported to and from a human-readable YAML format, and the `yaml_guide` directory holds the scripts used to import the GPT2 and LLaMa vocabularies into TokenMonster, so the YAML path is a supported interchange format rather than a debugging aid. Full support for special tokens and single byte tokens is listed among the features, which matters for models that need reserved control tokens.
Licensing is straightforward. The repository carries an MIT LICENSE file, so the code and the vocabularies are usable under permissive terms, and no copyleft obligation reaches a model you train with them. As with any MIT licensed asset, the notice files should travel with redistributed binaries and vocabulary files. The one caveat is that the pretrained vocabularies are distributed through a separate Hugging Face repository rather than from GitHub releases, so you have two places to track for versions.
Where TokenMonster is the wrong tool
TokenMonster is not a drop in replacement for a standard tokenizer when the surrounding system assumes a fixed segmentation. Anything that depends on exact token boundaries, such as a server that returns token level offsets for editing, or a prompt format validated against a specific tokenizer, will see different output once you switch. The `gpt2` and `llama` imports keep IDs stable but not boundaries, and no boundary compatibility guarantee is documented.
There is also no pure inference only mode that avoids the vocabulary model entirely, and the interesting performance claims come with a benchmark section of the project's own rather than from independent comparison. The reported figures, such as 37.5% fewer tokens at the same vocabulary size and a vocabulary reduced by 75% or more, point to pages hosted by the project author rather than to tables included in the repository text, so they are claims you have to check against your own corpus and your own model before you believe them.
Finally, the project is not presented as a streaming tokenizer for low latency serving, and the feature list leads with training and vocabulary generation. If your problem is choosing between three known tokenizers for an existing pipeline, this is far more machinery than the job needs. If your problem is that your corpus does not fit the assumptions of an existing vocabulary, and you can afford a day of training on a desktop, the tool matches the problem well.
Editorial conclusion
TokenMonster suits engineers who control their own training data and can retrain a vocabulary, or who want to reuse an existing GPT2 or LLaMa vocabulary while changing the tokenizer behaviour. It is a poor fit for teams that need one canonical tokenizer across many projects, since switching boundaries invalidates a previously trained model. Before adopting it, check the vocabulary listing on Hugging Face for your dataset and vocabulary size, read the optimization mode guidance to pick the grammar difficulty you are willing to pay for, and confirm that the language bindings in the repository cover the runtime you actually ship.
Frequently asked questions
How do I install TokenMonster for use in Python?
The project points at the python directory of the repository for the Python binding, and the usage notes show the library loading a vocabulary by name. No installation command for the package itself is documented. Vocabulary files are downloaded from Hugging Face, or fetched automatically by the library when you name a vocabulary.
Which TokenMonster vocabulary should I pick for code?
Choose a code dataset name with the clean optimization mode, for example code-4096-clean-nocapcode-v1. Clean is called the preferred mode in almost every case, and the unfiltered mode is warned against on code because it produces tokens for things like `\n\t\t\t\tif (`. A nocapcode name disables the capcode marker tokens.
Can I use the GPT2 or LLaMa vocabulary with TokenMonster?
Yes, both are included as imports of the Hugging Face Transformers tokenizers. The tokens and IDs are identical to the originals, but the tokenization boundaries are not always identical. The guidance is to use gpt2 and llama only if you have to, since trained TokenMonster vocabularies are more efficient.
How long does it take to train a TokenMonster vocabulary?
An optimal vocabulary can be trained and generated on a 1 GB dataset within 24 hours on a typical desktop. Vocabularies can also be modified and resized after training. The training files live in the training directory of the repository.
Does TokenMonster publish releases I can pin against?
The repository has no GitHub releases, and the last push was on 2026-07-10. Versioning of the pretrained vocabularies is handled inside the vocabulary names instead, where a trailing segment such as v1 marks the vocabulary version. Check the Hugging Face listing for the vocabulary builds.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/alasdairforsythe-tokenmonster)Was this useful?