跳到正文
Hugging Face Blog·· 2024-04-15精選AI 評分71

Hugging Face 發佈 8B 多模態模型 Idefics2,採 Apache-2.0 授權

Introducing Idefics2: A Powerful 8B Vision-Language Model for the community

AI 導讀

Hugging Face 發佈 Idefics2,這款 8B 參數多模態模型可接收文字與圖像序列並生成文字回應。模型權重採 Apache-2.0 授權,並已整合至 Transformers,支援圖像問答、OCR、圖表與文件理解。團隊亦公開 The Cauldron,收錄 50 個人工整理、供多輪對話使用的資料集。

推薦理由

Idefics2 同時公開 8B 權重、Apache-2.0 授權與多項視覺問答基準成績,便於對照小型多模態模型的效能表現和使用條件。

正文 · 繁體中文

Idefics-Obelics logo

我們很高興推出 Idefics2。這是一款通用多模態模型,可接收任意文字和圖片序列作為輸入,並生成文字回應。它可回答有關圖片的問題、描述視覺內容、根據多張圖片創作故事、從文件擷取資訊,亦能進行基本算術運算。
Idefics2 在 Idefics1 的基礎上改進:模型有 8B 參數,採用開放的 Apache 2.0 授權,並提升了 OCR(光學字元辨識)能力。Idefics2 是多模態社羣開發工作的穩固基礎。它在視覺問答基準測試中於同等規模模型中名列前茅,表現媲美大得多的 LLava-Next-34B 和 MM1-30B-chat。
Idefics2 從推出起便整合至 🤗 Transformers,方便針對各種多模態應用進行微調。你現在即可在 Hub 試用模型!

The Cauldron

模型 開放
權重
規模 每張圖片
token 數
MMMU
(驗證集/測試集)
MathVista
(testmini)
TextVQA
(驗證集)
MMBench
(測試集)
VQAv2
(測試開發集)
DocVQA
(測試集)
DeepSeek-VL ✅ 7B 576 36.6/- 36.1 64.4 73.2 - 49.6
LLaVa-NeXT-Mistral-7B ✅ 7B 2880 35.3/- 37.7 65.7 68.7 82.2 -
LLaVa-NeXT-13B ✅ 13B 2880 36.2/- 35.3 67.1 70.0 82.8 -
LLaVa-NeXT-34B ✅ 34B 2880 51.1/44.7 46.5 69.5 79.3 83.7 -
MM1-Chat-7B ❌ 7B 720 37.0/35.6 35.9 72.8 72.3 82.8 -
MM1-Chat-30B ❌ 30B 720 44.7/40.3 39.4 73.5 75.1 83.7
Gemini 1.0 Pro ❌ 🤷‍♂️ 🤷‍♂️ 47.9/- 45.2 74.6 - 71.2 88.1
Gemini 1.5 Pro ❌ 🤷‍♂️ 🤷‍♂️ 58.5/- 52.1 73.5 - 73.2 86.5
Claude 3 Haiku ❌ 🤷‍♂️ 🤷‍♂️ 50.2/- 46.4 - - - 88.8
Idefics1 instruct(32-shot) ✅ 80B - - - 39.3 - 68.8 -
Idefics2(不切分圖片)* ✅ 8B 64 43.5/37.9 51.6 70.4 76.8 80.8 67.3
Idefics2(切分圖片)* ✅ 8B 320 43.0/37.7 51.4 73.0 76.7 81.2 74.0

* 切分圖片:按照 SPHINX 和 LLaVa-NeXT 的方法,允許選擇把子圖片切分成 4 塊。

訓練數據

Idefics2 預訓練時使用多種公開資料集,包括交錯排列的網頁文件(Wikipedia、OBELICS)、圖片説明配對(Public Multimodal Dataset、LAION-COCO)、OCR 數據(PDFA(英語)、IDL和Rendered-text),以及圖片轉程式碼數據(WebSight)。
你可透過互動式視覺化工具探索 OBELICS 資料集。
按照基礎模型社羣的常見做法,我們進一步使用任務導向數據訓練基礎模型。然而,這些數據格式各異,散落在不同地方,收集起來成為社羣的障礙。為解決這個問題,我們公開推出精心整理的多模態指令微調資料集:The Cauldron,當中包含50 個經人工整理、適用於多輪對話的資料集。我們以 The Cauldron 和多個純文字指令微調資料集串接後,對 Idefics2 進行指令微調。

The Cauldron

相較 Idefics1 的改進

  • 我們按照 NaViT 方法,以圖片原生解像度(最高 980 x 980)和原生長寬比處理圖片,免除以往電腦視覺領域把圖片調整為固定正方形尺寸的需要。此外,我們參考 SPHINX 方法,亦可選擇切分子圖片,並傳入超高解像度圖片。
  • 我們加入需要模型轉錄圖片或文件中文字的數據,大幅提升 OCR 能力;亦透過適當訓練數據,改善模型回答圖表、圖形和文件問題的能力。
  • 我們不再沿用 Idefics1 的架構(閘控交叉注意力),而是簡化視覺特徵融入語言主幹網絡的方式。圖片先輸入視覺編碼器,再經過學習式 Perceiver 池化和 MLP 模態投影。然後把池化後的序列與文字嵌入串接,形成圖片和文字交錯排列的序列。

所有這些改進,加上更優質的預訓練主幹網絡,令模型規模小 10 倍,效能仍較 Idefics1 大幅提升。

Idefics2 Architecture

開始使用 Idefics2

Idefics2 已在 Hugging Face Hub 開放,並於最新版本的 transformers中支援。以下是試用程式碼示例:

import requests
import torch
from PIL import Image

from transformers import AutoProcessor, AutoModelForVision2Seq
from transformers.image_utils import load_image

DEVICE = "cuda:0"

# Note that passing the image urls (instead of the actual pil images) to the processor is also possible
image1 = load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg")
image2 = load_image("https://cdn.britannica.com/59/94459-050-DBA42467/Skyline-Chicago.jpg")
image3 = load_image("https://cdn.britannica.com/68/170868-050-8DDE8263/Golden-Gate-Bridge-San-Francisco.jpg")


processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b")
model = AutoModelForVision2Seq.from_pretrained(
    "HuggingFaceM4/idefics2-8b",
).to(DEVICE)


# Create inputs
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "text", "text": "What do we see in this image?"},
        ]
    },
    {
        "role": "assistant",
        "content": [
            {"type": "text", "text": "In this image, we can see the city of New York, and more specifically the Statue of Liberty."},
        ]
    },
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "text", "text": "And how about this image?"},
        ]
    },
]
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(text=prompt, images=[image1, image2], return_tensors="pt")
inputs = {k: v.to(DEVICE) for k, v in inputs.items()}


# Generate
generated_ids = model.generate(**inputs, max_new_tokens=500)
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)

print(generated_texts)

我們亦提供微調 Colab,方便希望針對特定用途提升 Idefics2 表現的用戶。

The Cauldron

相關資源

如想深入瞭解,以下是 Idefics2 的所有資源:

授權

此模型建基於兩個預訓練模型:Mistral-7B-v0.1和siglip-so400m-patch14-384,兩者均以 Apache-2.0 授權發布。 我們亦以 Apache-2.0 授權發布 Idefics2 權重。

致謝

感謝 Google 團隊和 Mistral AI 發布模型,並讓開源 AI 社羣使用!

特別感謝 Chun Te Lee 製作長條圖,以及 Merve Noyan 審閲網誌並提出建議 🤗

來源:Hugging Face Blog · huggingface.co