Skip to main content
QUICK REVIEW

[Paper Review] Llama Guard: LLM-based Input-Output Safeguard for Human-AI Conversations

Hakan Inan, Kartikeya Upasani|arXiv (Cornell University)|Dec 7, 2023
Hate Speech and Cyberbullying DetectionComputer Science44 citations
TL;DR

Llama Guard is an Llama2-7b-based model fine-tuned for input-output safety classification in human-AI conversations, with a safety taxonomy, zero-shot/few-shot adaptability, and public release of model weights.

ABSTRACT

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.

Motivation & Objective

  • Define a safety risk taxonomy for human-AI interaction covering legal and policy risks.
  • Develop Llama Guard, an Llama2-7b instruction-tuned model for prompt and response classification in conversations.
  • Enable zero-shot and few-shot adaptation to new taxonomies without retraining.
  • Provide a public release of model weights to foster community research and customization.

Proposed method

  • Propose a safety risk taxonomy with categories such as Violence & Hate, Sexual Content, Guns & Illegal Weapons, Regulated Substances, Suicide & Self-Harm, and Criminal Planning.
  • Fine-tune Llama2-7b on a dataset labeled according to the taxonomy to perform input (prompts) and output (responses) classification using instruction-following prompts.
  • Train with data augmentation to encourage taxonomy-subset awareness and category-shuffling to prevent format memorization.
  • Evaluate using in-domain and cross-taxonomy setups with zero-shot, few-shot, and fine-tuning adaptations; compare against OpenAI Moderation API, Perspective API, Azure Content Safety, and GPT-4.
Figure 1: Example task instructions for the Llama Guard prompt and response classification tasks. A task consists of four main components. Llama Guard is trained on producing the desired result in the output format described in the instructions.
Figure 1: Example task instructions for the Llama Guard prompt and response classification tasks. A task consists of four main components. Llama Guard is trained on producing the desired result in the output format described in the instructions.

Experimental results

Research questions

  • RQ1Can an LLM-based system accurately classify user prompts and AI responses for safety in human-AI conversations across multiple risk categories?
  • RQ2How well can the model adapt to new safety taxonomies via prompting and fine-tuning without extensive retraining?
  • RQ3How does Llama Guard perform relative to established moderation tools on standard benchmarks (e.g., ToxicChat, OpenAI Moderation) and across categories?
  • RQ4What is the impact of taxonomy adaptation (zero-shot vs few-shot vs fine-tuning) on cross-domain safety classification performance?

Key findings

  • Llama Guard achieves high AUPRC on its own internal test set for both prompt and response classification.
  • In zero-shot deployment with target taxonomy, Llama Guard matches or surpasses baselines on several benchmarks, and closely approaches OpenAI Moderation API on the OpenAI Mod dataset.
  • Llama Guard outperforms other baselines on the ToxicChat dataset.
  • Adapting to a new taxonomy via prompting (and especially few-shot prompting) improves alignment, sometimes surpassing dedicated moderation APIs on their own datasets.
  • Fine-tuning Llama Guard on a different taxonomy enables rapid adaptation, often achieving competitive or superior performance with less data than retraining from scratch.
  • The model supports customizing output formats and taxonomies at inference time, enabling zero-shot or few-shot adaptation for new use cases.
Figure 2: Category-wise performance (AUPRC) of Llama Guard when evaluated on the OpenAI Mod dataset (Markov et al., 2023 ) with zero-shot and few-shot prompting. Note that due to the 1-vs-all classification, combined with the policy mismatch, the performance is lower than binary classification: we p
Figure 2: Category-wise performance (AUPRC) of Llama Guard when evaluated on the OpenAI Mod dataset (Markov et al., 2023 ) with zero-shot and few-shot prompting. Note that due to the 1-vs-all classification, combined with the policy mismatch, the performance is lower than binary classification: we p

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.