There is no separate specification; tokenizer.json is whatever the
Hugging Face tokenizers
library serialises. This page follows its Rust source at release
v0.21.0
(tokenizer/serialization.rs, tokenizer/added_vocabulary.rs,
the model serialization.rs files, utils/truncation.rs,
utils/padding.rs and the component modules), read 2026-11-12. Newer
releases reorganise the source, so later fields may differ.
Top-level keys
One JSON object, written in this order:
| Key | Value |
|---|---|
version | The serialisation version, "1.0". |
truncation | null, or direction, max_length, strategy and stride. |
padding | null, or strategy, direction, pad_to_multiple_of, pad_id, pad_type_id and pad_token. |
added_tokens | The added tokens, in ascending ID order. |
normalizer | null or a normaliser object. |
pre_tokenizer | null or a pre-tokeniser object. |
post_processor | null or a post-processor object. |
decoder | null or a decoder object. |
model | The model, with its vocabulary. |
The component objects carry a type naming the component. The library
has normalisers such as NFC, NFD, NFKC, NFKD, lower-casing, accent stripping, BERT,
replace, prepend, byte-level, precompiled and sequences of others; pre-tokenisers
such as BERT, byte-level, whitespace, punctuation, digits, Metaspace, split,
Unicode scripts and sequences; post-processors for BERT, RoBERTa, byte-level,
templates and sequences; and decoders such as BPE, byte-level, byte fallback, CTC,
fuse, Metaspace, replace, strip, WordPiece and sequences.
Added tokens
| Field | Meaning |
|---|---|
id | The token’s ID. |
content | The token text. |
single_word | Whether it must be a whole word or can match inside words. |
lstrip, rstrip | Whether to strip white space on its left or right. |
normalized | Whether it is matched after normalisation. |
special | Whether it is a special token. |
Models
type | Fields, in order |
|---|---|
BPE | dropout, unk_token, continuing_subword_prefix, end_of_word_suffix, fuse_unk, byte_fallback, ignore_merges, vocab (token to ID, in ID order), merges (pairs of tokens in rank order, written as two-element arrays; the older form "a b" as one string is still read). |
WordPiece | unk_token, continuing_subword_prefix, max_input_chars_per_word, vocab. |
Unigram | unk_id, vocab (a list of [piece, score] pairs), byte_fallback. |
WordLevel | vocab, unk_token. |
Component objects
This section was read from the library at its current release tag,
v0.23.3 (the GitHub releases API names it the latest), in the folders
normalizers, pre_tokenizers, processors,
decoders, models, tokenizer and utils of
tokenizers/src, read 2026-11-13. Every component is a JSON object with a
type string equal to the Rust type's name, then its fields in the order below;
the model objects and the top-level keys above matched that source. A component can be
null at its place in the tokenizer. A reader accepts an older "legacy" form with no
type for several components by trying the variants in turn.
Normalisers
type | Fields (defaults) and behaviour |
|---|---|
BertNormalizer | clean_text (true: remove NUL, U+FFFD and control characters, turn all whitespace into a space; tab, line feed and carriage return count as whitespace), handle_chinese_chars (true: put spaces around characters in the CJK blocks 4E00–9FFF, 3400–4DBF, 20000–2A6DF, 2A700–2B73F, 2B740–2B81F, 2B920–2CEAF, F900–FAFF and 2F800–2FA1F), strip_accents (null, meaning the value of lowercase; when applied, NFD then remove non-spacing marks), lowercase (true). |
Strip | strip_left, strip_right (bool each). |
StripAccents, NFC, NFD, NFKC, NFKD, Lowercase, Nmt | No fields. StripAccents removes combining marks; the four Unicode forms are the standard ones; Nmt removes a fixed list of control characters (the code's list was not copied here). |
Sequence | normalizers: array of normaliser objects, applied in order. |
Replace | pattern (an object {"String": "…"} for a literal or {"Regex": "…"}), content (the replacement text). |
Prepend | prepend: text added at the start of a non-empty string. |
ByteLevel | No fields; maps bytes to the GPT-2 printable characters. |
Precompiled | Comes from the separate spm_precompiled crate, which was not read, so its fields (a SentencePiece character map) are not described here. |
Pre-tokenisers
type | Fields (defaults) and behaviour |
|---|---|
BertPreTokenizer | No fields. Splits on whitespace (dropped) and isolates punctuation. |
ByteLevel | add_prefix_space (true), trim_offsets (true), use_regex (true, default when absent: use the GPT-2 regex to split; false to supply your own splitting). |
Delimiter | delimiter: one character. |
Metaspace | replacement (one character, usually U+2581), prepend_scheme (first, never or always; default when absent always), split (default true when absent). Replaces whitespace with replacement, then splits on it. The legacy add_prefix_space key is still read: false forces never and a mismatch with prepend_scheme is an error. |
Whitespace, WhitespaceSplit | No fields. Whitespace splits with the regex \w+|[^\w\s]+; WhitespaceSplit splits on whitespace only. |
Sequence | pretokenizers: array of pre-tokeniser objects. |
Split | pattern ({"String": …} or {"Regex": …}), behavior (see below), invert (bool). |
Punctuation | behavior (default Isolated). |
Digits | individual_digits (default false: groups of digits stay together; true: every digit alone). |
UnicodeScripts | No fields (the splitting rule's code was not read). |
FixedLength | length (default 5 when absent); the splitting code was not read. |
behavior is one of Removed, Isolated,
MergedWithPrevious, MergedWithNext, Contiguous
(the library's examples: on "the-final--countdown" with "-" as the delimiter,
Contiguous gives "the", "-", "final", "--", "countdown", and MergedWithNext gives "the",
"-final", "-", "-countdown").
Post-processors
type | Fields (defaults) and behaviour |
|---|---|
BertProcessing | sep and cls: each a two-element array [token, id] (defaults ["[SEP]", 102] and ["[CLS]", 101]). Adds [CLS] first and [SEP] after each sequence (2 tokens added for one sequence, 3 for a pair). |
RobertaProcessing | sep (["</s>", 2]), cls (["<s>", 0]), trim_offsets (true), add_prefix_space (true). A reader tries Roberta before Bert because serde does not check the tags. |
ByteLevel | The same object as the byte-level pre-tokeniser: add_prefix_space, trim_offsets, use_regex; it fixes offsets. |
TemplateProcessing | single and pair (arrays of pieces; defaults $0 and $A:0 $B:1), special_tokens (an object from token name to {"id", "ids", "tokens"}, keys in sorted order). A piece is {"Sequence": {"id": "A" or "B", "type_id": n}} or {"SpecialToken": {"id": name, "type_id": n}}. In the template text form, $A or $B picks the sequence (type id 0), $0, $1… the type id with sequence A, $A:0 and $B:1 both, and any other word name or name:type_id a special token; the ids given are added without any check against the vocabulary. |
Sequence | processors: array of post-processor objects. |
Decoders
type | Fields (defaults) and behaviour |
|---|---|
BPEDecoder | suffix (</w>): the end-of-word marker. |
ByteLevel | The pre-tokeniser's object (same three fields). |
WordPiece | prefix (##), cleanup (true: tidy spaces before punctuation and some abbreviated English forms). |
Metaspace | The pre-tokeniser's object (replacement, prepend_scheme, split). |
CTC | pad_token (<pad>), word_delimiter_token (|, replaced by a space), cleanup (true). |
Sequence | decoders: array of decoder objects. |
Replace | The normaliser Replace object (pattern, content). |
Fuse, ByteFallback | No fields. Fuse joins all tokens into one string; ByteFallback turns byte tokens back into bytes and gives U+FFFD for each byte that cannot be decoded. |
Strip | content (one character), start, stop: from each token, remove up to start leading and up to stop trailing occurrences of content (it stops at the first different character). |
Truncation and padding objects
truncation:direction("Left"or"Right", default Right when absent),max_length(default 512 when built by default),strategy("LongestFirst","OnlyFirst"or"OnlySecond"),stride(0).padding:strategy("BatchLongest"or{"Fixed": n}),direction("Left"or"Right"),pad_to_multiple_of(integer or null),pad_id,pad_type_id(integers),pad_token(string).- Added token fields as on the table above;
AddedToken.from(content, special)givesnormalized= not special.
The files around tokenizer.json
From tokenization_utils_base.py and tokenization_utils_tokenizers.py of
Hugging Face transformers (main branch) and, for the vocabulary files, the tokenizers models'
save functions (read 2026-11-13).
tokenizer_config.json: written bysave_pretrainedwithjson.dumps(…, indent=2, sort_keys=True, ensure_ascii=False)and a final newline. It starts from the tokenizer's saved init arguments, then addsmodel_max_length, the named special tokens (bos_token,eos_token,unk_token,sep_token,pad_token,cls_token,mask_token, only those set),extra_special_tokenswhen there are some (an older name wasadditional_special_tokens, converted on load),chat_template(a string, or a list of{"name", "template"}when there are several; chat templates are also written as separate.jinjafiles by default),response_template,chat_control_tokens,init_inputswhen present,added_tokens_decoder(a map from token id as a string to the added-token fields),tokenizer_class(the class name, without a trailingFastwhen the slow class can be saved),auto_mapandprocessor_classwhen set. It removesname_or_path,special_tokens_map_file,tokenizer_file,device_map,slow_tokenizer_classandfiles_loaded, and the vocabulary file name keys. The tokenizers-backed classes also dropadded_tokens_decoderandadditional_special_tokens. An added token inside the config is written as an object of its fields plus"__type": "AddedToken"(convert_added_tokens, called withadd_type_field=True); a reader turns such an object back into an added token.special_tokens_map.json: now a legacy file. The loader still reads it when a repository has one and merges the keys into the init arguments; the currentsave_pretrainedwrites the special tokens intotokenizer_config.jsoninstead (seespecial_tokens_mapthere). The same loader namesadded_tokens.jsonas kept only for legacy.vocab.json: for BPE and WordLevel models the tokenizers library writes the vocabulary as one JSON object from token string to id, with entries in id order and no spaces (serde_json::to_string).merges.txt: the BPE merges: first the line#version: 0.2, then one merge per line as the two token strings separated by a space, in rank order (the order of merging).vocab.txt: a WordPiece vocabulary is a plain text file with one token per line in id order (the line number, counting from 0, is the id).- With a name prefix the files are called
<name>-vocab.json,<name>-merges.txt,<name>-vocab.txt.