mengsay commited on
Commit
8db1c8d
·
verified ·
1 Parent(s): 61ac069

Upload mengsay/Gemma-3-Tonsai-1B-v0.1

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - km
4
+ - en
5
+ license: gemma
6
+ base_model: google/gemma-3-1b-pt
7
+ tags:
8
+ - khmer
9
+ - continued-pretraining
10
+ - gemma3
11
+ - tonsai
12
+ - preview
13
+ library_name: transformers
14
+ pipeline_tag: text-generation
15
+ ---
16
+
17
+ # Gemma-3-Tonsai-1B-v0.1
18
+
19
+ > **Preview Release**: This is an early preview (v0.1) for validation purposes.
20
+ > Not intended for production use. Evaluation and model quality may improve in future versions.
21
+
22
+ **Gemma-3-Tonsai-1B** is a Khmer-enhanced language model built through Continued Pre-Training (CPT)
23
+ of Google's [Gemma 3 1B](https://huggingface.co/google/gemma-3-1b-pt) on a mixture of Khmer, English, and parallel data.
24
+
25
+ "Tonsai" (ទន្សាយ) means "rabbit" in Khmer.
26
+
27
+ > **Note**: This is a **base model** trained via Continued Pre-Training. It is designed as a
28
+ > foundation for downstream task-specific fine-tuning (e.g., translation, summarization,
29
+ > question answering). For best results, we recommend fine-tuning on your target task
30
+ > using Supervised Fine-Tuning (SFT) before deployment.
31
+
32
+ ## Model Details
33
+
34
+ | | |
35
+ |---|---|
36
+ | **Base Model** | [google/gemma-3-1b-pt](https://huggingface.co/google/gemma-3-1b-pt) |
37
+ | **Training Method** | Continued Pre-Training (CPT), full parameter update |
38
+ | **Languages** | Khmer (km), English (en) |
39
+ | **Parameters** | ~1B |
40
+ | **Context Length** | 4096 tokens |
41
+ | **Precision** | bfloat16 |
42
+ | **License** | [Gemma Terms of Use](https://ai.google.dev/gemma/terms) |
43
+
44
+ ### Model Lineage
45
+
46
+ ```
47
+ google/gemma-3-1b-pt
48
+ └── mengsay/Gemma-3-Tonsai-1B-v0.1 (CPT on Khmer data)
49
+ ```
50
+
51
+ ## Training
52
+
53
+ ### Data Mix
54
+
55
+ | Dataset | Type | Weight | Role |
56
+ |---------|------|--------|------|
57
+ | [CulturaX](https://huggingface.co/datasets/uonlp/CulturaX) (km) | Monolingual | 55% | Khmer web text |
58
+ | [Wikipedia](https://huggingface.co/datasets/wikimedia/wikipedia) (km) | Monolingual | 5% | High-quality Khmer |
59
+ | [CulturaX](https://huggingface.co/datasets/uonlp/CulturaX) (en) | Monolingual | 10% | English retention |
60
+ | [OPUS-100](https://huggingface.co/datasets/Helsinki-NLP/opus-100) (en-km) | Parallel | 15% | Cross-lingual alignment |
61
+ | [OpenHermes 2.5](https://huggingface.co/datasets/teknium/OpenHermes-2.5) | Instruction | 10% | Instruction following |
62
+ | [Khmer Dictionary 44K](https://huggingface.co/datasets/seanghay/khmer-dictionary-44k) | Dictionary | 5% | Vocabulary knowledge |
63
+
64
+ ### Hyperparameters
65
+
66
+ | Parameter | Value |
67
+ |-----------|-------|
68
+ | Effective batch size | 64 (32 per device x 2 grad accum) |
69
+ | Max sequence length | 4096 |
70
+ | Learning rate | 5e-5 (embedding: 1e-5) |
71
+ | LR scheduler | Cosine with warmup |
72
+ | Warmup steps | 200 |
73
+ | Weight decay | 0.01 |
74
+ | Optimizer | AdamW 8-bit |
75
+ | Gradient checkpointing | Unsloth |
76
+ | Hardware | NVIDIA RTX PRO 6000 Blackwell (95GB VRAM) |
77
+
78
+ ## Evaluation
79
+
80
+ Evaluation on OPUS-100 (en-km) translation and Khmer perplexity tasks.
81
+
82
+ ### Perplexity (lower is better)
83
+
84
+ | Dataset | Gemma-3-1B-PT (base) | Tonsai-1B v0.1 |
85
+ |---------|----------------------|----------------|
86
+ | Wikipedia (km) | 9.06 | **2.14** |
87
+ | CulturaX (km) | 7.09 | 7.90 |
88
+
89
+ Khmer Wikipedia perplexity drops dramatically (9.06 → 2.14), showing significant improvement in Khmer text prediction.
90
+ CulturaX perplexity is comparable, as the model is still mid-training.
91
+
92
+ ### Translation (OPUS-100, 500 samples)
93
+
94
+ | Task | Setting | Metric | Gemma-3-1B-PT (base) | Tonsai-1B v0.1 |
95
+ |------|---------|--------|----------------------|----------------|
96
+ | en→km | zero-shot | BLEU | 1.62 | **18.04** |
97
+ | en→km | 5-shot | BLEU | 3.71 | **19.34** |
98
+ | en→km | zero-shot | chrF | 4.45 | **36.25** |
99
+ | en→km | 5-shot | chrF | 16.60 | **37.14** |
100
+ | km→en | zero-shot | BLEU | 9.38 | **19.66** |
101
+ | km→en | 5-shot | BLEU | 13.12 | **19.00** |
102
+ | km→en | zero-shot | chrF | 31.21 | **44.57** |
103
+ | km→en | 5-shot | chrF | 35.70 | **42.09** |
104
+
105
+ Translation performance improves substantially in both directions, especially en→km zero-shot (BLEU 1.62 → 18.04).
106
+
107
+ ## Usage
108
+
109
+ ### Text Generation
110
+
111
+ ```python
112
+ from transformers import AutoModelForCausalLM, AutoTokenizer
113
+ import torch
114
+
115
+ model_name = "mengsay/Gemma-3-Tonsai-1B-v0.1"
116
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
117
+ model = AutoModelForCausalLM.from_pretrained(
118
+ model_name,
119
+ torch_dtype=torch.bfloat16,
120
+ device_map="auto",
121
+ )
122
+
123
+ prompt = "ជីវិតរស់នៅក្នុងទីក្រុងសព្វថ្ងៃពិតជា"
124
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
125
+ output = model.generate(**inputs, max_new_tokens=200)
126
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
127
+ ```
128
+
129
+ ### Translation Example
130
+
131
+ ```python
132
+ prompt = "English: Cambodia is a country in Southeast Asia.\nKhmer:"
133
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
134
+ output = model.generate(**inputs, max_new_tokens=256, do_sample=False)
135
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
136
+ ```
137
+
138
+ ### With vLLM Serving
139
+
140
+ ```bash
141
+ # Start vLLM server
142
+ python -m vllm.entrypoints.openai.api_server \
143
+ --model mengsay/Gemma-3-Tonsai-1B-v0.1 --port 8000
144
+ ```
145
+
146
+ ```python
147
+ from openai import OpenAI
148
+
149
+ client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
150
+ response = client.completions.create(
151
+ model="mengsay/Gemma-3-Tonsai-1B-v0.1",
152
+ prompt="Cambodia is",
153
+ max_tokens=200,
154
+ )
155
+ print(response.choices[0].text)
156
+ ```
157
+
158
+ ## Intended Use
159
+
160
+ This model is a **continual pre-trained base model** — it has been trained to improve Khmer language
161
+ understanding and generation but has **not** been fine-tuned for any specific task or instruction following.
162
+
163
+ **Recommended workflow:**
164
+ 1. Use this model as a starting point for **Supervised Fine-Tuning (SFT)** on your target task
165
+ 2. Example downstream tasks: translation (en↔km), summarization, question answering, text classification
166
+ 3. Fine-tuning with even a few thousand task-specific examples can significantly improve performance
167
+
168
+ **Not recommended for:**
169
+ - Direct use as a chatbot or instruction-following assistant (use an instruction-tuned variant instead)
170
+ - Production deployment without task-specific fine-tuning and evaluation
171
+
172
+ ## Limitations
173
+
174
+ - This is a **preview release (v0.1)** intended for validation and research
175
+ - This is a CPT base model — **fine-tuning on a specific task is recommended** before use
176
+ - Not optimized for instruction following or conversational use
177
+ - May generate incorrect, biased, or harmful content
178
+ - Khmer language quality is preliminary; comprehensive benchmarks will follow in future versions
179
+ - Training data may contain biases present in web-crawled corpora
180
+
181
+ ## Citation
182
+
183
+ ```bibtex
184
+ @misc{tonsai-lm-2026,
185
+ title = {Tonsai LM: Continued Pre-Training for Khmer Language Models},
186
+ author = {Mengsay Loem},
187
+ year = {2026},
188
+ url = {https://huggingface.co/mengsay/Gemma-3-Tonsai-1B-v0.1}
189
+ }
190
+ ```
191
+
192
+ ## Acknowledgements
193
+
194
+ - [Google Gemma](https://ai.google.dev/gemma) team for the base model
195
+ - [Unsloth](https://github.com/unslothai/unsloth) for training optimization
196
+ - HuggingFace dataset contributors for open Khmer language resources
197
+ - [Tonsai LM project](https://github.com/loem-ms/tonsai-lm)
config.json ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "Gemma3ForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "bos_token_id": 2,
10
+ "cache_implementation": "hybrid",
11
+ "dtype": "bfloat16",
12
+ "eos_token_id": 1,
13
+ "final_logit_softcapping": null,
14
+ "head_dim": 256,
15
+ "hidden_activation": "gelu_pytorch_tanh",
16
+ "hidden_size": 1152,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 6912,
19
+ "layer_types": [
20
+ "sliding_attention",
21
+ "sliding_attention",
22
+ "sliding_attention",
23
+ "sliding_attention",
24
+ "sliding_attention",
25
+ "full_attention",
26
+ "sliding_attention",
27
+ "sliding_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "sliding_attention",
31
+ "full_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "sliding_attention",
37
+ "full_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "sliding_attention",
43
+ "full_attention",
44
+ "sliding_attention",
45
+ "sliding_attention"
46
+ ],
47
+ "max_position_embeddings": 32768,
48
+ "model_name": "unsloth/gemma-3-1b-pt",
49
+ "model_type": "gemma3_text",
50
+ "num_attention_heads": 4,
51
+ "num_hidden_layers": 26,
52
+ "num_key_value_heads": 1,
53
+ "pad_token_id": 0,
54
+ "query_pre_attn_scalar": 256,
55
+ "rms_norm_eps": 1e-06,
56
+ "rope_local_base_freq": 10000.0,
57
+ "rope_parameters": {
58
+ "full_attention": {
59
+ "rope_theta": 1000000,
60
+ "rope_type": "default"
61
+ },
62
+ "sliding_attention": {
63
+ "rope_theta": 10000,
64
+ "rope_type": "default"
65
+ }
66
+ },
67
+ "rope_scaling": {
68
+ "rope_type": "default"
69
+ },
70
+ "rope_theta": 1000000.0,
71
+ "sliding_window": 512,
72
+ "sliding_window_pattern": 6,
73
+ "transformers_version": "4.57.6",
74
+ "unsloth_fixed": true,
75
+ "use_bidirectional_attention": false,
76
+ "use_cache": false,
77
+ "vocab_size": 262144
78
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "cache_implementation": "hybrid",
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 1,
7
+ 106
8
+ ],
9
+ "max_length": 32768,
10
+ "pad_token_id": 0,
11
+ "top_k": 64,
12
+ "top_p": 0.95,
13
+ "transformers_version": "4.57.6"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f2493b213c76018b83dfc5a14352066f212df339ff54483be77b660dcaafef7
3
+ size 1999811208
special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<bos>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<eos>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "mask_token": {
17
+ "content": "<mask>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "pad_token": {
24
+ "content": "<pad>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "<unk>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:daab2354f8a74e70d70b4d1f804939b68a8c9624dd06cb7858e52dd8970e9726
3
+ size 33384567
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff