gemma3-examgen / README.md
yongjin-KIM's picture
Update README.md
6ed0ceb verified
---
license: cc-by-nc-4.0
language:
- ko
base_model:
- google/gemma-3-4b-it
pipeline_tag: text-generation
library_name: transformers
tags:
- exam
- question-generation
- gemma-3
- korean
- xml
- sft
- dpo
- grpo
---
# Gemma3 ExamGen (Korean, XML)
**TL;DR**: A Gemma-3โ€“based model fine-tuned to generate **Korean** university-level exam questions in **strict XML** (5 problems: 2 MCQ, 2 short-answer, 1 essay).
> **Outputs are in Korean.**
---
## Overview
Gemma3 ExamGen is a fine-tuned variant of Gemma-3 designed to generate Korean university exam questions in a strict XML structure.
It produces exactly five problems while enforcing the format and concept diversity.
---
## Intended Use
- **Primary** : Generate Korean exam problems in XML.
- **Output Language** : Korean only.
- **Not for** : factual certification, grading, or unreviewed deployment.
---
## Training Pipeline
- **Base** : `google/gemma-3-4b-it`
- **Stages** : SFT โ†’ DPO โ†’ GRPO
- **Method** : LoRA fine-tuning
- **Data** : PDF-crawled educational materials (private)
- **Filtering** : ensured XML validity and unique concepts.
---
## Prompting Spec (Korean Prompt Template)
> The model must always produce **Korean outputs**.
> It strictly follows the XML schema and rules defined below.
> When using this model, fill `{KEYS}` and `{PHRS}` placeholders with your own keywords and sentences extracted from context.
---
### Prompt Template (in Korean)
```text
๋‹ค์Œ์˜ ๊ทœ์น™์„ ์ค€์ˆ˜ํ•˜์—ฌ ๋Œ€ํ•™๊ต ์‹œํ—˜ ๋ฌธ์ œ 5๊ฐœ๋ฅผ XML ํ˜•์‹์œผ๋กœ ์ƒ์„ฑํ•˜์„ธ์š”.
**์‘๋‹ต ํ˜•์‹ (๋ฐ˜๋“œ์‹œ ์ค€์ˆ˜):**
<problems>
<problem>
<number>1</number>
<type>๊ฐ๊ด€์‹</type>
<content>๋ฌธ์ œ๋‚ด์šฉ</content>
<description>ํ’€์ด๊ณผ์ •</description>
<answer>๋‹ต</answer>
</problem>
<problem>
<number>2</number>
<type>๊ฐ๊ด€์‹</type>
<content>๋ฌธ์ œ๋‚ด์šฉ</content>
<description>ํ’€์ด๊ณผ์ •</description>
<answer>๋‹ต</answer>
</problem>
<problem>
<number>3</number>
<type>๋‹จ๋‹ตํ˜•</type>
<content>๋ฌธ์ œ๋‚ด์šฉ</content>
<description>ํ’€์ด๊ณผ์ •</description>
<answer>๋‹ต</answer>
</problem>
<problem>
<number>4</number>
<type>๋‹จ๋‹ตํ˜•</type>
<content>๋ฌธ์ œ๋‚ด์šฉ</content>
<description>ํ’€์ด๊ณผ์ •</description>
<answer>๋‹ต</answer>
</problem>
<problem>
<number>5</number>
<type>์ฃผ๊ด€์‹</type>
<content>๋ฌธ์ œ๋‚ด์šฉ</content>
<answer>๋‹ต</answer>
</problem>
</problems>
**์ ˆ๋Œ€ ๊ทœ์น™ (์œ„๋ฐ˜ ์‹œ ์‘๋‹ต ๋ฌดํšจ):**
1. XML ํƒœ๊ทธ ๊ตฌ์กฐ๋งŒ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋‹ค๋ฅธ ํ…์ŠคํŠธ, ์„ค๋ช…, ์ฃผ์„์€ ํฌํ•จํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
2. ๋ชจ๋“  ๋‚ด์šฉ์€ CDATA ์„น์…˜ ์—†์ด ์ผ๋ฐ˜ ํ…์ŠคํŠธ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
3. ํŠน์ˆ˜๋ฌธ์ž๋Š” XML ์—”ํ‹ฐํ‹ฐ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. (&lt;, &gt;, &amp;, &quot;, &apos;)
**๋ฌธ์ œ ์ƒ์„ฑ ๊ทœ์น™:**
- ์ด 5๋ฌธ์ œ๋ฅผ ์ƒ์„ฑํ•˜๋ฉฐ, ๋ฌธ์ œ ์œ ํ˜•์€ ๋‹ค์Œ ๋น„์œจ์„ ๋ฐ˜๋“œ์‹œ ์ง€ํ‚ต๋‹ˆ๋‹ค: ๊ฐ๊ด€์‹ 2๋ฌธ์ œ, ๋‹จ๋‹ตํ˜• 2๋ฌธ์ œ, ์ฃผ๊ด€์‹ 1๋ฌธ์ œ.
- ๊ฐ ๋ฌธ์ œ์˜ <type>์€ ์œ„ ์‘๋‹ต ํ˜•์‹์—์„œ ์ด๋ฏธ ์ง€์ •๋œ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
- ๊ฐ๊ด€์‹ ๋ฌธ์ œ๋Š” ๋ณด๊ธฐ ๊ธฐํ˜ธ๋ฅผ โ‘ , โ‘ก, โ‘ข, โ‘ฃ, โ‘ค ํ˜•์‹์œผ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
- ๋ชจ๋“  ๋ฌธ์ œ๋Š” ์„œ๋กœ ๋‹ค๋ฅธ ์ฃผ์š” ๊ฐœ๋…์„ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋ฉฐ, ๋™์ผ ๊ฐœ๋…์ด๋‚˜ ๋™์ผ ์ธ๋ฌผ, ๋™์ผ ์‚ฌ๊ฑด์„ ๋‹ค๋ฅธ ๋ฌธ์ œ์—์„œ ์žฌ์‚ฌ์šฉํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
- ํ’€์ด๊ณผ์ •๊ณผ ๋‹ต์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
- ๋ฌธ์ œ ๋‚ด์šฉ์— ๋”ฐ์˜ดํ‘œ, ์ˆ˜์‹, ํŠน์ˆ˜๋ฌธ์ž ๋“ฑ์„ ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- ๋ฌธ์ œ๋Š” ๋‚œ์ด๋„์™€ ํ‘œํ˜„ ๋ฐฉ์‹์„ ๋‹ค์–‘ํ•˜๊ฒŒ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.
**์ค‘์š”ํ•œ ํ‚ค์›Œ๋“œ:**
{KEYS}
**์ค‘์š”ํ•œ ๋ฌธ์žฅ๋“ค:**
{PHRS}
```
---
## Example Usage
```python
from transformers import AutoProcessor, AutoModelForImageTextToText
import torch
model_id = "yongjin-KIM/gemma3-examgen"
model = AutoModelForImageTextToText.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto")
processor = AutoProcessor.from_pretrained(model_id)
tok = processor.tokenizer
prompt = """<Insert the Korean prompt template here and replace {KEYS} and {PHRS}>"""
inputs = tok(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=2000,
temperature=0.7,
top_p=0.9,
do_sample=True,
)
print(tok.decode(outputs[0], skip_special_tokens=True))
```
---
## Output Format Guarantees
- Always produces **well-formed XML**.
- Exactly **5 `<problem>` blocks**.
- Escapes all special characters (`&lt;`, `&gt;`, `&amp;`, `&quot;`, `&apos;`).
- Fixed type order:
**๊ฐ๊ด€์‹**, **๊ฐ๊ด€์‹**, **๋‹จ๋‹ตํ˜•**, **๋‹จ๋‹ตํ˜•**, **์ฃผ๊ด€์‹**.
---
## Limitations
- May occasionally omit `<description>` fields or produce overlong answers.
- Factual correctness is not guaranteed.
- Designed for **Korean text only**; English prompts are not supported.
- Contextual consistency may vary depending on {KEYS}/{PHRS} quality.
---
## Ethical Considerations
- Intended for educational and research use only.
- Should not be used for unsupervised or high-stakes exam generation.
- All generated content should be **reviewed by a human instructor** before use.
---
## Model Details
- **Base Model**: `google/gemma-3-4b-it`
- **Architecture**: Decoder-only transformer
- **Fine-tuning Method**: LoRA (r=8, ฮฑ=32)
- **Training Framework**: PEFT + TRL
- **Training Hardware**: 2 ร— A100 (80GB)
- **Training Duration**: ~48 hours
- **Stages**: SFT โ†’ DPO โ†’ GRPO
---
## License
- **Model**: CC-BY-NC-4.0
- **Base Model**: Gemma-3 (Google)
- **Dataset**: Private (PDF-crawled educational material)
- **Intended Use**: Research / Non-commercial
---
## Maintainer
**Author:** Yongjin Kim
**Hugging Face:** [@yongjin-KIM](https://huggingface.co/yongjin-KIM)
---