Thai-Legal-Gemma-4B-CPT คือ
Gemma-4-E4B ที่ผ่านกระบวนการ
Continued Pre-Training (CPT) บนชุดข้อมูลกฎหมายไทยขนาดใหญ่ เพื่อปลูกฝังความเข้าใจระดับรากฐานด้านภาษาและโครงสร้างของกฎหมายไทย
โมเดลนี้เทรนด้วยการผสมข้อมูลหลายประเภทในสัดส่วน (Mix Ratio) ที่ออกแบบมาเพื่อเน้นกฎหมายไทยเป็นหลัก:
Training Objective : Next-Token Prediction (CLM)
Sequence Length : 8,192 tokens (Packed, no padding)
Batch Size : 1 (effective 256 via gradient accumulation)
Gradient Accum. : 256 steps
Optimizer : AdamW (adamw_torch_fused)
Learning Rate : 2e-5 (with warmup)
Precision : bf16
Gradient Checkpointing: True
KV Cache : Disabled (use_cache=False)
Hub Strategy : all_checkpoints (auto-save every 5 steps)
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "Phonsiri/Thai-Legal-Gemma-4B-CPT"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 torch_dtype=torch.bfloat16,
10 device_map="auto",
11)
12
13prompt = "ตามประมวลกฎหมายแพ่งและพาณิชย์ การกู้ยืมเงินเกินกว่าสองพันบาทขึ้นไป"
14inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
15
16outputs = model.generate(
17 **inputs,
18 max_new_tokens=300,
19 temperature=0.3,
20 top_p=0.9,
21 repetition_penalty=1.1,
22 do_sample=True,
23)
24print(tokenizer.decode(outputs[0], skip_special_tokens=True))
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
3
4model_id = "Phonsiri/Thai-Legal-Gemma-4B-CPT"
5
6tokenizer = AutoTokenizer.from_pretrained(model_id)
7model = AutoModelForCausalLM.from_pretrained(
8 model_id,
9 quantization_config=BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_compute_dtype=torch.bfloat16,
12 ),
13 device_map="auto",
14)
โมเดลนี้กำลังเทรนต่อเนื่อง Checkpoint จะถูก Push ขึ้น Hub โดยอัตโนมัติทุก 5 steps
[] Phase 1: Data Pipeline — ราชกิจจาฯ OCR + Wikipedia + Legal Datasets
[] Phase 2: CPT Training — Full pre-training บน H200 (กำลังดำเนินการ)
[ ] Phase 3: SFT — ถาม-ตอบกฎหมาย แบบ Instruction Following
[ ] Phase 4: GRPO/RLHF — Legal Reasoning (IRAC Framework)
[ ] Phase 5: RAG Integration — เชื่อมต่อฐานข้อมูลกฎหมายแบบ Real-time
โมเดลนี้ใช้ Base Model จาก Google Gemma ซึ่งอยู่ภายใต้
Gemma Terms of Use
ชุดข้อมูลราชกิจจานุเบกษาอยู่ภายใต้
CC BY-SA 4.0