Downloads · 30 days
0
ahczhg/multi-model-lora-content-safety
multi-model-lora-content-safety is a machine learning model from ahczhg. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This project demonstrates fine-tuning multiple language models using LoRA (Low-Rank Adaptation) on the NVIDIA Aegis AI Content Safety Dataset for content moderation and safety classification tasks.
Downloads · 30 days
0
Access
Public
Updated Nov 13, 2025
Repo size
—
Likes
3
Trending 1
Click a slice to open those files.
.ipynb442 KB · 97%
From the Hugging Face model README
This project demonstrates fine-tuning multiple language models using LoRA (Low-Rank Adaptation) on the NVIDIA Aegis AI Content Safety Dataset for content moderation and safety classification tasks.
This repository contains a comprehensive Jupyter notebook that fine-tunes three different language models for content safety applications:
All models are fine-tuned using LoRA (Low-Rank Adaptation), an efficient parameter-efficient fine-tuning technique that reduces computational requirements while maintaining performance.
NVIDIA Aegis AI Content Safety Dataset 2.0
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install transformers>=4.38.0
pip install datasets>=2.16.0
pip install accelerate>=0.26.0
pip install peft>=0.8.0
pip install trl>=0.7.10
pip install bitsandbytes>=0.43.0
pip install sentencepiece>=0.1.99
pip install protobuf>=3.20.0
pip install huggingface_hub
pip install scikit-learn pandas numpy matplotlib seaborn
hg/
├── multi_model_finetuning.ipynb # Main training notebook
├── README.md # This file
├── LICENSE # Project license
├── output/ # Fine-tuned models (generated)
│ ├── qwen3-0.6b/
│ ├── llama-3.2-1b/
│ └── ernie-0.3b/
├── model_comparison.csv # Performance comparison (generated)
└── results_summary.json # Full results JSON (generated)
Open the Jupyter notebook and run the environment setup cells to install all dependencies:
# The notebook handles installation automatically
# Includes special handling for bitsandbytes and sentencepiece
from huggingface_hub import login
login() # Enter your HF token when prompted
The notebook includes pre-configured settings for:
Execute the notebook cells sequentially to:
Use the interactive testing cell to evaluate models:
test_model_interactive("qwen3-0.6b",
"### Instruction:\nIs this content safe? 'Hello, how are you?'\n\n### Response:\n")
{
"r": 16, # Rank of LoRA matrices
"lora_alpha": 32, # LoRA scaling parameter
"lora_dropout": 0.05, # Dropout for LoRA layers
"task_type": "CAUSAL_LM",
"target_modules": [ # Modules to apply LoRA
"q_proj", "k_proj", "v_proj", "o_proj",
"gate_proj", "up_proj", "down_proj"
]
}
{
"num_train_epochs": 3,
"per_device_train_batch_size": 4,
"gradient_accumulation_steps": 4,
"learning_rate": 2e-4,
"lr_scheduler_type": "cosine",
"warmup_ratio": 0.1,
"fp16": True,
"optim": "paged_adamw_8bit",
"max_seq_length": 512
}
After training, the notebook generates:
Results are saved to:
model_comparison.csv - Performance metrics tableresults_summary.json - Complete training results with metadataAll fine-tuned models are automatically uploaded to:
ahczhg/qwen3-0.6b-aegis-safety-loraahczhg/llama-3.2-1b-aegis-safety-loraahczhg/ernie-4.5-0.3b-aegis-safety-loraEach model includes:
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_name = "ahczhg/qwen3-0.6b-aegis-safety-lora"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16,
device_map="auto"
)
# Use for content safety classification
prompt = "### Instruction:\nAnalyze this content for safety: 'Your text here'\n\n### Response:\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=128)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
This project is designed for:
Not intended for:
Contributions are welcome! Areas for improvement:
If you use this project in your research or applications, please cite:
@misc{multi_model_lora_content_safety,
author = {ahczhg},
title = {Multi-Model Fine-Tuning with LoRA for Content Safety},
year = {2025},
publisher = {GitHub},
howpublished = {\url{https://github.com/ahczhg/hg}},
note = {Fine-tuned on NVIDIA Aegis AI Content Safety Dataset 2.0}
}
This project is licensed under the MIT License - see the LICENSE file for details.
For issues, questions, or feedback:
Generated with Claude Code | Last updated: 2025-11-13