Views
No views yet

colpali-engine==0.3.7.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/colqwen2.5-v0.1")
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 f"https://huggingface.co/datasets/sentence-transformers/example-documents/resolve/main/doc{i}.jpg" for i in range(1, 5)
11]
12
13query_embeddings = model.encode_query(queries)
14document_embeddings = model.encode_document(documents)
15print(f"Query 0 shape: {tuple(query_embeddings[0].shape)}")
16print(f"Document 0 shape: {tuple(document_embeddings[0].shape)}")
17# Query 0 shape: (25, 128)
18# Document 0 shape: (755, 128)
19
20# MaxSim late-interaction scoring (rows = queries, columns = images)
21scores = model.similarity(query_embeddings, document_embeddings)
22print(scores)
23# tensor([[14.3809, 13.6152, 12.5781, 12.1035],
24# [ 6.6104, 13.0527, 6.2793, 6.4658]])[!WARNING] Note:colpali-engine0.3.13 and later no longer send the"Query: "query prefix that this checkpoint was trained with (illuin-tech/colpali#280 dropped it fromColQwen2_5_Processor, and illuin-tech/colpali#339 then changed the base class default it fell back on to""). The Sentence Transformers configuration in this repository reproduces the original training-time format, so its embeddings differ slightly from currentcolpali-engineoutput.
colpali-engine is installed from source or with a version superior to 0.3.1.
transformers version must be > 4.45.0.pip install git+https://github.com/illuin-tech/colpali1import torch
2from PIL import Image
3from transformers.utils.import_utils import is_flash_attn_2_available
4
5from colpali_engine.models import ColQwen2_5, ColQwen2_5_Processor
6
7model = ColQwen2_5.from_pretrained(
8 "vidore/colqwen2.5-v0.1",
9 torch_dtype=torch.bfloat16,
10 device_map="cuda:0", # or "mps" if on Apple Silicon
11 attn_implementation="flash_attention_2" if is_flash_attn_2_available() else None,
12 ).eval()
13processor = ColQwen2_5_Processor.from_pretrained("vidore/colqwen2.5-v0.1")
14
15# Your inputs
16images = [
17 Image.new("RGB", (32, 32), color="white"),
18 Image.new("RGB", (16, 16), color="black"),
19]
20queries = [
21 "Is attention really all you need?",
22 "What is the amount of bananas farmed in Salvador?",
23]
24
25# Process the inputs
26batch_images = processor.process_images(images).to(model.device)
27batch_queries = processor.process_queries(queries).to(model.device)
28
29# Forward pass
30with torch.no_grad():
31 image_embeddings = model(**batch_images)
32 query_embeddings = model(**batch_queries)
33
34scores = processor.score_multi_vector(query_embeddings, image_embeddings)Qwen RESEARCH LICENSE AGREEMENT 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}