Datasets:

Modalities:
Image
Text
Formats:
parquet
Languages:
English
ArXiv:
Libraries:
Datasets
Dask
License:
elliesleightholm commited on
Commit
4944158
1 Parent(s): f9aa3cb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +303 -36
README.md CHANGED
@@ -1,36 +1,303 @@
1
- ---
2
- license: apache-2.0
3
- dataset_info:
4
- features:
5
- - name: image
6
- dtype: image
7
- - name: query
8
- dtype: string
9
- - name: product_id
10
- dtype: string
11
- - name: position
12
- dtype: int64
13
- - name: title
14
- dtype: string
15
- - name: pair_id
16
- dtype: string
17
- - name: score_linear
18
- dtype: int64
19
- - name: score_reciprocal
20
- dtype: float64
21
- - name: no_score
22
- dtype: int64
23
- - name: query_id
24
- dtype: string
25
- configs:
26
- - config_name: default
27
- data_files:
28
- - split: in_domain
29
- path: data/in_domain-*
30
- - split: novel_document
31
- path: data/novel_document-*
32
- - split: novel_query
33
- path: data/novel_query-*
34
- - split: zero_shot
35
- path: data/zero_shot-*
36
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ libraries:
4
+ - datasets
5
+ dataset_info:
6
+ features:
7
+ - name: image
8
+ dtype: image
9
+ - name: query
10
+ dtype: string
11
+ - name: product_id
12
+ dtype: string
13
+ - name: position
14
+ dtype: int64
15
+ - name: title
16
+ dtype: string
17
+ - name: pair_id
18
+ dtype: string
19
+ - name: score_linear
20
+ dtype: int64
21
+ - name: score_reciprocal
22
+ dtype: float64
23
+ - name: no_score
24
+ dtype: int64
25
+ - name: query_id
26
+ dtype: string
27
+ configs:
28
+ - config_name: default
29
+ data_files:
30
+ - split: in_domain
31
+ path: data/in_domain-*
32
+ - split: novel_document
33
+ path: data/novel_document-*
34
+ - split: novel_query
35
+ path: data/novel_query-*
36
+ - split: zero_shot
37
+ path: data/zero_shot-*
38
+ ---
39
+
40
+
41
+ # Marqo-GS-10M
42
+ This dataset is our multimodal, fine-grained, ranking dataset, **Marqo-GS-10M** followed by our novel training framework: Generalized Contrastive Learning (GCL).
43
+
44
+ Blog post: https://www.marqo.ai/blog/generalized-contrastive-learning-for-multi-modal-retrieval-and-ranking
45
+
46
+ Paper: https://arxiv.org/pdf/2404.08535.pdf
47
+
48
+ GitHub: https://github.com/marqo-ai/GCL
49
+
50
+ This work aims to improve and measure the **ranking** performance of information retrieval models,
51
+ especially for retrieving relevant **products** given a search query.
52
+
53
+ **Release WIP**: GCL Training Framework.
54
+ ## Table of Content
55
+ 1. Motivation
56
+ 2. Dataset and Benchmarks
57
+ 3. Instructions to evaluate with the GCL Benchmarks
58
+ 4. GCL Training Framwork and Models
59
+ 5. Example Usage of Models
60
+
61
+
62
+ ## 1. Motivation
63
+ Contrastive learning has gained widespread adoption for retrieval tasks due to its minimal requirement for manual annotations. However, popular contrastive frameworks typically learn from binary relevance, making them ineffective at incorporating direct fine-grained rankings.
64
+
65
+ In this paper, we curate a large-scale dataset: Marqo-GS-10M, featuring detailed relevance scores for each query-document pair to facilitate future research and evaluation.
66
+
67
+ Subsequently, we propose Generalized Contrastive Learning for Multi-Modal Retrieval and Ranking (GCL), which is designed to learn from fine-grained rankings beyond binary relevance score.
68
+
69
+ Our results show that GCL achieves a **94.5%** increase in NDCG@10 for in-domain and **26.3** to **48.8%** increases for cold-start evaluations, measured **relative** to the CLIP baseline within our curated ranked dataset.
70
+
71
+
72
+ ## 2. Dataset and Benchmarks
73
+
74
+ ### Dataset Structure
75
+ <img src="https://raw.githubusercontent.com/marqo-ai/GCL/main/assets/ms1.png" alt="multi split visual" width="500"/>
76
+
77
+ Illustration of multi-dimensional split along both query and document dimensions resulting in 4 splits:
78
+ training split with 80\% of queries and 50\% of documents, novel query splitwith the other 20\% of queries and the same documents as the training split,
79
+ novel corpus split with the same queries as the training split and unseen documents with the equal size of the training corpus,
80
+ and zero-shot split with unseen queries and documents.
81
+
82
+ ### Dataset Structure
83
+ In this section, we show the dataset structure.
84
+ ```
85
+ marqo-gs-dataset/
86
+ ├── marqo_gs_full_10m/
87
+ │ ├── corpus_1.json
88
+ │ ├── corpus_2.json
89
+ │ ├── query_0_product_id_0.csv
90
+ │ ├── query_0_product_id_0_gt_dev.json
91
+ │ ├── query_0_product_id_0_gt_test.json
92
+ │ ├── query_0_product_id_0_queries.json
93
+ │ ├── query_0_product_id_1.csv
94
+ │ ├── query_0_product_id_1_gt_dev.json
95
+ │ ├── query_0_product_id_1_gt_test.json
96
+ │ ├── query_0_product_id_1_queries.json
97
+ │ ├── query_1_product_id_0.csv
98
+ │ ├── query_1_product_id_0_gt_dev.json
99
+ │ ├── query_1_product_id_0_gt_test.json
100
+ │ ├── query_1_product_id_0_queries.json
101
+ │ ├── query_1_product_id_1.csv
102
+ │ ├── query_1_product_id_1_gt_dev.json
103
+ │ ├── query_1_product_id_1_gt_test.json
104
+ │ └── query_1_product_id_1_queries.json
105
+ ├── marqo_gs_fashion_5m/
106
+ ├── marqo_gs_wfash_1m/
107
+ ```
108
+ For each dataset such as marqo_gs_full_10m, there are 4 splits as discussed before.
109
+ - query_0_product_id_0 represents in-domain set,
110
+ - query_1_product_id_0 represents novel query set,
111
+ - query_0_product_id_1 represents novel document set,
112
+ - query_1_product_id_1 represents zero shot set,
113
+ For each split, there is a ground truth csv containing triplet information,
114
+ a set of validation ground truth and a set of test ground truth.
115
+
116
+
117
+ ### Dataset Downloads
118
+ The Marqo-GS-10M dataset is available for direct download. This dataset is pivotal for training and benchmarking in Generalized Contrastive Learning (GCL) frameworks and other multi-modal fine-grained ranking tasks.
119
+
120
+ - **Full Dataset**: [Download](https://marqo-gcl-public.s3.amazonaws.com/v1/marqo-gs-dataset.tar) - Link contains the entire Marqo-GS-10M dataset except for the images.
121
+ - **Full Images**: [Download](https://marqo-gcl-public.s3.amazonaws.com/v1/images_archive.tar) - Link contains the images of the entire Marqo-GS-10M dataset.
122
+ - **Sample Images**: [Download](https://marqo-gcl-public.s3.amazonaws.com/v1/images_wfash.tar) - Link contains the images for woman fashion category, it corresponds to the woman fashion sub-dataset.
123
+
124
+ ### Dataset Visualization
125
+ Visualization of the collected triplet dataset containing search queries (top row),
126
+ documents and scores, showcasing thumbnails of returned products with scores that decrease linearly according to their positions.
127
+ ![Dataset Qualitative](https://raw.githubusercontent.com/marqo-ai/GCL/main/assets/visual_dataset_4.png)
128
+
129
+
130
+ ## 3. Instructions to use the GCL Benchmarks
131
+ ### Install environment
132
+ ```bash
133
+ conda create -n gcl python=3.8
134
+ conda activate gcl
135
+ conda install pytorch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 pytorch-cuda=11.7 -c pytorch -c nvidia
136
+ pip install jupyterlab pandas matplotlib beir pytrec_eval braceexpand webdataset wandb notebook open_clip_torch
137
+ pip install --force-reinstall numpy==1.23.2
138
+ ```
139
+ ### Evaluate using GCL benchmarks
140
+ 1. Download the Dataset, links above. We recommend try out the Sample set first.
141
+ 2. Either prepare your own model or download our finetuned model down below.
142
+ 3. Modify [eval-vitb32-ckpt.sh](./scripts/eval-vitb32-ckpt.sh) to add image dir, eval dir and model path.
143
+ 4. Use [change_image_paths.py](./evals/change_image_paths.py) to modify image paths in the csv.
144
+
145
+ ```bash
146
+ python change_image_paths.py /dataset/csv/dir/path /image/root/path
147
+ # Example:
148
+ python change_image_paths.py /data/marqo-gs-dataset/marqo_gs_wfash_1m /data/marqo-gs-dataset/images_wfash
149
+
150
+ ```
151
+ 5. Run the eval script:
152
+ ```bash
153
+ bash ./scripts/eval-vitb32-ckpt.sh
154
+ ```
155
+
156
+
157
+ ## 4. GCL Training Framework and Models
158
+ ![Main Figure](https://raw.githubusercontent.com/marqo-ai/GCL/main/assets/main_figure1.png)
159
+ Overview of our Generalized Contrastive Learning (GCL) approach.
160
+ GCL integrates ranking information alongside multiple input fields for each sample (e.g., title and image)
161
+ across both left-hand-side (LHS) and right-hand-side (RHS).
162
+ Ground-truth ranking scores are transformed into weights,
163
+ which are used for computing contrastive losses, ensuring that pairs with higher weights incur greater penalties.
164
+ Please refer to the paper for full explanation.
165
+
166
+
167
+ ### Results and Model Downloads
168
+
169
+ Retrieval and ranking performance comparison of GCL versus publicly available contrastive learning methods assessed by NDCG@10, ERR, and RBP metrics on the GSFull-10M dataset for the **In-Domain** category. The methods are based on multi-modal approaches:
170
+
171
+ ### Multi-Field/Text-Image
172
+ | Methods | Models | Size | nDCG | ERR | RBP | Downloads |
173
+ |---------------|----------|-------|------------|-----------|-----------|--------------------------------------------------------------------------------------------------------|
174
+ | CLIP | ViT-L-14 | 1.6G | 0.310 | 0.093 | 0.252 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/clip-vitl14-110-gs-full-states.pt) |
175
+ | GCL (ours) | ViT-B-32 | 577M | 0.577 | 0.554 | 0.446 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/gcl-vitb32-117-gs-full-states.pt) |
176
+ | GCL (ours) | ViT-L-14 | 1.6G | 0.603 | 0.562 | 0.467 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/gcl-vitl14-120-gs-full-states.pt) |
177
+ | GCL (ours) | ViT-B-32 | 577M | 0.683 | 0.689 | 0.515 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/marqo-gcl-vitb32-127-gs-full_states.pt) |
178
+ | GCL (ours) | ViT-L-14 | 1.6G | **0.690** | **0.630** | **0.535** | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/marqo-gcl-vitl14-124-gs-full_states.pt) |
179
+
180
+ ### Text-only
181
+ | Methods | Models | nDCG | ERR | RBP | Downloads |
182
+ |---------------|----------------------------|-----------|------------|-----------|---------------------------------------------------------------------------------------------------|
183
+ | BM25 | - | 0.071 | 0.028 | 0.052 | |
184
+ | E5 | e5-large-v2 | 0.335 | 0.095 | 0.289 | |
185
+ | Cross Entropy | xlm-roberta-base-ViT-B-32 | 0.332 | 0.099 | 0.288 | |
186
+ | GCL (ours) | e5-large-v2 | 0.431 | 0.400 | 0.347 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/gcl-e5l-113-gs-full-states.pt) |
187
+ | GCL (ours) | xlm-roberta-base-ViT-B-32 | 0.441 | 0.404 | 0.355 | [model](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/gcl-robbxlm-105-gs-full-states.pt) |
188
+ | E5 | e5-large-v2 | **0.470** | **0.457** | **0.374** | Marqo/marqo-gcl-e5-large-v2-130 |
189
+
190
+ ## 5. Example Usage of Models
191
+ ### Quick Demo with OpenCLIP
192
+ Here is a quick example to use our model if you have installed open_clip_torch.
193
+ ```bash
194
+ python demos/openclip_demo.py
195
+ ```
196
+ or
197
+ ```python
198
+ import torch
199
+ from PIL import Image
200
+ import open_clip
201
+ import wget
202
+
203
+ model_url = "https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/gcl-vitb32-117-gs-full-states.pt"
204
+ wget.download(model_url, "gcl-vitb32-117-gs-full-states.pt")
205
+ model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='gcl-vitb32-117-gs-full-states.pt')
206
+ tokenizer = open_clip.get_tokenizer('ViT-B-32')
207
+
208
+ image = preprocess(Image.open('https://raw.githubusercontent.com/marqo-ai/GCL/main/assets/oxford_shoe.png')).unsqueeze(0)
209
+ text = tokenizer(["a dog", "Vintage Style Women's Oxfords", "a cat"])
210
+ logit_scale = 10
211
+ with torch.no_grad(), torch.cuda.amp.autocast():
212
+ image_features = model.encode_image(image)
213
+ text_features = model.encode_text(text)
214
+ image_features /= image_features.norm(dim=-1, keepdim=True)
215
+ text_features /= text_features.norm(dim=-1, keepdim=True)
216
+
217
+ text_probs = (logit_scale * image_features @ text_features.T).softmax(dim=-1)
218
+
219
+ print("Label probs:", text_probs)
220
+ ```
221
+ ### Quick Demo with Hugging Face for E5 models.
222
+ Here is a quick example to load our finetuned e5 text models from hugging face directly.
223
+ ```python
224
+ import torch.nn.functional as F
225
+
226
+ from torch import Tensor
227
+ from transformers import AutoTokenizer, AutoModel
228
+
229
+
230
+ def average_pool(last_hidden_states: Tensor,
231
+ attention_mask: Tensor) -> Tensor:
232
+ last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
233
+ return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
234
+
235
+
236
+ # Each input text should start with "query: " or "passage: ".
237
+ # For tasks other than retrieval, you can simply use the "query: " prefix.
238
+ input_texts = ['query: Espresso Pitcher with Handle',
239
+ 'query: Women’s designer handbag sale',
240
+ "passage: Dianoo Espresso Steaming Pitcher, Espresso Milk Frothing Pitcher Stainless Steel",
241
+ "passage: Coach Outlet Eliza Shoulder Bag - Black - One Size"]
242
+
243
+ tokenizer = AutoTokenizer.from_pretrained('Marqo/marqo-gcl-e5-large-v2-130')
244
+ model_new = AutoModel.from_pretrained('Marqo/marqo-gcl-e5-large-v2-130')
245
+
246
+ # Tokenize the input texts
247
+ batch_dict = tokenizer(input_texts, max_length=77, padding=True, truncation=True, return_tensors='pt')
248
+
249
+ outputs = model_new(**batch_dict)
250
+ embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
251
+
252
+ # normalize embeddings
253
+ embeddings = F.normalize(embeddings, p=2, dim=1)
254
+ scores = (embeddings[:2] @ embeddings[2:].T) * 100
255
+ print(scores.tolist())
256
+ ```
257
+ <!---
258
+ ### Using VITB32/VITL14/E5 with **marqo** vector search.
259
+ Using model download url for VIT models
260
+ ```python
261
+ import marqo
262
+ # create an index with your custom model
263
+ mq = marqo.Client(url='http://localhost:8882')
264
+ settings = {
265
+ "treatUrlsAndPointersAsImages": True,
266
+ "model": "generic-clip-test-model-1",
267
+ "modelProperties": {
268
+ "name": "ViT-B-32",
269
+ "dimensions": 512,
270
+ "url": "https://marqo-gcl-public.s3.us-west-2.amazonaws.com/v1/marqo-gcl-vitb32-127-gs-full_states.pt",
271
+ "type": "open_clip",
272
+ },
273
+ "normalizeEmbeddings": True,
274
+ }
275
+
276
+ response = mq.create_index("my-own-clip", settings_dict=settings)
277
+ ```
278
+ Using Hugging Face for our finetuned E5 models
279
+ ```python
280
+ import marqo
281
+ # create an index with your custom model
282
+ mq = marqo.Client(url='http://localhost:8882')
283
+ model_properties = {
284
+ "name": "Marqo/marqo-gcl-e5-large-v2-130",
285
+ "dimensions": 1024,
286
+ "type": "hf"
287
+ }
288
+
289
+ mq.create_index("test_e5", model="my_custom_e5", model_properties=model_properties)
290
+ ```
291
+ -->
292
+
293
+ ## Citation
294
+ ```
295
+ @misc{zhu2024generalized,
296
+ title={Generalized Contrastive Learning for Multi-Modal Retrieval and Ranking},
297
+ author={Tianyu Zhu and Myong Chol Jung and Jesse Clark},
298
+ year={2024},
299
+ eprint={2404.08535},
300
+ archivePrefix={arXiv},
301
+ primaryClass={cs.IR}
302
+ }
303
+ ```