Model Overview
Model Features
Model Capabilities
Use Cases
🚀 PaliGemma Model Card
PaliGemma is a versatile vision - language model that takes both images and text as input and generates text output. It's fine - tuned on specific datasets and offers multiple precision formats for research.
🚀 Quick Start
To access PaliGemma on Hugging Face, you’re required to review and agree to Google’s usage license. To do this, please ensure you’re logged - in to Hugging Face and click the “Acknowledge license” button below. Requests are processed immediately.
✨ Features
- Versatile Input: Accepts both image and text as input, supporting multiple languages.
- Rich Capabilities: Capable of tasks such as question answering, captioning, segmentation, etc.
- Fine - tuning Friendly: Works best when fine - tuned to specific use cases.
📦 Installation
If you want to run inference using 8 - bit or 4 - bit precision, you need to install bitsandbytes
and accelerate
:
pip install bitsandbytes accelerate
💻 Usage Examples
Basic Usage
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from PIL import Image
import requests
import torch
model_id = "google/paligemma-3b-mix-224"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id).eval()
processor = AutoProcessor.from_pretrained(model_id)
# Instruct the model to create a caption in Spanish
prompt = "caption es"
model_inputs = processor(text=prompt, images=image, return_tensors="pt")
input_len = model_inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=False)
generation = generation[0][input_len:]
decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
Advanced Usage
Running other precisions on CUDA
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from PIL import Image
import requests
import torch
model_id = "google/paligemma-3b-mix-224"
device = "cuda:0"
dtype = torch.bfloat16
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
model = PaliGemmaForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=dtype,
device_map=device,
revision="bfloat16",
).eval()
processor = AutoProcessor.from_pretrained(model_id)
# Instruct the model to create a caption in Spanish
prompt = "caption es"
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
input_len = model_inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=False)
generation = generation[0][input_len:]
decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
Loading in 4 - bit / 8 - bit
from transformers import AutoProcessor, PaliGemmaForConditionalGeneration
from PIL import Image
import requests
import torch
from bitsandbytes.nn import BitsAndBytesConfig
model_id = "google/paligemma-3b-mix-224"
device = "cuda:0"
dtype = torch.bfloat16
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
image = Image.open(requests.get(url, stream=True).raw)
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
model = PaliGemmaForConditionalGeneration.from_pretrained(
model_id, quantization_config=quantization_config
).eval()
processor = AutoProcessor.from_pretrained(model_id)
# Instruct the model to create a caption in Spanish
prompt = "caption es"
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device)
input_len = model_inputs["input_ids"].shape[-1]
with torch.inference_mode():
generation = model.generate(**model_inputs, max_new_tokens=100, do_sample=False)
generation = generation[0][input_len:]
decoded = processor.decode(generation, skip_special_tokens=True)
print(decoded)
📚 Documentation
Model Information
Model Summary
Description
PaliGemma is a versatile and lightweight vision - language model (VLM) inspired by PaLI - 3 and based on open components such as the SigLIP vision model and the Gemma language model. It takes both image and text as input and generates text as output, supporting multiple languages. It is designed for class - leading fine - tune performance on a wide range of vision - language tasks such as image and short video caption, visual question answering, text reading, object detection and object segmentation.
Model architecture
PaliGemma is the composition of a Transformer decoder and a Vision Transformer image encoder, with a total of 3 billion params. The text decoder is initialized from Gemma - 2B. The image encoder is initialized from [SigLIP - So400m/14](https://colab.research.google.com/github/google - research/big_vision/blob/main/big_vision/configs/proj/image_text/SigLIP_demo.ipynb). PaliGemma is trained following the PaLI - 3 recipes.
Inputs and outputs
- Input: Image and text string, such as a prompt to caption the image, or a question.
- Output: Generated text in response to the input, such as a caption of the image, an answer to a question, a list of object bounding box coordinates, or segmentation codewords.
Model data
Pre - train datasets
PaliGemma is pre - trained on the following mixture of datasets:
- WebLI: WebLI (Web Language Image) is a web - scale multilingual image - text dataset built from the public web. A wide range of WebLI splits are used to acquire versatile model capabilities, such as visual semantic understanding, object localization, visually - situated text understanding, multilinguality, etc.
- CC3M - 35L: Curated English image - alt_text pairs from webpages ([Sharma et al., 2018](https://aclanthology.org/P18 - 1238/)). We used the Google Cloud Translation API to translate into 34 additional languages.
- VQ²A - CC3M - 35L/VQG - CC3M - 35L: A subset of VQ2A - CC3M ([Changpinyo et al., 2022a](https://aclanthology.org/2022.naacl - main.142/)), translated into the same additional 34 languages as CC3M - 35L, using the Google Cloud Translation API.
- OpenImages: Detection and object - aware questions and answers (Piergiovanni et al. 2022) generated by handcrafted rules on the OpenImages dataset.
- WIT: Images and texts collected from Wikipedia (Srinivasan et al., 2021).
Data responsibility filtering
The following filters are applied to WebLI, with the goal of training PaliGemma on clean data:
- Pornographic image filtering: This filter removes images deemed to be of pornographic nature.
- Text safety filtering: We identify and filter out images that are paired with unsafe text. Unsafe text is any text deemed to contain or be about CSAI, pornography, vulgarities, or otherwise offensive.
- Text toxicity filtering: We further use the Perspective API to identify and filter out images that are paired with text deemed insulting, obscene, hateful or otherwise toxic.
- Text personal information filtering: We filtered certain personal information and other sensitive data using Cloud Data Loss Prevention (DLP) API to protect the privacy of individuals. Identifiers such as social security numbers and [other sensitive information types] were removed.
- Additional methods: Filtering based on content quality and safety in line with our policies and practices.
[other sensitive information types]: https://cloud.google.com/sensitive - data - protection/docs/high - sensitivity - infotypes - reference?_gl=1jg604m_gaODk5MzA3ODQyLjE3MTAzMzQ3NTk._ga_WH2QY8WWF5*MTcxMDUxNTkxMS4yLjEuMTcxMDUxNjA2NC4wLjAuMA..&_ga=2.172110058.-899307842.1710334759
How to Use
PaliGemma is a single - turn vision language model not meant for conversational use, and it works best when fine - tuning to a specific use case.
You can configure which task the model will solve by conditioning it with task prefixes, such as “detect” or “segment”. The pretrained models were trained in this fashion to imbue them with a rich set of capabilities (question answering, captioning, segmentation, etc.). However, they are not designed to be used directly, but to be transferred (by fine - tuning) to specific tasks using a similar prompt structure. For interactive testing, you can use the "mix" family of models, which have been fine - tuned on a mixture of tasks.
Please, refer to the [usage and limitations section](#usage - and - limitations) for intended use cases, or visit the [blog post](https://huggingface.co/blog/paligemma - google - vlm) for additional details and examples.
Implementation information
Hardware
PaliGemma was trained using the latest generation of Tensor Processing Unit (TPU) hardware (TPUv5e).
Software
Training was done using JAX, Flax, TFDS and [big_vision
](https://github.com/google - research/big_vision).
JAX allows researchers to take advantage of the latest generation of hardware, including TPUs, for faster and more efficient training of large models.
TFDS is used to access datasets and Flax is used for model architecture. The PaliGemma fine - tune code and inference code are released in the big_vision
GitHub repository.
Evaluation information
Benchmark results
In order to verify the transferability of PaliGemma to a wide variety of academic tasks, we fine - tune the pretrained models on each task. Additionally we train the mix model with a mixture of the transfer tasks. We report results on different resolutions to provide an impression of which tasks benefit from increased resolution. Importantly, none of these tasks or datasets are part of the pretraining data mixture, and their images are explicitly removed from the web - scale pre - training data.
Mix model (fine - tune on mixture of transfer tasks)
Benchmark | Metric (split) | mix - 224 | mix - 448 |
---|---|---|---|
MMVP | Paired Accuracy | 46.00 | 45.33 |
POPE | Accuracy (random/popular/adversarial) |
88.00 86.63 85.67 |
89.37 88.40 87.47 |
GQA | Accuracy (test) | 65.20 | 65.47 |
Single task (fine - tune on single task)
The detailed benchmark results for single - task fine - tuning are presented in a large table in the original document, which shows the performance of the model on various tasks such as captioning, question answering, segmentation, and video tasks at different resolutions.
🔧 Technical Details
- Model Composition: Composed of a Transformer decoder and a Vision Transformer image encoder.
- Training Hardware: Trained on TPUv5e hardware.
- Training Software: Utilizes JAX, Flax, TFDS, and
big_vision
for training.
📄 License
The license for PaliGemma is Gemma. You can find the terms of use [here](https://www.kaggle.com/models/google/paligemma - ft/license/consent/verify/huggingface?returnModelRepoId=google/paligemma - 3b - ft - science - qa - 224).
Model page: PaliGemma Resources and technical documentation:
- Responsible Generative AI Toolkit
- PaliGemma on Kaggle
- [PaliGemma on Vertex Model Garden](https://console.cloud.google.com/vertex - ai/publishers/google/model - garden/363) Authors: Google







