MRET 64K

A lossless Turkish tokenizer with a 65,536-token vocabulary. This repository contains only the tokenizer, no model weights. The MRET family has three sizes: MRET 32K, MRET 64K, MRET 128K.

Türkçe özet. MRET 64K, 65.536 tokenlik, kayıpsız bir Türkçe tokenizer: her metin birebir geri çözülür, bilinmeyen token üretilmez ve metin normalleştirilmez. Karşılaştırdığımız 12 tokenizer arasında kayıpsızlar içinde test metninin bütün sıkıştırma sütunlarında en az tokeni veriyor; morfoloji F1'inde ve kök isabetinde birinci. Kullanılan sözlük payında daha küçük sözlüklü tokenizer'lar önde. Ayrıntılar aşağıda (İngilizce).

Usage

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("egeboy35/mret-64k")
text = "Türkiye'nin başkenti Ankara'dır."
ids = tok(text)["input_ids"]
assert tok.decode(ids) == text

Plain encoding adds no <s> or </s>; add document boundaries yourself when pretraining. The tokenizer does not normalize text, and Turkish written in decomposed form (NFD) costs two to three times as many tokens, so convert your data to NFC first.

config.json only records the vocabulary size and the ids of <pad>, <s> and </s> (it also lets the Hub count downloads); there is no model.

Properties

  • Lossless: every input decodes back byte for byte, and <unk> is never produced.
  • Byte-level pre-tokenizer. A suffix after an apostrophe is its own piece ("Türkiye" + "'nin"). Standalone four-digit numbers (years) stay whole, longer numbers are split into groups of three, and a run of punctuation is one piece.
  • Numbers with separators are one piece ("12.03.2024", "14:30", "%45,5", "1.250,75", "1923-1938"). The vocabulary always contains the years 1900-2050, the numbers 0-999 and the pieces .d, .dd, ,d, ,dd, :00-:59 and %0-%100.
  • Unigram model with flexible segmentation: a word gets the fewest tokens unless an extra token puts a boundary on a morpheme boundary that is worth more than the extra token's cost (1.25 for this size; the end of the root counts three times). Token weights were trained on Zeyrek morphological analyses mapped to TrMorph conventions. Words that occur 50 or more times in our 300-million-word count sample and are a single token stay a single token.

Special tokens and chat template

id Token Use
0‑3 <pad>, <unk>, <s>, </s> padding, unknown (never produced), document start and end
4‑7 <|system|>, <|user|>, <|assistant|>, <|end|> chat roles and end of turn
8‑10 <|tool|>, <|tool_call|>, <|tools|> tool result role, tool call, tool definitions
11‑14 <|fim_prefix|>, <|fim_middle|>, <|fim_suffix|>, <|fim_pad|> fill-in-the-middle training
15‑71 <|reserved_7|> ... <|reserved_63|> reserved
messages = [{"role": "system", "content": "Sen yardımsever bir asistansın."},
            {"role": "user", "content": "Türkiye'nin başkenti neresi?"}]
tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
# '<s><|system|>\nSen yardımsever bir asistansın.<|end|>\n<|user|>\nTürkiye\'nin başkenti neresi?<|end|>\n<|assistant|>\n'

Roles are system, user, assistant and tool. With tools=, a <|tools|> block with the JSON list of tools comes first. An assistant tool call is written as <|tool_call|>{"name": ..., "arguments": ...} (arguments may be a string or a dict), and the result comes back in the tool role. Set <|end|> (id 7) as the stop token for generation; </s> is meant for pretraining. The template needs jinja2.

By default, the text <|user|> or <s> inside plain text becomes the special token, so user input could inject a fake role. Encode untrusted text with tok(text, add_special_tokens=False, split_special_tokens=True): special-token strings are then split as ordinary text, and the text still decodes back exactly.

Results

Test split of our corpus, scored with the metrics of the Turkish tokenizer comparison report "Türkçe Tokenizer Karşılaştırma" (13 November 2026). Text: official and legal, encyclopedic (Wikipedia) and informal (forum, social media, comments) documents from our test split, news from a separate set never used in training, and all 46 domains of the test split. Compression columns are tokens per 1,000 characters (lower is better); "4 domains" averages official, encyclopedic, informal and news. Round trip: share of documents decoded back exactly (output converted to NFC also counts). Vocab used: share of the vocabulary used at least once on the four-domain text. Morphology: turkish-nlp-suite/turkish-morph-analysis, inflected words (163,112), boundary F1 and root accuracy (a token boundary at the end of the root). Formats: average tokens over 2,000 synthetic examples each of dates, times, money, percentages, phone numbers, large numbers, year ranges and numbers with suffixes (these examples were also used when choosing settings). Bold: best among lossless tokenizers. "–": not measured.

