Hugging Face 发布 8B 多模态模型 Idefics2
Introducing Idefics2: A Powerful 8B Vision-Language Model for the community
Hugging Face 发布 Idefics2,一个 8B 参数、Apache 2.0 许可的多模态模型,可接受任意文本与图像序列输入并生成文本回复,支持图像问答、文档信息抽取和基础算术。
8B 参数、Apache 2.0 许可并同步放出多模态指令微调数据集,读者可据此判断开源多模态的可用起点。
我们很高兴发布 Idefics2,这是一个通用的多模态模型,可以接受任意序列的文本和图像作为输入,并生成文本回复。它可以回答关于图像的问题、描述视觉内容、基于多张图像创作故事、从文档中提取信息,以及执行基本的算术运算。
Idefics2 在 Idefics1 的基础上进行了改进:凭借 8B 参数、开放许可证(Apache 2.0)以及增强的 OCR(光学字符识别)能力,Idefics2 为从事多模态研究的社区奠定了坚实的基础。它在视觉问答基准测试上的性能在同规模中名列前茅,并可与 LLava-Next-34B 和 MM1-30B-chat 等更大的模型相竞争。
Idefics2 从一开始就集成在 🤗 Transformers 中,因此可以轻松地针对许多多模态应用进行微调。您现在就可以在 Hub 上试用这些 模型!
| 模型 | 开放 权重 |
规模 | 每张图像的 token 数 |
MMMU (验证/测试) |
MathVista (testmini) |
TextVQA (验证) |
MMBench (测试) |
VQAv2 (test-dev) |
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 (en)、IDL 和 Rendered-text),以及图像到代码数据(WebSight)。
交互式可视化允许探索 OBELICS 数据集。
遵循基础模型社区的常见做法,我们进一步在任务导向数据上训练基础模型。然而,这些数据通常格式各异,分散在不同地方。收集它们对社区来说是一个障碍。为了解决这个问题,我们发布了我们一直在准备的多模态指令微调数据集:The Cauldron,这是一个开放汇编,包含 50 个手动整理的数据集,格式化为多轮对话。我们在 The Cauldron 和各种纯文本指令微调数据集的拼接上对 Idefics2 进行了指令微调。
对 Idefics1 的改进
- 我们遵循 NaViT 策略,以原生分辨率(最高 980 x 980)和原生宽高比处理图像。这避免了计算机视觉领域历史上将图像调整为固定大小正方形的需要。此外,我们遵循 SPHINX 的策略,并(可选地)允许子图像拆分并传递非常大分辨率的图像。
- 我们通过整合要求模型转录图像或文档中文本的数据,显著增强了 OCR 能力。我们还通过适当的训练数据,提高了回答关于图表、图形和文档问题的能力。
- 我们从 Idefics1 的架构(门控交叉注意力)出发,简化了视觉特征与语言主干的集成。图像被送入视觉编码器,随后经过学习到的 Perceiver 池化和 MLP 模态投影。然后,该池化序列与文本嵌入拼接,得到图像和文本的(交错)序列。
所有这些改进,加上更好的预训练主干,使得模型在体积缩小 10 倍的情况下,性能相比 Idefics1 有了显著提升。
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 的任何人来说,这应该会派上用场。
资源
如果您想进一步深入了解,以下是 Idefics2 所有资源的汇编:
- Idefics2 集合
- 带有模型卡的 Idefics2 模型
- 带有模型卡的 Idefics2-base 模型
- 带有模型卡的 Idefics2-chat 模型
- 带有数据集卡的 The Cauldron
- 带有数据集卡的 OBELICS
- 带有数据集卡的 WebSight
- Idefics2 微调 colab
- Idefics2-8B 模型演示(非聊天模型)
- Idefics2 演示
- 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