Update README.md
Browse files
README.md
CHANGED
@@ -7,10 +7,126 @@ datasets:
|
|
7 |
- vidore/colpali_train_set
|
8 |
language:
|
9 |
- en
|
10 |
-
- fr
|
11 |
base_model:
|
12 |
-
-
|
13 |
---
|
14 |
|
15 |
> [!WARNING]
|
16 |
-
> DEV ONLY:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
- vidore/colpali_train_set
|
8 |
language:
|
9 |
- en
|
|
|
10 |
base_model:
|
11 |
+
- vidore/colpaligemma-3b-pt-448-base
|
12 |
---
|
13 |
|
14 |
> [!WARNING]
|
15 |
+
> DEV ONLY: do not use until the official transformers 🤗 release!
|
16 |
+
>
|
17 |
+
|
18 |
+
# ColPali: Visual Retriever based on PaliGemma-3B with ColBERT strategy
|
19 |
+
|
20 |
+
ColPali 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.
|
21 |
+
It is a [PaliGemma-3B](https://huggingface.co/google/paligemma-3b-mix-448) extension that generates [ColBERT](https://arxiv.org/abs/2004.12832)- style multi-vector representations of text and images.
|
22 |
+
It was introduced in the paper [ColPali: Efficient Document Retrieval with Vision Language Models](https://arxiv.org/abs/2407.01449) and first released in [this repository](https://github.com/ManuelFay/colpali)
|
23 |
+
|
24 |
+
<p align="center"><img width=800 src="https://github.com/illuin-tech/colpali/blob/main/assets/colpali_architecture.webp?raw=true"/></p>
|
25 |
+
|
26 |
+
## Version specificity
|
27 |
+
|
28 |
+
This version is trained with `colpali-engine==0.2.0` but can be loaded for any version `>=0.2.0`.
|
29 |
+
|
30 |
+
Compared to [`vidore/colpali`](https://huggingface.co/vidore/colpali), this version is trained with right padding for queries to fix unwanted tokens in the query encoding.
|
31 |
+
It also stems from the fixed `vidore/colpaligemma-3b-pt-448-base` to guarantee deterministic projection layer initialization.
|
32 |
+
It was trained for 5 epochs, with in-batch negatives and hard mined negatives and a warmup of 1000 steps (10x longer) to help reduce non-english language collapse.
|
33 |
+
|
34 |
+
Data is the same as the ColPali data described in the paper.
|
35 |
+
|
36 |
+
## Model Description
|
37 |
+
|
38 |
+
This model is built iteratively starting from an off-the-shelf [SigLIP](https://huggingface.co/google/siglip-so400m-patch14-384) model.
|
39 |
+
We finetuned it to create [BiSigLIP](https://huggingface.co/vidore/bisiglip) and fed the patch-embeddings output by SigLIP to an LLM, [PaliGemma-3B](https://huggingface.co/google/paligemma-3b-mix-448) to create [BiPali](https://huggingface.co/vidore/bipali).
|
40 |
+
|
41 |
+
One benefit of inputting image patch embeddings through a language model is that they are natively mapped to a latent space similar to textual input (query).
|
42 |
+
This enables leveraging the [ColBERT](https://arxiv.org/abs/2004.12832) strategy to compute interactions between text tokens and image patches, which enables a step-change improvement in performance compared to BiPali.
|
43 |
+
|
44 |
+
## Model Training
|
45 |
+
|
46 |
+
### Dataset
|
47 |
+
Our training dataset of 127,460 query-page pairs is comprised of train sets of openly available academic datasets (63%) and a synthetic dataset made up of pages from web-crawled PDF documents and augmented with VLM-generated (Claude-3 Sonnet) pseudo-questions (37%).
|
48 |
+
Our training set is fully English by design, enabling us to study zero-shot generalization to non-English languages. We explicitly verify no multi-page PDF document is used both [*ViDoRe*](https://huggingface.co/collections/vidore/vidore-benchmark-667173f98e70a1c0fa4db00d) and in the train set to prevent evaluation contamination.
|
49 |
+
A validation set is created with 2% of the samples to tune hyperparameters.
|
50 |
+
|
51 |
+
*Note: Multilingual data is present in the pretraining corpus of the language model (Gemma-2B) and potentially occurs during PaliGemma-3B's multimodal training.*
|
52 |
+
|
53 |
+
### Parameters
|
54 |
+
|
55 |
+
All models are trained for 1 epoch on the train set. Unless specified otherwise, we train models in `bfloat16` format, use low-rank adapters ([LoRA](https://arxiv.org/abs/2106.09685))
|
56 |
+
with `alpha=32` and `r=32` on the transformer layers from the language model,
|
57 |
+
as well as the final randomly initialized projection layer, and use a `paged_adamw_8bit` optimizer.
|
58 |
+
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.
|
59 |
+
|
60 |
+
## Usage
|
61 |
+
|
62 |
+
```python
|
63 |
+
import torch
|
64 |
+
from PIL import Image
|
65 |
+
|
66 |
+
from transformers import ColPali, ColPaliProcessor
|
67 |
+
|
68 |
+
model_name = "vidore/colpali-v1.2-hf"
|
69 |
+
|
70 |
+
model = ColPali.from_pretrained(
|
71 |
+
model_name,
|
72 |
+
torch_dtype=torch.bfloat16,
|
73 |
+
device_map="cuda:0", # or "mps" if on Apple Silicon
|
74 |
+
).eval()
|
75 |
+
|
76 |
+
processor = ColPaliProcessor.from_pretrained(model_name)
|
77 |
+
|
78 |
+
# Your inputs
|
79 |
+
images = [
|
80 |
+
Image.new("RGB", (32, 32), color="white"),
|
81 |
+
Image.new("RGB", (16, 16), color="black"),
|
82 |
+
]
|
83 |
+
queries = [
|
84 |
+
"What is the organizational structure for our R&D department?",
|
85 |
+
"Can you provide a breakdown of last year’s financial performance?",
|
86 |
+
]
|
87 |
+
|
88 |
+
# Process the inputs
|
89 |
+
batch_images = processor(images=images).to(model.device)
|
90 |
+
batch_queries = processor(text=queries).to(model.device)
|
91 |
+
|
92 |
+
# Forward pass
|
93 |
+
with torch.no_grad():
|
94 |
+
image_embeddings = model(**batch_images)
|
95 |
+
query_embeddings = model(**batch_queries)
|
96 |
+
|
97 |
+
scores = processor.score_retrieval(query_embeddings, image_embeddings)
|
98 |
+
```
|
99 |
+
|
100 |
+
## Limitations
|
101 |
+
|
102 |
+
- **Focus**: The model primarily focuses on PDF-type documents and high-ressources languages, potentially limiting its generalization to other document types or less represented languages.
|
103 |
+
- **Support**: The model relies on multi-vector retreiving derived from the ColBERT late interaction mechanism, which may require engineering efforts to adapt to widely used vector retrieval frameworks that lack native multi-vector support.
|
104 |
+
|
105 |
+
## License
|
106 |
+
|
107 |
+
ColPali's vision language backbone model (PaliGemma) is under `gemma` license as specified in its [model card](https://huggingface.co/google/paligemma-3b-mix-448). The adapters attached to the model are under MIT license.
|
108 |
+
|
109 |
+
## Contact
|
110 |
+
|
111 |
+
- Manuel Faysse: [email protected]
|
112 |
+
- Hugues Sibille: [email protected]
|
113 |
+
- Tony Wu: [email protected]
|
114 |
+
|
115 |
+
The HuggingFace transformers 🤗 implementation was contributed by Tony Wu (@tonywu71) and Yoni Gozlan (@yonigozlan).
|
116 |
+
|
117 |
+
|
118 |
+
## Citation
|
119 |
+
|
120 |
+
If you use any datasets or models from this organization in your research, please cite the original dataset as follows:
|
121 |
+
|
122 |
+
```bibtex
|
123 |
+
@misc{faysse2024colpaliefficientdocumentretrieval,
|
124 |
+
title={ColPali: Efficient Document Retrieval with Vision Language Models},
|
125 |
+
author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and Céline Hudelot and Pierre Colombo},
|
126 |
+
year={2024},
|
127 |
+
eprint={2407.01449},
|
128 |
+
archivePrefix={arXiv},
|
129 |
+
primaryClass={cs.IR},
|
130 |
+
url={https://arxiv.org/abs/2407.01449},
|
131 |
+
}
|
132 |
+
```
|