Tokenizer 4 domains ↓ Informal ↓ 46 domains ↓ Round trip % ↑ Vocab used % ↑ Morph F1 ↑ Root acc. ↑ Formats ↓
MRET 64K 199.2 207.7 206.3 100.0 58.17 61.37 72.14 3.40
NC-64k 207.9 210.2 212.9 100.0 57.98 57.10 59.83 4.89
TR-BPE-64k 213.2 219.2 216.7 100.0 56.42 49.42 52.48 4.67
TR-BPE FineWeb 64k 214.4 221.3 221.4 100.0 55.72 50.99 54.51 4.75
Cevher 216.9 221.1 224.3 100.0 53.95 49.37 50.18 4.23
RK-64k 224.2 227.1 225.9 100.0 49.98 52.53 54.78 4.73
RE-64k 237.8 234.1 233.0 100.0 48.82 48.96 51.79 8.22
Mürşit (59K) (lossy) 216.0 231.1 218.8 91.2 59.91 49.75 54.34 5.90
Cosmos GPT-2 (50K) 221.6 227.8 225.0 100.0 64.63 50.62 51.80 4.94
ModernBERT-TR (50K) (lossy) 209.6 221.5 211.2 16.3 62.61 46.80 51.86 4.72
SuperBPE 65536 (lossy) 249.8 246.0 248.0 97.9 41.90 49.70 51.71 6.83
Kumru (50K) 245.2 255.9 239.7 100.0 66.36 52.32 56.49 9.45
MoganBERT-TR (50K) 224.1 237.3 228.8 100.0 58.70 57.00 68.56 4.98

Word-level bootstrap on the morphology set (95% interval): root accuracy +3.57 points over MoganBERT-TR (+3.37 to +3.78) and +12.31 over NC-64k; morphology F1 +4.27 over NC-64k (+4.17 to +4.36). In a paired bootstrap over 14 metrics on the test split, significant wins / losses: NC-64k 8 / 0; RK-64k, RE-64k, Cevher, Cosmos GPT-2, ModernBERT-TR, SuperBPE, Kumru and MoganBERT-TR 9 / 0; TR-BPE-64k and Mürşit 8 / 1 (tokens per 16-20 letter word: 2.40 vs 2.35 and 2.38); TR-BPE FineWeb 64k 7 / 2 (tokens per word on held-out news, 1.205 vs 1.199, and 16-20 letter words). Smaller vocabularies naturally use a larger share of their vocabulary.

How it was made

  1. A 131,072-token byte-level BPE vocabulary was trained on a 1.3-billion-word mix, upsampled from 971 million words of cleaned Turkish text in 46 domains (web crawl subsets such as mC4, OSCAR and HPLT, Wikimedia projects, forums, social media, comments, legal and official texts, parliamentary records, academic text, subtitles, literature and others; web domains weighted 4x).
  2. The vocabulary was pruned toward the fewest tokens on a 300-million-word count sample (forum, social media and comments weighted 4x, 3% written without Turkish characters), starting from the BPE vocabulary plus frequent pre-tokens and number formats, with penalties for whole inflected words (0.2) and for pieces that cut across TrMorph morpheme boundaries (0.5). Junk tokens (mixed scripts, glued words, spam, long table rules) were replaced with Turkish words.
  3. Segmentation weights as described above, learned with an averaged perceptron on 1.46 million Zeyrek-analysed word types.
  4. Settings were chosen on a development split with rules written before the candidates were scored. Version 2.3 was chosen among 16 candidates; it was then measured on the test split, which had already been used for versions 2.1 and 2.2, so the test split is not untouched.

Limitations

  • Encoding speed: about 8.8-8.9 MB/s batched on our machine, 12-16% slower than the NC BPE tokenizers; the difference comes from the Unigram model, not the pre-tokenizer.
  • Very long runs of whitespace are slower than in other tokenizers: about 1-1.4 s for 1 MB of spaces (others: 0.4-0.5 s).
  • Compared with version 2.2, version 2.3 uses 0.2-0.5% more tokens on the test text and 2.8% more on 16-20 letter words, in exchange for +5.3 points root accuracy and +4.1 points morphology F1.
  • Not supported by llama.cpp / GGUF / Ollama: the converter does not recognize this pre-tokenizer, and a BPE copy derived from the vocabulary gives the same ids on only 12-22% of documents.
  • Tested with tokenizers 0.23.3 and transformers 5.22, and with the tokenizer layer of a vLLM 0.33 development build (ids identical to Hugging Face on 300 documents, same chat template output, streaming decode matches). transformers 4.x was not tested; the config uses PreTrainedTokenizerFast and sets clean_up_tokenization_spaces: false, which older versions need for exact decoding.
  • model_max_length is not set; set it to your model's context length.

Version

2.3 (18 November 2026).

License

Apache License 2.0.

Downloads last month
21
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support