amkyawdev commited on
Commit
f463bcd
·
verified ·
1 Parent(s): 98d2bbe

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +213 -69
README.md CHANGED
@@ -1,36 +1,37 @@
1
- ---
2
- license: mit
3
- tags:
4
- - burmese
5
- - myanmar
6
- - llm
7
- - code-generation
8
- - fine-tuned
9
- - lora
10
- - phi-2
11
- datasets:
12
- - amkyawdev/myanmar-llm-data
13
- ---
14
-
15
  # mm-llm-coder-lite-v1
16
 
17
- Myanmar Lightweight LLM for Code Generation and Conversation
 
 
 
 
 
18
 
19
  ## 📌 Overview
20
 
21
- This is a fine-tuned lightweight LLM model for Myanmar (Burmese) language understanding, code generation, and conversational tasks. The model is based on [microsoft/phi-2](https://huggingface.co/microsoft/phi-2) and fine-tuned using LoRA technique.
 
 
 
 
 
 
 
22
 
23
  ## 🏗️ Architecture
24
 
25
- - **Base Model**: microsoft/phi-2
26
- - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
27
- - **Training Framework**: Hugging Face Transformers + PEFT + TRL
28
- - **Language**: Burmese (Myanmar)
 
 
 
29
 
30
  ## 📊 Training Details
31
 
32
  | Parameter | Value |
33
- |-----------|-------|
34
  | Base Model | microsoft/phi-2 |
35
  | Training Epochs | 3 |
36
  | Learning Rate | 2e-4 |
@@ -45,52 +46,66 @@ This is a fine-tuned lightweight LLM model for Myanmar (Burmese) language unders
45
 
46
  Trained on [amkyawdev/myanmar-llm-data](https://huggingface.co/datasets/amkyawdev/myanmar-llm-data):
47
 
48
- | Tag | Description |
49
- |-----|-------------|
50
- | coding | Programming conversations (90%) |
51
- | translation | English-Myanmar translation (1%) |
52
- | general | General knowledge Q&A (1%) |
53
- | greeting | Burmese greetings (1%) |
54
 
55
  ### Dataset Statistics
56
- - Train: ~20,327 samples
57
- - Test: ~17,155 samples
58
- - Validation: ~17,071 samples
59
 
60
  ## 🚀 Quick Start
61
 
62
  ### Installation
63
 
64
  ```bash
65
- pip install -r requirements.txt
66
  ```
67
 
68
- ### Fine-tuning
69
-
70
- ```bash
71
- python finetune_mm_llm.py
72
- ```
73
-
74
- ### Inference
75
 
76
  ```python
77
  from transformers import AutoModelForCausalLM, AutoTokenizer
78
 
79
- # Load model
80
  model_name = "amkyawdev/mm-llm-coder-lite-v1"
81
  tokenizer = AutoTokenizer.from_pretrained(model_name)
82
- model = AutoModelForCausalLM.from_pretrained(model_name)
 
 
 
 
 
 
 
83
 
84
  # Generate response
85
- input_text = "System: သင်သည် မြန်မာစာကျွမ်းကျင်သော AI အကူအညီပေးသူဖြစ်သည်။\n\nUser: မင်္ဂလာပါ။"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
- inputs = tokenizer(input_text, return_tensors="pt")
88
- outputs = model.generate(**inputs, max_new_tokens=100)
89
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
90
  print(response)
91
  ```
92
 
93
- ### Using with Transformers Pipeline
94
 
95
  ```python
96
  from transformers import pipeline
@@ -98,13 +113,137 @@ from transformers import pipeline
98
  pipe = pipeline(
99
  "text-generation",
100
  model="amkyawdev/mm-llm-coder-lite-v1",
101
- tokenizer="amkyawdev/mm-llm-coder-lite-v1"
 
 
102
  )
103
 
104
- result = pipe("User: ဟိုင်း၊ေကေ်းား။")
 
 
 
 
 
 
105
  print(result[0]['generated_text'])
106
  ```
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  ## 📋 Requirements
109
 
110
  ```
@@ -118,36 +257,41 @@ datasets>=2.14.0
118
 
119
  ## 🔧 Configuration
120
 
121
- Edit `Config` class in `finetune_mm_llm.py` to customize:
122
-
123
  ```python
124
- class Config:
125
- MODEL_NAME = "microsoft/phi-2" # Change base model
126
- OUTPUT_DIR = "./mm-llm-coder-lite-v1"
127
- TRAIN_PATH = "/workspace/train.jsonl"
128
- # ... more settings
 
 
 
 
 
 
 
129
  ```
130
 
131
- ## 📝 Output
132
 
133
- After training, the model will be saved to `./mm-llm-coder-lite-v1/` with:
134
- - `adapter_config.json` - LoRA config
135
- - `adapter_model.safetensors` - LoRA weights
136
- - `tokenizer.json` - Tokenizer
137
- - `tokenizer_config.json` - Tokenizer config
138
- - `training_config.json` - Training config
139
 
140
- ## 🏷️ Tags
141
 
142
- - `burmese` - Myanmar language
143
- - `llm` - Large Language Model
144
- - `code-generation` - Code generation
145
- - `fine-tuned` - Fine-tuned model
146
 
147
- ## 📜 License
 
 
148
 
149
- MIT License
150
 
151
- ## 👤 Author
 
 
 
 
152
 
153
- [amkyawdev](https://huggingface.co/amkyawdev)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # mm-llm-coder-lite-v1
2
 
3
+ <p align="center">
4
+ <img src="https://img.shields.io/badge/Myanmar-LLM-blue?style=for-the-badge&logo=huggingface" alt="License">
5
+ <img src="https://img.shields.io/badge/License-MIT-green?style=for-the-badge" alt="License">
6
+ <img src="https://img.shields.io/badge/Model-phi--2-orange?style=for-the-badge" alt="Base Model">
7
+ <img src="https://img.shields.io/badge/Fine--tuned-LoRA-red?style=for-the-badge" alt="Method">
8
+ </p>
9
 
10
  ## 📌 Overview
11
 
12
+ **mm-llm-coder-lite-v1** is a specialized Large Language Model (LLM) fine-tuned for Myanmar (Burmese) language understanding, code generation, and conversational tasks. The model is based on Microsoft's `phi-2` and fine-tuned using Low-Rank Adaptation (LoRA) technique.
13
+
14
+ ### Key Features
15
+
16
+ - 🌍 **Myanmar Language Support**: Specialized in Burmese/Myanmar language processing
17
+ - 💻 **Code Generation**: Supports Python, JavaScript, and other programming languages
18
+ - 💬 **Conversational AI**: Can engage in natural dialogue in Myanmar language
19
+ - ⚡ **Lightweight**: Optimized for efficient inference with LoRA
20
 
21
  ## 🏗️ Architecture
22
 
23
+ | Component | Details |
24
+ |----------|---------|
25
+ | **Base Model** | microsoft/phi-2 |
26
+ | **Fine-tuning Method** | LoRA (Low-Rank Adaptation) |
27
+ | **Training Framework** | Hugging Face Transformers + PEFT + TRL |
28
+ | **Language** | Burmese (Myanmar) |
29
+ | **Parameters** | ~2.7B total (trainable: ~2.6M) |
30
 
31
  ## 📊 Training Details
32
 
33
  | Parameter | Value |
34
+ |----------|-------|
35
  | Base Model | microsoft/phi-2 |
36
  | Training Epochs | 3 |
37
  | Learning Rate | 2e-4 |
 
46
 
47
  Trained on [amkyawdev/myanmar-llm-data](https://huggingface.co/datasets/amkyawdev/myanmar-llm-data):
48
 
49
+ | Tag | Description | Percentage |
50
+ |-----|-------------|------------|
51
+ | coding | Programming conversations | 90% |
52
+ | translation | English-Myanmar translation | 1% |
53
+ | general | General knowledge Q&A | 1% |
54
+ | greeting | Burmese greetings | 1% |
55
 
56
  ### Dataset Statistics
57
+ - **Train**: ~20,327 samples
58
+ - **Test**: ~17,155 samples
59
+ - **Validation**: ~17,071 samples
60
 
61
  ## 🚀 Quick Start
62
 
63
  ### Installation
64
 
65
  ```bash
66
+ pip install torch transformers peft accelerate datasets
67
  ```
68
 
69
+ ### Basic Inference
 
 
 
 
 
 
70
 
71
  ```python
72
  from transformers import AutoModelForCausalLM, AutoTokenizer
73
 
74
+ # Load model and tokenizer
75
  model_name = "amkyawdev/mm-llm-coder-lite-v1"
76
  tokenizer = AutoTokenizer.from_pretrained(model_name)
77
+ model = AutoModelForCausalLM.from_pretrained(
78
+ model_name,
79
+ torch_dtype=torch.float16,
80
+ device_map="auto"
81
+ )
82
+
83
+ # Set pad token
84
+ tokenizer.pad_token = tokenizer.eos_token
85
 
86
  # Generate response
87
+ input_text = """System: သင်သည် မြန်မာစာကျွမ်းကျင်သော AI အကူအညီပေးသူဖြစ်သည်။
88
+
89
+ User: Python နဲ့ Fibonacci စီးရီးထုတ်တဲ့ function ရေးပေးပါ။
90
+
91
+ Assistant:"""
92
+
93
+ inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=512)
94
+ inputs = {k: v.to(model.device) for k, v in inputs.items()}
95
+
96
+ outputs = model.generate(
97
+ **inputs,
98
+ max_new_tokens=256,
99
+ temperature=0.7,
100
+ top_p=0.95,
101
+ do_sample=True
102
+ )
103
 
 
 
104
  response = tokenizer.decode(outputs[0], skip_special_tokens=True)
105
  print(response)
106
  ```
107
 
108
+ ### Using Pipeline
109
 
110
  ```python
111
  from transformers import pipeline
 
113
  pipe = pipeline(
114
  "text-generation",
115
  model="amkyawdev/mm-llm-coder-lite-v1",
116
+ tokenizer="amkyawdev/mm-llm-coder-lite-v1",
117
+ device_map="auto",
118
+ torch_dtype=torch.float16
119
  )
120
 
121
+ prompt = """System: င်သည် မြ်မစာကျွမ်းကျင်သေ AI အကူအညီပေသူဖြစ်သည်
122
+
123
+ User: ဟိုင်း၊ နေကောင်းလား။
124
+
125
+ Assistant:"""
126
+
127
+ result = pipe(prompt, max_new_tokens=128, temperature=0.7)
128
  print(result[0]['generated_text'])
129
  ```
130
 
131
+ ## 📝 Prompt Template
132
+
133
+ This model uses the following prompt format:
134
+
135
+ ```
136
+ System: <system_prompt>
137
+
138
+ User: <user_message>
139
+
140
+ Assistant: <assistant_response><eos>
141
+ ```
142
+
143
+ ### Example Prompt
144
+
145
+ ```
146
+ System: သင်သည် မြန်မာစာကျွမ်းကျင်သော AI အကူအညီပေးသူဖြစ်သည်။
147
+
148
+ User: မင်္ဂလာပါ။
149
+
150
+ Assistant: မင်္ဂလာပါရှင်း။ သင့်အား ကူညီပါသည်။<eos>
151
+ ```
152
+
153
+ ## 🖥️ Deployment
154
+
155
+ ### GGUF Conversion (for LM Studio / Ollama)
156
+
157
+ ```python
158
+ # Install required packages
159
+ # pip install transformers peft accelerate sentencepiece
160
+
161
+ from transformers import AutoModelForCausalLM, AutoTokenizer
162
+ import torch
163
+
164
+ # Load model
165
+ model_name = "amkyawdev/mm-llm-coder-lite-v1"
166
+ model = AutoModelForCausalLM.from_pretrained(
167
+ model_name,
168
+ torch_dtype=torch.float16,
169
+ device_map="cpu",
170
+ low_cpu_mem_usage=True
171
+ )
172
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
173
+
174
+ # Merge LoRA weights (if using PEFT)
175
+ # Note: This model uses LoRA adapters
176
+
177
+ # Save merged model
178
+ output_dir = "./mm-llm-merged"
179
+ model.save_merged(output_dir)
180
+ tokenizer.save_pretrained(output_dir)
181
+
182
+ # Convert to GGUF using llama.cpp
183
+ # Follow: https://github.com/ggerganov/llama.cpp/tree/master/convert
184
+ ```
185
+
186
+ ### Ollama Deployment
187
+
188
+ ```bash
189
+ # Create Modelfile
190
+ FROM ./mm-llm-coder-lite-v1
191
+
192
+ PARAMETER temperature 0.7
193
+ PARAMETER top_p 0.95
194
+ PARAMETER top_k 40
195
+
196
+ TEMPLATE """System: {{ .System }}
197
+
198
+ User: {{ .Prompt }}
199
+
200
+ Assistant: {{ .Response }}<eos>"""
201
+
202
+ # Create model in Ollama
203
+ ollama create mm-llm-coder -f Modelfile
204
+
205
+ # Run
206
+ ollama run mm-llm-coder
207
+ ```
208
+
209
+ ## 📈 Evaluation
210
+
211
+ ### Myanmar Code Evaluation
212
+
213
+ ```python
214
+ # Example evaluation for Myanmar code generation
215
+
216
+ myanmar_prompts = [
217
+ "Python နဲ့ list ကို sort လုပ်နည်းရေးပါ။",
218
+ "JavaScript နဲ့ function ရေးပေးပါ။",
219
+ "မြန်မာ Unicode ကို Zawgyi ပြောင်းတဲ့ code ရေးပါ။",
220
+ ]
221
+
222
+ # Run generation and evaluate
223
+ def evaluate_model(prompts):
224
+ results = []
225
+ for prompt in prompts:
226
+ # Generate code
227
+ output = generate(prompt)
228
+ results.append({
229
+ "prompt": prompt,
230
+ "generated": output,
231
+ "success": check_syntax(output)
232
+ })
233
+ return results
234
+
235
+ # Calculate pass rate
236
+ success_rate = sum(1 for r in results if r["success"]) / len(results)
237
+ print(f"Success Rate: {success_rate * 100:.2f}%")
238
+ ```
239
+
240
+ ### Benchmark Adaptation
241
+
242
+ For Myanmar-specific evaluation, consider:
243
+ 1. Translating MBPP/MathEval prompts to Myanmar
244
+ 2. Creating Myanmar coding benchmarks
245
+ 3. Using BLEU/ROUGE for translation quality
246
+
247
  ## 📋 Requirements
248
 
249
  ```
 
257
 
258
  ## 🔧 Configuration
259
 
 
 
260
  ```python
261
+ from transformers import TrainingArguments
262
+
263
+ training_args = TrainingArguments(
264
+ output_dir="./mm-llm-output",
265
+ num_train_epochs=3,
266
+ per_device_train_batch_size=4,
267
+ learning_rate=2e-4,
268
+ fp16=True,
269
+ save_steps=500,
270
+ eval_steps=500,
271
+ save_total_limit=2,
272
+ )
273
  ```
274
 
275
+ ## 📜 License
276
 
277
+ This project is licensed under the **MIT License**.
 
 
 
 
 
278
 
279
+ See [LICENSE](LICENSE) for details.
280
 
281
+ ## 👤 Author
 
 
 
282
 
283
+ **Amkyaw Dev**
284
+ - GitHub: [@amkyawdev](https://github.com/amkyawdev)
285
+ - Hugging Face: [amkyawdev](https://huggingface.co/amkyawdev)
286
 
287
+ ## 🙏 Acknowledgments
288
 
289
+ - Microsoft for the phi-2 model
290
+ - Hugging Face for Transformers and PEFT
291
+ - The Myanmar NLP community
292
+
293
+ ---
294
 
295
+ <p align="center">
296
+ Made with ❤️ for Myanmar AI Community
297
+ </p>