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. |