InstructSafety: A Unified Framework for Building Multidimensional and Explainable Safety Detector through Instruction Tuning

Zhexin Zhang, Jiale Cheng, Hao Sun, Jiawen Deng, Minlie Huang

TL;DR

InstructSafety is a unified framework that transforms safety detection from a simple "toxic or not" binary into a multidimensional, explainable conversation. By instruction-tuning Flan-T5 on 39 human-annotated datasets and using a novel robustness enhancement technique, the authors created Safety-Flan-T5, a model that outperforms both specialized APIs and general-purpose giants like GPT-3.5 in identifying and explaining nuanced safety risks.

The Safety Detection Bottleneck

As Large Language Models (LLMs) become more integrated into our daily lives, the "safety layer" that filters their inputs and outputs has become a critical bottleneck. Current safety detectors suffer from four major flaws:

  1. Lack of Granularity: Most tools only offer binary classification (Safe/Unsafe) or a limited range of categories.
  2. The "Black Box" Problem: They provide numerical scores but no natural language explanation for why a text is considered harmful.
  3. Context Blindness: They struggle with multi-turn dialogues where a single sentence might be safe in isolation but toxic within a specific conversation.
  4. Poor Generalization: They often fail on out-of-distribution (OOD) data or get "triggered" by sensitive keywords (like "gay" or "black") even when the context is neutral or positive.

The authors aim to bridge these gaps by creating a single, versatile model capable of handling multiple safety-related sub-tasks simultaneously.

Methods: The InstructSafety Framework

The core of the paper is Instruction Tuning. The researchers unified seven distinct safety sub-tasks into a consistent format: Instruction + Text ⇒ Output. This approach allows a single model to learn the underlying logic of safety across different domains rather than just memorizing toxic keywords.

The InstructSafety framework unifies seven safety sub-tasks into a single instruction-following format.

The seven tasks include Safety Judgement, Problem Detection (listing specific issues like lewdness), Problem Judgement, Safety Comparison, Target Detection, Span Detection (pinpointing exact words), and Safety Explanation (providing a rationale).

To make the model more robust, they introduced a Robustness Enhancement (RE) phase. They noticed that early versions of the model would flag neutral sentences like "His teacher is a woman" as unsafe simply because they contained specific group identifiers. To fix this, they used GPT-3.5/4 to generate thousands of safe, neutral descriptions of protected groups and added them to the training set, teaching the model to distinguish between mentioning a group and attacking it.

Aggregating Safety Knowledge

The authors aggregated 39 human-annotated datasets to create a training corpus of over 844,000 samples. These include well-known benchmarks like Jigsaw Toxic Comment Classification, HateXplain, HateCheck, ProsocialDialog, and DiaSafety. By processing these into a unified instruction-following format, the model gains a comprehensive understanding of safety across various contexts, including multi-turn dialogues and implicit hate speech.

Key Results and Scaling

The resulting model, Safety-Flan-T5-XXL (11B parameters), showed impressive performance across several benchmarks:

  • Outperforming the Giants: In zero-shot safety judgement on the HateCheck dataset, it achieved 96.3% accuracy, significantly higher than Perspective API (76.6%) and GPT-3.5-Turbo (90.0%).
  • Contextual Mastery: On the DiaSafety dataset, Safety-Flan-T5 achieved results comparable to specialized, fully fine-tuned RoBERTa models.
  • Scaling Behavior: The research demonstrates that performance improves significantly as both the model size and the number of training datasets increase.
Total accuracy scales with both model size and the number of datasets used during training.

Thanks to the RE method, the model maintained high accuracy on "non-hateful" samples that contain sensitive words—a common failure point for other detectors. Furthermore, by treating "Explanation" and "Span Detection" as formal tasks, the authors show that we can move beyond "vibes-based" safety and actually evaluate if a model understands the harm it is flagging.

Limitations and Future Work

While powerful, the authors acknowledge several limitations. The model is only as good as its training data; if the 39 human-annotated datasets contain subjective biases, the model will inherit them. Additionally, the current framework focuses on text content and does not yet address other safety dimensions like privacy leakage (PII) or prompt injection attacks. Future work should involve integrating more diverse safety scenarios and exploring how to maintain general model utility while maximizing safety performance.

Summary updated

BibTeX
@inproceedings{zhang2023instructsafety,
  author = {Zhexin Zhang and Jiale Cheng and Hao Sun and Jiawen Deng and Minlie Huang},
  title = {{InstructSafety: A Unified Framework for Building Multidimensional and Explainable Safety Detector through Instruction Tuning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.700},
}
Figure