Skip to main content

Samdei Type

Samdei Type converts romanized Khmer, the Latin spelling many people use in chat, to Khmer script:

$ samdei-type "knhom jong tov phsar"
ខ្ញុំចង់ទៅផ្សារ

This package runs the released Samdei Type models: a command-line converter and a Python API, with beam search, int8 ONNX decoding and the reranking used in the paper. The models are on the Hugging Face Hub and are downloaded on first use:

Model Parameters Decoded as in the paper with First download
Samdei Type Mini 7.2M int8 ONNX graphs + word LM about 9 MB
Samdei Type Base 18.2M PyTorch weights + character LM, word LM and the model itself as channel model about 97 MB

Both are character-level Transformer encoder-decoders. Mini is small enough for a phone keyboard; Base is more accurate. Their scores on Samdei Type Bench, training data and limitations are in the model cards. All releases: the Samdei Type collection. Paper: technical report (PDF). Release article: Samdei Type: open models that turn romanized Khmer into Khmer script.

Samdei (សំដី, "what you say") is our team, Samdei Labs.

Models v4.0 (2026-11-29). Samdei Type Bench CER: Mini 0.045, Base 0.036 (v1: 0.049, 0.040), on the 2,094 items whose Khmer does not occur in the training data. Every 1.0 release of the package runs them. Since 1.0.2, every Khmer output follows the encoding structure of Unicode Technical Note #61 (step 4 of "How decoding works"); the scores do not change. The earlier models are at revisions v1 and v0.1 of each repo: Converter("samdei/samdei-type-base", revision="v1").

Install

pip install "samdei-type[deploy]"

Python 3.10 or later. The deploy extra adds onnxruntime for the int8 ONNX graphs, which Mini is decoded with. Without it, Mini falls back to its PyTorch weights. PyTorch is needed either way: on macOS the install takes about 1 GB. On Linux, pip installs PyTorch with its CUDA libraries, several GB; for a CPU-only install, add PyTorch's CPU build first: pip install torch --index-url https://download.pytorch.org/whl/cpu.

Some onnxruntime builds send usage telemetry to Microsoft by default. The package turns it off by setting ORT_DISABLE_TELEMETRY=1 (unless you set it yourself). onnxruntime reads the variable when it is imported, so if your code imports onnxruntime before the converter loads, set the variable yourself first.

The latest code from GitHub: pip install "samdei-type[deploy] @ git+https://github.com/Samdei-Labs/samdei-type.git".

Command line

$ samdei-type "knhom jong tov phsar"                      # Samdei Type Mini
ខ្ញុំចង់ទៅផ្សារ
$ samdei-type -m samdei/samdei-type-base "bong nham bay nov?"
បងញ៉ាំបាយនៅ?
$ echo "saek nh tv rean" | samdei-type -                  # one message per line from stdin
ស្អែកខ្ញុំទៅរៀន
$ samdei-type --nbest "jam knhom bontech"                 # also each piece's candidates and scores
ចាំខ្ញុំបន្តិច
       -8.19  ចាំខ្ញុំបន្តិច
      -11.71  ចាំ ខ្ញុំបន្តិច
      ...

samdei-type --help lists the options: --backend torch|onnx, --beam, --no-rerank (beam search only), --no-chunk, --tsv, --device, --threads. python -m samdei_type runs the same command. Keep the pieces: --no-chunk (and chunk=False in Python) decodes each message whole, which the models were not trained for. On whole messages Mini v4.0 is clearly weaker than v1 (Samdei Type Bench CER without LMs 0.197 vs 0.157; Base 0.123 vs 0.120), and on long ones it can repeat words.

The first run downloads the files the model uses into the Hugging Face cache (~/.cache/huggingface). After that it only checks the Hub for updates and works offline; set HF_HUB_OFFLINE=1 to skip the check. -m also takes a local folder:

hf download samdei/samdei-type-mini --local-dir samdei-type-mini
samdei-type -m ./samdei-type-mini "ot mean wifi te"

Python

from samdei_type.pipeline import Converter

conv = Converter("samdei/samdei-type-base")              # a Hub repo id or a local model folder
conv.convert("knhom jong tov phsar")                     # 'ខ្ញុំចង់ទៅផ្សារ'
conv.convert_batch(["bong nham bay nov?", "ot mean wifi te"])
                                                         # ['បងញ៉ាំបាយនៅ?', 'អត់មាន wifi ទេ']
conv.convert("ខ្ញុំចង់ទៅផ្សារ", reverse=True)             # 'knhom chong tov phsar'
mini = Converter("samdei/samdei-type-mini")              # int8 ONNX graphs, as rerank.json says
mini.nbest(mini.pieces("jam knhom bontech"))             # [[('ចាំខ្ញុំបន្តិច', -8.19), ...]]

Converter reads the model's rerank.json, so it decodes as the published scores were computed: the backend, the beam size, the pieces and the rerank weights. backend="torch" or "onnx" overrides the backend. The same steps with the lower-level pieces:

import json
from huggingface_hub import snapshot_download
from samdei_type.evaluation import chunk_source, translate
from samdei_type.model import load
from samdei_type.rerank import Reranker
from samdei_type.text import drop_commas
from samdei_type.utn61 import clean_nbest

d = snapshot_download("samdei/samdei-type-base")
model, sv, tv = load(d)                                  # config.json + model.safetensors
weights = json.load(open(f"{d}/rerank.json"))["rerank_weights"]
rr = Reranker(weights, char_lm=f"{d}/lm/char5_nowiki.npz", word_lm=f"{d}/lm/wordfull_nowiki.json.gz",
              channel=(model, sv, tv))                   # rerank.json "channel_self": the model itself
