Views
No views yet
| Label | Description |
|---|---|
benign | Safe, harmless content |
bias_discrimination | Gender, race, religion, orientation bias |
compliance_vulnerability | Code vulnerabilities, CWE/MITRE issues |
fraud_misinfo | Fraud, deception, misinformation |
violence | Violent content |
self_harm | Self-harm related content |
hate_speech | Hate speech |
sexual_content | Sexual content |
illegal_activity | Illegal activities |
privacy_violation | Privacy violations |
cybersecurity | Cybersecurity threats |
child_safety | Child safety issues |
label_encoder.pkl)| Parameter | Value |
|---|---|
| Base Model | Qwen/Qwen2.5-3B |
| Method | LoRA (merged into full model) |
| LoRA r | 16 |
| LoRA alpha | 32 |
| LoRA targets | q_proj, v_proj, k_proj, o_proj |
| Max length | 256 |
| Batch size | 8 × 8 grad accum = 64 effective |
| Epochs | 4 |
| Learning rate | 2e-4 (cosine schedule) |
| Loss | Focal Loss (γ=2.0) + label smoothing |
| Balanced | 5,000 samples per class |
| F1 Macro | 0.6608 |
| Accuracy | 0.6803 |
1import torch, pickle
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3from huggingface_hub import hf_hub_download
4
5REPO_ID = 'jainsatyam26/light-safety-classifier-qwen2.5-3b'
6device = 'cuda' if torch.cuda.is_available() else 'cpu'
7
8model = AutoModelForSequenceClassification.from_pretrained(REPO_ID, trust_remote_code=True).to(device)
9tokenizer = AutoTokenizer.from_pretrained(REPO_ID, trust_remote_code=True)
10if tokenizer.pad_token is None:
11 tokenizer.pad_token = tokenizer.eos_token
12
13le_path = hf_hub_download(REPO_ID, 'label_encoder.pkl')
14with open(le_path, 'rb') as f:
15 meta = pickle.load(f)
16le = meta['label_encoder']
17
18def predict(text):
19 inputs = tokenizer(text, return_tensors='pt', truncation=True,
20 max_length=256, padding=True).to(device)
21 with torch.no_grad():
22 probs = torch.softmax(model(**inputs).logits, dim=1)[0].cpu().numpy()
23 return {
24 'label': le.classes_[probs.argmax()],
25 'confidence': float(probs.max()),
26 'is_safe': le.classes_[probs.argmax()] == 'benign',
27 }
28
29print(predict("How do I make a bomb?"))
30# {'label': 'violence', 'confidence': 0.97, 'is_safe': False}