orthomni-codeco
Vietnamese spelling correction model: a BARTpho / MBart seq2seq model (~400M parameters), quantized to INT8 for inference on CPU. Two formats ship in this repository: CTranslate2 (ct2/) and ONNX Runtime (onnx/).
This repository holds the model weights used by the Python package orthomni-codeco on PyPI. You normally don't download these files by hand: the package fetches the files of the backend you use on first run.
hom nay troi dep qua -> Hôm nay trời đẹp quá
toi di hoc -> Tôi đi học
Installation
pip install orthomni-codeco # library + CLI (CTranslate2 backend)
pip install "orthomni-codeco[onnx]" # + ONNX Runtime backend
pip install "orthomni-codeco[server]" # + FastAPI/uvicorn HTTP server
Requires Python >= 3.9. PyTorch is not needed: the default runtime dependencies are only ctranslate2, numpy, sentencepiece and huggingface-hub.
Usage
Python
from orthomni_codeco import OrthoMNIModel
model = OrthoMNIModel() # first run downloads the model to ~/.cache/orthomni_codeco/
model.correct("hom nay troi dep qua")
# 'Hôm nay trời đẹp quá'
model.correct(["xin chao", "toi di hoc"])
# ['Xin chào', 'Tôi đi học']
Create the model once and reuse it. Later runs load from the local cache and work offline. An async variant is also available:
await model.acorrect("xin chao")
To use the ONNX Runtime weights instead:
from orthomni_codeco import OrthoMNIModel, CorrectorConfig
model = OrthoMNIModel(CorrectorConfig(backend="onnx")) # or ORTHOMNI_BACKEND=onnx
Command line
orthomni download # download the model to the cache, print its path
orthomni download --backend onnx # same, ONNX files
orthomni correct "toi di hoc" "xin chao" # correct a few sentences
orthomni serve --port 8006 # start an HTTP server (needs the [server] extra)
curl -X POST localhost:8006/predict \
-H 'content-type: application/json' \
-d '{"text": "hom nay troi dep qua"}'
# {"result":"Hôm nay trời đẹp quá","latency_ms":...}
Using a local copy of this repo
If you already have the files (for example in an offline environment), point the package at the directory and nothing will be downloaded:
hf download nhatho1999/orthomni-codeco --local-dir ./orthomni-codeco
export ORTHOMNI_MODEL_DIR=./orthomni-codeco
or in Python:
from orthomni_codeco import OrthoMNIModel, CorrectorConfig
model = OrthoMNIModel(CorrectorConfig(model_dir="./orthomni-codeco"))
See the PyPI page for the full list of options (threads, batch size, max input length, server settings).
Files
| Path | Size | Content |
|---|---|---|
config.json, generation_config.json, tokenizer_config.json, special_tokens_map.json | Model and generation config | |
sentencepiece.bpe.model, dict.txt | ~5.4 MB | BARTpho tokenizer (SentencePiece BPE) |
ct2/model.bin (+ config.json, shared_vocabulary.json) | ~405 MB | CTranslate2 INT8: all linear layers and embeddings |
onnx/encoder_model.onnx | ~321 MB | ONNX Runtime dynamic INT8 encoder |
onnx/decoder_model_merged.onnx | ~414 MB | ONNX Runtime dynamic INT8 decoder, merged with/without KV-cache (Optimum layout) |
onnx/ort_config.json | ONNX quantization settings | |
model_info.json | Export metadata |
Model details
| Architecture | MBartForConditionalGeneration (BARTpho), 12 encoder + 12 decoder layers, d_model 1024 |
| Parameters | ~400M |
| Vocabulary | 40,030 (SentencePiece BPE, BartphoTokenizer) |
| CTranslate2 | INT8 |
| ONNX | Dynamic quantization, MatMul only, INT8 weights per-channel (symmetric), UINT8 activations |
| Decoding | Greedy |
| Max input | 256 tokens per sentence by default |
Limitations
- Input sentences longer than the token limit are rejected rather than truncated; split long text into sentences first.
- The ONNX weights use dynamic quantization: activation scales are computed over the whole batch, so the same sentence can occasionally differ in casing or punctuation depending on what it is batched with. The CTranslate2 weights do not depend on the CPU architecture.
- Package versions pin a commit of this repository. Earlier package versions keep working through their pinned commits: 0.1.0 used 3 ONNX files at the repository root, and 0.1.2 used an older checkpoint with
ct2/only.