Views
No views yet

colpali-engine==0.3.9.tsystems/vqa_de_en_batch1 dataset.llamaindex/vdr-multilingual-train.openbmb/VisRAG-Ret-Train-Synthetic-data dataset.openbmb/VisRAG-Ret-Train-In-domain-data dataset.vidore/colpali_train_set.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 format1pip install git+https://github.com/illuin-tech/colpali
2pip install transformers==4.49.0
3pip install flash-attn --no-build-isolationMultiVectorEncoder, which
exposes the familiar encode_query / encode_document / similarity API and computes the late interaction
MaxSim scores for you:pip install "sentence-transformers[image]>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("tsystems/colqwen2.5-3b-multilingual-v1.0-merged")
4
5queries = [
6 "What is the variable represented on the y-axis of the graph?",
7 "Total outlay is maximum in which year?",
8]
9documents = [
10 "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc1.jpg",
11 "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc2.jpg",
12 "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc3.jpg",
13 "https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc4.jpg",
14]
15
16query_embeddings = model.encode_query(queries)
17document_embeddings = model.encode_document(documents)
18print(query_embeddings[0].shape, document_embeddings[0].shape)
19# torch.Size([25, 128]) torch.Size([755, 128])
20
21scores = model.similarity(query_embeddings, document_embeddings)
22print(scores)
23# tensor([[14.0508, 8.3906, 9.0303, 8.1934],
24# [ 6.7480, 14.2441, 6.0889, 4.7104]], device='cuda:0')
25print("Best document per query:", scores.argmax(dim=1))
26# Best document per query: tensor([0, 1], device='cuda:0')PIL.Image objects. Text given to encode_document is
embedded as a plain passage, without the query augmentation tokens. The scores above come from the
default bfloat16 load.[!WARNING] Note: currentcolpali-engineno longer sends theQuery:prefix that this checkpoint was trained with.ColQwen2_5_Processorcarried it through 0.3.12 and it was dropped in 0.3.13 (illuin-tech/colpali#339). The Sentence Transformers configuration in this repository reproduces the original training-time format, so its embeddings differ slightly from currentcolpali-engineoutput. To restore the training format on thecolpali-enginepath, setprocessor.query_prefix = "Query: "before callingprocess_queries.
1import torch
2from PIL import Image
3
4from colpali_engine.models import ColQwen2_5, ColQwen2_5_Processor
5
6model = ColQwen2_5.from_pretrained(
7 "tsystems/colqwen2.5-3b-multilingual-v1.0",
8 torch_dtype=torch.bfloat16,
9 device_map="cuda:0", # or "mps" if on Apple Silicon
10 ).eval()
11processor = ColQwen2_5_Processor.from_pretrained("tsystems/colqwen2.5-3b-multilingual-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)apache2.0 license. The adapters attached to the model are under MIT license.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}