推出 Idefics2:一個強大的 8B 視覺語言模型,面向社群

釋出於 2024 年 4 月 15 日
在 GitHub 上更新

Idefics-Obelics logo

我們很高興釋出 Idefics2,這是一個通用的多模態模型,可以接收任意序列的文字和影像作為輸入,並生成文字響應。它可以回答關於影像的問題,描述視覺內容,根據多張影像建立故事,從文件中提取資訊,並執行基本的算術操作。
Idefics2 在 Idefics1 的基礎上進行了改進:Idefics2 擁有 8B 引數,採用開放許可證(Apache 2.0),並增強了 OCR(光學字元識別)功能,是多模態社群的強大基礎。其在視覺問答基準測試中的表現處於同類模型前列,並可與 LLaVa-Next-34BMM1-30B-chat 等更大模型競爭。
Idefics2 也從一開始就整合在 🤗 Transformers 中,因此很容易針對許多多模態應用進行微調。您現在就可以在 Hub 上試用這些模型

The Cauldron

模型 開放
權重
大小 每張影像的令牌數量
每張影像
MMMU
(驗證/測試)
MathVista
(測試迷你)
文字視覺問答
(驗證)
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 指令 (32-shots) 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

* w/ im. split: 遵循 SPHINX 和 LLaVa-NeXT 的策略,我們允許將子影像可選地分割成 4 份。

訓練資料

Idefics2 的預訓練資料混合了公開可用的資料集:交錯式網頁文件(Wikipedia、OBELICS)、影像-字幕對(Public Multimodal Dataset、LAION-COCO)、OCR 資料(PDFA (en)IDLRendered-text)以及影像到程式碼資料(WebSight)。
互動式視覺化允許探索 OBELICS 資料集。
遵循基礎模型社群的慣例,我們進一步在面向任務的資料上訓練了基礎模型。然而,這些資料通常格式不一,散落在各地。收集它們對社群來說是一個障礙。為了解決這個問題,我們釋出了我們一直在開發的通用多模態指令微調資料集:_《大熔爐 (The Cauldron)》_,這是一個包含 **50** 個手動策劃的、為多輪對話格式化的資料集的開放彙編。我們對 Idefics2 進行了指令微調,將其與《大熔爐》以及各種純文字指令微調資料集進行拼接。

The Cauldron

相較於 Idefics1 的改進

  • 我們遵循 NaViT 策略,以其原始解析度(最高 980 x 980)和原始寬高比處理影像。這避免了像計算機視覺社群以往那樣將影像調整為固定大小的正方形的需要。此外,我們遵循 SPHINX 的策略,並(可選地)允許子影像分割和傳遞非常大解析度的影像。
  • 我們透過整合要求模型轉錄影像或文件中文字的資料,顯著增強了 OCR 能力。我們還透過適當的訓練資料,改進了在圖表、圖形和文件上回答問題的能力。
  • 我們摒棄了 Idefics1 的架構(門控交叉注意力),並簡化了視覺特徵與語言主幹的整合。影像被送入視覺編碼器,然後是學習的 Perceiver pooling 和 MLP 模態投影。該 pooling 序列隨後與文字嵌入拼接,以獲得影像和文字的(交錯)序列。

所有這些改進,加上更好的預訓練主幹,使得一個比 Idefics1 小 10 倍的模型在效能上有了顯著提升。

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.1siglip-so400m-patch14-384。兩者均已在 Apache-2.0 許可下發布。我們也將 Idefics2 的權重在 Apache-2.0 許可下發布。

致謝

感謝 Google 團隊和 Mistral AI 釋出其模型並向開源 AI 社群提供!

特別感謝 Chun Te Lee 提供的條形圖,以及 Merve Noyan 對部落格文章的審閱和建議 🤗

社群

註冊登入 評論

© . This site is unofficial and not affiliated with Hugging Face, Inc.