Views
No views yet

[!NOTE] This version is similar tovidore/colpali-v1.3, except that the LoRA adapter was merged into the base model. Thus, loading ColPali from this checkpoint saves you the trouble of merging the pre-trained adapter yourself.This can be useful if you want to train a new adpter from scratch.
bfloat16 format, use low-rank adapters (LoRA)
with alpha=32 and r=32 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 8 GPU setup with data parallelism, a learning rate of 5e-5 with linear decay with 2.5% warmup steps, and a batch size of 32.MultiVectorEncoder:pip install "sentence-transformers[image]>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("vidore/colpali-v1.3-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]
9images = [
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(images)
18print(f"Query 0 shape: {query_embeddings[0].shape}")
19print(f"Document 0 shape: {document_embeddings[0].shape}")
20"""
21Query 0 shape: torch.Size([28, 128])
22Document 0 shape: torch.Size([1030, 128])
23"""
24
25scores = model.similarity(query_embeddings, document_embeddings)
26print(scores)
27"""
28tensor([[22.3359, 19.8555, 19.6582, 19.0928],
29 [ 5.8828, 13.3398, 6.1621, 6.8135]])
30"""[!WARNING] Note: currentcolpali-engineno longer sends the query prefix and trailing newline that this checkpoint was trained with. The trailing newline went in 0.3.11 (illuin-tech/colpali#280) and the prefix 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.The Sentence Transformers configuration also sendstoken_type_idsto the model, which ontransformers5.x is what makes PaliGemma build an explicit attention mask at all. Without it no mask is materialized and the shorter queries in a batch attend to their own padding.
colpali-engine:pip install colpali-engine>=0.3.0,<0.4.01from typing import cast
2
3import torch
4from PIL import Image
5
6from colpali_engine.models import ColPali, ColPaliProcessor
7
8model_name = "vidore/colpali-v1.3-merged"
9
10model = ColPali.from_pretrained(
11 model_name,
12 torch_dtype=torch.bfloat16,
13 device_map="cuda:0", # or "mps" if on Apple Silicon
14).eval()
15processor = ColPaliProcessor.from_pretrained(model_name)
16
17# Your inputs
18images = [
19 Image.new("RGB", (32, 32), color="white"),
20 Image.new("RGB", (16, 16), color="black"),
21]
22queries = [
23 "Is attention really all you need?",
24 "Are Benjamin, Antoine, Merve, and Jo best friends?",
25]
26
27# Process the inputs
28batch_images = processor.process_images(images).to(model.device)
29batch_queries = processor.process_queries(queries).to(model.device)
30
31# Forward pass
32with torch.no_grad():
33 image_embeddings = model(**batch_images)
34 querry_embeddings = model(**batch_queries)
35
36scores = processor.score_multi_vector(querry_embeddings, image_embeddings)gemma license as specified in its model card.
Because the pre-trained adapter got merged in this model, the license for these weights are also under the gemma license1@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}