Downloads · 30 days
55
15% of all-time downloads
Nozim6690/hugging-face_shieldgemma-2-4b-it
hugging-face_shieldgemma-2-4b-it is a image-text-to-text model from Nozim6690. Use it for the image-text-to-text task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as gemma.
Downloads · 30 days
55
15% of all-time downloads
All-time downloads
369
Public
Parameters
4.3B
8.6 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8.6 GB · 100%
From the Hugging Face model README
Model Page: ShieldGemma
Resources and Technical Documentation:
Terms of Use: Terms
Authors: Google
ShieldGemma 2 is a model trained on Gemma 3's 4B IT checkpoint for image safety classification across key categories that takes in images and outputs safety labels per policy.
ShieldGemma 2, built on Gemma 3, is a 4 billion (4B) parameter model that checks the safety of both synthetic and natural images against key categories to help you build robust datasets and models. With this addition to the Gemma family of models, researchers and developers can now easily minimize the risk of harmful content in their models across key areas of harm as defined below:
We recommend using ShieldGemma 2 as an input filter to vision language models, or as an output filter of image generation systems. To train a robust image safety model, we curated training datasets of natural and synthetic images and instruction-tuned Gemma 3 to demonstrate strong performance. A comparison to safety policies and benchmarks can be found in the ShieldGemma 2 technical report.
Here is our prompt instruction:
You are a policy expert trying to help determine whether a generated or real image is in violation of the safety policy
below. Your decision must very clearly follow the specific language used in the safety policy and should not include
any interpretation outside of the safety policy.
<BEGIN_SAFETY_POLICY>
{policy}
</END_SAFETY_POLICY>
Does the image violate the above policy? Your Answer must start with with 'Yes' or 'No'.
Below there are some code snippets on how to get quickly started with running the model. First, install the Transformers library with the version made for Gemma 3:
$ pip install -U transformers
Then, copy the snippet from the section that is relevant for your use case.
# pip install accelerate
from transformers import AutoProcessor, ShieldGemma2ForImageClassification
from PIL import Image
import requests
import torch
model_id = "google/shieldgemma-2-4b-it"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/bee.jpg"
image = Image.open(requests.get(url, stream=True).raw)
model = ShieldGemma2ForImageClassification.from_pretrained(model_id).eval()
processor = AutoProcessor.from_pretrained(model_id)
model_inputs = processor(images=[image], return_tensors="pt")
with torch.inference_mode():
scores = model(**model_inputs)
print(scores.probabilities)
@misc{zeng2025shieldgemma2robusttractable,
title={ShieldGemma 2: Robust and Tractable Image Content Moderation},
author={Wenjun Zeng and Dana Kurniawan and Ryan Mullins and Yuchi Liu and Tamoghna Saha and Dirichi Ike-Njoku and Jindong Gu and Yiwen Song and Cai Xu and Jingjing Zhou and Aparna Joshi and Shravan Dheep and Mani Malek and Hamid Palangi and Joon Baek and Rick Pereira and Karthik Narasimhan},
year={2025},
eprint={2504.01081},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2504.01081},
}
Our training dataset consists of both natural images and synthetic images. For natural images, we sample a subset of images from the WebLI (Web Language and Image) dataset that are relevant to the safety tasks. For synthetic images, we leverage an internal data generation pipeline to enable controlled generation of prompts and corresponding images that balance the diversity and severity of images that target dangerous content, sexually explicit, and violent content in English only. Our data generation taxonomy diversely ranges over a number of dimensions including demographics, context, regional aspects, and more.
Here are the key data cleaning and filtering methods applied to the training data:
ShieldGemma 2 was trained using the latest generation of Tensor Processing Unit (TPU) hardware (TPUv5e), for more details refer to the Gemma 3 model card.
Training was done using JAX and ML Pathways. For more details refer to the Gemma 3 model card.
ShieldGemma 2 4B was evaluated against internal and external datasets. Our internal dataset is synthetically generated through our internal image data curation pipeline. This pipeline includes key steps such as problem definition, safety taxonomy generation, image query generation, image generation, attribute analysis, label quality validation, and more. We have approximately 500 examples for each harm policy. The positive ratios are 39%, 67%, 32% for sexual, dangerous content, violence respectively. See the technical report for evaluation details.
Internal Benchmark Evaluation Results
| Sexually Explicit | Dangerous Content | Violence & Gore | |
|---|---|---|---|
| LlavaGuard 7B | 47.6/93.1/63.0 | 67.8/47.2/55.7 | 36.8/100.0/53.8 |
| GPT-4o mini | 68.3/97.7/80.3 | 84.4/99.0/91.0 | 40.2/100.0/57.3 |
| Gemma-3-4B-IT | 77.7/87.9/82.5 | 75.9/94.5/84.2 | 78.2/82.2/80.1 |
| shieldgemma-2-4b-it | 87.6/89.7/88.6 | 95.6/91.9/93.7 | 80.3/90.4/85.0 |
Table 1: Result format–precision/recall/optimal F1 (%, higher is better). Evaluation results on our internal benchmarks shows ShieldGemma 2 outperforming external baseline models.
Ethics and Safety
Ethics and safety evaluation approach and results.
Although the ShieldGemma 2 models are nominally generative models, they are designed to run in scoring mode to
predict the probability that the next token would be Yes or No. Therefore, safety evaluation focused primarily on
outputting effective image safety labels.
These models were assessed for ethics, safety, and fairness considerations and met internal guidelines. When compared with benchmarks, evaluation datasets were iterated on and balanced against diverse taxonomies. Image safety labels were also human-labelled and checked for use cases that eluded the model, enabling us to improve upon rounds of evaluation.
Usage and Limitations
These models have certain limitations that users should be aware of.
ShieldGemma 2 is intended to be used as a safety content moderator, either for human user inputs, model outputs, or both. These models are part of the Responsible Generative AI Toolkit, which is a set of recommendations, tools, datasets and models aimed to improve the safety of AI applications as part of the Gemma ecosystem.
All the usual limitations for large language models apply, see the Gemma 3 model card for more details. Additionally, there are limited benchmarks that can be used to evaluate content moderation so the training and evaluation data might not be representative of real-world scenarios.
ShieldGemma 2 is also highly sensitive to the specific user-provided description of safety principles, and might perform unpredictably under conditions that require a good understanding of language ambiguity and nuance.
As with other models that are part of the Gemma ecosystem, ShieldGemma 2 is subject to Google's prohibited use policies.
The development of large language models (LLMs) raises several ethical concerns. We have carefully considered multiple aspects in the development of these models.
Refer to the Gemma 3 model card for more details.
At the time of release, this family of models provides high-performance open large language model implementations designed from the ground up for Responsible AI development compared to similarly sized models.
Using the benchmark evaluation metrics described in this document, these models have been shown to provide superior performance to other, comparably-sized open model alternatives.