alanztymarqo commited on
Commit
f24a2b0
·
verified ·
1 Parent(s): 8a6aa5f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +142 -3
README.md CHANGED
@@ -1,3 +1,142 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+ # Marqo E-commerce Embedding Models
5
+ In this work, we introduce two state-of-the-art embedding models for e-commerce:
6
+ Marqo-Ecommerce-B and Marqo-Ecommerce-L.
7
+ They are over 30% better compared to Amazon Titan Embedding services for e-commerce retrieval tasks.
8
+
9
+ **Released Content**:
10
+ 1) Marqo-Ecommerce-B and Marqo-Ecommerce-L embedding models
11
+ 2) GoogleShopping-1m and AmazonProducts-3m for evaluation
12
+ 3) Evaluation Code
13
+
14
+ <img src="performance.png" alt="multi split visual" width="500"/>
15
+
16
+ ## Models
17
+
18
+ | **Embedding Model** | **#Params (m)** | **Dimension** | **HuggingFace** | **Download .pt** |
19
+ |---------------------| --- |---------------|------------------------------------|-------------------------------------------------------------------------------------------------------------|
20
+ | Marqo-Ecommerce-B | 203 | 768 | Marqo/marqo-ecommerce-embeddings-B | [link](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/marqo-general-ecomm/marqo-ecomm-embeddings-b.pt) |
21
+ | Marqo-Ecommerce-L | 652 | 1024 | Marqo/marqo-ecommerce-embeddings-L | [link](https://marqo-gcl-public.s3.us-west-2.amazonaws.com/marqo-general-ecomm/marqo-ecomm-embeddings-l.pt) |
22
+
23
+ ### HuggingFace with OpenCLIP
24
+ ```
25
+ pip install open_clip_torch
26
+ ```
27
+ ```python
28
+ from PIL import Image
29
+ import open_clip
30
+ import requests
31
+ import torch
32
+
33
+ # Specify model from Hugging Face Hub
34
+ model_name = 'hf-hub:Marqo/marqo-ecommerce-embeddings-B'
35
+ model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms(model_name)
36
+ tokenizer = open_clip.get_tokenizer(model_name)
37
+
38
+ # Preprocess the image and tokenize text inputs
39
+ # Load an example image from a URL
40
+ img = Image.open(requests.get('https://raw.githubusercontent.com/marqo-ai/marqo-FashionCLIP/main/docs/fashion-hippo.png', stream=True).raw)
41
+ image = preprocess_val(img).unsqueeze(0)
42
+ text = tokenizer(["a hat", "a t-shirt", "shoes"])
43
+
44
+ # Perform inference
45
+ with torch.no_grad(), torch.cuda.amp.autocast():
46
+ image_features = model.encode_image(image, normalize=True)
47
+ text_features = model.encode_text(text, normalize=True)
48
+
49
+ # Calculate similarity probabilities
50
+ text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
51
+
52
+ # Display the label probabilities
53
+ print("Label probs:", text_probs)
54
+ # [9.9955e-01, 4.4712e-04, 4.4010e-06]]
55
+ ```
56
+ ### HuggingFace with transformers
57
+ ```python
58
+ from transformers import AutoModel, AutoProcessor
59
+ import torch
60
+ from PIL import Image
61
+ import requests
62
+ # model_name= 'Marqo/marqo-ecommerce-embeddings-L'
63
+ model_name = 'Marqo/marqo-ecommerce-embeddings-B'
64
+
65
+ model_1 = AutoModel.from_pretrained(model_name, trust_remote_code=True)
66
+ processor_1 = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
67
+
68
+ img = Image.open(requests.get('https://raw.githubusercontent.com/marqo-ai/marqo-FashionCLIP/main/docs/fashion-hippo.png', stream=True).raw).convert("RGB")
69
+ image_1 = [img]
70
+ text_1 = ["a hat", "a t-shirt", "shoes"]
71
+ processed_1 = processor_1(text=text_1, images=image_1, padding='max_length', return_tensors="pt")
72
+ processor_1.image_processor.do_rescale = False
73
+ with torch.no_grad():
74
+ image_features_1 = model_1.get_image_features(processed_1['pixel_values'], normalize=True)
75
+ text_features_1 = model_1.get_text_features(processed_1['input_ids'], normalize=True)
76
+
77
+ text_probs_1 = (100 * image_features_1 @ text_features_1.T).softmax(dim=-1)
78
+
79
+ print(text_probs_1)
80
+ # [9.9955e-01, 4.4712e-04, 4.4010e-06]]
81
+ ```
82
+
83
+ ### Evaluation with GCL
84
+ ```
85
+ git clone https://github.com/marqo-ai/GCL
86
+ ```
87
+ Install the packages required by GCL.
88
+ ```
89
+ cd ./GCL
90
+ MODEL=hf-hub:Marqo/marqo-ecommerce-B
91
+ outdir=/MarqoModels/GE/marqo-ecommerce-B/gs-title2image2
92
+ hfdataset=Marqo/google-shopping-general-eval
93
+ python evals/eval_hf_datasets_v1.py \
94
+ --model_name $MODEL \
95
+ --hf-dataset $hfdataset \
96
+ --output-dir $outdir \
97
+ --batch-size 1024 \
98
+ --num_workers 8 \
99
+ --left-key "['title']" \
100
+ --right-key "['image']" \
101
+ --img-or-txt "[['txt'], ['img']]" \
102
+ --left-weight "[1]" \
103
+ --right-weight "[1]" \
104
+ --run-queries-cpu \
105
+ --top-q 4000 \
106
+ --doc-id-key item_ID \
107
+ --context-length "[[64], [0]]"
108
+ ```
109
+
110
+
111
+ ## Detailed Performance
112
+ **GoogleShopping-Text2Image Retrieval.**
113
+
114
+ | **Embedding Model** | **mAP** | **P@10** | **R@10** | **MRR** |
115
+ | --- | --- | --- | --- | --- |
116
+ | Marqo-Ecommerce-L | **0.682** | **0.089** | **0.878** | **0.683** |
117
+ | Marqo-Ecommerce-B | 0.623 | 0.084 | 0.832 | 0.624 |
118
+ | Amazon-Titan-MultiModal | 0.475 | 0.065 | 0.648 | 0.475 |
119
+ | ViT-B-16-SigLip | 0.476 | 0.067 | 0.660 | 0.477 |
120
+ | ViT-L-16-SigLip | 0.540 | 0.073 | 0.722 | 0.540 |
121
+
122
+
123
+ **GoogleShopping-Category2Image Retrieval.**
124
+
125
+ | **Embedding Model** | **mAP** | **P@10** | **MRR** | **nDCG@10** |
126
+ | --- | --- | --- | --- | --- |
127
+ | Marqo-Ecommerce-L | **0.463** | **0.652** | **0.822** | **0.666** |
128
+ | Marqo-Ecommerce-B | 0.423 | 0.629 | 0.810 | 0.644 |
129
+ | Amazon-Titan-MultiModal | 0.246 | 0.429 | 0.642 | 0.446 |
130
+ | ViT-B-16-SigLip | 0.277 | 0.458 | 0.660 | 0.473 |
131
+ | ViT-L-16-SigLip | 0.324 | 0.497 | 0.687 | 0.509 |
132
+
133
+ **AmazonProducts-Text2Image Retrieval.**
134
+
135
+ | **Embedding Model** | **mAP** | **P@10** | **R@10** | **MRR** |
136
+ | --- | --- | --- | --- | --- |
137
+ | Marqo-Ecommerce-L | **0.658** | **0.096** | **0.854** | **0.663** |
138
+ | Marqo-Ecommerce-B | 0.592 | 0.089 | 0.795 | 0.597 |
139
+ | Amazon-Titan-MultiModal | 0.456 | 0.064 | 0.627 | 0.457 |
140
+ | ViT-B-16-SigLip | 0.480 | 0.070 | 0.650 | 0.484 |
141
+ | ViT-L-16-SigLip | 0.544 | 0.077 | 0.715 | 0.548 |
142
+