File size: 8,241 Bytes
65b7bd8
 
 
 
 
286eeb4
 
 
 
 
 
 
65b7bd8
286eeb4
65b7bd8
d6d47f7
65b7bd8
 
 
286eeb4
65b7bd8
286eeb4
65b7bd8
 
 
 
286eeb4
65b7bd8
 
 
b6332e2
286eeb4
5ce551b
286eeb4
65b7bd8
 
6d88bb9
286eeb4
5ce551b
8af3832
b6332e2
d6d47f7
286eeb4
 
 
 
 
 
 
b6332e2
d6d47f7
286eeb4
b6332e2
286eeb4
b6332e2
 
65b7bd8
b6332e2
286eeb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbcd3f7
d6a8617
286eeb4
65b7bd8
cbcd3f7
 
 
 
65b7bd8
d83e639
 
 
 
cbcd3f7
d83e639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbcd3f7
 
 
d83e639
 
 
d6a8617
 
286eeb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d956e9
 
286eeb4
 
 
 
 
 
8d956e9
 
d6a8617
286eeb4
d6a8617
286eeb4
d6a8617
286eeb4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
license: gemma
language:
- ko
pipeline_tag: text-generation
tags:
- spam-detection
- explainable-ai
- on-device
- korean
datasets:
- Devocean-06/Spam_QA-Corpus
---

<p align="left">
  <img src="https://huggingface.co/Devocean-06/Spam_Filter-gemma/resolve/main/skitty.png" width="50%"/>
</p>

# Devocean-06/Spam_Filter-gemma

> Update @ 2025.10.19: First release of Spam filter XAI

<!-- Provide a quick summary of what the model is/does. -->

