Views
No views yet

[!NOTE] This version is similar tovidore/colqwen2-v0.1, except that the LoRA adapter was merged into the base model. Thus, loading ColQwen2 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 adapter 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, exposing the familiar encode_query / encode_document / similarity API.pip install "sentence-transformers[image]>=6.0.0"1from sentence_transformers import MultiVectorEncoder
2
3model = MultiVectorEncoder("vidore/colqwen2-v0.1-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: {tuple(query_embeddings[0].shape)}")
19print(f"Document 0 shape: {tuple(document_embeddings[0].shape)}")
20# Query 0 shape: (25, 128)
21# Document 0 shape: (4115, 128)
22
23scores = model.similarity(query_embeddings, document_embeddings)
24print(scores)
25# tensor([[15.6562, 13.0996, 9.3330, 7.7490],
26# [ 7.3848, 15.4883, 6.3789, 6.8916]])[!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 fromColQwen2Processor, 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, ColQwen2Processor
6
7model = ColQwen2.from_pretrained(
8 "vidore/colqwen2-v0.1-merged",
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, # or "eager" if "mps"
12).eval()
13processor = ColQwen2Processor.from_pretrained("vidore/colqwen2-v0.1-merged")
14
15# Your inputs
16images = [
17 Image.new("RGB", (128, 128), color="white"),
18 Image.new("RGB", (64, 32), 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)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}