|
|
--- |
|
|
license: apache-2.0 |
|
|
datasets: |
|
|
- UpMath/Thai-HomeworkGen-138K |
|
|
base_model: |
|
|
- Qwen/Qwen2.5-7B |
|
|
pipeline_tag: text-generation |
|
|
--- |
|
|
|
|
|
# 🤖 Thai-HomeworkGen — โมเดลสร้าง/แก้โจทย์คณิตศาสตร์ภาษาไทย |
|
|
|
|
|
**Thai-HomeworkGen** เป็นโมเดลภาษาไทยขนาด 4B ที่ถูก fine-tune ด้วยเทคนิค **Supervised Fine-tuning (SFT)** |
|
|
โดยใช้ไลบรารี [`trl`](https://github.com/huggingface/trl) ร่วมกับ **QLoRA** บนฐาน [Qwen/Qwen2.5-7B](https://huggingface.co/Qwen/Qwen2.5-7B) |
|
|
|
|
|
--- |
|
|
|
|
|
## 🧪 ตัวอย่างการใช้งาน |
|
|
|
|
|
```python |
|
|
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM |
|
|
import torch |
|
|
|
|
|
tokenizer = AutoTokenizer.from_pretrained("UpMath/Thai-HomeworkGen-4B-v2") |
|
|
model = AutoModelForCausalLM.from_pretrained("UpMath/Thai-HomeworkGen-4B-v2",device_map="auto") |
|
|
|
|
|
generator = pipeline( |
|
|
"text-generation", |
|
|
model=model, |
|
|
tokenizer=tokenizer, |
|
|
device_map="auto", |
|
|
max_new_tokens=2048, |
|
|
do_sample=True, |
|
|
temperature=0.7, |
|
|
pad_token_id=tokenizer.eos_token_id |
|
|
) |
|
|
|
|
|
prompt = """ |
|
|
โปรดสร้างโจทย์คณิตศาสตร์ใหม่ โดยมีรายละเอียดดังนี้: |
|
|
ระดับ Bloom: ["วิเคราะห์"] # หรือ ["วิเคราะห์", "จดจำ", .....] |
|
|
ระดับชั้น: มัธยมศึกษาปีที่ 4 |
|
|
รูปแบบ: ปรนัย # หรือ อัตนัย |
|
|
โปรดสร้างโจทย์ พร้อมวิธีทำและคำตอบ: |
|
|
""" |
|
|
|
|
|
result = generator(prompt)[0]['generated_text'] |
|
|
print(result) |
|
|
``` |
|
|
|
|
|
--- |
|
|
|
|
|
## 🎯 จุดประสงค์ของโมเดล |
|
|
|
|
|
- ✅ สร้างโจทย์คณิตศาสตร์ใหม่ในรูปแบบภาษาไทย |
|
|
- ✅ แสดงวิธีทำและคำตอบที่ชัดเจน |
|
|
- ✅ รองรับระดับความคิดตามแนวทาง **Bloom’s Taxonomy** |
|
|
- ✅ ออกแบบมาเพื่อใช้ในบริบทการศึกษา การสอน และการวัดผล reasoning |
|
|
|
|
|
--- |
|
|
|
|
|
## 🧠 ข้อมูลการฝึก (Training Details) |
|
|
|
|
|
- **Base Model:** `Qwen/Qwen2.5-7B` |
|
|
- **Library:** [`trl`](https://github.com/huggingface/trl) (`SFTTrainer`) |
|
|
- **Adapter:** QLoRA (`peft`) |
|
|
- **Batch Size:** 2 × 4 (gradient_accumulation) |
|
|
- **Epochs:** 3 |
|
|
- **Sequence Length:** 1024 |
|
|
- **Dataset:** Thai Math Dataset (~138K examples, translated + aligned) |
|
|
|
|
|
โมเดลถูกฝึกด้วย QLoRA โดยใช้เทคนิค **low-rank adapter (LoRA)** ร่วมกับ quantization 4-bit |
|
|
เพื่อให้สามารถฝึกบน GPU ขนาดกลาง เช่น A100 หรือ Colab Pro ได้อย่างมีประสิทธิภาพ |
|
|
|
|
|
--- |
|
|
|
|
|
## 📦 Dataset ที่ใช้ |
|
|
ชื่อชุดข้อมูล: **Thai-HomeworkGen-138K** |
|
|
เนื้อหา: โจทย์คณิตศาสตร์ภาษาไทยระดับมัธยมปลาย พร้อมวิธีทำ คำตอบ และระดับ Bloom Taxonomy |
|
|
ต้นฉบับแปลจากชุดข้อมูลภาษาอังกฤษ |
|
|
1. [MathQA (allenai)](https://huggingface.co/datasets/allenai/math_qa) |
|
|
2. [MATH-500 (HuggingFaceH4)](https://huggingface.co/datasets/HuggingFaceH4/MATH-500) |
|
|
3. [MATH-Algebra](https://huggingface.co/datasets/themanas021/MATH-Algebra) |
|
|
4. [math-mixture: mix_intermediate_algebra97_algebra01_prealgebra00](https://huggingface.co/datasets/andrewsiah/math-mixture-mix_intermediate_algebra97_algebra01_prealgebra00) |
|
|
5. [math-mixture: mix_algebra76_prealgebra12_number_theory08](https://huggingface.co/datasets/andrewsiah/math-mixture-mix_algebra76_prealgebra12_number_theory08) |
|
|
6. [Math-algebra (datafreak)](https://huggingface.co/datasets/datafreak/Math-algebra) |
|
|
7. [MATH Dataset (Hendrycks et al.)](https://github.com/hendrycks/math/) |
|
|
8. [GSM8K (openai)](https://huggingface.co/datasets/openai/gsm8k) |
|
|
9. [Math QSA Dataset (Kaggle)](https://www.kaggle.com/datasets/awsaf49/math-qsa-dataset) |
|
|
10. [AQuA (DeepMind)](https://github.com/google-deepmind/AQuA) |
|
|
|
|
|
ชุดข้อมูลถูกแปลและจัดโครงสร้างโดยใช้ LLM (Gemma 2 27B) พร้อมตรวจสอบโดยผู้เชี่ยวชาญจาก สวทช. |
|
|
|
|
|
👉 [ดูรายละเอียดของ Dataset](https://huggingface.co/datasets/UpMath/Thai-HomeworkGen-138K) |
|
|
|
|
|
--- |
|
|
|
|
|
## การอ้างอิง |
|
|
หากคุณใช้งานโมเดลนี้ สามารถให้เครดิตโปรเจกต์นี้ได้ด้วย |