IDEFICS 簡介:尖端視覺語言模型的開放復現

釋出於 2023 年 8 月 22 日
在 GitHub 上更新

我們很高興釋出 IDEFICS (Image-aware Decoder Enhanced à la Flamingo with Interleaved Cross-attentionS),這是一個開放獲取的視覺語言模型。IDEFICS 基於 Flamingo,這是 DeepMind 最初開發的尖端視覺語言模型,但尚未公開發布。與 GPT-4 類似,該模型接受任意序列的影像和文字輸入並生成文字輸出。IDEFICS 完全基於公開可用的資料和模型(LLaMA v1 和 OpenCLIP)構建,並提供兩種變體——基礎版本和指令版本。每個變體都有 90 億和 800 億引數兩種大小。

尖端 AI 模型的發展應該更加透明。我們開發 IDEFICS 的目標是復現併為 AI 社群提供與 Flamingo 等大型專有模型能力相匹配的系統。因此,我們採取了重要措施,為這些 AI 系統的透明度做出貢獻:我們只使用了公開可用的資料,我們提供了探索訓練資料集的工具,我們分享了構建此類工件的技術經驗和錯誤,並在釋出前透過對抗性提示評估了模型的危害性。我們希望 IDEFICS 能為多模態 AI 系統領域的更多開放研究奠定堅實基礎,與 OpenFlamingo 等模型並駕齊驅——OpenFlamingo 是 Flamingo 在 90 億引數規模上的另一個開放復現。

在 Hub 上試用 演示模型

Screenshot of IDEFICS generation for HF Woodstock of AI

什麼是 IDEFICS?

IDEFICS 是一個擁有 800 億引數的多模態模型,接受影像和文字序列作為輸入,並生成連貫的文字作為輸出。它可以回答有關影像的問題,描述視覺內容,建立基於多張影像的故事等。

IDEFICS 是 Flamingo 的開放式復現,在各種影像-文字理解基準測試中,其效能與原始閉源模型相當。它有兩種變體——800 億引數和 90 億引數。

Plot comparing the performance of Flamingo, OpenFlamingo and IDEFICS

我們還提供微調版本 idefics-80B-instructidefics-9B-instruct,適用於對話用例。

訓練資料

IDEFICS 在混合的公開可用資料集上進行訓練:維基百科、公共多模態資料集和 LAION,以及我們建立的一個新的 115B token 資料集,名為 OBELICS。OBELICS 包含從網路抓取的 1.41 億個交錯影像-文字文件和 3.53 億張影像。

我們提供了 OBELICS 的互動式視覺化,可以使用 Nomic AI 探索資料集內容。

Interactive visualization of OBELICS

有關 IDEFICS 架構、訓練方法和評估的詳細資訊,以及資料集資訊,請參閱模型卡片和我們的研究論文。此外,我們還記錄了模型訓練的技術見解和經驗,為 IDEFICS 的開發提供了寶貴的視角。

倫理評估

在專案開始時,透過一系列討論,我們制定了一份倫理章程,以指導專案期間的決策。該章程規定了包括自我批判、透明和公平在內的價值觀,我們在處理專案和釋出模型時力求遵循這些價值觀。

作為釋出過程的一部分,我們透過對抗性提示模型(一種稱為紅隊測試的過程),用可能引發我們不希望模型做出的響應的影像和文字,對模型的潛在偏差進行了內部評估。

請透過演示試用 IDEFICS,檢視相應的模型卡片資料集卡片,並透過社群選項卡向我們提供您的反饋!我們致力於改進這些模型,並使大型多模態 AI 模型可供機器學習社群使用。

許可證

該模型建立在兩個預訓練模型之上:laion/CLIP-ViT-H-14-laion2B-s32B-b79Khuggyllama/llama-65b。第一個以 MIT 許可證釋出,而第二個以專注於研究目的的特定非商業許可證釋出。因此,使用者應透過直接向 Meta 的表格申請來遵守該許可證。

這兩個預訓練模型透過我們訓練的新初始引數相互連線。這些引數不基於構成複合模型的任何兩個基礎凍結模型。我們以 MIT 許可證釋出我們訓練的附加權重。

IDEFICS 入門

IDEFICS 模型可在 Hugging Face Hub 上獲取,並受最新版 transformers 支援。以下是嘗試它的程式碼示例

import torch
from transformers import IdeficsForVisionText2Text, AutoProcessor

device = "cuda" if torch.cuda.is_available() else "cpu"

checkpoint = "HuggingFaceM4/idefics-9b-instruct"
model = IdeficsForVisionText2Text.from_pretrained(checkpoint, torch_dtype=torch.bfloat16).to(device)
processor = AutoProcessor.from_pretrained(checkpoint)

# We feed to the model an arbitrary sequence of text strings and images. Images can be either URLs or PIL Images.
prompts = [
    [
        "User: What is in this image?",
        "https://upload.wikimedia.org/wikipedia/commons/8/86/Id%C3%A9fix.JPG",
        "<end_of_utterance>",

        "\nAssistant: This picture depicts Idefix, the dog of Obelix in Asterix and Obelix. Idefix is running on the ground.<end_of_utterance>",

        "\nUser:",
        "https://static.wikia.nocookie.net/asterix/images/2/25/R22b.gif/revision/latest?cb=20110815073052",
        "And who is that?<end_of_utterance>",

        "\nAssistant:",
    ],
]

# --batched mode
inputs = processor(prompts, add_end_of_utterance_token=False, return_tensors="pt").to(device)
# --single sample mode
# inputs = processor(prompts[0], return_tensors="pt").to(device)

# Generation args
exit_condition = processor.tokenizer("<end_of_utterance>", add_special_tokens=False).input_ids
bad_words_ids = processor.tokenizer(["<image>", "<fake_token_around_image>"], add_special_tokens=False).input_ids

generated_ids = model.generate(**inputs, eos_token_id=exit_condition, bad_words_ids=bad_words_ids, max_length=100)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)
for i, t in enumerate(generated_text):
    print(f"{i}:\n{t}\n")

社群

註冊登入 以評論

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