Instructions to use egeboy35/mret-32k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use egeboy35/mret-32k with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("egeboy35/mret-32k", device_map="auto") - Notebooks
- Google Colab
- Kaggle
MRET 32K
A lossless Turkish tokenizer with a 32,768-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 32K, 32.768 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 32K sınıfı tokenizer'lar arasında kayıpsızlar içinde test metninde en az tokeni veriyor (günlük dilde NC-32k çok az önde); morfoloji F1'inde ve kök isabetinde birinci. Ayrıntılar aşağıda (İngilizce).
Usage
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("egeboy35/mret-32k")
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.
- Unigram model. Segmentation uses the fewest tokens; among equally short segmentations, token weights trained on Zeyrek morphological analyses pick the one that best follows Turkish morpheme boundaries.
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 32K | 214.9 | 228.7 | 222.5 | 100.0 | 79.47 | 58.70 | 69.60 | 4.63 |
| NC-32k | 227.3 | 228.3 | 232.8 | 100.0 | 77.24 | 57.75 | 63.07 | 5.10 |
| TR-BPE-32k | 232.2 | 238.0 | 235.4 | 100.0 | 77.13 | 49.06 | 54.60 | – |
| RK-32k | 244.0 | 246.0 | 245.3 | 100.0 | 69.05 | 52.73 | 57.25 | – |
| RE-32k | 256.5 | 251.1 | 251.4 | 100.0 | 68.11 | 48.79 | 53.85 | – |
| Kanarya | 234.3 | 239.2 | 236.1 | 100.0 | 77.86 | 49.08 | 54.80 | – |
| TURNA (lossy) | 217.5 | 229.2 | 218.7 | 22.9 | 77.10 | 57.24 | 69.00 | 4.50 |
| BERTurk (lossy) | 222.2 | 234.2 | 224.1 | 16.1 | 74.12 | 47.32 | 55.99 | – |
NC-32k uses slightly fewer tokens on informal text (228.3 vs 228.7). TURNA uses fewer tokens on the 46 domains and on formats, but decodes only 22.9% of the documents back exactly. In a paired bootstrap over 14 metrics on the test split (95%), MRET 32K is significantly better than TURNA on 6 metrics and worse on 2 (rate of unsplit words, tokens per byte).
How it was made
- 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).
- The vocabulary was pruned toward the fewest tokens on a 30-million-word count sample, with 3% of the sample also written without Turkish characters ("cok guzel"); the years 1900-2050 were added.
- Segmentation weights as described above.
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 slow: 4-7 s for 1 MB of spaces (other tokenizers: 0.4-0.5 s).
- Numbers with separators are split into several pieces ("12.03.2024" is not one piece as in MRET 64K and 128K).
- 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
PreTrainedTokenizerFastand setsclean_up_tokenization_spaces: false, which older versions need for exact decoding. model_max_lengthis not set; set it to your model's context length.
Version
1.0 (17 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
- 23