**Resources and Technical Documentation**:
* [Gemma3 Model](https://huggingface.co/google/gemma-3-4b-it)
* [Training Dataset](https://huggingface.co/datasets/Devocean-06/Spam_QA-Corpus)

**Model Developers**: SK Devoceon-06 On device LLM

## Model Information

- Skitty is an explainable small language model (sLLM) that classifies spam messages and provides brief reasoning for each decision.

---

## Description

- Skitty was trained on an updated 2025 spam message dataset collected through the Smart Police Big Data Platform in South Korea.  
- The model leverages deduplication, curriculum sampling, and off-policy distillation to improve both classification accuracy and interpretability.

## Data and Preprocessing

- **Data source**: 2025 Smart Police Big Data Platform spam message dataset  
- **Dataset**: [Devocean-06/Spam_QA-Corpus](https://huggingface.co/datasets/Devocean-06/Spam_QA-Corpus)
- **Format**: Alpaca instruction format (instruction, input, output)
- **Deduplication**: Performed near-duplicate removal using SimHash filtering  
- **Sampling strategy**: Applied curriculum-based sampling to control difficulty and improve generalization  
- **Labeling**: Trained using hard-label supervision after label confidence refinement

## Training and Distillation

- Utilized off-policy distillation to compress the decision process of a large teacher LLM into a smaller student model  
- Instead of directly mimicking the teacher's text generation, the model distills the reasoning trace for spam detection  
- Combined curriculum learning with hard-label distillation to balance accuracy, interpretability, and generalization

---

## Training Configuration

### Base Model
- **Base Model**: [google/gemma-3-4b-it](https://huggingface.co/google/gemma-3-4b-it)
- **Training Framework**: [Axolotl](https://github.com/OpenAccess-AI-Collective/axolotl)
- **Fine-tuning Method**: QLoRA (Quantized Low-Rank Adaptation)

### Hyperparameters

| Parameter | Value | Description |
|-----------|-------|-------------|
| **Quantization** | 4-bit | Load pretrained model in 4-bit |
| **Adapter** | QLoRA | Low-rank adaptation method |
| **LoRA Rank (r)** | 16 | Rank of low-rank matrices |
| **LoRA Alpha** | 32 | Scaling factor for LoRA |
| **LoRA Dropout** | 0.05 | Dropout rate for LoRA layers |
| **Target Modules** | attention + MLP | Applied to q,k,v,o,up,down,gate projections |
| **Sequence Length** | 1500 | Maximum input sequence length |
| **Sample Packing** | True | Pack multiple samples into one sequence |
| **Micro Batch Size** | 10 | Batch size per GPU |
| **Gradient Accumulation** | 15 | Effective batch size: 150 |
| **Number of Epochs** | 5 | Total training epochs |
| **Learning Rate** | 2e-5 | Peak learning rate |
| **LR Scheduler** | Cosine | Cosine annealing schedule |
| **Warmup Steps** | 10 | Learning rate warmup steps |
| **Optimizer** | AdamW (8-bit) | 8-bit quantized AdamW |
| **Weight Decay** | 0.0 | L2 regularization |
| **Precision** | BF16 | Brain floating point 16 |
| **Gradient Checkpointing** | True | Save memory by recomputing gradients |
| **Flash Attention** | True | Optimized attention kernel |

### Training Monitoring
- **Logging Steps**: 100
- **Evaluation Steps**: 50
- **Save Steps**: 50
- **Evaluation Strategy**: Steps-based
- **Tracking**: Weights & Biases (wandb)

---

## Running with the `vllm` API

You can initialize the model and processor for inference with `pipeline` as follows.

```sh
vllm serve Devocean-06/Spam_Filter-gemma
```

```python
from openai import OpenAI

client = OpenAI(
    base_url="model-endpoint",
    api_key="api-key"  
)

SYSTEM_PROMPT = """๋‹น์‹ ์€ ์ŠคํŒธ ๋ฌธ์ž๋กœ ํŒ์ •ํ•œ ๊ทผ๊ฑฐ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋Œ€ํ˜• ์–ธ์–ด ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
์•„๋ž˜ ๊ธฐ์ค€์— ๋”ฐ๋ผ ์ŠคํŒธ์—ฌ๋ถ€ ํŒ์ •์˜ ๊ทผ๊ฑฐ๋ฅผ ๊ฐ„๋‹จ๋ช…๋ฃŒํ•˜๊ฒŒ ํ•œ ๋ฌธ์žฅ์œผ๋กœ ์ž‘์„ฑํ•ด ์ฃผ์„ธ์š”. ์ถœ๋ ฅ ํฌ๋งท์€ XAI ์„ค๋ช…์— ์ ํ•ฉํ•˜๋„๋ก ์ผ๊ด€์„ฑ ์žˆ๊ฒŒ ํ…œํ”Œ๋ฆฟ ํ˜•์‹์œผ๋กœ ๊ณ ์ •๋˜์–ด์•ผ ํ•˜๋ฉฐ, ์ŠคํŒธ ์—ฌ๋ถ€ ๋ฐ ๊ทธ ๊ทผ๊ฑฐ๋ฅผ ๋ช…์พŒํ•˜๊ฒŒ ์ œ์‹œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

**1. ํŒ์ • ๊ทผ๊ฑฐ(ํ•œ ๋ฌธ์žฅ, ํ…œํ”Œ๋ฆฟ):**
- **๊ฐœ์ธ ์ •๋ณด ์š”๊ตฌ:** ์‹ ๋ถ„์ฆ, ๋น„๋ฐ€๋ฒˆํ˜ธ, ์นด๋“œ ๋ฒˆํ˜ธ ๋“ฑ ๊ฐœ์ธ ์ •๋ณด๋ฅผ ์š”๊ตฌํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
- **๊ธฐํƒ€ ํŠน์ด์‚ฌํ•ญ:** ์œ„ ํ•ญ๋ชฉ ์™ธ์— ์ŠคํŒธ์œผ๋กœ ์˜์‹ฌ๋˜๋Š” ๋‹ค๋ฅธ ํŒจํ„ด์ด ์žˆ์Šต๋‹ˆ๋‹ค.
- **๋ฐœ์‹ ์ž/์ˆ˜์‹ ์ž:** ๋ฐœ์‹  ๋ฒˆํ˜ธ๊ฐ€ ์ผ๋ฐ˜์ ์ด์ง€ ์•Š๊ฑฐ๋‚˜ ๋ถˆ๋ถ„๋ช…ํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
- **๋‚ด์šฉ์˜ ๋ชฉ์ :** ๊ธˆ์œต ์ƒํ’ˆ, ๋Œ€์ถœ, ๋„๋ฐ•, ํˆฌ์ž, ๋ถˆ๋ฒ• ๋ณต์ œ ๋“ฑ์˜ ํ™๋ณด๋‚˜ ๊ถŒ์œ ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
- **์‹ฌ๋ฆฌ์  ์••๋ฐ•:** ๊ธด๊ธ‰์„ฑ, ๊ณตํฌ, ํ˜ธ๊ธฐ์‹ฌ์„ ์œ ๋ฐœํ•˜์—ฌ ์ฆ‰๊ฐ์ ์ธ ํ–‰๋™์„ ์œ ๋„ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. (์˜ˆ: "๊ธฐ๊ฐ„ ํ•œ์ •", "์ง€๊ธˆ ์ฆ‰์‹œ", "ํด๋ฆญํ•˜์ง€ ์•Š์œผ๋ฉด ๋ถˆ์ด์ต")
- **๋งํฌ/URL:** ์ผ๋ฐ˜์ ์ด์ง€ ์•Š์€ ์งง์€ URL, ๋‹จ์ถ• URL ๋˜๋Š” ์˜์‹ฌ์Šค๋Ÿฌ์šด ๋งํฌ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

**2. ํ•„์ˆ˜ ์กฐ๊ฑด**
- ๋ฐ˜๋“œ์‹œ ์ถœ๋ ฅ ํ˜•์‹์— ๋”ฐ๋ผ์„œ [์ŠคํŒธ ํŒ์ • ์ด์œ ] ํ…œํ”Œ๋ฆฟ์„ ์‚ฌ์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- ์ŠคํŒธ์œผ๋กœ ํŒ์ •ํ•œ ์ด์œ ์— ๋Œ€ํ•ด์„œ ๊ตฌ์ฒด์ ์ธ ์ด์œ ๋กœ 100์ž ์ด์ƒ์œผ๋กœ ์„ค๋ช…ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- ๋ฐ˜๋“œ์‹œ ์œ„ ํŒ์ • ๊ทผ๊ฑฐ๋ฅผ ๋จผ์ € ์–ธ๊ธ‰ํ•œ ๋’ค์— ์ถœ๋ ฅ ํ˜•์‹์— ๋งž๊ฒŒ ์ŠคํŒธ ํŒ์ • ์ด์œ ๋ฅผ ์ƒ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
- ์ŠคํŒธ ํŒ์ • ์ด์œ  ์ƒ์„ฑ ์‹œ, ์œ„ ์ŠคํŒธ ๋ฌธ์ž๋Š” ~~ ์œผ๋กœ ์‹œ์ž‘ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.
- ๊ทธ๋ฆฌ๊ณ  ์ „์ œ์กฐ๊ฑด์€ ๋ชจ๋‘ ์ŠคํŒธ ๋ฌธ์ž๋กœ ๋ถ„๋ฅ˜๋œ ํ˜•์‹์ด๋‹ˆ ์ŠคํŒธ์ด ์•„๋‹ˆ๋ผ๊ณ  ์–ธ๊ธ‰ํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

### ์ถœ๋ ฅ ํ˜•์‹ ์˜ˆ์‹œ
- ํŒ์ • ๊ทผ๊ฑฐ : ๊ฐœ์ธ์ •๋ณด ์š”๊ตฌ
- ์ŠคํŒธ ํŒ์ • ์ด์œ : ์œ„ ์ŠคํŒธ ๋ฌธ์ž๋Š” ๊ฐœ์ธ์ •๋ณด๋ฅผ ์š”๊ตฌํ•˜๋Š” ์ŠคํŒธ์œผ๋กœ ์•„ํŒŒํŠธ ๋ถ„์–‘ ๋ฐ ๋ถ€๋™์‚ฐ ํˆฌ์ž ๊ถŒ์œ ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์œผ๋ฉฐ, ๊ธด๊ธ‰์„ฑ์„ ๊ฐ•์กฐํ•˜์—ฌ ์ฆ‰๊ฐ์ ์ธ ํ–‰๋™์„ ์œ ๋„ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค."""

response = client.chat.completions.create(
        model="Devocean-06/Spam_Filter-gemma",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message}
        ],
        temperature=0.7,
        max_tokens=2048
    )
print(response.choices[0].message.content)

```
## ๐Ÿง  Example Output
```sh
- ํŒ์ • ๊ทผ๊ฑฐ: ๋‚ด์šฉ์˜ ๋ชฉ์   
- ์ŠคํŒธ ํŒ์ • ์ด์œ : ์œ„ ์ŠคํŒธ ๋ฌธ์ž๋Š” ๊ธˆ์œต ์ƒํ’ˆ๊ณผ ๋Œ€์ถœ ๊ด€๋ จ ๊ถŒ์œ  ๋‚ด์šฉ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์œผ๋ฉฐ,
  โ€˜์ง€๊ธˆ ๋ฐ”๋กœโ€™, โ€˜์ฆ‰์‹œ ์‹ ์ฒญโ€™๊ณผ ๊ฐ™์€ ์‹ฌ๋ฆฌ์  ์••๋ฐ• ์–ด๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆ˜์‹ ์ž์˜ ํ–‰๋™์„ ์œ ๋„ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
```

---

## Software

Training was conducted using the **Axolotl framework**, a flexible and efficient fine-tuning system designed for large language models.

Axolotl enables seamless configuration and execution of full fine-tuning, LoRA, and DPO pipelines through simple YAML-based workflows. It integrates with PyTorch and Hugging Face Transformers, supporting distributed strategies such as FSDP and DeepSpeed for optimized performance on multi-GPU environments.

This framework streamlines experimentation and scaling by allowing researchers to define training parameters, datasets, and model behaviors declaratively โ€” reducing boilerplate and ensuring reproducible results across setups.

**Key Features Used:**
- QLoRA for parameter-efficient fine-tuning
- 4-bit quantization during training
- Flash Attention for faster training
- Gradient checkpointing for memory efficiency
- Alpaca dataset format support

---

## Citation

```bibtex
@misc{Devocean-06/Spam_Filter-gemma,
  author       = { {SK Devoceon-06 On device LLM} },
  title        = { Spam filter & XAI },
  year         = 2025,
  url          = { https://huggingface.co/Devocean-06/Spam_Filter-gemma },
  publisher    = { Hugging Face }
}
```

---

## License

This model is released under the Gemma license. Please refer to the original [Gemma license](https://ai.google.dev/gemma/terms) for usage terms and conditions.