Instructions to use noson71/albert-khmer-codeswitch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use noson71/albert-khmer-codeswitch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="noson71/albert-khmer-codeswitch")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("noson71/albert-khmer-codeswitch") model = AutoModelForMaskedLM.from_pretrained("noson71/albert-khmer-codeswitch", device_map="auto") - Notebooks
- Google Colab
- Kaggle
albert-khmer-codeswitch-tokenizer
This model is a Khmer-English Code-Switching ALBERT based on seanghay/albert-khmer-small, further pre-trained on a massive bilingual corpus with explicit code-switching data.
The model excels at understanding and processing mixed Khmer-English text, making it ideal for applications like sentiment analysis, 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: Handles mixed Khmer-English text.
- Technical vocabulary: Better understanding of tech terms, URLs, and 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 (injected synthetic examples)
Training Procedure
Tokenizer Specifications
- Algorithm: SentencePiece Unigram
- Vocabulary Size: 64,000 tokens
- Character Coverage: 1.0 (ensures perfect handling of all Khmer diacritics and subscripts)
- Special Handling: Forced vocabulary injection for critical technical terms.
Evaluation Results
Lower TPC is better; higher percentages are better for integrity.
| Metric | This Model (64K) | ALBERT Base (16K) | XLM-R Base (250K) |
|---|---|---|---|
| TPC (Khmer) | 0.114 β | 0.164 | 0.264 |
| Lossless Round-Trip | Yes β | Yes | Yes |
| Tokenization Speed | 0.3M tok/s | 0.3M tok/s | 0.4M tok/s |
Complex Word Integrity Breakdown
| Complex Word | Meaning | This Model | ALBERT Base | XLM-R Base |
|---|---|---|---|---|
| ααα | 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 | β 1 token | β 2 tokens | β 2 tokens |
| α’αα·αααααα | Sovereignty | β 1 token | β 2 tokens | β 5 tokens |
π Tokenization Examples
The true power of this custom 64K tokenizer is visible in how it handles complex Khmer morphology, mixed scripts, and English words without unnecessary fragmentation.
Click to expand detailed tokenization comparisons
1. Mixed Script Words
Text: The Khmer-English dictionary is very ααα’ααΆααα
- β
OUR (11 tokens):
['The', 'Khmer', '-', 'English', '', 'dictionary', 'is', 'very', '', 'ααα’ααΆαα', 'α'] - β ALBERT (18 tokens):
['The', 'Kh', 'mer', '-', 'E', 'ng', 'li', 'sh', '', 'dict', 'ion', 'ary', 'is', 'very', '', 'ααα’', 'ααΆαα', 'α'](Fractures "Khmer", "English", "dictionary") - β οΈ XLM-R (12 tokens):
['The', 'Khmer', '-', 'English', 'di', 'ction', 'ary', 'is', 'very', 'ααα’', 'ααΆαα', 'α']
2. Pure Khmer (Complex Compound)
Text: αααααα»αααααΆαααΆααΆαααΆααααααΆααα
- β
OUR (3 tokens):
['αααααα»αααααΆαααΆ', 'ααΆαααΆααααααΆαα', 'α'](Perfectly intact) - β ALBERT (4 tokens):
['', 'αααααα»αααααΆαααΆ', 'ααΆαααΆααααααΆαα', 'α'] - β XLM-R (8 tokens):
['αααα', 'αα»ααα', 'ααΆαααΆ', 'ααΆα', 'ααΆα', 'α', 'ααααΆαα', 'α'](Severely fractured)
3. Pure Khmer (Formal)
Text: ααΆαααααααααααααΈααΆαααααααα»αααααααΆ
- β
OUR (3 tokens):
['ααΆαααααααααααααΈ', 'ααΆαααααα', 'αα»αααααααΆ'] - β
ALBERT (3 tokens):
['ααΆαααααααααααααΈ', 'ααΆα', 'ααααααα»αααααααΆ'] - β XLM-R (9 tokens):
['', 'ααΆαααααααααααααΈ', 'ααΆα', 'αα', 'ααα', 'αα»', 'ααα', 'αα', 'ααΆ'](Fractures sub-consonants)
4. Pure Khmer (Long Sentence)
Text: αααααα»αααααΆαααΆααΊααΆααΆαααΆα
αααααααα»αααααααααααα»ααΆα
- β
OUR (6 tokens):
['αααααα»αααααΆαααΆ', 'ααΊααΆ', 'ααΆαααΆ', 'α αααα', 'αααα»α', 'ααααααααααα»ααΆα'] - β ALBERT (8 tokens):
['', 'αααααα»αααααΆαααΆ', 'ααΊααΆ', 'ααΆαααΆ', 'α αααα', 'αααα»α', 'ααααααααααα»ααΆ', 'α'] - β XLM-R (10 tokens):
['αααα', 'αα»ααα', 'ααΆαααΆ', 'ααΊααΆ', 'ααΆαααΆ', 'α αα', 'αα', 'αααα»α', 'ααααααααααα»ααΆ', 'α']
5. Pure English (Complex)
Text: The quick brown fox jumps over the lazy dog.
- β
OUR (10 tokens):
['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', '.'] - β ALBERT (13 tokens):
['The', 'quick', 'brown', 'f', 'ox', 'jump', 's', 'over', 'the', 'la', 'zy', 'dog', '.'] - β XLM-R (13 tokens):
['The', 'quick', 'brown', '', 'fox', 'jump', 's', 'over', 'the', 'la', 'zy', 'dog', '.']
π» How to Use
1. Load the Model and Tokenizer
from transformers import AutoTokenizer, AlbertForMaskedLM
# Load from Hugging Face Hub
tokenizer = AutoTokenizer.from_pretrained("noson71/albert-khmer-codeswitch-64k")
model = AlbertForMaskedLM.from_pretrained("noson71/albert-khmer-codeswitch-64k")
# Test tokenization
text = "ααΎααααα»ααα·ααααΆα’αααΈ machine learning αα·α blockchain technologyα"
tokens = tokenizer.tokenize(text)
print(tokens)
# Output: ['ααΎα', 'αααα»α', 'αα·ααααΆα’αααΈ', 'β', 'machine', 'β', 'learning', 'αα·α', 'β', 'blockchain', 'β', 'technology', 'α']
# Note: 'β' represents a space prefix in the SentencePiece Metaspace decoder.
Citation
@misc{{noson71-albert-khmer-codeswitch-tokenizer,
author = {{NOSON.AI}},
title = {{ALBERT Khmer Code-Switching}},
year = {{2026}},
publisher = {{Hugging Face}},
url = {{https://huggingface.co/noson71/albert-khmer-codeswitch}}
}}
- Downloads last month
- 31