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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
- de
|
| 6 |
+
- es
|
| 7 |
+
- fr
|
| 8 |
+
- it
|
| 9 |
+
- ja
|
| 10 |
+
- ko
|
| 11 |
+
- pl
|
| 12 |
+
- ru
|
| 13 |
+
- tr
|
| 14 |
+
- zh
|
| 15 |
+
- ar
|
| 16 |
+
---
|
| 17 |
+
<h1 align="center">UForm</h1>
|
| 18 |
+
<h3 align="center">
|
| 19 |
+
Multi-Modal Inference Library<br/>
|
| 20 |
+
For Semantic Search Applications<br/>
|
| 21 |
+
</h3>
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
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!
|
| 26 |
+
|
| 27 |
+
This is model card of the __Multilingual model__ (21 languages) with:
|
| 28 |
+
|
| 29 |
+
* 12 layers BERT (8 layers for unimodal encoding and rest layers for multimodal encoding)
|
| 30 |
+
* ViT-B/16 (image resolution is 224x224)
|
| 31 |
+
|
| 32 |
+
The model was trained on balanced multilingual dataset.
|
| 33 |
+
|
| 34 |
+
If you need English model, check [this](https://huggingface.co/unum-cloud/uform-vl-english).
|
| 35 |
+
|
| 36 |
+
## Evaluation
|
| 37 |
+
|
| 38 |
+
For all evaluations, the multimodal part was used unless otherwise stated.
|
| 39 |
+
|
| 40 |
+
**Monolingual**
|
| 41 |
+
|
| 42 |
+
| Dataset | Recall@1 | Recall@5 | Recall@10 |
|
| 43 |
+
| :-------- | ------: | --------: | --------: |
|
| 44 |
+
| Zero-Shot Flickr | 0.558 | 0.813 | 0.874 |
|
| 45 |
+
| MS-COCO (train split was in training data) | 0.401 | 0.680 | 0.781 |
|
| 46 |
+
|
| 47 |
+
**Multilingual**
|
| 48 |
+
|
| 49 |
+
[XTD-10](https://github.com/adobe-research/Cross-lingual-Test-Dataset-XTD10)
|
| 50 |
+
|
| 51 |
+
Metric is recall@10
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
| English | German | Spanish | French | Italian | Russian | Japanese | Korean | Turkish | Chinese | Polish |
|
| 55 |
+
| -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------: | -------:
|
| 56 |
+
96.1 | 93.5 | 95.7 | 94.1 | 94.4 | 90.4 | 90.2 | 91.3 | 95.2 | 93.8 | 95.8 |
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
[COCO-SM](https://github.com/kimihailv/coco-sm/tree/main)
|
| 60 |
+
|
| 61 |
+
For this evaluation only unimodal part was used.
|
| 62 |
+
|
| 63 |
+
Recall
|
| 64 |
+
|
| 65 |
+
| Target Language | OpenCLIP @ 1 | UForm @ 1 | OpenCLIP @ 5 | UForm @ 5 | OpenCLIP @ 10 | UForm @ 10 | Speakers |
|
| 66 |
+
| :-------------------- | -----------: | ------------: | -----------: | -------------:| ------------: | --------------:| -------: |
|
| 67 |
+
| Arabic | 22.7 | **31.7** | 44.9 | **57.8** | 55.8 | **69.2** | 274 M |
|
| 68 |
+
| Armenian | 5.6 | **22.0** | 14.3 | **44.7** | 20.2 | **56.0** | 4 M |
|
| 69 |
+
| Chinese | 27.3 | **32.2** | 51.3 | **59.0** | 62.1 | **70.5** | 1'118 M |
|
| 70 |
+
| English | **37.8** | 37.7 | 63.5 | **65.0** | 73.5 | **75.9** | 1'452 M |
|
| 71 |
+
| French | 31.3 | **35.4** | 56.5 | **62.6** | 67.4 | **73.3** | 274 M |
|
| 72 |
+
| German | 31.7 | **35.1** | 56.9 | **62.2** | 67.4 | **73.3** | 134 M |
|
| 73 |
+
| Hebrew | 23.7 | **26.7** | 46.3 | **51.8** | 57.0 | **63.5** | 9 M |
|
| 74 |
+
| Hindi | 20.7 | **31.3** | 42.5 | **57.9** | 53.7 | **69.6** | 602 M |
|
| 75 |
+
| Indonesian | 26.9 | **30.7** | 51.4 | **57.0** | 62.7 | **68.6** | 199 M |
|
| 76 |
+
| Italian | 31.3 | **34.9** | 56.7 | **62.1** | 67.1 | **73.1** | 67 M |
|
| 77 |
+
| Japanese | 27.4 | **32.6** | 51.5 | **59.2** | 62.6 | **70.6** | 125 M |
|
| 78 |
+
| Korean | 24.4 | **31.5** | 48.1 | **57.8** | 59.2 | **69.2** | 81 M |
|
| 79 |
+
| Persian | 24.0 | **28.8** | 47.0 | **54.6** | 57.8 | **66.2** | 77 M |
|
| 80 |
+
| Polish | 29.2 | **33.6** | 53.9 | **60.1** | 64.7 | **71.3** | 41 M |
|
| 81 |
+
| Portuguese | 31.6 | **32.7** | 57.1 | **59.6** | 67.9 | **71.0** | 257 M |
|
| 82 |
+
| Russian | 29.9 | **33.9** | 54.8 | **60.9** | 65.8 | **72.0** | 258 M |
|
| 83 |
+
| Spanish | 32.6 | **35.6** | 58.0 | **62.8** | 68.8 | **73.7** | 548 M |
|
| 84 |
+
| Thai | 21.5 | **28.7** | 43.0 | **54.6** | 53.7 | **66.0** | 61 M |
|
| 85 |
+
| Turkish | 25.5 | **33.0** | 49.1 | **59.6** | 60.3 | **70.8** | 88 M |
|
| 86 |
+
| Ukranian | 26.0 | **30.6** | 49.9 | **56.7** | 60.9 | **68.1** | 41 M |
|
| 87 |
+
| Vietnamese | 25.4 | **28.3** | 49.2 | **53.9** | 60.3 | **65.5** | 85 M |
|
| 88 |
+
| | | | | | | | |
|
| 89 |
+
| 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** | - |
|
| 90 |
+
| 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** | - |
|
| 91 |
+
| 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** | - |
|
| 92 |
+
| 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** | - |
|
| 93 |
+
|
| 94 |
+
NDCG@20
|
| 95 |
+
|
| 96 |
+
| | 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)
|
| 97 |
+
| :------------ | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: | ----: |
|
| 98 |
+
| 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
|
| 99 |
+
| 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
|
| 100 |
+
|
| 101 |
+
## Installation
|
| 102 |
+
|
| 103 |
+
```bash
|
| 104 |
+
pip install uform
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
## Usage
|
| 108 |
+
|
| 109 |
+
To load the model:
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
import uform
|
| 113 |
+
|
| 114 |
+
model = uform.get_model('unum-cloud/uform-vl-english')
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
To encode data:
|
| 118 |
+
|
| 119 |
+
```python
|
| 120 |
+
from PIL import Image
|
| 121 |
+
|
| 122 |
+
text = 'a small red panda in a zoo'
|
| 123 |
+
image = Image.open('red_panda.jpg')
|
| 124 |
+
|
| 125 |
+
image_data = model.preprocess_image(image)
|
| 126 |
+
text_data = model.preprocess_text(text)
|
| 127 |
+
|
| 128 |
+
image_embedding = model.encode_image(image_data)
|
| 129 |
+
text_embedding = model.encode_text(text_data)
|
| 130 |
+
joint_embedding = model.encode_multimodal(image=image_data, text=text_data)
|
| 131 |
+
```
|
| 132 |
+
|
| 133 |
+
To get features:
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
image_features, image_embedding = model.encode_image(image_data, return_features=True)
|
| 137 |
+
text_features, text_embedding = model.encode_text(text_data, return_features=True)
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
These features can later be used to produce joint multimodal encodings faster, as the first layers of the transformer can be skipped:
|
| 141 |
+
|
| 142 |
+
```python
|
| 143 |
+
joint_embedding = model.encode_multimodal(
|
| 144 |
+
image_features=image_features,
|
| 145 |
+
text_features=text_features,
|
| 146 |
+
attention_mask=text_data['attention_mask']
|
| 147 |
+
)
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
There are two options to calculate semantic compatibility between an image and a text: [Cosine Similarity](#cosine-similarity) and [Matching Score](#matching-score).
|
| 151 |
+
|
| 152 |
+
### Cosine Similarity
|
| 153 |
+
|
| 154 |
+
```python
|
| 155 |
+
import torch.nn.functional as F
|
| 156 |
+
|
| 157 |
+
similarity = F.cosine_similarity(image_embedding, text_embedding)
|
| 158 |
+
```
|
| 159 |
+
|
| 160 |
+
The `similarity` will belong to the `[-1, 1]` range, `1` meaning the absolute match.
|
| 161 |
+
|
| 162 |
+
__Pros__:
|
| 163 |
+
|
| 164 |
+
- Computationally cheap.
|
| 165 |
+
- Only unimodal embeddings are required, unimodal encoding is faster than joint encoding.
|
| 166 |
+
- Suitable for retrieval in large collections.
|
| 167 |
+
|
| 168 |
+
__Cons__:
|
| 169 |
+
|
| 170 |
+
- Takes into account only coarse-grained features.
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
### Matching Score
|
| 174 |
+
|
| 175 |
+
Unlike cosine similarity, unimodal embedding are not enough.
|
| 176 |
+
Joint embedding will be needed and the resulting `score` will belong to the `[0, 1]` range, `1` meaning the absolute match.
|
| 177 |
+
|
| 178 |
+
```python
|
| 179 |
+
score = model.get_matching_scores(joint_embedding)
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
__Pros__:
|
| 183 |
+
|
| 184 |
+
- Joint embedding captures fine-grained features.
|
| 185 |
+
- Suitable for re-ranking – sorting retrieval result.
|
| 186 |
+
|
| 187 |
+
__Cons__:
|
| 188 |
+
|
| 189 |
+
- Resource-intensive.
|
| 190 |
+
- Not suitable for retrieval in large collections.
|