Spam_Filter-gemma / README.md
nebchi's picture
Update README.md
cbcd3f7 verified
---
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.