ashvardanian commited on
Commit
039f477
1 Parent(s): af83b6b

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -25,7 +25,6 @@
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
  *.tflite filter=lfs diff=lfs merge=lfs -text
30
  *.tgz filter=lfs diff=lfs merge=lfs -text
31
  *.wasm filter=lfs diff=lfs merge=lfs -text
 
25
  *.safetensors filter=lfs diff=lfs merge=lfs -text
26
  saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
  *.tar.* filter=lfs diff=lfs merge=lfs -text
 
28
  *.tflite filter=lfs diff=lfs merge=lfs -text
29
  *.tgz filter=lfs diff=lfs merge=lfs -text
30
  *.wasm filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ pipeline_tag: feature-extraction
4
+ tags:
5
+ - clip
6
+ - vision
7
+ datasets:
8
+ - sbu_captions
9
+ - visual_genome
10
+ - ChristophSchuhmann/MS_COCO_2017_URL_TEXT
11
+ ---
12
+ <h1 align="center">UForm</h1>
13
+ <h3 align="center">
14
+ Multi-Modal Inference Library<br/>
15
+ For Semantic Search Applications<br/>
16
+ </h3>
17
+
18
+ ---
19
+
20
+ 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!
21
+
22
+ This is model card of the __English only model__ with:
23
+
24
+ * 4 layers BERT (2 layers for unimodal encoding and rest layers for multimodal encoding)
25
+ * ViT-B/16 (image resolution is 224x224)
26
+
27
+
28
+ If you need Multilingual model, check [this](https://huggingface.co/unum-cloud/uform-vl-multilingual).
29
+
30
+ ## Evaluation
31
+
32
+ The following metrics were obtained with multimodal re-ranking:
33
+
34
+ | Dataset | Recall@1 | Recall@5 | Recall@10 |
35
+ | :-------- | ------: | --------: | --------: |
36
+ | Zero-Shot Flickr | 0.727 | 0.915 | 0.949 |
37
+ | MS-COCO (train split was in training data) | 0.510 | 0.761 | 0.838 |
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install uform[torch]
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ To load the model:
48
+
49
+ ```python
50
+ import uform
51
+
52
+ model, processor = uform.get_model('unum-cloud/uform-vl-english')
53
+ ```
54
+
55
+ To encode data:
56
+
57
+ ```python
58
+ from PIL import Image
59
+
60
+ text = 'a small red panda in a zoo'
61
+ image = Image.open('red_panda.jpg')
62
+
63
+ image_data = processor.preprocess_image(image)
64
+ text_data = processor.preprocess_text(text)
65
+
66
+ image_features, image_embedding = model.encode_image(image_data, return_features=True)
67
+ text_features, text_embedding = model.encode_text(text_data, return_features=True)
68
+ ```
69
+
70
+ To get features:
71
+
72
+ ```python
73
+ image_features, image_embedding = model.encode_image(image_data, return_features=True)
74
+ text_features, text_embedding = model.encode_text(text_data, return_features=True)
75
+ ```
76
+
77
+ These features can later be used to produce joint multimodal encodings faster, as the first layers of the transformer can be skipped:
78
+
79
+ ```python
80
+ joint_embedding = model.encode_multimodal(
81
+ image_features=image_features,
82
+ text_features=text_features,
83
+ attention_mask=text_data['attention_mask']
84
+ )
85
+ ```
86
+
87
+ There are two options to calculate semantic compatibility between an image and a text: [Cosine Similarity](#cosine-similarity) and [Matching Score](#matching-score).
88
+
89
+ ### Cosine Similarity
90
+
91
+ ```python
92
+ import torch.nn.functional as F
93
+
94
+ similarity = F.cosine_similarity(image_embedding, text_embedding)
95
+ ```
96
+
97
+ The `similarity` will belong to the `[-1, 1]` range, `1` meaning the absolute match.
98
+
99
+ __Pros__:
100
+
101
+ - Computationally cheap.
102
+ - Only unimodal embeddings are required, unimodal encoding is faster than joint encoding.
103
+ - Suitable for retrieval in large collections.
104
+
105
+ __Cons__:
106
+
107
+ - Takes into account only coarse-grained features.
108
+
109
+
110
+ ### Matching Score
111
+
112
+ Unlike cosine similarity, unimodal embedding are not enough.
113
+ Joint embedding will be needed and the resulting `score` will belong to the `[0, 1]` range, `1` meaning the absolute match.
114
+
115
+ ```python
116
+ score = model.get_matching_scores(joint_embedding)
117
+ ```
118
+
119
+ __Pros__:
120
+
121
+ - Joint embedding captures fine-grained features.
122
+ - Suitable for re-ranking – sorting retrieval result.
123
+
124
+ __Cons__:
125
+
126
+ - Resource-intensive.
127
+ - Not suitable for retrieval in large collections.
128
+
config.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "text_encoder": {
3
+ "tokenizer_class": "bert",
4
+ "model_type": "bert",
5
+ "dim": 768,
6
+ "context_dim": 768,
7
+ "vocab_size": 30522,
8
+ "padding_idx": 0,
9
+ "num_layers": 4,
10
+ "num_heads": 12,
11
+ "embedding_dim": 256,
12
+ "multimodal_layers_ids": [
13
+ 2,
14
+ 3
15
+ ],
16
+ "head_one_neuron": false,
17
+ "pooling": "cls",
18
+ "max_position_embeddings": 77,
19
+ "dropout_prob": 0.1
20
+ },
21
+ "image_encoder": {
22
+ "normalization_means": [
23
+ 0.48145466,
24
+ 0.4578275,
25
+ 0.40821073
26
+ ],
27
+ "normalization_deviations": [
28
+ 0.26862954,
29
+ 0.26130258,
30
+ 0.27577711
31
+ ],
32
+ "dim": 768,
33
+ "patch_size": 16,
34
+ "image_size": 224,
35
+ "num_layers": 12,
36
+ "num_heads": 12,
37
+ "embedding_dim": 256,
38
+ "pooling": "cls"
39
+ }
40
+ }
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:d795737604c1677ff6b2e5fa8bceface13912a9baecea99b6ef3e24efa050464
3
+ size 344067136
image_encoder.mlpackage/Manifest.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "ADEDA51D-BFFF-46BC-AF60-BF0FB2F3BB19": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "CoreML Model Specification",
7
+ "name": "model.mlmodel",
8
+ "path": "com.apple.CoreML/model.mlmodel"
9
+ },
10
+ "F1FDEC64-5002-491E-8C51-99A28404DD54": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "CoreML Model Weights",
13
+ "name": "weights",
14
+ "path": "com.apple.CoreML/weights"
15
+ }
16
+ },
17
+ "rootModelIdentifier": "ADEDA51D-BFFF-46BC-AF60-BF0FB2F3BB19"
18
+ }
image_encoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:54ea2e32abb19d5a8415143f3d2d87ce3e96ccc0a031653af198db6fd13ecef8
3
+ size 87267681
image_encoder.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea4548002193d407577533b6a98596a9903f9576c4c8de574b06050aaa5c92d7
3
+ size 172100742
image_encoder.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:800f75efc508c0eb3445ec270152194e692860656eef32b8ebab888ff5946351
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:f1428abd50aa8fe334c81f5bc88c8fb62b9903ba05ad94e61d0f6d73f3cf5c42
3
+ size 21788
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:8dd08b0a4867b25785d44b8dce1c37174894c788a732dd18c2ab3f8b47f048d3
3
+ size 151499200
text_encoder.mlpackage/Manifest.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fileFormatVersion": "1.0.0",
3
+ "itemInfoEntries": {
4
+ "546A7C3A-6CCD-42C4-A20B-507DBA62CEA6": {
5
+ "author": "com.apple.CoreML",
6
+ "description": "CoreML Model Specification",
7
+ "name": "model.mlmodel",
8
+ "path": "com.apple.CoreML/model.mlmodel"
9
+ },
10
+ "D48DD071-5007-4390-BF8E-9D05D8483749": {
11
+ "author": "com.apple.CoreML",
12
+ "description": "CoreML Model Weights",
13
+ "name": "weights",
14
+ "path": "com.apple.CoreML/weights"
15
+ }
16
+ },
17
+ "rootModelIdentifier": "546A7C3A-6CCD-42C4-A20B-507DBA62CEA6"
18
+ }
text_encoder.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ac4e7765b4951b4ebe9001f35d7deb1dadf77cde697c363ba90d2c44f71c052b
3
+ size 38004782
text_encoder.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:50bc23ed1f2642decba5e2bc7eca5bc9d83cdc7e13f44fd00298395d90849cb3
3
+ size 113589216
text_encoder.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7001e423ec999a2bfbd33683f48f8163942d3e9a7259944db170129e0857ffdf
3
+ size 113566956
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff