🚀 ColQwen2:基于Qwen2-VL-2B-Instruct与ColBERT策略的视觉检索器
ColQwen2是一个基于视觉语言模型(VLMs)的新型模型架构和训练策略的模型,可从文档的视觉特征中高效索引文档。它是Qwen2-VL-2B的扩展,能生成ColBERT风格的文本和图像多向量表示。该模型在论文ColPali: Efficient Document Retrieval with Vision Language Models中被提出,并首次在此仓库中发布。

HuggingFace transformers
🤗 的实现由Tony Wu (@tonywu71) 和Yoni Gozlan (@yonigozlan) 贡献。
🚀 快速开始
重要提示
⚠️ 重要提示
实验性:在使用前,请等待 https://github.com/huggingface/transformers/pull/35778 合并!
⚠️ 重要提示
此版本的ColQwen2应使用 transformers 🤗
版本加载,而不是 colpali-engine
。它是使用 convert_colqwen2_weights_to_hf.py
脚本从 vidore/colqwen2-v1.0-merged
检查点转换而来。
✨ 主要特性
ColQwen2基于视觉语言模型(VLMs)的新型架构和训练策略,能够从文档的视觉特征中高效索引文档。它是Qwen2-VL-2B的扩展,可生成ColBERT风格的文本和图像多向量表示。
📚 详细文档
模型描述
阅读 transformers
🤗 模型卡片:https://huggingface.co/docs/transformers/en/model_doc/colqwen2。
模型训练
数据集
我们的训练数据集包含127,460个查询 - 页面对,由公开可用的学术数据集的训练集(63%)和一个合成数据集组成。合成数据集由网络爬取的PDF文档页面构成,并使用VLM生成(Claude-3 Sonnet)的伪问题进行扩充(37%)。我们的训练集设计为全英文,以便研究对非英语语言的零样本泛化能力。我们明确验证了没有多页PDF文档同时用于 ViDoRe 和训练集,以防止评估污染。使用2%的样本创建验证集来调整超参数。
💻 使用示例
基础用法
import torch
from PIL import Image
from transformers import ColQwen2ForRetrieval, ColQwen2Processor
from transformers.utils.import_utils import is_flash_attn_2_available
model_name = "vidore/colqwen2-v1.0-hf"
model = ColQwen2ForRetrieval.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="cuda:0",
attn_implementation="flash_attention_2" if is_flash_attn_2_available() else None,
).eval()
processor = ColQwen2Processor.from_pretrained(model_name)
images = [
Image.new("RGB", (128, 128), color="white"),
Image.new("RGB", (64, 32), color="black"),
]
queries = [
"What is the organizational structure for our R&D department?",
"Can you provide a breakdown of last year’s financial performance?",
]
batch_images = processor(images=images).to(model.device)
batch_queries = processor(text=queries).to(model.device)
with torch.no_grad():
image_embeddings = model(**batch_images).embeddings
query_embeddings = model(**batch_queries).embeddings
scores = processor.score_retrieval(query_embeddings, image_embeddings)
🔧 技术细节
局限性
- 聚焦范围:该模型主要聚焦于PDF类型文档和资源丰富的语言,可能限制其对其他文档类型或代表性不足语言的泛化能力。
- 支持情况:该模型依赖于从ColBERT后期交互机制派生的多向量检索,可能需要工程努力才能适应缺乏原生多向量支持的广泛使用的向量检索框架。
📄 许可证
ColQwen2的视觉语言骨干模型(Qwen2-VL)遵循 apache-2.0
许可证。ColQwen2继承了此 apache-2.0
许可证。
📞 联系信息
- Manuel Faysse: manuel.faysse@illuin.tech
- Hugues Sibille: hugues.sibille@illuin.tech
- Tony Wu: tony.wu@illuin.tech
📚 引用
如果您在研究中使用了该组织的任何数据集或模型,请按以下方式引用原始数据集:
@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},
}