Instructions to use UpMath/Thai-HomeworkGen-7.2B-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use UpMath/Thai-HomeworkGen-7.2B-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="UpMath/Thai-HomeworkGen-7.2B-v1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("UpMath/Thai-HomeworkGen-7.2B-v1") model = AutoModelForCausalLM.from_pretrained("UpMath/Thai-HomeworkGen-7.2B-v1") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use UpMath/Thai-HomeworkGen-7.2B-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "UpMath/Thai-HomeworkGen-7.2B-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UpMath/Thai-HomeworkGen-7.2B-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/UpMath/Thai-HomeworkGen-7.2B-v1
- SGLang
How to use UpMath/Thai-HomeworkGen-7.2B-v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "UpMath/Thai-HomeworkGen-7.2B-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UpMath/Thai-HomeworkGen-7.2B-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "UpMath/Thai-HomeworkGen-7.2B-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "UpMath/Thai-HomeworkGen-7.2B-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use UpMath/Thai-HomeworkGen-7.2B-v1 with Docker Model Runner:
docker model run hf.co/UpMath/Thai-HomeworkGen-7.2B-v1
🤖 Thai-HomeworkGen — โมเดลสร้าง/แก้โจทย์คณิตศาสตร์ภาษาไทย
Thai-HomeworkGen เป็นโมเดลภาษาไทยขนาด 7B ที่ถูก fine-tune ด้วยเทคนิค Supervised Fine-tuning (SFT)
โดยใช้ไลบรารี trl ร่วมกับ QLoRA บนฐาน mistralai/Mistral-7B-Instruct-v0.3
🧪 ตัวอย่างการใช้งาน
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
import torch
tokenizer = AutoTokenizer.from_pretrained("UpMath/Thai-HomeworkGen-7.2B-v1")
model = AutoModelForCausalLM.from_pretrained("UpMath/Thai-HomeworkGen-7.2B-v1",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:
mistralai/Mistral-7B-Instruct-v0.3 - Library:
trl(SFTTrainer) - Adapter: QLoRA (
peft) - Batch Size: 2 × 4 (gradient_accumulation)
- Epochs: 3
- Sequence Length: 1024
- Dataset: Thai Math Dataset (~32K examples, translated + aligned)
โมเดลถูกฝึกด้วย QLoRA โดยใช้เทคนิค low-rank adapter (LoRA) ร่วมกับ quantization 4-bit
เพื่อให้สามารถฝึกบน GPU ขนาดกลาง เช่น A100 หรือ Colab Pro ได้อย่างมีประสิทธิภาพ
📦 Dataset ที่ใช้
ชื่อชุดข้อมูล: Thai-HomeworkGen-32K เนื้อหา: โจทย์คณิตศาสตร์ภาษาไทยระดับมัธยมปลาย พร้อมวิธีทำ คำตอบ และระดับ Bloom Taxonomy ต้นฉบับแปลจากชุดข้อมูลภาษาอังกฤษ
- MathQA (allenai)
- MATH-500 (HuggingFaceH4)
- MATH-Algebra
- math-mixture: mix_intermediate_algebra97_algebra01_prealgebra00
- math-mixture: mix_algebra76_prealgebra12_number_theory08
- Math-algebra (datafreak)
- MATH Dataset (Hendrycks et al.)
- GSM8K (openai)
- Math QSA Dataset (Kaggle)
- AQuA (DeepMind)
ชุดข้อมูลถูกแปลและจัดโครงสร้างโดยใช้ LLM (Gemma 2 27B) พร้อมตรวจสอบโดยผู้เชี่ยวชาญจาก สวทช.
การอ้างอิง
หากคุณใช้งานโมเดลนี้ สามารถให้เครดิตโปรเจกต์นี้ได้ด้วย
- Downloads last month
- 2
Model tree for UpMath/Thai-HomeworkGen-7.2B-v1
Base model
mistralai/Mistral-7B-v0.3