CoolFace
Modelpublic

savinugunarathna/Gemma3-Singlish-Sinhala-CodeMix

sourceHugging Faceapache-2.0updated 7mo agoView on Hugging Face
0likes34downloads
Model Card

Gemma3-Singlish-Sinhala-CodeMix

A fine-tuned Gemma-3-270M-IT model for Singlish -> Sinhala transliteration and code-mixed text translation.

The model handles both:

  • Pure Singlish: Roman-script Sinhala → Sinhala Unicode
  • Code-mixed text: English-Sinhala mixed text → pure Sinhala (English words translated to Sinhala)

Examples

InputOutputTask
ara politician wa mama dannawaඅර දේශපාලකයෝ මම දන්නවාCode-mix
meka harima boring panthiyakමේක හරිම කම්මැලි පන්තියක්Code-mix
oyage phone eka koඔයාගේ දුරකථනය කෝCode-mix
mama gedara yanawaමම ගෙදර යනවාTransliteration
oyata kohomadaඔයාට කොහොමදTransliteration

Evaluation Results

Phonetic Test Set

MetricScore
CER0.0191
WER0.0876
Exact Match Accuracy41.01%

Adhoc Test Set

MetricScore
CER0.0416
WER0.1484
Exact Match Accuracy22.17%

Sample Predictions

Phonetic Test
Inputawankawama mata eya mathaka ethi akaraya eyayi namuth eya wikarayaki mama obata ashwaya kerehi wedi elmak nodakwana namuth eya mage wilasithawa nowe
Targetඅවංකවම මට එය මතක ඇති ආකාරය එයයි නමුත් එය විකාරයකි මම ඔබට අශ්වයා කෙරෙහි වැඩි ඇල්මක් නොදක්වන නමුත් එය මගේ විලාසිතාව නොවේ
Predඅවංකවම මට එය මතක ඇති ආකාරය එයයි නමුත් එය විකාරයකි මම ඔබට අශ්වයා කෙරෙහි වැඩි ඇල්මක් නොදක්වන නමුත් එය මගේ විලාසිතාව නොවේ ✓
Inputoba mage aneka yeyi adahas karanne kese ho oba ema wilasithawata andinne mandeyi mama asami
Targetඔබ මගේ අනෙකා යැයි අදහස් කරන්නේ කෙසේ හෝ ඔබ එම විලාසිතාවට අඳින්නේ මන්දැයි මම අසමි
Predඔබ මගේ අනෙකා යැයි අදහස් කරන්නේ කෙසේ හෝ ඔබ එම විලාසිතාවට අඳින්නේ මන්දැයි මම අසමි ✓
Adhoc Test
Inputkmk nehe modyi wge
Targetකමක් නැහැ මෝඩයි වගේ
Predකමක් නැහැ මෝඩයි වගේ ✓
Inputeya wda honda deyi asanna
Targetඑය වඩා හොඳ දැයි අසන්න
Predඑය වඩා හොඳ දැයි අසන්න ✓
Code-Mix Translation
InputPrediction
ara politician wa mama dannawaඅර දේශපාලකයෝ මම දන්නවා
meka harima boring panthiyakමේක හරිම කම්මැලි පන්තියක්
oyage phone eka koඔයාගේ දුරකථනය කෝ

Training

Architecture & Method

  • Base model: google/gemma-3-270m-it (273M parameters)
  • Method: Multi-phase LoRA fine-tuning
  • Saved precision: bfloat16

Phase 1–3: Transliteration Foundation

The base transliteration model (Gemma3-Singlish-Sinhala-Merged) was trained in 3 progressive phases on the Swa-bhasha phonetic dataset:

PhaseDataEpochsLearning RateLoRA Config
Phase 1: Foundation650K phonetic samples + augmentation21e-4r=64, α=128
Phase 2: Expansion350K new + adhoc + replay + augmentation25e-5r=64, α=128
Phase 3: MasteryAdhoc-heavy + phonetic mix + augmentation22e-5r=64, α=128

Target modules: q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj

After each phase, the LoRA adapter was merged into the base model.

Phase 4: Code-Mix Fine-tuning

A new LoRA adapter was trained on top of the merged Phase 3 model to add code-mix translation capability:

ParameterValue
Training data~57K samples (77% code-mix, 23% replay)
Code-mix data~27K unique samples × 2 upsample
Replay data10K phonetic + 3K adhoc (anti-forgetting)
LoRA rank32
LoRA alpha64
LoRA dropout0.05
Target modulesq, k, v, o, gate, up, down projections
Learning rate3e-5 (cosine decay)
Effective batch size32
Epochs3 (with early stopping, patience=5)
Training precisionfloat32 (P100 stability)
Saved precisionbfloat16
HardwareNVIDIA Tesla P100 16GB

