Transformers
PyTorch
English
bridgetower
gaudi
Inference Endpoints
shaoyent commited on
Commit
771c8aa
1 Parent(s): d2a805e

Add new model

Browse files
Files changed (6) hide show
  1. README.md +109 -0
  2. config.json +56 -0
  3. preprocessor_config.json +6 -0
  4. pytorch_model.bin +3 -0
  5. tokenizer.json +0 -0
  6. vocab.json +0 -0
README.md CHANGED
@@ -1,3 +1,112 @@
1
  ---
 
 
 
 
2
  license: mit
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language: en
3
+ tags:
4
+ - bridgetower
5
+ - gaudi
6
  license: mit
7
+ datasets:
8
+ - conceptual_captions
9
+ - conceptual_12m
10
+ - sbu_captions
11
+ - visual_genome
12
+ - mscoco_captions
13
  ---
14
+
15
+ # BridgeTower large-itm-mlm-gaudi model
16
+
17
+ The BridgeTower model was proposed in "BridgeTower: Building Bridges Between Encoders in Vision-Language Representative Learning" by Xiao Xu, Chenfei Wu, Shachar Rosenman, Vasudev Lal, Wanxiang Che, Nan Duan.
18
+ The model was pretrained on English language using masked language modeling (MLM) and image text matching (ITM)objectives. It was introduced in
19
+ [this paper](https://arxiv.org/pdf/2206.08657.pdf) and first released in
20
+ [this repository](https://github.com/microsoft/BridgeTower).
21
+
22
+ BridgeTower got accepted to [AAAI'23](https://aaai.org/Conferences/AAAI-23/).
23
+
24
+ ## Model description
25
+
26
+ The abstract from the paper is the following:
27
+ Vision-Language (VL) models with the Two-Tower architecture have dominated visual-language representation learning in recent years. Current VL models either use lightweight uni-modal encoders and learn to extract, align and fuse both modalities simultaneously in a deep cross-modal encoder, or feed the last-layer uni-modal representations from the deep pre-trained uni-modal encoders into the top cross-modal encoder. Both approaches potentially restrict vision-language representation learning and limit model performance. In this paper, we propose BridgeTower, which introduces multiple bridge layers that build a connection between the top layers of uni-modal encoders and each layer of the cross-modal encoder. This enables effective bottom-up cross-modal alignment and fusion between visual and textual representations of different semantic levels of pre-trained uni-modal encoders in the cross-modal encoder. Pre-trained with only 4M images, BridgeTower achieves state-of-the-art performance on various downstream vision-language tasks. In particular, on the VQAv2 test-std set, BridgeTower achieves an accuracy of 78.73%, outperforming the previous state-of-the-art model METER by 1.09% with the same pre-training data and almost negligible additional parameters and computational costs. Notably, when further scaling the model, BridgeTower achieves an accuracy of 81.15%, surpassing models that are pre-trained on orders-of-magnitude larger datasets.
28
+
29
+ ## Intended uses & limitations
30
+
31
+
32
+ ### How to use
33
+
34
+ Here is how to use this model to perform image and text matching:
35
+
36
+ ```python
37
+ from transformers import BridgeTowerProcessor, BridgeTowerForImageAndTextRetrieval
38
+ import requests
39
+ from PIL import Image
40
+
41
+ url = "http://images.cocodataset.org/val2017/000000039769.jpg"
42
+ image = Image.open(requests.get(url, stream=True).raw)
43
+ texts = ["An image of two cats chilling on a couch", "A football player scoring a goal"]
44
+
45
+ processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-gaudi")
46
+ model = BridgeTowerForImageAndTextRetrieval.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-gaudi")
47
+
48
+ # forward pass
49
+ scores = dict()
50
+ for text in texts:
51
+ # prepare inputs
52
+ encoding = processor(image, text, return_tensors="pt")
53
+ outputs = model(**encoding)
54
+ scores[text] = outputs.logits[0,1].item()
55
+ ```
56
+
57
+ Here is how to use this model to perform masked language modeling:
58
+
59
+ ```python
60
+ from transformers import BridgeTowerProcessor, BridgeTowerForMaskedLM
61
+ from PIL import Image
62
+ import requests
63
+
64
+ url = "http://images.cocodataset.org/val2017/000000360943.jpg"
65
+ image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
66
+ text = "a <mask> looking out of the window"
67
+
68
+ processor = BridgeTowerProcessor.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-gaudi")
69
+ model = BridgeTowerForMaskedLM.from_pretrained("BridgeTower/bridgetower-large-itm-mlm-gaudi")
70
+
71
+ # prepare inputs
72
+ encoding = processor(image, text, return_tensors="pt")
73
+
74
+ # forward pass
75
+ outputs = model(**encoding)
76
+
77
+ results = processor.decode(outputs.logits.argmax(dim=-1).squeeze(0).tolist())
78
+
79
+ print(results)
80
+ #.a cat looking out of the window.
81
+ ```
82
+
83
+ ## Training data
84
+
85
+ The BridgeTower model was pretrained on four public image-caption datasets:
86
+ - [Conceptual Captions (CC3M)](https://ai.google.com/research/ConceptualCaptions/)
87
+ - [Conceptual 12M (CC12M)](https://github.com/google-research-datasets/conceptual-12m)
88
+ - [SBU Captions](https://www.cs.rice.edu/~vo9/sbucaptions/)
89
+ - [MSCOCO Captions](https://arxiv.org/pdf/1504.00325.pdf)
90
+ - [Visual Genome](https://visualgenome.org/)
91
+
92
+ The total number of unique images in the combined data is around 16M.
93
+
94
+ ## Training procedure
95
+
96
+ ### Pretraining
97
+
98
+ The model was pre-trained for 10 epochs on an Intel AI supercomputing cluster using 512 Gaudis and 128 Xeons with a batch size of 2048.
99
+ The optimizer used was AdamW with a learning rate of 1e-7. No data augmentation was used except for center-crop. The image resolution in pre-training is set to 294 x 294.
100
+
101
+ ## Evaluation results
102
+ Please refer to [Table 5](https://arxiv.org/pdf/2206.08657.pdf) for BridgeTower's performance on Image Retrieval and other downstream tasks.
103
+
104
+ ### BibTeX entry and citation info
105
+ ```bibtex
106
+ @article{xu2022bridge,
107
+ title={BridgeTower: Building Bridges Between Encoders in Vision-Language Representation Learning},
108
+ author={Xu, Xiao and Wu, Chenfei and Rosenman, Shachar and Lal, Vasudev and Che, Wanxiang and Duan, Nan},
109
+ journal={arXiv preprint arXiv:2206.08657},
110
+ year={2022}
111
+ }
112
+ ```
config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "contrastive_hidden_size": 512,
3
+ "share_cross_modal_transformer_layers": true,
4
+ "drop_rate": 0.1,
5
+ "head_hidden_scale": 2,
6
+ "hidden_act": "gelu",
7
+ "hidden_size": 1024,
8
+ "initializer_factor": 1,
9
+ "is_encoder_decoder": false,
10
+ "layer_norm_eps": 1e-05,
11
+ "share_link_tower_layers": false,
12
+ "link_tower_type": "add",
13
+ "num_attention_heads": 16,
14
+ "num_hidden_layers": 6,
15
+ "tie_word_embeddings": false,
16
+ "text_config_dict": null,
17
+ "init_layernorm_from_vision_encoder": false,
18
+ "text_config": {
19
+ "architectures": [
20
+ "BridgeTowerTextModel"
21
+ ],
22
+ "vocab_size": 50265,
23
+ "hidden_size": 1024,
24
+ "num_hidden_layers": 24,
25
+ "num_attention_heads": 16,
26
+ "intermediate_size": 4096,
27
+ "hidden_act": "gelu",
28
+ "hidden_dropout_prob": 0.1,
29
+ "attention_probs_dropout_prob": 0.1,
30
+ "max_position_embeddings": 514,
31
+ "type_vocab_size": 1,
32
+ "initializer_factor": 1,
33
+ "initializer_range": 0.02,
34
+ "layer_norm_eps": 1e-05,
35
+ "pad_token_id": 1,
36
+ "bos_token_id": 0,
37
+ "eos_token_id": 2,
38
+ "position_embedding_type": "absolute",
39
+ "use_cache": true,
40
+ "classifier_dropout": null
41
+ },
42
+ "vision_config_dict": null,
43
+ "vision_config": {
44
+ "architectures": [
45
+ "BridgeTowerVisionModel"
46
+ ],
47
+ "hidden_size": 1024,
48
+ "num_hidden_layers": 24,
49
+ "patch_size": 14,
50
+ "image_size": 294,
51
+ "initializer_factor": 1,
52
+ "stop_gradient": false,
53
+ "share_layernorm": true,
54
+ "remove_last_layer": false
55
+ }
56
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "max_text_len":50,
3
+ "size":294,
4
+ "tokenizer":"roberta-large",
5
+ "vocab_size":50265
6
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c29278f0447e2d3139382eb658be43f297b1ec492b298ef7a0ee65863e88e743
3
+ size 3677121923
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
vocab.json ADDED
The diff for this file is too large to render. See raw diff