Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: Qwen/Qwen2.5-3B-Instruct
|
| 4 |
+
library_name: peft
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- lora
|
| 8 |
+
- transformers
|
| 9 |
+
- korean
|
| 10 |
+
- npc
|
| 11 |
+
- game-ai
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# npc_LoRA
|
| 15 |
+
|
| 16 |
+
**npc_LoRA** is a LoRA adapter built on top of [Qwen/Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct), designed to generate emotionally rich, context-aware dialogue for non-player characters (NPCs) in Korean-language game environments.
|
| 17 |
+
|
| 18 |
+
This project is part of a portfolio for industrial service roles in AI and game development, showcasing practical model design, multi-head training, and real-world integration strategies.
|
| 19 |
+
|
| 20 |
+
## π§ Model Architecture
|
| 21 |
+
|
| 22 |
+
- **Base model**: Qwen2.5-3B-Instruct
|
| 23 |
+
- **Adapter type**: LoRA (via PEFT)
|
| 24 |
+
- **Language**: Korean
|
| 25 |
+
- **Task**: Text generation with auxiliary heads
|
| 26 |
+
- **Heads added**:
|
| 27 |
+
- `delta_head`: Predicts 2D continuous values for narrative state change
|
| 28 |
+
- `flag_head`: Predicts 3 or more binary flags for game logic triggers
|
| 29 |
+
|
| 30 |
+
## ποΈ Training Setup
|
| 31 |
+
|
| 32 |
+
- **Environment**: Google Colab with A100 GPU
|
| 33 |
+
- **Quantization**: 4-bit (nf4) via BitsAndBytes
|
| 34 |
+
- **Batch size**: 2 (gradient accumulation: 8)
|
| 35 |
+
- **Epochs**: 6
|
| 36 |
+
- **Losses**:
|
| 37 |
+
- Language modeling (CrossEntropy)
|
| 38 |
+
- Delta prediction (MSE)
|
| 39 |
+
- Flag prediction (BCE)
|
| 40 |
+
|
| 41 |
+
## π Prompt Format
|
| 42 |
+
|
| 43 |
+
```text
|
| 44 |
+
<SYS>
|
| 45 |
+
NPC_ID=...
|
| 46 |
+
TAGS:
|
| 47 |
+
location=...
|
| 48 |
+
quest_stage=...
|
| 49 |
+
relationship=...
|
| 50 |
+
trust=...
|
| 51 |
+
npc_mood=...
|
| 52 |
+
player_reputation=...
|
| 53 |
+
style=...
|
| 54 |
+
REQUIRE:
|
| 55 |
+
...
|
| 56 |
+
FORMAT:
|
| 57 |
+
<RESPONSE>...</RESPONSE>
|
| 58 |
+
<DELTA ...>
|
| 59 |
+
<FLAG ...>
|
| 60 |
+
</SYS>
|
| 61 |
+
<CTX>
|
| 62 |
+
player: ...
|
| 63 |
+
npc: ...
|
| 64 |
+
</CTX>
|
| 65 |
+
<PLAYER>...
|
| 66 |
+
<NPC>
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
## π Inference Example
|
| 70 |
+
|
| 71 |
+
```python
|
| 72 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 73 |
+
from peft import PeftModel
|
| 74 |
+
import torch.nn as nn
|
| 75 |
+
|
| 76 |
+
BASE_MODEL = "Qwen/Qwen2.5-3B-Instruct"
|
| 77 |
+
ADAPTER_PATH = "minjae/npc_LoRA"
|
| 78 |
+
|
| 79 |
+
tokenizer = AutoTokenizer.from_pretrained(ADAPTER_PATH, use_fast=True)
|
| 80 |
+
model = AutoModelForCausalLM.from_pretrained(BASE_MODEL, device_map="auto", trust_remote_code=True)
|
| 81 |
+
model = PeftModel.from_pretrained(model, ADAPTER_PATH)
|
| 82 |
+
|
| 83 |
+
# Add heads
|
| 84 |
+
hidden_size = model.config.hidden_size
|
| 85 |
+
model.delta_head = nn.Linear(hidden_size, 2).to(model.device)
|
| 86 |
+
model.flag_head = nn.Linear(hidden_size, 3).to(model.device)
|
| 87 |
+
|
| 88 |
+
prompt = "<SYS>...<CTX>...<PLAYER>...<NPC>"
|
| 89 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 90 |
+
|
| 91 |
+
with torch.no_grad():
|
| 92 |
+
outputs = model(**inputs, output_hidden_states=True)
|
| 93 |
+
gen_ids = model.generate(**inputs, max_new_tokens=100)
|
| 94 |
+
generated_text = tokenizer.decode(gen_ids[0], skip_special_tokens=True)
|
| 95 |
+
|
| 96 |
+
last_hidden = outputs.hidden_states[-1][:, -1, :]
|
| 97 |
+
delta = model.delta_head(last_hidden)
|
| 98 |
+
flag = model.flag_head(last_hidden)
|
| 99 |
+
|
| 100 |
+
print("Response:", generated_text)
|
| 101 |
+
print("Delta:", delta)
|
| 102 |
+
print("Flags:", torch.sigmoid(flag))
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## π§© Use Cases
|
| 106 |
+
|
| 107 |
+
- NPC dialogue generation in Korean RPGs
|
| 108 |
+
- Emotionally adaptive storytelling
|
| 109 |
+
- Game logic trigger prediction (e.g., quest progression, item handoff)
|
| 110 |
+
|
| 111 |
+
## π Repository Structure
|
| 112 |
+
|
| 113 |
+
```
|
| 114 |
+
npc_LoRA/
|
| 115 |
+
βββ lora-output-jason-mom-head/ # LoRA adapter files
|
| 116 |
+
βββ README.md
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## π Notes
|
| 120 |
+
|
| 121 |
+
- Adapter is optimized for Korean-language prompts and multi-turn dialogue.
|
| 122 |
+
- Designed to integrate with game engines or AI-driven simulation platforms.
|
| 123 |
+
- Compatible with Hugging Face Spaces (CPU/GPU) and local inference.
|
| 124 |
+
|
| 125 |
+
## π License
|
| 126 |
+
|
| 127 |
+
MIT
|
| 128 |
+
|
| 129 |
+
## π€ Author
|
| 130 |
+
|
| 131 |
+
Created by **Minjae**
|
| 132 |
+
Portfolio: [GitHub Profile](https://github.com/m97j)
|
| 133 |
+
Contact: [mmnkjiae@gmail.com]
|
| 134 |
+
|
| 135 |
+
|