Anti-Forgetting Strategy

  • Replay buffer: 13K transliteration samples mixed into code-mix training
  • Small LoRA rank (r=32): limits capacity to prevent overwriting base knowledge
  • Low learning rate (3e-5): gentle updates to existing weights

Usage

python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
import warnings, os
warnings.filterwarnings("ignore")

MODEL_ID = "savinugunarathna/Gemma3-Singlish-Sinhala-CodeMix"

tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
if tokenizer.pad_token is None:
    tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "left"

model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID, torch_dtype=torch.bfloat16,
    trust_remote_code=True,
).to("cuda" if torch.cuda.is_available() else "cpu")
model.eval()

PROMPT = "Translate the following code-mixed text into pure Sinhala:\n{input}\nSinhala:"

gen_config = GenerationConfig(
    max_new_tokens=256, num_beams=3, do_sample=False,
    repetition_penalty=1.2, pad_token_id=tokenizer.pad_token_id,
    eos_token_id=tokenizer.eos_token_id, top_p=None, top_k=None,
)

def convert(text):
    prompt = PROMPT.format(input=text)
    inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=True).to(model.device)
    in_len = inputs["input_ids"].shape[1]
    with torch.no_grad():
        out = model.generate(**inputs, generation_config=gen_config)
    return tokenizer.decode(out[0, in_len:], skip_special_tokens=True).strip()

# Transliteration
print(convert("mama gedara yanawa"))            

# Code-mix translation
print(convert("ara politician wa mama dannawa"))  
print(convert("meka harima boring panthiyak"))   
print(convert("oyage phone eka ko"))              

Prompt Format

Single unified prompt for both tasks:

"Transliterate the following Singlish text to Sinhala by considering the context:\n{input}\nSinhala:"

Limitations

  • Conjunct consonants: Occasionally produces ්ය instead of ්‍ය (ZWJ variants)
  • Punctuation: May drop or alter commas and periods
  • Rare English words: Very uncommon English words in code-mix may be transliterated phonetically instead of translated
  • Long sequences: Quality may degrade for inputs longer than ~200 tokens

Model Details

PropertyValue
Parameters273M
Precisionbfloat16
Model size~536MB
Context length256 tokens
LanguagesSinhala (si), English (en)
LicenseApache 2.0
Base modelgoogle/gemma-3-270m-it

Citation

If you use this model, please cite:

bibtex
@misc{gunarathna2025codemix,
  title={Gemma3-Singlish-Sinhala-CodeMix: Multi-Phase LoRA Fine-Tuning for Singlish-to-Sinhala Transliteration and Code-Mix Translation},
  author={Gunarathna, Savinu},
  year={2025},
  url={https://huggingface.co/savinugunarathna/Gemma3-Singlish-Sinhala-CodeMix}
}

Related Work

bibtex
@article{sumanathilaka2025swa,
  title={Swa-bhasha Resource Hub: Romanized Sinhala to Sinhala Transliteration Systems and Data Resources},
  author={Sumanathilaka, Deshan and Perera, Sameera and Dharmasiri, Sachithya and Athukorala, Maneesha and Herath, Anuja Dilrukshi and Dias, Rukshan and Gamage, Pasindu and Weerasinghe, Ruvan and Priyadarshana, YHPP},
  journal={arXiv preprint arXiv:2507.09245},
  year={2025}
}

@article{ranasinghe2022sold,
  title={SOLD: Sinhala Offensive Language Dataset},
  author={Ranasinghe, Tharindu and Anuradha, Isuri and Premasiri, Damith and Silva, Kanishka and Hettiarachchi, Hansi and Uyangodage, Lasitha and Zampieri, Marcos},
  journal={arXiv preprint arXiv:2212.00851},
  year={2022}
}

@inproceedings{Nsina2024,
  author={Hettiarachchi, Hansi and Premasiri, Damith and Uyangodage, Lasitha and Ranasinghe, Tharindu},
  title={{NSINA: A News Corpus for Sinhala}},
  booktitle={The 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)},
  year={2024},
  month={May},
}

Acknowledgments

  • Google for the Gemma model family
  • Swa-bhasha Resource Hub for the phonetic transliteration dataset
  • Hugging Face for the transformers ecosystem
  • Training compute provided by Kaggle (P100 GPU)