Gemma 3 4b Xinyi Gazetteer LoRA
twinkle-ai/gemma-3-4B-T1-it(Gemma 3 4B,台灣語境 fine-tuned 開源模型)上的 QLoRA adapter,用《南投縣信義鄉志》編纂用論文語料庫的合成問答對微調,直接把信義鄉相關知識(歷史、地理、社會、文化、產業)微調進模型權重。
Fuente del modelo
- Tipo
- Other
- Tamaño del archivo
- 114 MB
- Modelo base
- twinkle-ai/gemma-3-4B-T1-it
- Versión
- vRevision 1b13a79
- Actualizado
- 22 oct 2026
- Descargas
- 10
- Fuente
- Hugging Face
Descripción de la fuente
gemma-3-4b-xinyi-gazetteer-lora
twinkle-ai/gemma-3-4B-T1-it(Gemma 3 4B,台灣語境 fine-tuned 開源模型)上的 QLoRA adapter,用《南投縣信義鄉志》編纂用論文語料庫的合成問答對微調,直接把信義鄉相關知識(歷史、地理、社會、文化、產業)微調進模型權重。
這是個人作品集/AI 工程練習的展示模型,示範本機 GPU(8GB VRAM)做 LoRA 微調的完整流程,不是給正式場合查證史實用的知識庫。 若需要有引用來源可查證的問答,請改用同一個專案裡的 RAG 系統(src/rag/query_engine.py/src/langchain_pipeline/answer_agent.py),每個論點都附真實段落來源與頁碼。
授權與來源標註(Attribution & Notice)
本模型的模型脈絡(lineage):
google/gemma-3-4b-pt (Google 原始基底模型)
→ twinkle-ai/gemma-3-4B-T1-it (Liang Hsun Huang、Min Yi Chen、
Wen Bin Lin、Dave Sung 開發;
APMIC、Jerry Wu 贊助;訓練資料含
nvidia/Nemotron-Instruction-Following-Chat-v1、
lianghsun/tw-contract-review-chat、
lianghsun/tw-reasoning-instruct)
→ 本 repo 的 LoRA adapter (用《南投縣信義鄉志》論文語料生成的
合成問答對做 QLoRA 微調,訓練程式碼與
流程見下方 GitHub 連結)
本模型是 Gemma 的修改版本(Model Derivative),使用與散布皆受 Gemma Terms of Use 拘束,並適用 Gemma Prohibited Use Policy——下載、使用、或進一步微調本模型的人,同樣需要遵守上述條款與禁止使用政策,不會因為經過我這層微調就不受拘束。
Notice: This model is a modification of Gemma, fine-tuned from
twinkle-ai/gemma-3-4B-T1-it(itself fine-tuned fromgoogle/gemma-3-4b-pt) via LoRA on a synthetic Q&A dataset derived from Xinyi Township Gazetteer research papers. Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms, and use of Gemma is subject to the Gemma Prohibited Use Policy. This is not an official Google product, and is not an official Twinkle AI product.
已知限制(務必先讀)
實測(evaluate.py,20 筆 held-out QA 肉眼比對)發現一個一致的模式:這個規模的 LoRA(可訓練參數僅佔全模型 0.76%)能學到語氣、格式、大致主題範圍,但對長尾的具體事實(專有名詞、確切數字、精確用語)記憶不穩定——模型仍然會用完全自信的語氣回答,而不是坦承不確定,產生「聽起來合理但細節錯誤」的內容(例如捏造人名、講反因果關係、用錯專有名詞)。
因此本模型不適合直接拿來回答需要精確史實的問題;比較適合的用途是:示範微調工作流程、觀察模型語氣/格式的學習效果、或作為需要進一步強化訓練資料與規模的起點。
訓練方式
- 基底模型:
twinkle-ai/gemma-3-4B-T1-it(gated,需先在 HF 接受授權才能載入) - 方法:Unsloth QLoRA(4-bit 量化基底 + LoRA),
r=16、lora_alpha=16、lora_dropout=0.0,target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"] - 只對 assistant 回答算 loss(
train_on_responses_only),不浪費訓練訊號在系統提示與問題上 - 訓練資料:Gemini(
gemini-3.1-flash-lite)針對已分類的鄉志論文段落生成的合成問答對,共 9,848 筆訓練樣本、152 筆 held-out 評估樣本;參考答案是 LLM 生成的合成資料,不是人工撰寫或校對過的 ground truth - 硬體:RTX 5060 Laptop GPU,8GB VRAM
- 訓練 3 個 epoch,但依 held-out loss 選擇最終權重:epoch 2(
eval_loss=1.961)優於 epoch 1(1.981)與 epoch 3(2.04,train loss 持續下降但 held-out loss 回升,是典型過擬合訊號),因此這個 repo 上傳的是 epoch 2 checkpoint 的權重,不是訓練跑完的最後一個 epoch
如何使用
基底模型是 gated model,需要先到 twinkle-ai/gemma-3-4B-T1-it 接受授權,並用自己的 HF token 載入:
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE_MODEL = "twinkle-ai/gemma-3-4B-T1-it"
ADAPTER = "wesleyishere123/gemma-3-4b-xinyi-gazetteer-lora"
tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, token="hf_你的token")
model = PeftModel.from_pretrained(model, ADAPTER)
messages = [
{"role": "system", "content": "你是熟悉《南投縣信義鄉志》相關知識的在地知識助理,請根據你所學到的信義鄉歷史、地理、社會、文化、產業等知識,用完整、正確的中文直接回答使用者的問題。"},
{"role": "user", "content": "布農族的射耳祭有什麼意義?"},
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(**inputs, max_new_tokens=300, do_sample=False)
print(tokenizer.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
相關連結
完整訓練流程(notebook、資料生成腳本、品質評測)與同專案的 RAG/LangChain agent 對照實驗,請見:github.com/boy8801127-sys/Xinyi_Township_Gazetteer
Framework versions
- PEFT 0.19.1
Fuentes
1 fuente
Fuentes
1 fuenteVerificado 22 oct
Artefactos del modelo
1 artefacto
Artefactos del modelo
1 artefactoExtractos de fuentes
3 extractos
Extractos de fuentes
3 extractos--- base_model: twinkle-ai/gemma-3-4B-T1-it library_name: peft license: gemma pipeline_tag: text-generation language: - zh tags: - lora - sft - unsloth - trl - gemma3 --- # gemma-3-4b-xinyi-gazetteer-lora `twinkle-ai/gemma-3-4B-T1-it`(Gemma 3 4B,台灣語境 fine-tuned 開源模型)上的 QLoRA adapter,用《南投縣信義鄉志》編纂用論文語料庫的合成問答對微調,直接把信義鄉相關知識(歷史、地理、社會、文化、產業)微調進模型權重。 **這是個人作品集/AI 工程練習的展示模型,示範本機 GPU(8GB VRAM)做 LoRA 微調的完整流程,不是給正式場合查證史實用的知識庫。** 若需要有引用來源可查證的問答,請改用同一個專案裡的 [RAG 系統](https://github.com/boy8801127-sys/Xinyi_Township_Gazetteer)(`src/rag/query_engine.py`/`src/langchain_pipeline/answer_agent.py`),每個論點都附真實段落來源與頁碼。 ## 授權與來源標註(Attribution & Notice) 本模型的模型脈絡(lineage): ``` google/gemma-3-4b-pt (Google 原始基底模型) → twinkle-ai/gemma-3-4B-T1-it (Liang Hsun Huang、Min Yi Chen、 Wen Bin Lin、Dave Sung 開發; APMIC、Jerry Wu 贊助;訓練資料含 nvidia/Nemotron-Instruction-Following-Chat-v1、 lianghsun/tw-contract-review-chat、 lianghsun/tw-reasoning-instruct) → 本 repo 的 LoRA adapter (用《南投縣信義鄉志》論文語料生成的 合成問答對做 QLoRA 微調,訓練程式碼與 流程見下方 GitHub 連結) ``` 本模型是 Gemma 的修改版本(Model Derivative),使用與散布皆受 [Gemma Terms of Use](https://ai.google.dev/gemma/terms) 拘束,並適用 [Gemma Prohibited Use Policy](https://ai.google.dev/gemma/prohibited_use_policy)——**下載、使用、或進一步微調本模型的人,同樣需要遵守上述條款與禁止使用政策**,不會因為經過我這層微調就不受拘束。 > **Notice**: This model is a modification of Gemma, fine-tuned from `twinkle-ai/gemma-3-4B-T1-it` (itself fine-tuned from `google/gemma-3-4b-pt`) via LoRA on a synthetic Q&A dataset derived from Xinyi Township Gazetteer research papers. Gemma is provided under and subject to the Gemma Terms of Use found at ai.google.dev/gemma/terms, and use of Gemma is subject to the Gemma Prohibited Use Policy. This is not an official Google product, and is not an official Twinkle AI product. ## 已知限制(務必先讀) 實測(`evaluate.py`,20 筆 held-out QA 肉眼比對)發現一個一致的模式:**這個規模的 LoRA(可訓練參數僅佔全模型 0.76%)能學到語氣、格式、大致主題範圍,但對長尾的具體事實(專有名詞、確切數字、精確用語)記憶不穩定**——模型仍然會用完全自信的語氣回答,而不是坦承不確定,產生「聽起來合理但細節錯誤」的內容(例如捏造人名、講反因果關係、用錯專有名詞)。 **因此本模型不適合直接拿來回答需要精確史實的問題**;比較適合的用途是:示範微調工作流程、觀察模型語氣/格式的學習效果、或作為需要進一步強化訓練資料與規模的起點。 ## 訓練方式 - 基底模型:`twinkle-ai/gemma-3-4B-T1-it`(gated,需先在 HF 接受授權才能載入) - 方法:Unsloth QLoRA(4-bit 量化基底 + LoRA),`r=16`、`lora_alpha=16`、`lora_dropout=0.0`,`target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]` - 只對 assistant 回答算 loss(`train_on_responses_only`),不浪費訓練訊號在系統提示與問題上 - 訓練資料:Gemini(`gemini-3.1-flash-lite`)針對已...
Source context: 10 downloads · 0 likes · Pipeline text-generation · Library peft · Repo wesleyishere123/gemma-3-4b-xinyi-gazetteer-lora
Source context: 83 downloads · 0 likes · Pipeline text-generation · Library peft · Repo wesleyishere123/gemma-3-4b-xinyi-gazetteer-lora
