[!IMPORTANT] 此版本的 ColPali 应使用
transformers 🤗版本加载,而非colpali-engine。 它是使用convert_colpali_weights_to_hf.py脚本 从vidore/colpali-v1.3-merged检查点转换而来。
ColPali 是一款基于新颖模型架构和训练策略的模型,它以视觉语言模型(VLMs)为基础,能够从文档的视觉特征中高效地建立索引。 它是 PaliGemma-3B 的扩展,可生成 ColBERT 风格的文本和图像多向量表示。 该模型在论文 ColPali: Efficient Document Retrieval with Vision Language Models 中首次提出,并在 此仓库 中首次发布。
HuggingFace transformers 🤗 实现由 Tony Wu(@tonywu71)和 Yoni Gozlan(@yonigozlan)贡献。

请阅读 transformers 🤗 模型卡片:https://huggingface.co/docs/transformers/en/model_doc/colpali。
我们的训练数据集包含 127,460 个查询-页面对,由公开可用的学术数据集的训练集(占 63%)和一个合成数据集组成。合成数据集由网络爬取的 PDF 文档页面构成,并通过 VLM 生成(Claude-3 Sonnet)的伪问题进行增强(占 37%)。 我们的训练集特意设计为全英文,以便我们研究其对非英语语言的零样本泛化能力。我们明确确保没有多页 PDF 文档同时用于 ViDoRe 和训练集,以防止评估污染。 我们还创建了一个包含 2% 样本的验证集,用于超参数调优。
注:语言模型(Gemma-2B)的预训练语料中存在多语言数据,并且可能在 PaliGemma-3B 的多模态训练过程中出现。
所有模型均在训练集上训练 1 个 epoch。除非另有说明,否则我们以 bfloat16 格式训练模型,在语言模型的 transformer 层以及最终随机初始化的投影层上使用低秩适配器(LoRA),其中 alpha=32 且 r=32,并使用 paged_adamw_8bit 优化器。我们在 8 GPU 设备上采用数据并行方式进行训练,学习率为 5e-5,采用线性衰减策略,预热步数为 2.5%,批大小为 32。
import torch
from PIL import Image
from transformers import ColPaliForRetrieval, ColPaliProcessor
model_name = "vidore/colpali-v1.3-hf"
model = ColPaliForRetrieval.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="cuda:0", # or "mps" if on Apple Silicon
).eval()
processor = ColPaliProcessor.from_pretrained(model_name)
# Your inputs
images = [
Image.new("RGB", (32, 32), color="white"),
Image.new("RGB", (16, 16), color="black"),
]
queries = [
"What is the organizational structure for our R&D department?",
"Can you provide a breakdown of last year’s financial performance?",
]
# Process the inputs
batch_images = processor(images=images).to(model.device)
batch_queries = processor(text=queries).to(model.device)
# Forward pass
with torch.no_grad():
image_embeddings = model(**batch_images)
query_embeddings = model(**batch_queries)
# Score the queries against the images
scores = processor.score_retrieval(query_embeddings.embeddings, image_embeddings.embeddings)colpali-engine 包的原始模型实现代码可在 此处 找到。🌎ColPali 的视觉语言骨干模型(PaliGemma)遵循其 模型卡片 中指定的 gemma 许可证。ColPali 继承此 gemma 许可证。
如果您在研究中使用了本组织的任何数据集或模型,请按以下方式引用原始数据集:
@misc{faysse2024colpaliefficientdocumentretrieval,
title={ColPali: Efficient Document Retrieval with Vision Language Models},
author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and Céline Hudelot and Pierre Colombo},
year={2024},
eprint={2407.01449},
archivePrefix={arXiv},
primaryClass={cs.IR},
url={https://arxiv.org/abs/2407.01449},
}