Instructions to use samdei/samdei-type-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use samdei/samdei-type-base with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "translation" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("translation", model="samdei/samdei-type-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("samdei/samdei-type-base") model = AutoModelForSeq2SeqLM.from_pretrained("samdei/samdei-type-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Samdei Type Base
Samdei Type Base converts romanized Khmer, as people type it in chat, into Khmer script. It is an 18.2M-parameter character-level encoder-decoder, the most accurate open Samdei Type model, for desktop and server use. For a phone, use Samdei Type Mini.
| Input | Output |
|---|---|
knhom jong tov phsar |
αααα»αα αααα ααααΆα |
ot mean wifi te |
α’ααααΆα wifi αα |
Release article: Samdei Type: open models that turn romanized Khmer into Khmer script.
Quick start
With transformers alone (pip install transformers torch):
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
repo = "samdei/samdei-type-base"
tok = AutoTokenizer.from_pretrained(repo)
model = AutoModelForSeq2SeqLM.from_pretrained(repo)
def pieces(text: str, max_words: int = 8) -> list[str]:
"""At most max_words words per piece, with a break after punctuation, as in the paper."""
out, cur = [], []
for w in text.split():
cur.append(w)
if len(cur) == max_words or w[-1] in ",.;:?!α":
out.append(" ".join(cur))
cur = []
if cur:
out.append(" ".join(cur))
return out or [text]
def convert(text: str) -> str:
batch = tok(pieces(text), padding=True, truncation=True, return_tensors="pt")
out = model.generate(**batch) # beam search, k = 5 (generation_config.json)
return " ".join(tok.batch_decode(out, skip_special_tokens=True))
print(convert("knhom jong tov phsar")) # αααα»αα
αααα
ααααΆα
This is beam search alone (CER 0.062 on Samdei Type Bench). For the best quality, rerank with the two LMs and the channel model of this repo (0.052), using the samdei-type package:
pip install samdei-type
from samdei_type.pipeline import Converter
conv = Converter("samdei/samdei-type-base") # PyTorch weights + full rerank, as in the paper
print(conv.convert("knhom jong tov phsar")) # αααα»αα
αααα
ααααΆα
Or on the command line: samdei-type -m samdei/samdei-type-base "knhom jong tov phsar".
Files
config.json, generation_config.json, model.safetensors (71.1 MiB), tokenizer*.json fp32 model (transformers)
onnx/encoder_kv.int8.onnx (11.3 MiB), onnx/decoder_step.int8.onnx (6.3 MiB), onnx/vocab.json int8 ONNX
channel/ (28.4 MiB) reverse model (Khmer -> romanized) for reranking, same format
lm/char5_nowiki.npz (8.9 MiB) character 5-gram LM
lm/wordfull_nowiki.json.gz (12.2 MiB) word bigram LM
rerank.json decoding and rerank settings
Reranking scores each beam hypothesis y for input x as log P(y|x) + 0.3 log P_char(y) + 0.3 log P_word(y) β 1.0 #OOV(y) + 0.3 log P_ch(x|y). The channel term checks that y explains all of the input, so the LMs cannot swap a rare word for a frequent one. Nothing in this repo is a pickle.
Results
Samdei Type Bench: 2,155 everyday messages and words with human-checked Khmer. The metrics are CER after normalization and exact match.
| System | CER | Exact |
|---|---|---|
| Samdei Type Base, reranked | 0.052 | 30% |
| Samdei Type Base, beam only (the transformers example above) | 0.062 | 24% |
| Samdei Type Mini, reranked | 0.058 | 24% |
| Samdei Type Prime (not released) | 0.027 | 61% |
| Akkhara-mini, 6-word pieces (0.159 on whole inputs) | 0.066 | 23% |
| AkaraAlpha | 0.281 | 2% |
- Prime is Base trained further on scenario-designed, LLM-drafted, human-audited data. Most bench items share that scenario design, so its lead is an upper bound.
- Without punctuation, Base's CER is 0.046. Decode long messages in pieces, as above. On whole inputs, beam-only CER is 0.133.
- On one Apple M5 Pro CPU thread with int8 ONNX, beam 5 takes 9.3 ms per input (p50).
Model and training
Architecture. Pre-LN Transformer encoder-decoder: 6 encoder and 3 decoder layers, d_model 384, 6 heads, FFN 1536. It has 216 input and 228 output symbols. The channel model is Mini-sized (7.1M) and reads in the reverse direction.
transformers format. It loads as
BlenderbotForConditionalGenerationbecause the architecture is the same; it has nothing else in common with BlenderBot. Both vocabularies share one id space (output symbols first), so transformers counts 18.63M parameters.Training. Three stages on one laptop GPU (Apple M5 Pro), about 6 hours in all:
- pretraining on 12.8M pairs: real Khmer sentences spelled by a rule-based typing generator (
samdei-type-base-pretrained); - fine-tuning on 1.16M chat-like pairs;
- adaptation to casual register (1.59M pairs, with replay).
The rerank LMs are built from HPLT v2, FineWeb-2, ALT and our LLM-written chat sentences, without Wikipedia.
- pretraining on 12.8M pairs: real Khmer sentences spelled by a rule-based typing generator (
Data. The exact training files are in
samdei-type-pretraining-dataandsamdei-type-finetuning-data, withrecipes.json. No evaluation data and no other romanization system's data was trained on. Akkhara-Preview, a public 110-row preview, was used only to pick stage 1β2 checkpoints; stage 3 used a closed development set.
Limitations
- Every romanized input seen in training is synthetic (rules, mined spelling tables, an LLM). Real typing appears only in the evaluation.
- Homophones that need more context than a word bigram: ααΎα / ααα (
der), ααΉα / ααα / ααα (dek). - Loanwords typed in English (
checkfor ααα) stay English. A Latin comma is copied, and a missing final α is never added. - Rare dictionary words without context are hard, many of them Pali-Sanskrit.
- The Khmer side is mostly web text, with its topics and biases.
- Not for Khmer β Latin, official romanization of names, or output nobody checks.
License
Apache-2.0 (LICENSE; keep NOTICE when redistributing).
- LMs: built without Wikipedia, from HPLT v2, FineWeb-2 (ODC-By), ALT (CC BY) and our LLM-written chat sentences.
- Training data: CC BY-SA 4.0, with its sources in the dataset cards.
- Tools:
khmercut(Apache-2.0) and SILkhnormal(MIT).
Citation
@misc{samdei-type-2026,
title = {Samdei Type: Separating What Is Written from How It Is Spelled for Romanized Khmer Transliteration},
author = {Mengsay Loem},
year = {2026},
note = {Technical report},
url = {https://github.com/Samdei-Labs/samdei-type/blob/main/paper/samdei-type.pdf}
}
- Downloads last month
- 62
Model tree for samdei/samdei-type-base
Base model
samdei/samdei-type-base-pretrainedDatasets used to train samdei/samdei-type-base
samdei/samdei-type-pretraining-data
Collection including samdei/samdei-type-base
Evaluation results
- CER (beam 5, char LM + word LM + OOV + channel rerank, 8-word pieces) on Samdei Type Benchtest set self-reported0.052
- Exact match on Samdei Type Benchtest set self-reported0.303