tattrongvu
commited on
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
datasets:
|
4 |
+
- tattrongvu/vqa_de_en_batch1
|
5 |
+
- vidore/colpali_train_set
|
6 |
+
- tattrongvu/sharegpt4v_vqa_200k_batch1
|
7 |
+
language:
|
8 |
+
- en
|
9 |
+
- de
|
10 |
+
base_model:
|
11 |
+
- Qwen/Qwen2-VL-7B-Instruct
|
12 |
+
tags:
|
13 |
+
- vidore
|
14 |
+
- multimodal-embedding
|
15 |
+
library_name: peft
|
16 |
+
---
|
17 |
+
# ColQwen2-7B: Visual Retriever based on Qwen2-VL-7B-Instruct with ColBERT strategy
|
18 |
+
|
19 |
+
### This is the base version trained with batch_size 8x64 for 5 epoch and with the updated pad token
|
20 |
+
|
21 |
+
ColQwen 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.
|
22 |
+
It is a [Qwen2-VL-2B](https://huggingface.co/Qwen/Qwen2-VL-2B-Instruct) extension that generates [ColBERT](https://arxiv.org/abs/2004.12832)- style multi-vector representations of text and images.
|
23 |
+
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)
|
24 |
+
|
25 |
+
This version is the untrained base version to guarantee deterministic projection layer initialization.
|
26 |
+
<p align="center"><img width=800 src="https://github.com/illuin-tech/colpali/blob/main/assets/colpali_architecture.webp?raw=true"/></p>
|
27 |
+
|
28 |
+
## Version specificity
|
29 |
+
|
30 |
+
|
31 |
+
This model takes dynamic image resolutions in input and does not resize them, changing their aspect ratio as in ColPali.
|
32 |
+
Maximal resolution is set so that 768 image patches are created at most. Experiments show clear improvements with larger amounts of image patches, at the cost of memory requirements.
|
33 |
+
|
34 |
+
This version is trained with `colpali-engine==0.3.4`.
|
35 |
+
|
36 |
+
Data is the same as the ColPali data described in the paper.
|
37 |
+
|
38 |
+
|
39 |
+
## Model Training
|
40 |
+
|
41 |
+
### Dataset
|
42 |
+
The dataset was extended from the original colpali train set with the gemini 1.5 flash generated QA on 35k images scraped from internet.
|
43 |
+
|
44 |
+
*Note: Multilingual data is present in the pretraining corpus of the language model and most probably in the multimodal training.*
|
45 |
+
|
46 |
+
### Parameters
|
47 |
+
We train models use low-rank adapters ([LoRA](https://arxiv.org/abs/2106.09685))
|
48 |
+
with `alpha=64` and `r=64` on the transformer layers from the language model,
|
49 |
+
as well as the final randomly initialized projection layer, and use a `paged_adamw_8bit` optimizer.
|
50 |
+
We train on an 8xH100 GPU setup with distributed data parallelism (via accelerate), a learning rate of 2e-4 with linear decay with 1% warmup steps, batch size per device is 64, in `bfloat16` format
|
51 |
+
|
52 |
+
## Usage
|
53 |
+
|
54 |
+
Make sure `colpali-engine` is installed from source or with a version superior to 0.3.4.
|
55 |
+
`transformers` version must be > 4.46.1.
|
56 |
+
|
57 |
+
```bash
|
58 |
+
pip install git+https://github.com/illuin-tech/colpali
|
59 |
+
```
|
60 |
+
|
61 |
+
```python
|
62 |
+
import torch
|
63 |
+
from PIL import Image
|
64 |
+
|
65 |
+
from colpali_engine.models import ColQwen2, ColQwen2Processor
|
66 |
+
|
67 |
+
model = ColQwen2.from_pretrained(
|
68 |
+
"tsystems/colqwen2-7b-v1.0",
|
69 |
+
torch_dtype=torch.bfloat16,
|
70 |
+
device_map="cuda:0", # or "mps" if on Apple Silicon
|
71 |
+
).eval()
|
72 |
+
processor = ColQwen2Processor.from_pretrained("tsystems/colqwen2-7b-v1.0")
|
73 |
+
|
74 |
+
# Your inputs
|
75 |
+
images = [
|
76 |
+
Image.new("RGB", (32, 32), color="white"),
|
77 |
+
Image.new("RGB", (16, 16), color="black"),
|
78 |
+
]
|
79 |
+
queries = [
|
80 |
+
"Is attention really all you need?",
|
81 |
+
"What is the amount of bananas farmed in Salvador?",
|
82 |
+
]
|
83 |
+
|
84 |
+
# Process the inputs
|
85 |
+
batch_images = processor.process_images(images).to(model.device)
|
86 |
+
batch_queries = processor.process_queries(queries).to(model.device)
|
87 |
+
|
88 |
+
# Forward pass
|
89 |
+
with torch.no_grad():
|
90 |
+
image_embeddings = model(**batch_images)
|
91 |
+
query_embeddings = model(**batch_queries)
|
92 |
+
|
93 |
+
scores = processor.score_multi_vector(query_embeddings, image_embeddings)
|
94 |
+
```
|
95 |
+
|
96 |
+
|
97 |
+
## Limitations
|
98 |
+
|
99 |
+
- **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.
|
100 |
+
- **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.
|
101 |
+
|
102 |
+
## License
|
103 |
+
|
104 |
+
ColQwen2's vision language backbone model (Qwen2-VL) is under `apache2.0` license. The adapters attached to the model are under MIT license.
|