模型概述
模型特點
模型能力
使用案例
🚀 PaliGemma 2模型卡片
PaliGemma 2是一款視覺語言模型(VLM),它結合了Gemma 2模型的能力,能同時處理圖像和文本輸入,並生成文本輸出,可用於圖像和短視頻字幕、視覺問答、文本閱讀、目標檢測和目標分割等多種視覺語言任務。
🚀 快速開始
訪問權限
要在Hugging Face上訪問PaliGemma,請查看並同意Google的使用許可。請確保您已登錄Hugging Face,然後點擊下方按鈕。請求將立即處理。 確認許可
使用示例
您可以使用以下提示模板執行不同的任務:
"cap {lang}"
:原始短字幕(來自WebLI-alt)"caption {lang}"
:美觀的、類似COCO的短字幕"describe {lang}"
:更長、更具描述性的字幕"ocr"
:光學字符識別"answer {lang} {question}"
:關於圖像內容的問答"question {lang} {answer}"
:根據給定答案生成問題"detect {object} ; {object}"
:在圖像中定位列出的對象並返回這些對象的邊界框"segment {object}"
:在圖像中定位對象佔據的區域,為該對象創建圖像分割
from transformers import (
PaliGemmaProcessor,
PaliGemmaForConditionalGeneration,
)
from transformers.image_utils import load_image
import torch
model_id = "google/paligemma2-3b-mix-224"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg"
image = load_image(url)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto").eval()
processor = PaliGemmaProcessor.from_pretrained(model_id)
prompt = "describe en"
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(torch.bfloat16).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)
這裡有一個筆記本展示瞭如何微調PaliGemma 2。
✨ 主要特性
- 多模態處理:能夠同時處理圖像和文本輸入,並生成文本輸出。
- 多語言支持:支持多種語言,可應用於不同語言的視覺語言任務。
- 廣泛的任務支持:可用於圖像和短視頻字幕、視覺問答、文本閱讀、目標檢測和目標分割等多種視覺語言任務。
- 可微調性:預訓練模型可以在各種視覺語言任務上進行微調,以適應特定的領域和任務。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
from transformers import (
PaliGemmaProcessor,
PaliGemmaForConditionalGeneration,
)
from transformers.image_utils import load_image
import torch
model_id = "google/paligemma2-3b-mix-224"
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg"
image = load_image(url)
model = PaliGemmaForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map="auto").eval()
processor = PaliGemmaProcessor.from_pretrained(model_id)
prompt = "describe en"
model_inputs = processor(text=prompt, images=image, return_tensors="pt").to(torch.bfloat16).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)
高級用法
文檔未提及高級用法相關代碼示例,故跳過此部分。
📚 詳細文檔
模型信息
模型概述
PaliGemma 2是PaliGemma視覺語言模型(VLM)的更新版本,它融合了Gemma 2模型的能力。PaliGemma系列模型受到PaLI - 3的啟發,基於SigLIP視覺模型和Gemma 2語言模型等開放組件構建。它以圖像和文本作為輸入,生成文本作為輸出,支持多種語言,旨在為廣泛的視覺語言任務提供領先的微調性能,如圖像和短視頻字幕、視覺問答、文本閱讀、目標檢測和目標分割。
模型架構
PaliGemma 2由Transformer解碼器和視覺Transformer圖像編碼器組成。文本解碼器從參數大小為2B、9B和27B的Gemma 2初始化,圖像編碼器從SigLIP - So400m/14初始化。與原始的PaliGemma模型類似,PaliGemma 2按照PaLI - 3的方法進行訓練。
輸入和輸出
- 輸入:圖像和文本字符串,如圖像字幕提示或問題。
- 輸出:對輸入的響應生成的文本,如圖像字幕、問題答案、對象邊界框座標列表或分割碼字。
模型數據
預訓練數據集
PaliGemma 2在以下數據集的混合上進行預訓練:
- WebLI:WebLI(Web Language Image)是一個基於公共網絡構建的網絡規模多語言圖像 - 文本數據集。使用了多種WebLI分割來獲取通用的模型能力,如視覺語義理解、對象定位、視覺情境文本理解和多語言能力。
- CC3M - 35L:從網頁中精心挑選的英語圖像 - 替代文本對(Sharma等人,2018)。使用Google Cloud Translation API將其翻譯成另外34種語言。
- VQ²A - CC3M - 35L/VQG - CC3M - 35L:VQ2A - CC3M的一個子集(Changpinyo等人,2022a),使用Google Cloud Translation API翻譯成與CC3M - 35L相同的另外34種語言。
- OpenImages:在OpenImages數據集上通過手工規則生成的檢測和對象感知問題及答案(Piergiovanni等人,2022)。
- WIT:從維基百科收集的圖像和文本(Srinivasan等人,2021)。
PaliGemma 2基於Gemma 2,您可以在Gemma 2模型卡片中找到Gemma 2預訓練數據集的信息。
數據責任過濾
為了在安全和負責任的數據上訓練PaliGemma 2,對WebLI應用了以下過濾器:
- 色情圖像過濾:此過濾器去除被認為具有色情性質的圖像。
- 文本安全過濾:識別並過濾掉與不安全文本配對的圖像。不安全文本是指任何被認為包含或涉及兒童性虐待圖像(CSAI)、色情內容、粗俗內容或以其他方式冒犯他人的文本。
- 文本毒性過濾:進一步使用Perspective API識別並過濾掉與被認為具有侮辱性、淫穢、仇恨或其他毒性的文本配對的圖像。
- 文本個人信息過濾:使用Cloud Data Loss Prevention (DLP) API過濾某些個人信息和其他敏感數據,以保護個人隱私。去除了如社會安全號碼和其他敏感信息類型等標識符。
- 其他方法:根據我們的政策和實踐,基於內容質量和安全性進行過濾。
實現信息
硬件
PaliGemma 2使用最新一代的張量處理單元(TPU)硬件(TPUv5e)進行訓練。
軟件
使用JAX、Flax、TFDS和big_vision
完成訓練。
JAX允許研究人員利用最新一代的硬件(包括TPU),以更快、更高效地訓練大型模型。TFDS用於訪問數據集,Flax用於模型架構。PaliGemma 2的微調代碼和推理代碼在big_vision
GitHub倉庫中發佈。
評估信息
基準測試結果
為了驗證PaliGemma 2在各種學術任務上的可遷移性,我們在每個任務上對預訓練模型進行微調。我們報告了不同分辨率下的結果,以瞭解哪些任務受益於更高的分辨率,哪些任務受益於更大的模型。重要的是,這些任務或數據集都不是預訓練數據混合的一部分,並且它們的圖像已從網絡規模的預訓練數據中明確移除。
PaliGemma 2按模型分辨率和大小的結果
基準測試 | 224 - 3B | 224 - 10B | 224 - 28B | 448 - 3B | 448 - 10B | 448 - 28B |
---|---|---|---|---|---|---|
AI2D | 74.7 | 83.1 | 83.2 | 76.0 | 84.4 | 84.6 |
[AOKVQA - DA](https://allenai.org/project/a - okvqa/home) (val) | 64.2 | 68.9 | 70.2 | 67.9 | 70.8 | 71.2 |
[AOKVQA - MC](https://allenai.org/project/a - okvqa/home) (val) | 79.7 | 83.7 | 84.7 | 82.5 | 85.9 | 87.0 |
[ActivityNet - CAP](https://paperswithcode.com/dataset/activitynet - captions) | 34.2 | 35.9 | - | - | - | - |
ActivityNet - QA | 51.3 | 53.2 | - | - | - | - |
COCO - 35L (avg34) | 113.9 | 115.8 | 116.5 | 115.8 | 117.2 | 117.2 |
COCO - 35L (en) | 138.4 | 140.8 | 142.4 | 140.4 | 142.4 | 142.3 |
COCOcap | 141.3 | 143.7 | 144.0 | 143.4 | 145.0 | 145.2 |
ChartQA (aug) | 74.4 | 74.2 | 68.9 | 89.2 | 90.1 | 85.1 |
ChartQA (human) | 42.0 | 48.4 | 46.8 | 54.0 | 66.4 | 61.3 |
[CountBenchQA](https://github.com/google - research/big_vision/blob/main/big_vision/datasets/countbenchqa/) | 81.0 | 84.0 | 86.4 | 82.0 | 85.3 | 87.4 |
DocVQA (val) | 39.9 | 43.9 | 44.9 | 73.6 | 76.6 | 76.1 |
GQA | 66.2 | 67.2 | 67.3 | 68.1 | 68.3 | 68.3 |
InfoVQA (val) | 25.2 | 33.6 | 36.4 | 37.5 | 47.8 | 46.7 |
[MARVL](https://marvl - challenge.github.io/) (avg5) | 83.5 | 89.5 | 90.6 | 82.7 | 89.1 | 89.7 |
[MSRVTT - CAP](https://paperswithcode.com/dataset/msr - vtt) | 68.5 | 72.1 | - | - | - | - |
[MSRVTT - QA](https://paperswithcode.com/dataset/msr - vtt) | 50.5 | 51.9 | - | - | - | - |
[MSVD - QA](https://paperswithcode.com/dataset/msvd - qa) | 61.1 | 62.5 | - | - | - | - |
NLVR2 | 91.4 | 93.9 | 94.2 | 91.6 | 93.7 | 94.1 |
NoCaps | 123.1 | 126.3 | 127.1 | 123.5 | 126.9 | 127.0 |
[OCR - VQA](https://ocr - vqa.github.io/) | 73.4 | 74.7 | 75.3 | 75.7 | 76.3 | 76.6 |
OKVQA | 64.2 | 68.0 | 71.2 | 64.1 | 68.6 | 70.6 |
RSVQA - hr (test) | 92.7 | 92.6 | 92.7 | 92.8 | 92.8 | 92.8 |
RSVQA - hr (test2) | 90.9 | 90.8 | 90.9 | 90.7 | 90.7 | 90.8 |
RSVQA - lr | 93.0 | 92.8 | 93.5 | 92.7 | 93.1 | 93.7 |
RefCOCO (testA) | 75.7 | 77.2 | 76.8 | 78.6 | 79.7 | 79.3 |
RefCOCO (testB) | 71.0 | 74.2 | 73.9 | 73.5 | 76.2 | 74.8 |
RefCOCO (val) | 73.4 | 75.9 | 75.0 | 76.3 | 78.2 | 77.3 |
[RefCOCO +](https://aclanthology.org/D14 - 1086) (testA) | 72.7 | 74.7 | 73.6 | 76.1 | 77.7 | 76.6 |
[RefCOCO +](https://aclanthology.org/D14 - 1086) (testB) | 64.2 | 68.4 | 67.1 | 67.0 | 71.1 | 68.6 |
[RefCOCO +](https://aclanthology.org/D14 - 1086) (val) | 68.6 | 72.0 | 70.3 | 72.1 | 74.4 | 72.8 |
RefCOCOg (test) | 69.0 | 71.9 | 70.7 | 72.7 | 74.8 | 73.7 |
RefCOCOg (val) | 68.3 | 71.4 | 70.5 | 72.3 | 74.4 | 73.0 |
ST - VQA (val) | 61.9 | 64.3 | 65.1 | 80.5 | 82.0 | 81.8 |
SciCap | 165.1 | 159.5 | 156.9 | 183.3 | 177.2 | 172.7 |
ScienceQA | 96.1 | 98.2 | 98.2 | 96.2 | 98.5 | 98.6 |
Screen2Words | 113.3 | 117.8 | 122.8 | 114.0 | 119.1 | 123.4 |
TallyQA (complex) | 70.3 | 73.4 | 74.2 | 73.6 | 76.7 | 76.8 |
TallyQA (simple) | 81.8 | 83.2 | 83.4 | 85.3 | 86.2 | 85.7 |
TextCaps | 127.5 | 137.9 | 139.9 | 152.1 | 157.7 | 153.6 |
TextVQA (val) | 59.6 | 64.0 | 64.7 | 75.2 | 76.6 | 76.2 |
VATEX | 80.8 | 82.7 | - | - | - | - |
VQAv2 (minival) | 83.0 | 84.3 | 84.5 | 84.8 | 85.8 | 85.8 |
[VizWizVQA](https://vizwiz.org/tasks - and - datasets/vqa/) (val) | 76.4 | 78.1 | 78.7 | 77.5 | 78.6 | 78.9 |
WidgetCap | 138.1 | 139.8 | 138.8 | 151.4 | 151.9 | 148.9 |
XM3600 (avg35) | 42.8 | 44.5 | 45.2 | 43.2 | 44.6 | 45.2 |
XM3600 (en) | 79.8 | 80.7 | 81.0 | 80.3 | 81.5 | 81.0 |
[xGQA](https://aclanthology.org/2022.findings - acl.196/) (avg7) | 58.6 | 61.4 | 61.1 | 60.4 | 62.6 | 62.1 |
附加基準測試
模型 | 精度 | 召回率 | F1 |
---|---|---|---|
PaliGemma 2 3B | 81.9 | 70.7 | 75.9 |
[Total - Text](https://paperswithcode.com/paper/total - text - a - comprehensive - dataset - for - scene)
模型 | 精度 | 召回率 | F1 |
---|---|---|---|
PaliGemma 2 3B | 73.8 | 74.5 | 74.2 |
模型 | S - TEDS | TEDS | GriTS - Top | GriTS - Con |
---|---|---|---|---|
PaliGemma 2 3B | 99.2 | 98.9 | 99.4 | 99.2 |
模型 | S - TEDS | TEDS | GriTS - Top | GriTS - Con |
---|---|---|---|---|
PaliGemma 2 3B | 97.6 | 97.3 | 97.9 | 97.8 |
[GrandStaff](https://link.springer.com/article/10.1007/s10032 - 023 - 00432 - z)
模型 | CER | LER | SER |
---|---|---|---|
PaliGemma 2 3B | 1.6 | 6.7 | 2.3 |
- PaliGemma 2 3B,完全匹配:94.8
[DOCCI](https://research.google/pubs/docci - descriptions - of - connected - and - contrasting - images/)
模型 | avg#char | avg#sent | NES % |
---|---|---|---|
PaliGemma 2 3B | 529 | 7.7 | 28.4 |
PaliGemma 2 10B | 521 | 7.5 | 20.3 |
- avg#char:平均字符數
- avg#sent:平均句子數
- NES:非蘊含句子
[MIMIC - CXR](https://paperswithcode.com/dataset/mimic - cxr)
模型 | CIDEr | BLEU4 | Rouge - L | RadGraph F1 |
---|---|---|---|---|
PaliGemma 2 3B | 19.9 | 14.6 | 31.9 | 28.8 |
PaliGemma 2 10B | 17.4 | 15.0 | 32.4 | 29.5 |
[Visual Spatial Reasoning](https://direct.mit.edu/tacl/article/doi/10.1162/tacl_a_00566/116470/Visual - Spatial - Reasoning)
模型 | VSR零樣本分割 (test) | VSR隨機分割 (test) |
---|---|---|
PaliGemma 2 3B | 74.8 | 81.6 |
PaliGemma 2 10B | 79.8 | 86.8 |
倫理與安全
評估方法
我們的評估方法包括跨相關內容政策的結構化倫理和安全評估,包括:
- 對涵蓋兒童安全、內容安全和代表性危害的提示進行人工評估。有關評估方法的更多詳細信息,請參閱Gemma模型卡片,但採用圖像字幕和視覺問答設置。
- 圖像到文本基準評估:針對相關學術數據集(如FairFace數據集(Karkkainen等人,2021))進行基準測試。
評估結果
- 倫理和安全評估的人工評估結果在可接受的閾值內,符合[內部政策](https://storage.googleapis.com/gweb - uniblog - publish - prod/documents/2023_Google_AI_Principles_Progress_Update.pdf#page = 11)中關於兒童安全、內容安全和代表性危害等類別。
- 除了嚴格的內部評估外,我們還使用Perspective API(閾值為0.8)來衡量從FairFace數據集中獲取的圖像生成字幕中的毒性、褻瀆和其他潛在問題。我們報告了每個感知性別、種族和年齡屬性子組中觀察到的最大值和中值。
指標 | 感知性別(3B) | 感知性別(10B) | 感知性別(28B) | 種族(3B) | 種族(10B) | 種族(28B) | 年齡組(3B) | 年齡組(10B) | 年齡組(28B) |
---|---|---|---|---|---|---|---|---|---|
最大值 | |||||||||
毒性 | 0.14% | 0.15% | 0.19% | 0.29% | 0.39% | 0.39% | 0.26% | 0.18% | 0.32% |
身份攻擊 | 0.04% | 0.02% | 0.02% | 0.13% | 0.06% | 0.06% | 0.06% | 0.03% | 0.06% |
侮辱 | 0.17% | 0.25% | 0.17% | 0.37% | 0.52% | 0.52% | 0.27% | 0.39% | 0.24% |
威脅 | 0.55% | 0.43% | 0.57% | 0.83% | 0.48% | 0.48% | 0.64% | 0.43% | 0.64% |
褻瀆 | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% |
中值 | |||||||||
毒性 | 0.13% | 0.10% | 0.18% | 0.07% | 0.07% | 0.14% | 0.12% | 0.08% | 0.12% |
身份攻擊 | 0.02% | 0.01% | 0.02% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% |
侮辱 | 0.15% | 0.23% | 0.14% | 0.14% | 0.17% | 0.13% | 0.09% | 0.18% | 0.16% |
威脅 | 0.35% | 0.27% | 0.41% | 0.28% | 0.19% | 0.42% | 0.27% | 0.31% | 0.40% |
褻瀆 | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% | 0.00% |
使用與限制
預期用途
開放視覺語言模型(VLMs)在各個行業和領域有廣泛的應用。以下潛在用途列表並不全面。此列表的目的是提供有關模型創建者在模型訓練和開發過程中考慮的可能用例的上下文信息。Gemma模型的禁止使用情況在Gemma禁止使用政策中列出。
特定視覺語言任務的微調
- 預訓練模型可以在廣泛的視覺語言任務上進行微調,如圖像字幕、短視頻字幕、視覺問答、文本閱讀、目標檢測和目標分割。
- 預訓練模型可以針對特定領域進行微調,如遙感問答、盲人的視覺問題、科學問答、描述UI元素功能。
- 預訓練模型可以針對具有非文本輸出的任務進行微調,如邊界框或分割掩碼。
視覺語言研究
- 預訓練模型和微調模型可以為研究人員提供基礎,用於試驗VLM技術、開發算法並推動該領域的發展。
倫理考慮和風險
視覺語言模型(VLMs)的發展引發了一些倫理問題。在創建開放模型時,我們仔細考慮了以下方面:
- 偏差和公平性:在大規模、真實世界的圖像 - 文本數據上訓練的VLMs可能反映訓練材料中嵌入的社會文化偏差。這些模型經過了仔細審查,本卡片中描述了輸入數據預處理和後續評估。
- 錯誤信息和濫用:VLMs可能被濫用來生成虛假、誤導或有害的文本。提供了負責任使用模型的指南,請參閱Responsible Generative AI Toolkit。
- 透明度和問責制:本模型卡片總結了模型架構、能力、限制和評估過程的詳細信息。負責任開發的開放模型為AI生態系統中的開發者和研究人員提供了共享創新的機會,使VLM技術更易於獲取。
已識別的風險和緩解措施
- 偏差的延續:鼓勵在模型訓練、微調及其他用例中進行持續監控(使用評估指標、人工審查)並探索去偏差技術。
- 有害內容的生成:內容安全機制和指南至關重要。鼓勵開發者根據其特定產品政策和應用用例謹慎行事並實施適當的內容安全保障措施。
- 惡意用途:技術限制以及對開發者和最終用戶的教育有助於減輕LLMs被惡意使用的風險。提供了教育資源和用戶舉報濫用行為的機制,請參閱Responsible Generative AI Toolkit。Gemma模型的禁止使用情況在Gemma禁止使用政策中列出。
- 隱私侵犯:模型在經過過濾以去除某些個人信息和敏感數據的數據上進行訓練。鼓勵開發者遵守隱私法規並採用隱私保護技術。
限制
- 大多數繼承自基礎Gemma 2模型的限制仍然適用:
- VLMs在具有明確提示和說明的任務上表現更好。開放式或高度複雜的任務可能具有挑戰性。
- 自然語言本質上是複雜的。VLMs可能難以理解微妙的細微差別、諷刺或比喻語言。
- VLMs根據從訓練數據集中學習到的信息生成響應,但它們不是知識庫。它們可能生成不正確或過時的事實陳述。
- VLMs依賴於語言和圖像中的統計模式。它們可能在某些情況下缺乏應用常識推理的能力。
- PaliGemma 2首先是作為通用預訓練模型設計的,用於微調至特定任務。因此,其“開箱即用”或“零樣本”性能可能落後於專門為通用目的設計的模型。
- PaliGemma 2不是多輪聊天機器人。它設計用於單輪圖像和文本輸入。
🔧 技術細節
文檔中關於技術細節部分的描述較為分散,未形成超過50字的具體技術說明,故跳過此章節。
📄 許可證
本項目使用gemma
許可證。
📖 引用
如果您在研究中使用了PaliGemma 2,請使用以下BibTeX引用:
@article{
title={PaliGemma 2: A Family of Versatile VLMs for Transfer},
author={Andreas Steiner and André Susano Pinto and Michael Tschannen and Daniel Keysers and Xiao Wang and Yonatan Bitton and Alexey Gritsenko and Matthias Minderer and Anthony Sherbondy and Shangbang Long and Siyang Qin and Reeve Ingle and Emanuele Bugliarello and Sahar Kazemzadeh and Thomas Mesnard and Ibrahim Alabdulmohsin and Lucas Beyer and Xiaohua Zhai},
year={2024},
journal={arXiv preprint arXiv:2412.03555}
}
您可以在這裡找到相關論文。