pieces = chunk_source("knhom jong tov phsar", 8)
nbest = translate(model, sv, tv, pieces, beam=5)
best = [clean_nbest(rr.rerank(p, hyps), fallback=p) for p, hyps in zip(pieces, nbest)]   # as Converter.nbest
print(drop_commas(" ".join(b[0][0] if b else "" for b in best)))

For the int8 graphs, OnnxConverter(f"{d}/onnx").beam(piece, k=5) from samdei_type.onnx_infer gives a piece's n-best list. That module uses only numpy and onnxruntime, and is the reference to port to a phone runtime.

How decoding works

  1. The input is cut into pieces of at most eight words, with a break after any punctuation mark (samdei_type.evaluation.chunk_source). The models were trained on short pieces, and decoding whole messages (chunk=False, --no-chunk) is worse, most of all with Mini v4.0.
  2. Each piece gets a beam search with k = 5 (samdei_type.model.beam_cached, or OnnxConverter.beam). A piece longer than 249 characters is cut.
  3. Each hypothesis y of input x is scored as log P(y|x) + a·log P_char(y) + b·log P_word(y) − c·#OOV(y) + d·log P_ch(x|y) (samdei_type.rerank). The channel model P_ch reads Khmer and predicts the romanized input, so it checks that a hypothesis explains all of the input. Since v1, Base is its own channel model ("channel_self" in rerank.json). The weights a–d come from the model's rerank.json.
  4. Each n-best list is brought into the encoding structure of Unicode Technical Note #61 (samdei_type.utn61.clean_nbest, since 1.0.2): every hypothesis is normalized (SIL khnormal, with coeng TA U+17D2 U+178F and coeng DA U+17D2 U+178A both kept as written; the visual form does not change), hypotheses that become identical are merged, and hypotheses that still do not follow the structure are dropped (if none does, the romanized piece itself, when it passes the check; else nothing). nbest() returns these lists.
  5. The best hypotheses of the pieces are joined with a space, and a comma that is not between two digits becomes a space, as in Khmer writing (samdei_type.text.drop_commas).

Limitations

  • The models convert what people type in chat. They are not a dictionary: an unusual spelling, a name or a rare word can come out as a common word that sounds alike. The model cards give the error rates and examples.
  • English words are often spelled out in Khmer script (see you → ស៊ីយូ); some, like wifi, are kept.
  • Emoji, URLs and @mentions are not passed through: emoji are dropped and other symbols can change. Split them off before converting if you need to keep them.

Package layout

Module What it does
samdei_type.pipeline Converter: a model folder or Hub repo id → convert(text)
samdei_type.model the encoder-decoder, load, KV-cached greedy and beam search
samdei_type.onnx_infer int8 ONNX decoding with numpy and onnxruntime
samdei_type.rerank, samdei_type.lm n-best reranking; hashed character n-gram LM and word bigram LM
samdei_type.evaluation input chunking, batched decoding, CER and exact match (score, as for Samdei Type Bench)
samdei_type.text, samdei_type.khnormal Khmer normalization
samdei_type.utn61 the UTN #61 check and normalization of the Khmer outputs (normalize, is_valid, clean_nbest)
samdei_type.vocab character vocabularies
samdei_type.cli the samdei-type command

Training code and the data generator are not part of this package. The training data are on the Hub: samdei/samdei-type-pretraining-data and samdei/samdei-type-finetuning-data.

Development

git clone https://github.com/Samdei-Labs/samdei-type && cd samdei-type
pip install -e ".[deploy]"
python -m unittest discover -s tests
SAMDEI_TYPE_MODEL=samdei/samdei-type-mini python -m unittest discover -s tests   # also an end-to-end conversion

License

The code is licensed under the Apache License 2.0 (see LICENSE and NOTICE). src/samdei_type/khnormal.py is vendored from SIL Global's khmer-character-specification under the MIT License. The models and datasets on the Hub have their own licenses, given in their cards.

Citation

The technical report is paper/samdei-type.pdf.

@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}
}

Metadata

Release files for samdei-type 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for samdei-type 1.0.2
File Size Uploaded Provenance Actions
samdei_type-1.0.2.tar.gz 54.8 kB With provenance Details for samdei_type-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for samdei-type 1.0.2
File Interpreter ABI Platform Actions
samdei_type-1.0.2-py3-none-any.whl Python 3 none any Details for samdei_type-1.0.2-py3-none-any.whl

Total release size: 93.1 kB

Release files / samdei_type-1.0.2.tar.gz

Download URL samdei_type-1.0.2.tar.gz
Size 54.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b13f1ce5ff1db4afadd47feb8ce8c2cd3752ec6df990700da47f20ca90adb0e7
BLAKE2b-256 checksum
How to use checksums
24d4bb9914bbbbe394a5c43df2246f1a56e6ed05cb97aba457b5fcc44f678dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / samdei_type-1.0.2-py3-none-any.whl

Download URL samdei_type-1.0.2-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a078c13e0ba74802b3b0042a7f2b647e5e87298404eaf8fc968cba413998c4da
BLAKE2b-256 checksum
How to use checksums
4bd3327e8d68703c201056a1241312a7502cdfec0d6d516b46e47233fa7bbf26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for samdei-type 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for samdei_type-1.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page