ColQwen is a model based on a novel model architecture and training strategy based on Vision Language Models (VLMs) to efficiently index documents from their visual features.
It is a
Qwen2-VL-2B extension that generates
ColBERT- style multi-vector representations of text and images.
It was introduced in the paper
ColPali: Efficient Document Retrieval with Vision Language Models and first released in
this repository
This version is the untrained base version to guarantee deterministic projection layer initialization.
This model takes dynamic image resolutions in input and does not resize them, changing their aspect ratio as in ColPali.
Maximal resolution is set so that 1024 image patches are created at most. Experiments show clear improvements with larger amounts of image patches, at the cost of memory requirements.
Data is the same as the ColPali data described in the paper.
We train models use low-rank adapters (
LoRA)
with
alpha=128 and
r=128 on the transformer layers from the language model,
as well as the final randomly initialized projection layer, and use a
paged_adamw_8bit optimizer.
We train on an 8xH100 GPU setup with distributed data parallelism (via accelerate), a learning rate of 2e-4 with linear decay with 1% warmup steps, batch size per device is 128, in
bfloat16 format
1import torch
2from PIL import Image
3
4from colpali_engine.models import ColQwen2, ColQwen2Processor
5
6model = ColQwen2.from_pretrained(
7 "tsystems/colqwen2-2b-v1.0",
8 torch_dtype=torch.bfloat16,
9 device_map="cuda:0", # or "mps" if on Apple Silicon
10 ).eval()
11processor = ColQwen2Processor.from_pretrained("tsystems/colqwen2-2b-v1.0")
12
13# Your inputs
14images = [
15 Image.new("RGB", (32, 32), color="white"),
16 Image.new("RGB", (16, 16), color="black"),
17]
18queries = [
19 "Is attention really all you need?",
20 "What is the amount of bananas farmed in Salvador?",
21]
22
23# Process the inputs
24batch_images = processor.process_images(images).to(model.device)
25batch_queries = processor.process_queries(queries).to(model.device)
26
27# Forward pass
28with torch.no_grad():
29 image_embeddings = model(**batch_images)
30 query_embeddings = model(**batch_queries)
31
32scores = processor.score_multi_vector(query_embeddings, image_embeddings)
If you use this models from this organization in your research, please cite the original paper as follows:
1@misc{faysse2024colpaliefficientdocumentretrieval,
2 title={ColPali: Efficient Document Retrieval with Vision Language Models},
3 author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and Céline Hudelot and Pierre Colombo},
4 year={2024},
5 eprint={2407.01449},
6 archivePrefix={arXiv},
7 primaryClass={cs.IR},
8 url={https://arxiv.org/abs/2407.01449},
9}