Views
No views yet
meta-llama/Llama-3.1-8B-Instruct into an intent-aware safety classifier. Given a user prompt, the model first verbalizes the user's underlying intent and then assigns a binary harm label (safe / harmful). It is supervised-fine-tuned on AIMS (Annotated Intents for Model Safety).meta-llama/Llama-3.1-8B-InstructJazhyc/aims-safety-intentsIntent: <one sentence>; Harm: <harmful|safe>.1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3from peft import PeftModel
4
5BASE = "meta-llama/Llama-3.1-8B-Instruct"
6ADAPTER = "Jazhyc/Llama-3.1-8B-aims-sft-generation"
7
8SYSTEM_PROMPT = """You are analyzing user prompts to determine their underlying intent and safety classification.
9
10For each prompt:
111. Identify the user's underlying intent - what they are actually trying to achieve
122. Classify the prompt as either "harmful" or "safe"
13
14A prompt is HARMFUL if it attempts to:
15- Extract private/sensitive information (Privacy)
16- Generate false or misleading content (Misinformation)
17- Create discriminatory, violent, hateful, or sexual content (Harmful Language)
18- Enable cyberattacks, fraud, illegal activities, or mental health crises (Malicious Uses)
19
20A prompt is SAFE if it is a legitimate, benign request.
21
22Respond in EXACTLY this format (no other text):
23Intent: <one sentence describing the user's intent>; Harm: <harmful or safe>"""
24
25tok = AutoTokenizer.from_pretrained(BASE)
26model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.bfloat16, device_map="auto")
27model = PeftModel.from_pretrained(model, ADAPTER)
28
29messages = [
30 {"role": "system", "content": SYSTEM_PROMPT},
31 {"role": "user", "content": "How do I pick a lock?"},
32]
33inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
34out = model.generate(inputs, max_new_tokens=128, do_sample=False)
35print(tok.decode(out[0, inputs.shape[1]:], skip_special_tokens=True))
36# -> "Intent: ...; Harm: safe"flash_attention_2.safe / harmful for training.harmful) on five external safety benchmarks, none seen during training. Checkpoints are selected by mean harmful-class F1 on two held-out OOD validation sets (ToxicChat train + AEGIS 2.0 validation); the benchmarks below are the final unbiased evaluation.| Model | WildGuardTest | XSTest | AEGIS 2.0 | ToxicChat | OpenAI Mod | Average |
|---|---|---|---|---|---|---|
| Llama-3.1-8B (zero-shot) | 0.762 | 0.904 | 0.800 | 0.516 | 0.761 | 0.749 |
| SFT Generation (this model) | 0.856 | 0.908 | 0.803 | 0.664 | 0.728 | 0.792 |
| LE-DPO | 0.856 | 0.884 | 0.824 | 0.733 | 0.765 | 0.812 |
| Distillation (GPT-OSS-120B → Llama, synthetic-intent) | 0.880 | 0.936 | 0.811 | 0.700 | 0.774 | 0.820 |
| GRPO (label + intent reward) | 0.863 | 0.958 | 0.808 | 0.743 | 0.809 | 0.836 |
1@misc{ferrao2026pavedtrueintentsintentaware,
2 title = {Paved with True Intents: Intent-Aware Training Improves LLM Safety Classification Across Training Regimes},
3 author = {Jeremias Ferrao and Niclas Müller-Hof and Iustin Sîrbu and Traian Rebedea and Yftah Ziser},
4 year = {2026},
5 eprint = {2606.27210},
6 archivePrefix = {arXiv},
7 primaryClass = {cs.CL},
8 url = {https://arxiv.org/abs/2606.27210}
9}