PaliGemma

Keras

Model Details

PaliGemma model card


Model page: PaliGemma

Resources and technical documentation:

  1. Responsible Generative AI Toolkit
  2. PaliGemma on Vertex Model Garden
  3. PaliGemma on HuggingFace

Terms of Use: Terms

Authors: Google

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. PaliGemma is trained following the PaLI-3 recipes.

Inputs and outputs


  1. Input: Image and text string, such as a prompt to caption the image, or a question.
  2. 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.

Citation


@article{beyer2024paligemma,
title={{PaliGemma: A versatile 3B VLM for transfer}},
author={Lucas Beyer* and Andreas Steiner* and André Susano Pinto* and Alexander Kolesnikov* and Xiao Wang* and Daniel Salz and Maxim Neumann and Ibrahim Alabdulmohsin and Michael Tschannen and Emanuele Bugliarello and Thomas Unterthiner and Daniel Keysers and Skanda Koppula and Fangyu Liu and Adam Grycner and Alexey Gritsenko and Neil Houlsby and Manoj Kumar and Keran Rong and Julian Eisenschlos and Rishabh Kabra and Matthias Bauer and Matko Bošnjak and Xi Chen and Matthias Minderer and Paul Voigtlaender and Ioana Bica and Ivana Balazevic and Joan Puigcerver and Pinelopi Papalampidi and Olivier Henaff and Xi Xiong and Radu Soricut and Jeremiah Harmsen and Xiaohua Zhai*},
year={2024},
journal={arXiv preprint arXiv:2407.07726}
}


Model data


Pre-train datasets

PaliGemma is pre-trained on the following mixture of datasets:

  1. 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.
  2. CC3M-35L: Curated English image-alt_text pairs from webpages (Sharma et al., 2018). We used the Google Cloud Translation API to translate into 34 additional languages.
  3. VQ²A-CC3M-35L/VQG-CC3M-35L: A subset of VQ2A-CC3M (Changpinyo et al., 2022a), translated into the same additional 34 languages as CC3M-35L, using the Google Cloud Translation API.
  4. OpenImages: Detection and object-aware questions and answers (Piergiovanni et al. 2022) generated by handcrafted rules on the OpenImages dataset.
  5. 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:

  1. Pornographic image filtering: This filter removes images deemed to be of pornographic nature.
  2. 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.
  3. 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.
  4. 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.
  5. Additional methods: Filtering based on content quality and safety in line with our policies and practices.

Implementation information


Hardware


PaliGemma was trained using the latest generation of Tensor Processing Unit (TPU) hardware (TPUv5e).


Software

Training was done using JAXFlaxTFDS and 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.


Usage and limitations


Intended usage


Open Vision Language Models (VLMs) have a wide range of applications across various industries and domains. The following list of potential uses is not comprehensive. The purpose of this list is to provide contextual information about the possible use-cases that the model creators considered as part of model training and development.

Fine-tune on specific vision-language task:

  1. The pre-trained models can be fine-tuned on a wide range of vision-language tasks such as: image captioning, short video caption, visual question answering, text reading, object detection and object segmentation.
  2. The pre-trained models can be fine-tuned for specific domains such as remote sensing question answering, visual questions from people who are blind, science question answering, describe UI element functionalities.
  3. The pre-trained models can be fine-tuned for tasks with non-textual outputs such as bounding boxes or segmentation masks.

Vision-language research:

  1. The pre-trained models and fine-tuned models can serve as a foundation for researchers to experiment with VLM techniques, develop algorithms, and contribute to the advancement of the field.


Ethical considerations and risks


The development of vision-language models (VLMs) raises several ethical concerns. In creating an open model, we have carefully considered the following:

  1. Bias and Fairness
  2. VLMs trained on large-scale, real-world image-text data can reflect socio-cultural biases embedded in the training material. These models underwent careful scrutiny, input data pre-processing described and posterior evaluations reported in this card.
  3. Misinformation and Misuse
  4. VLMs can be misused to generate text that is false, misleading, or harmful.
  5. Guidelines are provided for responsible use with the model, see the Responsible Generative AI Toolkit.
  6. Transparency and Accountability
  7. This model card summarizes details on the models' architecture, capabilities, limitations, and evaluation processes.
  8. A responsibly developed open model offers the opportunity to share innovation by making VLM technology accessible to developers and researchers across the AI ecosystem.

