ashvardanian
commited on
Commit
•
eae7164
1
Parent(s):
1894a0d
Upload folder using huggingface_hub
Browse files- README.md +208 -0
- config.json +42 -0
- image_encoder.mlpackage/Data/com.apple.CoreML/model.mlmodel +3 -0
- image_encoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin +3 -0
- image_encoder.mlpackage/Manifest.json +18 -0
- image_encoder.onnx +3 -0
- image_encoder.pt +3 -0
- image_encoder.safetensors +3 -0
- text_encoder.mlpackage/Data/com.apple.CoreML/model.mlmodel +3 -0
- text_encoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin +3 -0
- text_encoder.mlpackage/Manifest.json +18 -0
- text_encoder.onnx +3 -0
- text_encoder.pt +3 -0
- text_encoder.safetensors +3 -0
- tokenizer.json +0 -0
README.md
ADDED
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
- ar
|
6 |
+
- hy
|
7 |
+
- zh
|
8 |
+
- fr
|
9 |
+
- de
|
10 |
+
- he
|
11 |
+
- hi
|
12 |
+
- id
|
13 |
+
- it
|
14 |
+
- ja
|
15 |
+
- ko
|
16 |
+
- fa
|
17 |
+
- pl
|
18 |
+
- pt
|
19 |
+
- ru
|
20 |
+
- es
|
21 |
+
- th
|
22 |
+
- tr
|
23 |
+
- uk
|
24 |
+
- vi
|
25 |
+
pipeline_tag: feature-extraction
|
26 |
+
tags:
|
27 |
+
- clip
|
28 |
+
- vision
|
29 |
+
datasets:
|
30 |
+
- sbu_captions
|
31 |
+
- visual_genome
|
32 |
+
- ChristophSchuhmann/MS_COCO_2017_URL_TEXT
|
33 |
+
---
|
34 |
+
|
35 |
+
<h1 align="center">UForm</h1>
|
36 |
+
<h3 align="center">
|
37 |
+
Multi-Modal Inference Library<br/>
|
38 |
+
For Semantic Search Applications<br/>
|
39 |
+
</h3>
|
40 |
+
|
41 |
+
---
|
42 |
+
|
43 |
+
UForm is a Multi-Modal Modal Inference package, designed to encode Multi-Lingual Texts, Images, and, soon, Audio, Video, and Documents, into a shared vector space!
|
44 |
+
|
45 |
+
This is model card of the __Multilingual model__ (21 languages) with:
|
46 |
+
|
47 |
+
* 12 layers BERT (8 layers for unimodal encoding and rest layers for multimodal encoding)
|
48 |
+
* ViT-B/16 (image resolution is 224x224)
|
49 |
+
|
50 |
+
The model was trained on balanced multilingual dataset.
|
51 |
+
|
52 |
+
If you need English model, check [this](https://huggingface.co/unum-cloud/uform-vl-english).
|
53 |
+
|
54 |
+
## Evaluation
|
55 |
+
|
56 |
+
For all evaluations, the multimodal part was used unless otherwise stated.
|
57 |
+
|
58 |
+
**Monolingual**
|
59 |
+
|
60 |
+
| Dataset | Recall@1 | Recall@5 | Recall@10 |
|
61 |
+
| :-------- | ------: | --------: | --------: |
|
62 |
+
| Zero-Shot Flickr | 0.558 | 0.813 | 0.874 |
|
63 |
+
| MS-COCO (train split was in training data) | 0.401 | 0.680 | 0.781 |
|
64 |
+
|
65 |
+
**Multilingual**
|
66 |
+
|
67 |
+
[XTD-10](https://github.com/adobe-research/Cross-lingual-Test-Dataset-XTD10)
|
68 |
+
|
69 |
+
Metric is recall@10
|
70 |
+
|
71 |
+
|
72 |
+
| English | German | Spanish | French | Italian | Russian | Japanese | Korean | Turkish | Chinese | Polish |
|
73 |
+
| -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | ------:|
|
74 |
+
| 96.1 | 93.5 | 95.7 | 94.1 | 94.4 | 90.4 | 90.2 | 91.3 | 95.2 | 93.8 | 95.8 |
|
75 |
+
|
76 |
+
|
77 |
+
[COCO-SM](https://github.com/kimihailv/coco-sm/tree/main)
|
78 |
+
|
79 |
+
For this evaluation only unimodal part was used.
|
80 |
+
|
81 |
+
Recall
|
82 |
+
|
83 |
+
| Target Language | OpenCLIP @ 1 | UForm @ 1 | OpenCLIP @ 5 | UForm @ 5 | OpenCLIP @ 10 | UForm @ 10 | Speakers |
|
84 |
+
| :-------------------- | -----------: | ------------: | -----------: | -------------:| ------------: | --------------:| -------: |
|
85 |
+
| Arabic | 22.7 | **31.7** | 44.9 | **57.8** | 55.8 | **69.2** | 274 M |
|
86 |
+
| Armenian | 5.6 | **22.0** | 14.3 | **44.7** | 20.2 | **56.0** | 4 M |
|
87 |
+
| Chinese | 27.3 | **32.2** | 51.3 | **59.0** | 62.1 | **70.5** | 1'118 M |
|
88 |
+
| English | **37.8** | 37.7 | 63.5 | **65.0** | 73.5 | **75.9** | 1'452 M |
|
89 |
+
| French | 31.3 | **35.4** | 56.5 | **62.6** | 67.4 | **73.3** | 274 M |
|
90 |
+
| German | 31.7 | **35.1** | 56.9 | **62.2** | 67.4 | **73.3** | 134 M |
|
91 |
+
| Hebrew | 23.7 | **26.7** | 46.3 | **51.8** | 57.0 | **63.5** | 9 M |
|
92 |
+
| Hindi | 20.7 | **31.3** | 42.5 | **57.9** | 53.7 | **69.6** | 602 M |
|
93 |
+
| Indonesian | 26.9 | **30.7** | 51.4 | **57.0** | 62.7 | **68.6** | 199 M |
|
94 |
+
| Italian | 31.3 | **34.9** | 56.7 | **62.1** | 67.1 | **73.1** | 67 M |
|
95 |
+
| Japanese | 27.4 | **32.6** | 51.5 | **59.2** | 62.6 | **70.6** | 125 M |
|
96 |
+
| Korean | 24.4 | **31.5** | 48.1 | **57.8** | 59.2 | **69.2** | 81 M |
|
97 |
+
| Persian | 24.0 | **28.8** | 47.0 | **54.6** | 57.8 | **66.2** | 77 M |
|
98 |
+
| Polish | 29.2 | **33.6** | 53.9 | **60.1** | 64.7 | **71.3** | 41 M |
|
99 |
+
| Portuguese | 31.6 | **32.7** | 57.1 | **59.6** | 67.9 | **71.0** | 257 M |
|
100 |
+
| Russian | 29.9 | **33.9** | 54.8 | **60.9** | 65.8 | **72.0** | 258 M |
|
101 |
+
| Spanish | 32.6 | **35.6** | 58.0 | **62.8** | 68.8 | **73.7** | 548 M |
|
102 |
+
| Thai | 21.5 | **28.7** | 43.0 | **54.6** | 53.7 | **66.0** | 61 M |
|
103 |
+
| Turkish | 25.5 | **33.0** | 49.1 | **59.6** | 60.3 | **70.8** | 88 M |
|
104 |
+
| Ukranian | 26.0 | **30.6** | 49.9 | **56.7** | 60.9 | **68.1** | 41 M |
|
105 |
+
| Vietnamese | 25.4 | **28.3** | 49.2 | **53.9** | 60.3 | **65.5** | 85 M |
|
106 |
+
| | | | | | | | |
|
107 |
+
| Mean | 26.5±6.4 | **31.8±3.5** | 49.8±9.8 | **58.1±4.5** | 60.4±10.6 | **69.4±4.3** | - |
|
108 |
+
| Google Translate | 27.4±6.3 | **31.5±3.5** | 51.1±9.5 | **57.8±4.4** | 61.7±10.3 | **69.1±4.3** | - |
|
109 |
+
| Microsoft Translator | 27.2±6.4 | **31.4±3.6** | 50.8±9.8 | **57.7±4.7** | 61.4±10.6 | **68.9±4.6** | - |
|
110 |
+
| Meta NLLB | 24.9±6.7 | **32.4±3.5** | 47.5±10.3 | **58.9±4.5** | 58.2±11.2 | **70.2±4.3** | - |
|
111 |
+
|
112 |
+
NDCG@20
|
113 |
+
|
114 |
+
| | Arabic | Armenian | Chinese | French | German | Hebrew | Hindi | Indonesian | Italian | Japanese | Korean | Persian | Polish | Portuguese | Russian | Spanish | Thai | Turkish | Ukranian | Vietnamese | Mean (all) | Mean (Google Translate) | Mean(Microsoft Translator) | Mean(NLLB)
|
115 |
+
| :------------ | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: |
|
116 |
+
| OpenCLIP NDCG | 0.639 | 0.204 | 0.731 | 0.823 | 0.806 | 0.657 | 0.616 | 0.733 | 0.811 | 0.737 | 0.686 | 0.667 | 0.764 | 0.832 | 0.777 | 0.849 | 0.606 | 0.701 | 0.704 | 0.697 | 0.716 ± 0.149 | 0.732 ± 0.145 | 0.730 ± 0.149 | 0.686 ± 0.158
|
117 |
+
| UForm NDCG | 0.868 | 0.691 | 0.880 | 0.932 | 0.927 | 0.791 | 0.879 | 0.870 | 0.930 | 0.885 | 0.869 | 0.831 | 0.897 | 0.897 | 0.906 | 0.939 | 0.822 | 0.898 | 0.851 | 0.818 | 0.875 ± 0.064 | 0.869 ± 0.063 | 0.869 ± 0.066 | 0.888 ± 0.064
|
118 |
+
|
119 |
+
## Installation
|
120 |
+
|
121 |
+
```bash
|
122 |
+
pip install uform[torch]
|
123 |
+
```
|
124 |
+
|
125 |
+
## Usage
|
126 |
+
|
127 |
+
To load the model:
|
128 |
+
|
129 |
+
```python
|
130 |
+
import uform
|
131 |
+
|
132 |
+
model, processor = uform.get_model('unum-cloud/uform-vl-multilingual-v2')
|
133 |
+
```
|
134 |
+
|
135 |
+
To encode data:
|
136 |
+
|
137 |
+
```python
|
138 |
+
from PIL import Image
|
139 |
+
|
140 |
+
text = 'a small red panda in a zoo'
|
141 |
+
image = Image.open('red_panda.jpg')
|
142 |
+
|
143 |
+
image_data = processor.preprocess_image(image)
|
144 |
+
text_data = processor.preprocess_text(text)
|
145 |
+
|
146 |
+
image_features, image_embedding = model.encode_image(image_data, return_features=True)
|
147 |
+
text_features, text_embedding = model.encode_text(text_data, return_features=True)
|
148 |
+
joint_embedding = model.encode_multimodal(image=image_data, text=text_data)
|
149 |
+
```
|
150 |
+
|
151 |
+
To get features:
|
152 |
+
|
153 |
+
```python
|
154 |
+
image_features, image_embedding = model.encode_image(image_data, return_features=True)
|
155 |
+
text_features, text_embedding = model.encode_text(text_data, return_features=True)
|
156 |
+
```
|
157 |
+
|
158 |
+
These features can later be used to produce joint multimodal encodings faster, as the first layers of the transformer can be skipped:
|
159 |
+
|
160 |
+
```python
|
161 |
+
joint_embedding = model.encode_multimodal(
|
162 |
+
image_features=image_features,
|
163 |
+
text_features=text_features,
|
164 |
+
attention_mask=text_data['attention_mask']
|
165 |
+
)
|
166 |
+
```
|
167 |
+
|
168 |
+
There are two options to calculate semantic compatibility between an image and a text: [Cosine Similarity](#cosine-similarity) and [Matching Score](#matching-score).
|
169 |
+
|
170 |
+
### Cosine Similarity
|
171 |
+
|
172 |
+
```python
|
173 |
+
import torch.nn.functional as F
|
174 |
+
|
175 |
+
similarity = F.cosine_similarity(image_embedding, text_embedding)
|
176 |
+
```
|
177 |
+
|
178 |
+
The `similarity` will belong to the `[-1, 1]` range, `1` meaning the absolute match.
|
179 |
+
|
180 |
+
__Pros__:
|
181 |
+
|
182 |
+
- Computationally cheap.
|
183 |
+
- Only unimodal embeddings are required, unimodal encoding is faster than joint encoding.
|
184 |
+
- Suitable for retrieval in large collections.
|
185 |
+
|
186 |
+
__Cons__:
|
187 |
+
|
188 |
+
- Takes into account only coarse-grained features.
|
189 |
+
|
190 |
+
|
191 |
+
### Matching Score
|
192 |
+
|
193 |
+
Unlike cosine similarity, unimodal embedding are not enough.
|
194 |
+
Joint embedding will be needed and the resulting `score` will belong to the `[0, 1]` range, `1` meaning the absolute match.
|
195 |
+
|
196 |
+
```python
|
197 |
+
score = model.get_matching_scores(joint_embedding)
|
198 |
+
```
|
199 |
+
|
200 |
+
__Pros__:
|
201 |
+
|
202 |
+
- Joint embedding captures fine-grained features.
|
203 |
+
- Suitable for re-ranking – sorting retrieval result.
|
204 |
+
|
205 |
+
__Cons__:
|
206 |
+
|
207 |
+
- Resource-intensive.
|
208 |
+
- Not suitable for retrieval in large collections.
|
config.json
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text_encoder": {
|
3 |
+
"tokenizer_class": "bert",
|
4 |
+
"model_type": "bert",
|
5 |
+
"dim": 384,
|
6 |
+
"context_dim": 768,
|
7 |
+
"vocab_size": 250037,
|
8 |
+
"padding_idx": 1,
|
9 |
+
"num_layers": 12,
|
10 |
+
"num_heads": 12,
|
11 |
+
"embedding_dim": 256,
|
12 |
+
"multimodal_layers_ids": [
|
13 |
+
8,
|
14 |
+
9,
|
15 |
+
10,
|
16 |
+
11
|
17 |
+
],
|
18 |
+
"head_one_neuron": false,
|
19 |
+
"pooling": "mean",
|
20 |
+
"max_position_embeddings": 50,
|
21 |
+
"dropout_prob": 0.1
|
22 |
+
},
|
23 |
+
"image_encoder": {
|
24 |
+
"normalization_means": [
|
25 |
+
0.48145466,
|
26 |
+
0.4578275,
|
27 |
+
0.40821073
|
28 |
+
],
|
29 |
+
"normalization_deviations": [
|
30 |
+
0.26862954,
|
31 |
+
0.26130258,
|
32 |
+
0.27577711
|
33 |
+
],
|
34 |
+
"dim": 768,
|
35 |
+
"patch_size": 16,
|
36 |
+
"image_size": 224,
|
37 |
+
"num_layers": 12,
|
38 |
+
"num_heads": 12,
|
39 |
+
"embedding_dim": 256,
|
40 |
+
"pooling": "cls"
|
41 |
+
}
|
42 |
+
}
|
image_encoder.mlpackage/Data/com.apple.CoreML/model.mlmodel
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:101d2a485d7f1fb9b13bb2e9b21017d41e0484c09d7252fa48cd45663bf6a7a0
|
3 |
+
size 111239
|
image_encoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2b24c24003fc3acf7635ad22f5c7114e2332dcdc7d0bc54ca0a037c777240646
|
3 |
+
size 344067136
|
image_encoder.mlpackage/Manifest.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"fileFormatVersion": "1.0.0",
|
3 |
+
"itemInfoEntries": {
|
4 |
+
"690CB1E0-62DD-45EA-948E-FBBD7B246BE6": {
|
5 |
+
"author": "com.apple.CoreML",
|
6 |
+
"description": "CoreML Model Specification",
|
7 |
+
"name": "model.mlmodel",
|
8 |
+
"path": "com.apple.CoreML/model.mlmodel"
|
9 |
+
},
|
10 |
+
"83ED2C72-7659-440D-A7C9-61793559340B": {
|
11 |
+
"author": "com.apple.CoreML",
|
12 |
+
"description": "CoreML Model Weights",
|
13 |
+
"name": "weights",
|
14 |
+
"path": "com.apple.CoreML/weights"
|
15 |
+
}
|
16 |
+
},
|
17 |
+
"rootModelIdentifier": "690CB1E0-62DD-45EA-948E-FBBD7B246BE6"
|
18 |
+
}
|
image_encoder.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b764843eeaa20a981f5f1baf19f4fedf33ee0385483fc0d30e15d5aa6ea4912e
|
3 |
+
size 87267684
|
image_encoder.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:02b7d4306999f49a70ddfe60e69932428a9c81709bef702f99d9c4380f987645
|
3 |
+
size 172100742
|
image_encoder.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fb3c5dc0ecabbafcaab8011112b07ef01d39e006cae25de0b7cc60dc0b42213c
|
3 |
+
size 172047072
|
text_encoder.mlpackage/Data/com.apple.CoreML/model.mlmodel
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b388380d8fdcd0271c9b851c22348453c36463cf43aa3d656b7fa9aa6ea52c42
|
3 |
+
size 74060
|
text_encoder.mlpackage/Data/com.apple.CoreML/weights/weight.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:064e0da61cc46b74a9a5f799c529fcbdb00cb19b6603e152b6ede7e3bdbed017
|
3 |
+
size 441322432
|
text_encoder.mlpackage/Manifest.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"fileFormatVersion": "1.0.0",
|
3 |
+
"itemInfoEntries": {
|
4 |
+
"09A10422-686F-432D-B684-1B0F05B38FC0": {
|
5 |
+
"author": "com.apple.CoreML",
|
6 |
+
"description": "CoreML Model Weights",
|
7 |
+
"name": "weights",
|
8 |
+
"path": "com.apple.CoreML/weights"
|
9 |
+
},
|
10 |
+
"0C92F7F7-B285-45D6-9DF1-DCC71E38166D": {
|
11 |
+
"author": "com.apple.CoreML",
|
12 |
+
"description": "CoreML Model Specification",
|
13 |
+
"name": "model.mlmodel",
|
14 |
+
"path": "com.apple.CoreML/model.mlmodel"
|
15 |
+
}
|
16 |
+
},
|
17 |
+
"rootModelIdentifier": "0C92F7F7-B285-45D6-9DF1-DCC71E38166D"
|
18 |
+
}
|
text_encoder.onnx
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e4dfc9d14b13c871a55386fdfc9d787446535dcb013c9ccf8c9db0323db3febf
|
3 |
+
size 110689743
|
text_encoder.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:373485cd65cc62c3e41bf623b75171981fe1160e13f84d5f05499e8e2c34e63f
|
3 |
+
size 240262678
|
text_encoder.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:400b19de2ca7380307010f006f2823cd953fa4d63d90ec5d2e572beb2d5dc512
|
3 |
+
size 240204124
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|