[论文解读] Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations
Llama Guard 是基于 Llama2-7b 的模型,针对人机对话中的输入输出安全分类进行微调,具备安全分类体系、零样本/少样本的自适应性,并公开发布模型权重。
We introduce Llama Guard, an LLM-based input-output safeguard model geared towards Human-AI conversation use cases. Our model incorporates a safety risk taxonomy, a valuable tool for categorizing a specific set of safety risks found in LLM prompts (i.e., prompt classification). This taxonomy is also instrumental in classifying the responses generated by LLMs to these prompts, a process we refer to as response classification. For the purpose of both prompt and response classification, we have meticulously gathered a dataset of high quality. Llama Guard, a Llama2-7b model that is instruction-tuned on our collected dataset, albeit low in volume, demonstrates strong performance on existing benchmarks such as the OpenAI Moderation Evaluation dataset and ToxicChat, where its performance matches or exceeds that of currently available content moderation tools. Llama Guard functions as a language model, carrying out multi-class classification and generating binary decision scores. Furthermore, the instruction fine-tuning of Llama Guard allows for the customization of tasks and the adaptation of output formats. This feature enhances the model's capabilities, such as enabling the adjustment of taxonomy categories to align with specific use cases, and facilitating zero-shot or few-shot prompting with diverse taxonomies at the input. We are making Llama Guard model weights available and we encourage researchers to further develop and adapt them to meet the evolving needs of the community for AI safety.
研究动机与目标
- 定义覆盖法律与政策风险的人机交互安全风险分类体系。
- 开发 Llama Guard,一种在 Llama2-7b 上进行指令微调的模型,用于对话中的提示和回应分类。
- 实现对新分类体系的零样本和少样本适应,而无需重新训练。
- 公开发布模型权重,以促进社区研究和定制化。
提出的方法
- 提出一个安全风险分类体系,类别包括 Violence & Hate(暴力与仇恨)、Sexual Content(性内容)、Guns & Illegal Weapons(枪支与非法武器)、Regulated Substances(受管制物质)、Suicide & Self-Harm(自杀与自我伤害)以及 Criminal Planning(犯罪计划)。
- 在按照该分类标签的数据集上对 Llama2-7b 进行微调,以通过指令跟随提示执行对输入(提示)和输出(回应)的分类。
- 通过数据增强训练,以促进对分类子集的意识,并通过类别打乱来防止格式记忆。
- 在领域内及跨分类设置下,使用零-shot、少-shot以及微调适配进行评估;并与 OpenAI Moderation API、Perspective API、Azure Content Safety、GPT-4 进行对比。

实验结果
研究问题
- RQ1一个基于 LLM 的系统是否能够在多种风险类别中,准确地对用户提示和 AI 响应进行人机对话的安全分类?
- RQ2通过提示和微调而无需大量再训练,模型在新的安全分类体系上的适应能力有多强?
- RQ3在标准基准上(如 ToxicChat、OpenAI Moderation)以及跨类别,Llama Guard 的表现相较于公认的 moderation 工具如何?
- RQ4分类体系自适应(零样本 vs 少样本 vs 微调)对跨领域安全分类性能的影响是什么?
主要发现
- Llama Guard 在自身内部测试集上同时对提示和回应分类实现了较高的 AUPRC。
- 在目标分类体系的零样本部署中,Llama Guard 在多个基准上达到或超过基线,并在 OpenAI Mod 数据集上与 OpenAI Moderation API 相近。
- Llama Guard 在 ToxicChat 数据集上超越了其他基线。
- 通过提示(尤其是少样本提示)对新分类体系进行适配可以提高对齐度,有时甚至超过它们自己数据集上的专用 moderation API。
- 在不同分类体系上对 Llama Guard 进行微调能够实现快速适应,通常在数据量少于从头训练的情况下也能达到具竞争力或更优的性能。
- 该模型支持在推理时自定义输出格式和分类体系,使新用例实现零样本或少样本自适应成为可能。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。