Risks identified and mitigations:

  1. Perpetuation of biases: It's encouraged to perform continuous monitoring (using evaluation metrics, human review) and the exploration of de-biasing techniques during model training, fine-tuning, and other use cases.
  2. Generation of harmful content: Mechanisms and guidelines for content safety are essential. Developers are encouraged to exercise caution and implement appropriate content safety safeguards based on their specific product policies and application use cases.
  3. Misuse for malicious purposes: Technical limitations and developer and end-user education can help mitigate against malicious applications of LLMs. Educational resources and reporting mechanisms for users to flag misuse are provided. Prohibited uses of Gemma models are outlined in the Gemma Prohibited Use Policy.
  4. Privacy violations: Models were trained on data filtered to remove certain personal information and sensitive data. Developers are encouraged to adhere to privacy regulations with privacy-preserving techniques.


Limitations


  1. Most limitations inherited from the underlying Gemma model still apply:
  2. VLMs are better at tasks that can be framed with clear prompts and instructions. Open-ended or highly complex tasks might be challenging.
  3. Natural language is inherently complex. VLMs might struggle to grasp subtle nuances, sarcasm, or figurative language.
  4. VLMs generate responses based on information they learned from their training datasets, but they are not knowledge bases. They may generate incorrect or outdated factual statements.
  5. VLMs rely on statistical patterns in language and images. They might lack the ability to apply common sense reasoning in certain situations.
  6. PaliGemma was designed first and foremost to serve as a general pre-trained model for transfer to specialized tasks. Hence, its "out of the box" or "zero-shot" performance might lag behind models designed specifically for that.
  7. PaliGemma is not a multi-turn chatbot. It is designed for a single round of image and text input.


Example Use

!pip install -U -q keras-nlp

Pick a backend of your choice


import os
os.environ["KERAS_BACKEND"] = "jax"

Now we can load the PaliGemma "causal language model" from the Models hub. A causal language model is just a LLM that is ready for generation, by training with a causal mask, and running generation a token at a time in a recurrent loop.

keras.config.set_floatx("bfloat16")
pali_gemma_lm = keras_nlp.models.PaliGemmaCausalLM.from_preset(
"pali_gemma_3b_224"
)

Function that reads an image from a given URL

def read_image(url):
contents = io.BytesIO(requests.get(url).content)
image = PIL.Image.open(contents)
image = np.array(image)
# Remove alpha channel if neccessary.
if image.shape[2] == 4:
image = image[:, :, :3]
return image
image_url = 'https://storage.googleapis.com/keras-cv/models/paligemma/cow_beach_1.png'
image = read_image(image_url)

Use generate() call with a single image and prompt. The text prompt has to end with  .

prompt = 'answer en where is the cow standing? '
output = pali_gemma_lm.generate(
inputs={
"images": image,
"prompts": prompt,
}
)
print(output)

Use generate() call with a batched images and prompts.

prompts = [
'answer en where is the cow standing? ',
'answer en what color is the cow? ',
'describe en ',
'detect cow ',
'segment cow ',
]
images = [image, image, image, image, image]
outputs = pali_gemma_lm.generate(
inputs={
"images": images,
"prompts": prompts,
}
)
for output in outputs:
print(output)

There's a few other style of prompts this model can handle out of the box…

cap {lang} : very raw short caption (from WebLI-alt).

caption {lang} : nice, coco-like short captions.

describe {lang} : somewhat longer more descriptive captions.

ocr : optical character recognition.

answer en {question} : question answering about the image contents.

question {lang} {answer} : question generation for a given answer.

detect {thing} ; {thing} : count objects in a scene.

Call fit() on a single batch





Model Files

index.py
                                            import numpy as np
image = np.random.uniform(-1, 1, size=(224, 224, 3))
x = {
    "images": [image, image],
    "prompts": ["answer en Where is the cow standing?\n", "caption en\n"],
}
y = {
    "responses": ["beach", "A brown cow standing on a beach next to the ocean."],
}
pali_gemma_lm = keras_nlp.models.PaliGemmaCausalLM.from_preset("pali_gemma_3b_224")
pali_gemma_lm.fit(x=x, y=y, batch_size=2)

                                        

Model Comments

1 comments
avatar
Jinendra
Jul 25, 2024 02:09 pm

molums new is magnificent