ikala/tmmluplus
Viewer • Updated • 22.2k • 6.68k • 242
How to use bjo4/Inkling-2-Mini-TW-Sovereign with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("thinkingmachines/Inkling-2-Mini")
model = PeftModel.from_pretrained(base_model, "bjo4/Inkling-2-Mini-TW-Sovereign")📄 點此閱讀/下載完整學術研究論文 PDF(8 頁 A4 期刊排版格式)
🔗 線上預覽論文 PDF (Hugging Face 檔案檢視器)
📝 閱讀完整技術文章(kuroshimae research)
Inkling-2-Mini-TW-Sovereign 是以 thinkingmachines/Inkling-2-Mini(26.4B 總參數的稀疏 MoE 模型,24 層權重、每層 128 個 expert 選 8 個;中段 12 層重複跑 3 次共 48 次 layer 運算,單次 forward 啟用 3.4B 參數、有效啟用參數 5.4B)為基底,在單張 NVIDIA GeForce RTX 5090(32 GB)上使用台灣法規、國考、歷屆學測/指考/分科測驗與在地知識進行 QLoRA(load_in_4bit=True, r=16, α=32,可訓練參數 405,110,784 個,佔 26.8B 之 1.51%)微調之台灣主權 AI 小模型(純訓練時間約 94.2 分鐘)。
| 評測時間點與模型版本 | 測試模式 | Formosa-bench台灣常識 (349) |
tw-legal-v1台灣法規 (209) |
TMMLU+ test國考專業 (200) |
CEEC學測/指考 (300) |
1,058 題總分 (答對題數) |
|---|---|---|---|---|---|---|
| 1. 原始模型 (Stage 0) | 閉卷 | 56.73% (198) | 28.71% (60) | 53.00% (106) | 63.00% (189) | 52.27% (553) |
| 2. Phase 1(SFT 300 步之後) | 閉卷 | 67.34% (235) | 40.67% (85) | 61.50% (123) | 73.00% (219) | 62.57% (662) |
| 3. Phase 2(SFT 160 步之後)★ 閉卷最高 | 閉卷 | 70.77% (247) | 49.76% (104) | 63.50% (127) | 76.00% (228) | 66.73% (706) |
| 4. Phase 2(再做 DPO 80 對+RLVR 20 題) | 閉卷 | 69.05% (241) | 47.85% (100) | 62.50% (125) | 75.00% (225) | 65.31% (691) |
| 5. Phase 3(閉卷) | 閉卷 | 66.19% (231) | 47.85% (100) | 60.50% (121) | 73.67% (221) | 63.61% (673) |
| 6. Phase 3(開卷:BM25 Top-3 檢索)★ 總分最高 | 開卷 | 68.48% (239) | 61.24% (128) | 65.50% (131) | 75.67% (227) | 68.53% (725) |
48.02% 升到 58.44%(+79 題);接續的 DPO(120 對)僅 +1 題(58.58%),RLVR(30 題 × 4 次取樣,平均獎勵由前 10 步 0.856 降至後 10 步 0.550)則為 +0 題。62.57% 升到 66.73%(閉卷最高分);但接著做 DPO+RLVR 反而掉到 65.31%(少 15 題)。因此 Phase 3 合併的是 Phase 1 與 Phase 2 的 SFT adapter。tw-legal-benchmark-v1 從閉卷的 47.85% 跳到 **61.24%**(比原始模型 28.71% 多對 68 題)。Formosa-bench 在 Phase 2 閉卷最高(**70.77%**)。import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE_MODEL = "thinkingmachines/Inkling-2-Mini"
# 預設根目錄為 Phase 3(適合搭配 BM25 法規檢索開卷問答)
# 若為無檢索之閉卷一般問答,可指定 subfolder="phase2_closed_book_lora"
LORA_ADAPTER = "bjo4/Inkling-2-Mini-TW-Sovereign"
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
base_model = AutoModelForCausalLM.from_pretrained(
BASE_MODEL,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True,
)
model = PeftModel.from_pretrained(base_model, LORA_ADAPTER)
model.eval()
<|content_thinking|> + <|content_text|>)與法規檢索推論範例
system_prompt = (
"你是台灣主權 AI 助手,熟悉台灣法規、考試與在地知識。"
"請先在思考段進行推理與選項消去,再於回答段最後給出『最終答案:X』。"
)
user_question = """[檢索參考資料]
- [法規知識 #1] 依中華民國《民法》第 12 條規定(民國 110 年修正,112 年 1 月 1 日施行):「滿十八歲為成年。」
- [法規知識 #2] 《民法》第 13 條:「未滿七歲之未成年人,無行為能力。滿七歲以上之未成年人,有限制行為能力。」
問題:依現行中華民國《民法》規定,幾歲為成年,具備完全行為能力?
(A) 滿 16 歲
(B) 滿 18 歲
(C) 滿 20 歲
(D) 滿 21 歲"""
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_question},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
pad_token_id=tokenizer.eos_token_id,
)
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False)
print(response)
Inkling_2_Mini_TW_Sovereign_Academic_Paper.pdf(直接下載 PDF):完整 8 頁 A4 學術論文形式研究與實測報告 PDF。adapter_model.safetensors *(根目錄)*:Phase 3 開卷檢索增強版 LoRA 權重(1,058 題開卷總分 **68.53%**、台灣法規 **61.24%**、TMMLU+ **65.50%**)。phase2_closed_book_lora/:Phase 2 閉卷版 LoRA 權重(適合不加檢索之閉卷問答,1,058 題閉卷總分 **66.73%**、Formosa-bench **70.77%**、大考中心 CEEC **76.00%**)。raft_index/taiwan_sovereign_kb.jsonl:21,729 段台灣法規條文、學科筆記與考題解析檢索庫(供 rank_bm25 檢索 Top-3 段落使用)。phase3_evaluation_report.json:1,058 題保留測試集各階段原始評測結果 JSON。@techreport{inkling2_mini_tw_sovereign_2026,
title={Post-Training a Lightweight Taiwan Sovereign Language Model on a Single RTX 5090: Multi-Stage QLoRA Fine-Tuning and Retrieval-Augmented Evaluation on Inkling-2-Mini (26.4B MoE)},
author={Warren},
year={2026},
month={November},
url={https://www.kuroshimae.cc/research/inkling-2-mini-tw-finetune},
note={Model & Paper PDF: https://huggingface.co/bjo4/Inkling-2-Mini-TW-Sovereign}
}
Base model
thinkingmachines/Inkling-2-Mini