Safetensors
English
French
vidore
manu commited on
Commit
f573453
1 Parent(s): 1e993e2

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +138 -0
README.md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language:
4
+ - en
5
+ - fr
6
+ tags:
7
+ - vidore
8
+ ---
9
+ # ColPali: Visual Retriever based on PaliGemma-3B with ColBERT strategy
10
+ ### Idefics2 version
11
+
12
+ ColIdefics 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.
13
+ It is a Idefics2 extension that generates [ColBERT](https://arxiv.org/abs/2004.12832)- style multi-vector representations of text and images.
14
+ 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)
15
+
16
+ ## Model Description
17
+
18
+ This model is built iteratively starting from an off-the-shelf [SigLIP](https://huggingface.co/google/siglip-so400m-patch14-384) model.
19
+ 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).
20
+
21
+ 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).
22
+ 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.
23
+
24
+ ## Model Training
25
+
26
+ ### Dataset
27
+ 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%).
28
+ 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.
29
+ A validation set is created with 2% of the samples to tune hyperparameters.
30
+
31
+ *Note: Multilingual data is present in the pretraining corpus of the language model (Gemma-2B) and potentially occurs during PaliGemma-3B's multimodal training.*
32
+
33
+ ### Parameters
34
+
35
+ 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))
36
+ with `alpha=32` and `r=32` on the transformer layers from the language model,
37
+ as well as the final randomly initialized projection layer, and use a `paged_adamw_8bit` optimizer.
38
+ 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.
39
+
40
+ ## Usage
41
+
42
+ ```python
43
+ import torch
44
+ import typer
45
+ from torch.utils.data import DataLoader
46
+ from tqdm import tqdm
47
+ from transformers import AutoProcessor
48
+ from PIL import Image
49
+
50
+ from colpali_engine.models.paligemma_colbert_architecture import ColPali
51
+ from colpali_engine.trainer.retrieval_evaluator import CustomEvaluator
52
+ from colpali_engine.utils.colpali_processing_utils import process_images, process_queries
53
+ from colpali_engine.utils.image_from_page_utils import load_from_dataset
54
+
55
+
56
+ def main() -> None:
57
+ """Example script to run inference with ColPali"""
58
+
59
+ # Load model
60
+ model_name = "vidore/colpali"
61
+ model = ColPali.from_pretrained("google/paligemma-3b-mix-448", torch_dtype=torch.bfloat16, device_map="cuda").eval()
62
+ model.load_adapter(model_name)
63
+ processor = AutoProcessor.from_pretrained(model_name)
64
+
65
+ # select images -> load_from_pdf(<pdf_path>), load_from_image_urls(["<url_1>"]), load_from_dataset(<path>)
66
+ images = load_from_dataset("vidore/docvqa_test_subsampled")
67
+ queries = ["From which university does James V. Fiorca come ?", "Who is the japanese prime minister?"]
68
+
69
+ # run inference - docs
70
+ dataloader = DataLoader(
71
+ images,
72
+ batch_size=4,
73
+ shuffle=False,
74
+ collate_fn=lambda x: process_images(processor, x),
75
+ )
76
+ ds = []
77
+ for batch_doc in tqdm(dataloader):
78
+ with torch.no_grad():
79
+ batch_doc = {k: v.to(model.device) for k, v in batch_doc.items()}
80
+ embeddings_doc = model(**batch_doc)
81
+ ds.extend(list(torch.unbind(embeddings_doc.to("cpu"))))
82
+
83
+ # run inference - queries
84
+ dataloader = DataLoader(
85
+ queries,
86
+ batch_size=4,
87
+ shuffle=False,
88
+ collate_fn=lambda x: process_queries(processor, x, Image.new("RGB", (448, 448), (255, 255, 255))),
89
+ )
90
+
91
+ qs = []
92
+ for batch_query in dataloader:
93
+ with torch.no_grad():
94
+ batch_query = {k: v.to(model.device) for k, v in batch_query.items()}
95
+ embeddings_query = model(**batch_query)
96
+ qs.extend(list(torch.unbind(embeddings_query.to("cpu"))))
97
+
98
+ # run evaluation
99
+ retriever_evaluator = CustomEvaluator(is_multi_vector=True)
100
+ scores = retriever_evaluator.evaluate(qs, ds)
101
+ print(scores.argmax(axis=1))
102
+
103
+
104
+ if __name__ == "__main__":
105
+ typer.run(main)
106
+
107
+ ```
108
+
109
+ ## Limitations
110
+
111
+ - **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.
112
+ - **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.
113
+
114
+ ## License
115
+
116
+ The base model behing ColIdefics (Idefics2) is under MIT license. The adapters attached to the model are under MIT license.
117
+
118
+ ## Contact
119
+
120
+ - Manuel Faysse: manuel.faysse@illuin.tech
121
+ - Hugues Sibille: hugues.sibille@illuin.tech
122
+ - Tony Wu: tony.wu@illuin.tech
123
+
124
+ ## Citation
125
+
126
+ If you use any datasets or models from this organization in your research, please cite the original dataset as follows:
127
+
128
+ ```bibtex
129
+ @misc{faysse2024colpaliefficientdocumentretrieval,
130
+ title={ColPali: Efficient Document Retrieval with Vision Language Models},
131
+ author={Manuel Faysse and Hugues Sibille and Tony Wu and Bilel Omrani and Gautier Viaud and Céline Hudelot and Pierre Colombo},
132
+ year={2024},
133
+ eprint={2407.01449},
134
+ archivePrefix={arXiv},
135
+ primaryClass={cs.IR},
136
+ url={https://arxiv.org/abs/2407.01449},
137
+ }
138
+ ```