Instructions to use noson71/albert-kh-en-codeswitch-32k with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use noson71/albert-kh-en-codeswitch-32k with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="noson71/albert-kh-en-codeswitch-32k")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("noson71/albert-kh-en-codeswitch-32k") model = AutoModelForMaskedLM.from_pretrained("noson71/albert-kh-en-codeswitch-32k", device_map="auto") - Notebooks
- Google Colab
- Kaggle
albert-kh-en-codeswitch-32k
This model is a Khmer-English Code-Switching ALBERT based on seanghay/albert-khmer-small, further pre-trained on a bilingual corpus with explicit code-switching data.
The model excels at understanding and processing mixed Khmer-English text, named entity recognition, and question answering in code-switched contexts.
Model Details
- Developed by: NOSON
- Model type: ALBERT (A Lite BERT)
- Language(s): Khmer (km), English (en)
- License: Apache-2.0
- Finetuned from model: seanghay/albert-khmer-small
Model Description
This model extends the original Khmer ALBERT with enhanced capabilities for:
- Code-switching: Seamlessly handles mixed Khmer-English text.
- Technical vocabulary: Better understanding of tech terms modern language.
- Cultural preservation: Maintains high integrity of complex Khmer words.
Training Data
The model was trained on a carefully balanced corpus consisting of:
- Khmer Wikipedia (2023-2024 dumps)
- WikiText-103 (English)
- MC4 (Khmer & English subsets)
- Custom Code-Switching Corpus (30,000+ injected examples)
Training Procedure
Preprocessing
- Custom 32,000 token SentencePiece Unigram tokenizer.
- Character coverage: 1.0 (perfect for Khmer diacritics).
- Forced vocabulary for technical terms and complex Khmer words.
- Maximum sequence length: 512 tokens.
Evaluation Results
Lower TPC is better; higher percentages are better for integrity.
| Metric | This Model (32K) | ALBERT Base (16K) | XLM-R Base (250K) |
|---|---|---|---|
| TPC (Khmer) | 0.143 | 0.164 | 0.264 |
| Tokenization Speed | 0.3M tok/s | 0.3M tok/s | 0.4M tok/s |
Complex Word Integrity Breakdown
A critical challenge in Khmer NLP is preventing the fragmentation of complex Sanskrit/Pali loanwords and compound words. Our custom tokenizer significantly outperforms baselines in keeping these words intact as single tokens:
| Complex Word | Meaning | Our Model (32K) | ALBERT Base (16K) | XLM-R Base (250K) |
|---|---|---|---|---|
| ααα | Dharma | β 1 token | β 2 tokens | β 2 tokens |
| αααα | Karma | β 1 token | β 2 tokens | β 2 tokens |
| αα·ααααΆα | Nirvana | β 1 token | β 4 tokens | β 3 tokens |
| α’αα·αααααα | Development | β 2 tokens | β 2 tokens | β 2 tokens |
| ααααααα·α αα | Economy | β 1 token | β 2 tokens | β 1 token |
| αααααΆαα·αααααα | Democracy | β 2 tokens | β 2 tokens | β 2 tokens |
| α’αα·αααααα | Sovereignty | β 2 tokens | β 2 tokens | β 5 tokens |
MLM Performance Examples
Example 1: Technical Code-Switching
- Input: ααΎααααα»ααα·ααααΆα’αααΈ
[MASK]learning αα·α blockchain technologyα - Top 5: machine, technology, data, software, learning
Example 2: Common Code-Switching
- Input: ααΆααΆααααα is the official
[MASK]of Cambodia. - Top 5: language, government, official, learning, data
Example 3: Pure Khmer
- Input: αααααα»αααααΆαααΆααΊααΆααΆαααΆα
αααααααα»α
[MASK]ααααα»ααΆα - Top 5: ααααααΆααΆααΆα ααα, ααααααααααα»ααΆ, ααΆαααΆ, αααααααα·ααΆααααα, αα»αααααΆαααΆ
How to Use
Load the model
from transformers import AutoTokenizer, AlbertForMaskedLM
tokenizer = AutoTokenizer.from_pretrained("noson71/albert-kh-en-codeswitch-32k")
model = AlbertForMaskedLM.from_pretrained("noson71/albert-kh-en-codeswitch-32k")
text = "ααΎααααα»ααα·ααααΆα’αααΈ machine learning αα·α blockchain technologyα"
tokens = tokenizer.tokenize(text)
print(tokens)
# Output: ['ααΎα', 'αααα»α', 'αα·ααααΆα’αααΈ', 'β', 'machine', 'β', 'learning', 'αα·α', 'β', 'blockchain', 'β', 'technology', 'α']
Masked Language Modeling (Inference)
import torch
text = "ααΆααΆααααα is the official [MASK] of Cambodia."
inputs = tokenizer(text, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
# Find the [MASK] token position and get the top prediction
mask_token_index = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
predicted_token_id = logits[0, mask_token_index].argmax(axis=-1).item()
print("Prediction:", tokenizer.decode([predicted_token_id]))
# Expected output: 'language' or 'government'
Citation
@misc{noson71-khmer-en-codeswitch-albert,
author = {NOSON},
title = {ALBERT Khmer-English Code-Switching 32K},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/noson71/albert-kh-en-codeswitch-32k}
}
- Downloads last month
- 59