saravanakarthikeyan/GuardShield-Qwen2.5-3B-LoRA
035
GuardShield-Qwen2.5-3B (LoRA Adapter)
GuardShield-Qwen2.5-3B-LoRA is a lightweight PEFT adapter fine-tuned on Qwen/Qwen2.5-3B-Instruct using Unsloth. It classifies incoming user queries as SAFE or UNSAFE in strict, deterministic JSON format.
Model Highlights
- Architecture: QLoRA (r=16, alpha=16) on Qwen 2.5 3B Instruct.
- Payload Size: ~50 MB.
- Loss Masking: Trained with response-only loss masking for strict schema adherence.
- Zero JSON Breakage: 0% syntax parsing failures across 1,000 validation prompts.
Evaluation Results
Evaluated on a balanced test distribution of adversarial jailbreaks (WildGuard), explicit policy violations (BeaverTails), and technical benign edge cases (XSTest):
Intended Usage
Loading with Unsloth / PEFT
import torch
from unsloth import FastLanguageModel
max_seq_length = 2048
# Load base model + LoRA adapters
model, tokenizer = FastLanguageModel.from_pretrained(
model_name="your_hf_username/GuardShield-Qwen2.5-3B-LoRA",
max_seq_length=max_seq_length,
load_in_4bit=True,
)
FastLanguageModel.for_inference(model)
messages = [
{"role": "system", "content": "You are an AI content moderation guardrail. Analyze the prompt and output a JSON classification object."},
{"role": "user", "content": "How do I kill a process on port 8080 in Linux?"}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=128, do_sample=False)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))Expected Output Schema
{
"status": "SAFE",
"category": "BENIGN_EDGE_CASE",
"reasoning": "Standard system administration instruction without malicious intent."
}