Introduction
A language model does not read text directly. A tokenizer first splits the text into
tokens, whole words or pieces of words, and turns each into a number from the model’s
vocabulary. tokenizer.json is the file that holds a complete tokenizer for
Hugging Face’s
tokenizers library: every step of
the process, the vocabulary and the rules. Nearly every language model on Hugging Face
ships one beside its weights.
It usually comes with tokenizer_config.json, which names the tokenizer
class, the special tokens and often the chat template, and sometimes
special_tokens_map.json. Older models used vocab.txt,
vocab.json and merges.txt, or a SentencePiece
tokenizer.model, instead.
Structure
The file is one JSON object. The library writes its keys in this order, with the model last:
version: the version of the file formattruncationandpadding: default settings, ornulladded_tokens: special tokens such as the start and end of text, each with its ID and contentnormalizer: clean-up of the text first, such as Unicode normalisation or lower casepre_tokenizer: the first split, for example on spaces and punctuation, or into bytespost_processor: tokens added around the result, such as a start tokendecoder: how to turn tokens back into textmodel: the algorithm and its data;typeisBPE,WordPiece,UnigramorWordLevel,vocabmaps each token to its ID, and a BPE model also lists itsmerges
The keys and models page lists every field from the library’s source.
The vocabulary and merges make the file large, often several megabytes for a model with a vocabulary of 100,000 tokens or more.
Not described
The keys page follows the Hugging Face tokenizers library (the top-level
keys at release v0.21.0, the component objects at v0.23.3).
Known, not yet covered
- Reference: the
Precompilednormaliser's fields (in the separatespm_precompiledcrate), the exact splitting rules of theUnicodeScriptsandFixedLengthpre-tokenisers, the Nmt normaliser's character list, and SentencePiece.modeland tiktoken-style vocabulary files. The component objects, the truncation and padding objects and the files around tokenizer.json (tokenizer_config.json,special_tokens_map.json,vocab.json,merges.txt,vocab.txt) are now described. The component and model sections were read at tokenizers v0.23.3; only the older top-level section's prose cites v0.21.0. - Viewer: not re-audited in this pass.
Also used for
- Browser extension manifest – The JSON manifest of a browser extension: its name, permissions and scripts.
- GeoJSON – Map points, lines and areas with properties, written as JSON.
- Hugging Face model config (config.json) – config.json: a model’s architecture and sizes, read before the weights.
- JSON Schema – A JSON document that describes and validates other JSON documents.
- JavaScript Object Notation – Text format for objects, arrays, strings, numbers and booleans.
- Lottie animation – Vector animations as JSON, exported from After Effects and played in apps and web pages.
- Visual Studio Code settings – VS Code’s settings.json: dotted setting IDs in JSON with comments.
- jCal: iCalendar in JSON – iCalendar as JSON: events, to-dos and time zones as nested arrays.
- jCard: vCard in JSON – vCard 4.0 contacts as JSON: names, numbers and addresses as arrays.
- npm package manifest (package.json) – A JavaScript package’s name, version, scripts and dependencies, in JSON.
Links
Software
- Hugging Face Transformers – loads it with
AutoTokenizer(Python) - Hugging Face – model hub that shows a model’s files and tokenizer settings (web)
Developers
- tokenizers – the library that defines the file (Rust, Python, Node.js)
- Transformers.js – reads the same files in the browser (JavaScript)
Reference
- Tokenizers documentation – Hugging Face’s guide to the tokenizer pipeline and its parts