Downloads · 30 days
7
8% of all-time downloads
savinugunarathna/small-100-Singlish-Sinhala-CodeMix2-ONNX-INT8
small-100-Singlish-Sinhala-CodeMix2-ONNX-INT8 is a machine learning model from savinugunarathna. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
Fine-tuned and quantized small-100 seq2seq model for translating Roman-script Sinhala (Singlish) mixed with English into pure Sinhala Unicode script. Exported to ONNX and quantized to INT8 for fast CPU inference.
Downloads · 30 days
7
8% of all-time downloads
All-time downloads
93
Public
Repo size
918 MB
Likes
0
Public
Click a slice to open those files.
.onnx916 MB · 99%
From the Hugging Face model README
Fine-tuned and quantized small-100 seq2seq model for translating Roman-script Sinhala (Singlish) mixed with English into pure Sinhala Unicode script. Exported to ONNX and quantized to INT8 for fast CPU inference.
Takes informal Singlish text typed by Sri Lankans on social media and converts it to Sinhala script. English words are translated to their Sinhala meaning — not transliterated phonetically.
| Input (Singlish) | Output (Sinhala) |
|---|---|
| mama hungry, kanna yamu | මම බඩගිනියි, කෑම කමු |
| bro API eka call karanna puluwanda | බ්රෝ API එක කෝල් කරන්න පුළුවන්ද |
| today weather eka honda ne | අද කාලගුණය හොඳයි නේ |
| mage salary eka late una | මගේ වැටුප ප්රමාද වුණා |
| traffic eka godak awul | වාහන තදබදය ගොඩක් අවුල් |
optimumpip install optimum[onnxruntime] transformers sentencepiece
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers import AutoTokenizer
model_id = "savinugunarathna/small-100-Singlish-Sinhala-CodeMix2-ONNX-INT8"
model = ORTModelForSeq2SeqLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.src_lang = "en"
tgt_lang_id = tokenizer.lang_code_to_id["si"]
def translate(text):
inputs = tokenizer(
text,
return_tensors="pt",
truncation=True,
max_length=128,
)
outputs = model.generate(
**inputs,
max_new_tokens=64,
num_beams=1, # greedy — fastest on CPU
forced_bos_token_id=tgt_lang_id,
)
return tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
print(translate("mama hungry, kanna yamu"))
# → මම බඩගිනියි, කෑම කමු
texts = [
"mama hungry, kanna yamu",
"bro API eka call karanna puluwanda",
"today weather eka honda ne",
]
inputs = tokenizer(
texts,
return_tensors="pt",
padding=True,
truncation=True,
max_length=128,
)
outputs = model.generate(
**inputs,
max_new_tokens=64,
num_beams=1,
forced_bos_token_id=tgt_lang_id,
)
for out in outputs:
print(tokenizer.decode(out, skip_special_tokens=True).strip())
from fastapi import FastAPI
from pydantic import BaseModel
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers import AutoTokenizer
app = FastAPI()
model_id = "savinugunarathna/small-100-Singlish-Sinhala-CodeMix2-ONNX-INT8"
model = ORTModelForSeq2SeqLM.from_pretrained(model_id)
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.src_lang = "en"
tgt_lang_id = tokenizer.lang_code_to_id["si"]
class Request(BaseModel):
text: str
@app.post("/translate")
def translate(req: Request):
inputs = tokenizer(req.text, return_tensors="pt", truncation=True, max_length=128)
outputs = model.generate(
**inputs,
max_new_tokens=128,
num_beams=3,
forced_bos_token_id=tgt_lang_id,
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True).strip()
return {"input": req.text, "output": result}
Run with:
uvicorn app:app --host 0.0.0.0 --port 8000
Benchmarked on CPU (single thread, greedy decoding, max_new_tokens=64):
| Setup | Latency per sentence |
|---|---|
| PyTorch fp32 + beam=3 | ~3-5 seconds |
| ONNX INT8 + greedy | ~200-400ms |