Grouped tokenizer: English with French, Chinese, Swahili and Afrikaans (32k)
A byte-level BPE tokenizer with 32,768 tokens, trained with grouptok on 4M sentence pairs: 1M pairs of English with each of French, Chinese, Swahili and Afrikaans.
grouptok aligns the subwords of every pair with a neural word aligner. Tokens that translate each other then share a group, for example house, huis (Afrikaans) and nyumba (Swahili). Every token is a lossless (group, member) pair: its group and its position within that group.
- As an ordinary tokenizer, it loads with
transformers.AutoTokenizer, which ignores the groups. - For a model with a grouped vocabulary,
groups.jsonholds the grouping. Such a model has one embedding row per group plus a few member rows, and predicts the group and then the member.
| Vocabulary | 32,768 tokens (byte-level BPE, so any text encodes) |
| Groups | 22,892 |
| Multi-member groups | 4,985, holding 14,861 tokens (45% of the vocabulary); 1,364 of them contain a Chinese token |
| Group sizes | 2 members: 2,389 groups · 3: 1,291 · 4: 711 · 5: 344 · 6: 145 · 7: 64 · 8: 41 (at most 8) |
| Lexical rows of a grouped model | 22,892 groups + 8 member rows, 30% fewer than the 32,768 rows of an ungrouped one |
| Reserved tokens | 24 (ids 0–23), never grouped |
| Chat template | ChatML style (<|im_start|>role\n…<|im_end|>), with <think> support |
Files
.
├── README.md this card
├── tokenizer.json the BPE in Hugging Face tokenizers format: vocabulary, merges, pre-tokenizer (byte-level) and the 24 reserved tokens
├── tokenizer_config.json transformers settings: PreTrainedTokenizerFast, pad / bos / eos / unk tokens, the chat template
└── groups.json the grouping: the group and member of every token id, and the reserved tokens
groups.json is one JSON object:
| Key | Value |
|---|---|
token_group |
list of 32,768 ints: the group id of token i (0 to 22,891) |
token_member |
list of 32,768 ints: the position of token i within its group (0 to 7) |
max_group_size |
8, the largest group size, i.e. the number of member rows a grouped model needs |
special_tokens |
["<|endoftext|>", "<|im_start|>", "<|im_end|>"] |
additional_tokens |
the other 21 reserved tokens, in id order (<think>, </think>, then Qwen2.5's) |
A token's (group, member) pair is unique, so token ids and pairs convert into each other without loss. Tokens without a translation, the reserved tokens, and byte fragments that are only part of a UTF-8 character each form a group of their own, as member 0.
Usage
As an ordinary tokenizer, with transformers:
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("henryhale/grouptok-en-fr-zh-sw-af-32k")
ids = tokenizer("The house is new.", add_special_tokens=False).input_ids
prompt = tokenizer.apply_chat_template([{"role": "user", "content": "Translate into Swahili:\nThe house is new."}],
tokenize=False, add_generation_prompt=True)
With the groups, with grouptok (pip install grouptok), which loads a local directory:
from huggingface_hub import snapshot_download
from grouptok import GroupedTokenizer
tokenizer = GroupedTokenizer.from_pretrained(snapshot_download("henryhale/grouptok-en-fr-zh-sw-af-32k"))
ids = tokenizer.encode("The house is new.")
tokenizer.pairs(ids) # [(group, member), ...], one per token
tokenizer.group_of(" house") # [' house', ' huis', ' nyumba', ' home', ' nyumbani']
tokenizer.readable_groups() # every multi-member group, as text
Or read groups.json directly, for example to build a model's group and member lookup tables:
import json
groups = json.load(open("groups.json"))
group_of_token, member_of_token = groups["token_group"], groups["token_member"]
num_groups, num_members = max(group_of_token) + 1, groups["max_group_size"]
Reserved tokens
| Id | Token | Role |
|---|---|---|
| 0 | <|endoftext|> |
padding (also the unknown token, which byte-level BPE never needs) |
| 1 | <|im_start|> |
beginning of a message (bos) |
| 2 | <|im_end|> |
end of a message (eos) |
| 3, 4 | <think>, </think> |
reasoning delimiters used by the chat template |
| 5–23 | <|object_ref_start|>, <|object_ref_end|>, <|box_start|>, <|box_end|>, <|quad_start|>, <|quad_end|>, <|vision_start|>, <|vision_end|>, <|vision_pad|>, <|image_pad|>, <|video_pad|>, <tool_call>, </tool_call>, <|fim_prefix|>, <|fim_middle|>, <|fim_suffix|>, <|fim_pad|>, <|repo_name|>, <|file_sep|> |
Qwen2.5's other reserved tokens, kept for later use |
The reserved tokens have Qwen2.5's names but not its ids (Qwen2.5 puts them after its 151k-token vocabulary). Ids 0–2 are special tokens; 3–23 are added tokens that are not stripped when decoding.
Training
The tokenizer was trained with grouptok on Kaggle using one T4 GPU.
| Language | Dataset | Pairs | What they are |
|---|---|---|---|
| French | wmt/wmt14 fr-en |
the first 1M | Europarl (European Parliament proceedings); WMT19 has no French-English |
| Chinese | wmt/wmt19 zh-en |
the first 1M | 311,542 News Commentary sentences, then about 688k Wikipedia titles |
| Swahili | michsethowusu/english-swahili_sentence-pairs |
the best-scored 1M | NLLB's mined pairs (the eng-swh pairs of allenai/wmt22_african), sorted by alignment score |
| Afrikaans | michsethowusu/afrikaans-english_sentence-pairs |
the best-scored 1M | NLLB's mined pairs (afr-eng), sorted by alignment score |
BPE. A byte-level BPE with 32,768 tokens, the 24 reserved ones included, is trained on both sides of all 4M pairs.
Alignment.
- French and Chinese use awesome-align's fine-tuned mBERT (
aneuraz/awesome-align-with-co, whose fine-tuning pairs include fr-en and zh-en). - Swahili and Afrikaans share one pass of XLM-R base (
FacebookAI/xlm-roberta-base), since awesome-align was not fine-tuned on either. - Both use vectors from layer 8. A link is kept when its softmax similarity exceeds 10⁻³ in both directions.
- Sentences longer than 512 wordpieces are encoded in overlapping windows. Each BPE token takes the mean of the wordpiece vectors it overlaps.
- French and Chinese use awesome-align's fine-tuned mBERT (
Grouping. The link counts of the aligner passes are pooled. Token pairs with at least 5 links and a Dice score of at least 0.1 are visited in decreasing Dice order:
- two ungrouped tokens start a group;
- a token joins its partner's group if that group has fewer than 8 members;
- two existing groups are never merged.
Reserved tokens and byte fragments are never grouped. English is the first side of every pair, so member 0 of a group is usually its English word.
Example groups
Chinese tokens carry no leading space, because Chinese has none.
| Group | Members |
|---|---|
| house | house, huis (af), nyumba (sw), home, nyumbani (sw, "at home") |
| water | water, maji (sw), eau (fr), 水 (zh) |
| world | world, wêreld (af), monde (fr), 世界 (zh), ulimwengu (sw) |
| children | children, kinders (af), watoto (sw), enfants (fr), kids |
| government | government, 政府 (zh), regering (af), serikali (sw) |
| country | countries, pays (fr), country, land (af), nchi (sw), lande (af), 国家 (zh) |
| economic | economic, économique, économiques (fr), 经济 (zh), Economic, ekonomiese (af), 的经济 (zh, "'s economy") |
| new | new, nuwe (af), nouveaux, nouvelle, nouvelles (fr), mpya (sw), nouveau (fr), 新 (zh) |
| health | health, santé (fr), gesondheid (af), afya (sw), Health, Afya |
| the | the, die (af), la, le, l, les (fr) |
Members are listed in member order (member 0 first).
Limitations
- The groups come from automatic alignment and are not checked against a dictionary.
- Many groups also gather inflections (
nouveau…nouvelles), near-synonyms (home,kids) or case variants (Health). - Some groups are led by a related form: the group of
countryhascountriesas its member 0. - Function words group by role:
thewith Afrikaansdieand the French articles.
- Many groups also gather inflections (
- The training text is unevenly distributed across domains.
- About 69% of the Chinese pairs are Wikipedia titles, so Chinese groups lean towards names and terms.
- The top-scored NLLB pairs of Swahili and Afrikaans include many religious texts.
- The French pairs are parliamentary speech.
- Other languages encode byte by byte or in small pieces, as with any BPE, and have no translation groups.
- The groups only matter to a model built for them. An ordinary model can use
tokenizer.jsonalone, as a plain 32k BPE.
License
The tokenizer files are released under the Apache 2.0 license. The training data keeps its own terms; see each dataset's card.
Citation
If you use this tokenizer, please cite it and grouptok:
@misc{grouptok_en_fr_zh_sw_af_32k,
title = {grouptok-en-fr-zh-sw-af-32k: A Translation-Grouped Tokenizer for English, French, Chinese, Swahili and Afrikaans},
author = {Henry Ssenono},
year = {2026},
howpublished = {\url{https://huggingface.co/henryhale/grouptok-en-fr-zh-sw-af-32k}},
note = {32,768-token byte-level BPE with translation groups, trained with grouptok}
}
@misc{grouptok2026,
title = {grouptok: Translation-Grouped Tokenizers},
author = {Henry Ssenono},
year = {2026},
howpublished = {\url{https://github.com/henryhale/grouptok}},
note = {Python package}
}