MRET 128K

A lossless Turkish tokenizer with a 131,072-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 128K, 131.072 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 128K sınıfı tokenizer'lar 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. Bazı sıkıştırma sütunlarında yalnız metni birebir geri çözemeyen (kayıplı) tokenizer'lar önde. Ayrıntılar aşağıda (İngilizce).

Usage

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained("egeboy35/mret-128k")
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.5 for this size). 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 128K 187.6 197.2 192.4 100.0 37.06 58.77 64.50 3.28
NC-128k 194.9 198.6 199.1 100.0 36.08 57.28 58.00 4.56
TR-BPE-128k 199.7 205.3 202.9 100.0 35.72 49.13 49.52 4.29
RK-128k 209.6 213.3 211.5 100.0 32.31 51.57 51.52 4.44
RE-128k 225.0 222.3 219.5 100.0 30.74 47.59 48.91 8.22
turkish-nimbus-128k (lossy) 186.5 186.9 194.5 29.9 38.21 51.21 51.09 3.69
BERTurk 128K (lossy) 191.2 201.5 192.2 16.1 35.30 46.65 48.17 4.16
BERTurk 128K uncased (lossy) 209.4 212.2 209.8 1.1 24.10 44.21 48.91 4.14
Qwen3 356.3 353.7 353.1 100.0 8.13 32.59 41.45 9.59

Word-level bootstrap on the morphology set (95% interval): morphology F1 +1.49 over NC-128k (+1.40 to +1.60), root accuracy +6.51 (+6.28 to +6.73). In a paired bootstrap over 14 metrics on the test split, significant wins / losses: NC-128k, RK-128k, RE-128k, turkish-nimbus-128k and Qwen3 9 / 0; TR-BPE-128k 8 / 1 (16-20 letter words on the sample; on the full test word frequencies MRET 128K is ahead); BERTurk 128K 8 / 1 (rate of unsplit words); BERTurk 128K uncased 8 / 1 (all-caps words). turkish-nimbus-128k and BERTurk use fewer tokens in some columns but do not decode 70% and 84% of the documents back exactly.

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.2 was then measured on the test split, which had already been used for version 2.1.

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.2 s for 1 MB of spaces (others: 0.4-0.5 s).
  • 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.2 (18 November 2026). The 2.3 release of the family only added clean_up_tokenization_spaces: false to the config; ids are unchanged.

License

Apache License 2.0.

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