ShieldGemma: Generative AI Content Moderation Based on Gemma

Wenjun Zeng, Yuchi Liu, Ryan Mullins, Ludovic Peran, Joe Fernandez, Hamza Harkous, Karthik Narasimhan, Drew Proud, Piyush Kumar, Bhaktipriya Radharapu, Olivia Sturman, Oscar WahltinezarXiv 2024

Abstract: We present ShieldGemma, a comprehensive suite of LLM-based safety content moderation models built upon Gemma2. These models provide robust, state-of-the-art predictions of safety risks across key harm types (sexually explicit, dangerous content, harassment, hate speech) in both user input and LLM-generated output. By evaluating on both public and internal benchmarks, we demonstrate superior performance compared to existing models, such as Llama Guard (+10.8% AU-PRC on public benchmarks) and WildCard (+4.3%). Additionally, we present a novel LLM-based data curation pipeline, adaptable to a variety of safety-related tasks and beyond. We have shown strong generalization performance for model trained mainly on synthetic data. By releasing ShieldGemma, we provide a valuable resource to the research community, advancing LLM safety and enabling the creation of more effective content moderation solutions for developers.

Introduction

As Large Language Models (LLMs) become more integrated into daily workflows, the "safety layer"—the software that sits between the user and the model to filter out harmful content—has become as critical as the core model itself. ShieldGemma is a suite of state-of-the-art content moderation models designed to make AI interactions safer and more customizable, offering granular harm detection across a family of models ranging from 2B to 27B parameters.

The Challenge of Content Moderation

Deploying LLMs in the real world requires a delicate balance between helpfulness and safety. Developers must prevent models from generating or responding to harmful content such as hate speech, harassment, or dangerous instructions. Current moderation tools often suffer from a lack of granularity (providing only binary safe/unsafe labels), rigid model sizes that impact latency, and a scarcity of high-quality, human-annotated adversarial data.

Methodology: Architecture and Data Pipeline

ShieldGemma is built on the Gemma 2 architecture and fine-tuned using Supervised Fine-Tuning (SFT). The moderation task is framed as a classification problem where the model predicts a "Yes" or "No" token indicating whether a prompt violates a specific policy.

A core innovation of ShieldGemma is its synthetic data curation pipeline, which allows for high performance even with minimal human annotation. This pipeline utilizes AI-Assisted Red-Teaming (AART) to generate diverse adversarial topics, followed by a "critic" LLM that suggests ways to increase the difficulty and semantic diversity of the data.

The ShieldGemma synthetic data curation pipeline, illustrating the flow from raw data curation to model fine-tuning.

To optimize the training set, the researchers employed cluster-margin subsampling, an active learning technique that prioritizes examples where the model shows the highest uncertainty. Furthermore, a fairness expansion stage uses LLMs to swap identity terms, ensuring the model remains unbiased across different demographic groups.

Key Insights and Results

ShieldGemma demonstrates that models trained primarily on synthetic data (approximately 134k examples) can generalize exceptionally well to real-world, human-generated benchmarks. By leveraging "scoring mode"—analyzing the log-probabilities of the "Yes" and "No" tokens—developers can tune the sensitivity of the filter to suit specific application needs, such as stricter filtering for children's applications.

ShieldGemma sets a new benchmark for open-weight safety models. On public benchmarks, the ShieldGemma 9B model achieved a 10.8% improvement in Area Under the Precision-Recall Curve (AU-PRC) over Llama Guard and a 4.3% lead over WildGuard. Notably, ShieldGemma models outperformed GPT-4 (evaluated zero-shot) in specific harm categories like "Hate Speech."

Performance comparison (AU-PRC) of ShieldGemma variants (2B, 9B, 27B) against GPT-4 across various harm categories.

Limitations and Future Work

While ShieldGemma provides robust protection, challenges remain regarding implicit cultural harms and "dog whistles" that lack explicit toxicity. There is also an inherent trade-off between safety and helpfulness, as overly conservative models may refuse benign prompts. Finally, ShieldGemma is strictly a classifier; it is not intended for use as a conversational chatbot, as it has not been tuned for dialogue and could produce unsafe content if forced to converse.

Future research will focus on refining these classifiers to better handle cultural nuances and reducing false positive rates to ensure that safe, helpful content is not inadvertently flagged.

Summary updated

BibTeX
@misc{zeng2024shieldgemma,
  author = {Wenjun Zeng and Yuchi Liu and Ryan Mullins and Ludovic Peran and Joe Fernandez and Hamza Harkous and Karthik Narasimhan and Drew Proud and Piyush Kumar and Bhaktipriya Radharapu and Olivia Sturman and Oscar Wahltinez},
  title = {{ShieldGemma: Generative AI Content Moderation Based on Gemma}},
  year = {2024},
  eprint = {2407.21772},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.21772},
}
Figure