bhavitvyamalik commited on
Commit
14ee591
1 Parent(s): db63674

init uploads

Browse files
README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CLIP-Vision-Marian Seq2Seq Encoder-Decoder Model
2
+
3
+ Pretrained CLIP-Vision-Marian pre-trained on subset of Spanish translated Conceptual-12M image-text pairs using a seq2seq model training objective. 2.5M cleaned English image-text pairs are translated using Spanish Marian Model. We trained CLIP-Vision-Marian model during community week hosted by Huggingface 🤗 using JAX/Flax.
4
+
5
+ ## Model description
6
+ CLIP-Vision-Marian is a modified Marian model which takes in visual embeddings from CLIP-Vision transformer and concatenates them with Marian textual embeddings before passing them to the self-attention layers of Marian. This is done for deep cross-modal interaction between the two modes.
7
+
8
+ ## Intended uses & limitations❗️
9
+ You can use the raw model for encoder decoder network where you want the encoder to encode images and decoder to decode text.
10
+
11
+ Note that this model is primarily aimed at being fine-tuned on tasks like Spanish image captioning.
12
+
13
+ ### How to use❓
14
+ You will need to clone the model from [here](https://github.com/bhavitvyamalik/spanish-image-captioning). An example of usage is shown below:
15
+ ```python
16
+ >>> from torchvision.io import read_image
17
+ >>> import numpy as np
18
+ >>> import wget
19
+ >>> import os
20
+ >>> from transformers import CLIPProcessor, MarianTokenizer
21
+ >>> from models.flax_clip_vision_marian.modeling_clip_vision_marian import FlaxCLIPVisionMarianMT
22
+ img = wget.download("https://huggingface.co/streamlitiframe/flax-community/spanish-image-captioning/+/media/55a8898e61131569cc0ed4e72a8b3092969d63c2dff4f47ed9ef0d89.jpeg")
23
+ >>> img = read_image(img) # reading image
24
+ >>> clip_processor = CLIPProcessor.from_pretrained('flax-community/clip-vit-base-patch32_marian')
25
+ >>> clip_outputs = clip_processor(images=img)
26
+ >>> clip_outputs['pixel_values'][0] = clip_outputs['pixel_values'][0].transpose(1,2,0) # Need to transpose images as model expected channel last images.
27
+ >>> tokenizer = MarianTokenizer.from_pretrained('Helsinki-NLP/opus-mt-en-es')
28
+ >>> model = FlaxCLIPVisionMarianMT.from_pretrained('')
29
+ >>> output_ids = model.generate(batch["pixel_values"], early_stopping=True, num_beams=4, max_length=64).sequences
30
+ >>> output_string = tokenizer.batch_decode(output_ids.reshape(-1, 64), skip_special_tokens=True, max_length=64)
31
+ >>> output_string
32
+ # Sopa de avena en un tazón blanco con arándanos frescos
33
+ ```
34
+
35
+ ## Training data 🏋🏻‍♂️
36
+ The Spanish image captioning model was trained on a subset of Conceptual 12M dataset by Google:
37
+ <br>
38
+ <br>
39
+ [Conceptual 12M](https://github.com/google-research-datasets/conceptual-12m), Introduced by Changpinyo et al. in [Conceptual 12M: Pushing Web-Scale Image-Text Pre-Training To Recognize Long-Tail Visual Concepts](https://arxiv.org/abs/2102.08981).
40
+
41
+ ### Please update the dataset link here
42
+ The translated dataset can be downloaded from [conceptual-12m-multilingual-marian](https://huggingface.co/datasets/flax-community/conceptual-12m-multilingual-marian). We do not provide images as we do not own any of them. One can download images from the `image_url` section of the original Conceptual 12M dataset.
43
+
44
+ ## Data Cleaning 🧹
45
+ Though the original dataset contains 12M image-text pairs, a lot of the URLs are invalid now, and in some cases, images are corrupt or broken. We remove such examples from our data, which leaves us with approximately 10M image-text pairs, out of which we took only 2.5M image, caption pairs.
46
+
47
+ #### **Train set:**
48
+ Total data: <br>
49
+ 2500000 captions <br>
50
+ 2500000 images <br>
51
+
52
+ #### **Validation set**
53
+ Total data: <br>
54
+ 25000 captions <br>
55
+ 25000 images <br><br>
56
+
57
+
58
+ ## Training procedure 👨🏻‍💻
59
+ ### Training
60
+ The model was trained on Google Cloud Engine TPUv3-8 machine (with 335 GB of RAM, 1000 GB of hard drive, 96 CPU cores) **8 v3 TPU cores** for 42K steps with a batch size of 128 and a sequence length of 128. The
61
+ optimizer used is Adam with a learning rate of 3e-4, β1 = 0.9, β2 = 0.98 and
62
+ ε = 1e-8, a weight decay of 0.01, learning rate warmup for 1,000 steps and linear decay of the learning
63
+ rate after.
64
+
65
+ We tracked experiments using Tensorboard which can be found in `Training Metrics` tab.
66
+
67
+ #### **Pretraining Results 📊**
68
+
69
+ Our model reached **eval loss of ~3.1** around ~20K steps. Here are the BLEU^ scores for different languages:
70
+
71
+ |Language |BLEU-1|BLEU-2|BLEU-3|BLEU-4|
72
+ |--------------------------|------|------|------|------|
73
+ |Spanish | 0.2015| 0.1348| 0.09982| 0.0748|
74
+
75
+ ^BLEU scores are out of 1
76
+
77
+
78
+ ## **App Demo**
79
+
80
+ You can try out our model on 🤗 Huggingface's spaces 🪐 :
81
+ [Streamlit app of Spanish Image Captioning model on Huggingface Spaces](https://huggingface.co/spaces/flax-community/spanish-image-captioning)
82
+
83
+
84
+ ## Team Members
85
+ - Bhavitvya Malik [@bhavitvyamalik](https://github.com/bhavitvyamalik)
86
+ - Gunjan Chhablani [@gchhablani](https://github.com/gchhablani)
87
+
88
+ ## Credits
89
+ Thanks to Huggingface 🤗 & Google JAX/Flax team for such a wonderful community week. Big thanks to [@patrickvonplaten](https://github.com/patrickvonplaten) and [@patil-suraj](https://github.com/patil-suraj) for helping us with our solution during the community week.
90
+
91
+ <img src=https://pbs.twimg.com/media/E443fPjX0AY1BsR.jpg:large>
config.json ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "CLIPVisionMarianMT"
4
+ ],
5
+ "clip_vision_config": {
6
+ "_name_or_path": "",
7
+ "add_cross_attention": false,
8
+ "architectures": [
9
+ "CLIPModel"
10
+ ],
11
+ "attention_dropout": 0.0,
12
+ "bad_words_ids": null,
13
+ "bos_token_id": null,
14
+ "chunk_size_feed_forward": 0,
15
+ "decoder_start_token_id": null,
16
+ "diversity_penalty": 0.0,
17
+ "do_sample": false,
18
+ "dropout": 0.0,
19
+ "early_stopping": false,
20
+ "encoder_no_repeat_ngram_size": 0,
21
+ "eos_token_id": null,
22
+ "finetuning_task": null,
23
+ "forced_bos_token_id": null,
24
+ "forced_eos_token_id": null,
25
+ "gradient_checkpointing": false,
26
+ "hidden_act": "quick_gelu",
27
+ "hidden_size": 768,
28
+ "id2label": {
29
+ "0": "LABEL_0",
30
+ "1": "LABEL_1"
31
+ },
32
+ "image_size": 224,
33
+ "initializer_factor": 1.0,
34
+ "initializer_range": 0.02,
35
+ "intermediate_size": 3072,
36
+ "is_decoder": false,
37
+ "is_encoder_decoder": false,
38
+ "label2id": {
39
+ "LABEL_0": 0,
40
+ "LABEL_1": 1
41
+ },
42
+ "layer_norm_eps": 1e-05,
43
+ "length_penalty": 1.0,
44
+ "max_length": 20,
45
+ "min_length": 0,
46
+ "model_type": "clip_vision_model",
47
+ "no_repeat_ngram_size": 0,
48
+ "num_attention_heads": 12,
49
+ "num_beam_groups": 1,
50
+ "num_beams": 1,
51
+ "num_hidden_layers": 12,
52
+ "num_return_sequences": 1,
53
+ "output_attentions": false,
54
+ "output_hidden_states": false,
55
+ "output_scores": false,
56
+ "pad_token_id": null,
57
+ "patch_size": 32,
58
+ "prefix": null,
59
+ "problem_type": null,
60
+ "projection_dim": 512,
61
+ "pruned_heads": {},
62
+ "remove_invalid_values": false,
63
+ "repetition_penalty": 1.0,
64
+ "return_dict": true,
65
+ "return_dict_in_generate": false,
66
+ "sep_token_id": null,
67
+ "task_specific_params": null,
68
+ "temperature": 1.0,
69
+ "text_config": {
70
+ "_name_or_path": "",
71
+ "add_cross_attention": false,
72
+ "architectures": null,
73
+ "attention_dropout": 0.0,
74
+ "bad_words_ids": null,
75
+ "bos_token_id": 0,
76
+ "chunk_size_feed_forward": 0,
77
+ "decoder_start_token_id": null,
78
+ "diversity_penalty": 0.0,
79
+ "do_sample": false,
80
+ "dropout": 0.0,
81
+ "early_stopping": false,
82
+ "encoder_no_repeat_ngram_size": 0,
83
+ "eos_token_id": 2,
84
+ "finetuning_task": null,
85
+ "forced_bos_token_id": null,
86
+ "forced_eos_token_id": null,
87
+ "gradient_checkpointing": false,
88
+ "hidden_act": "quick_gelu",
89
+ "hidden_size": 512,
90
+ "id2label": {
91
+ "0": "LABEL_0",
92
+ "1": "LABEL_1"
93
+ },
94
+ "initializer_factor": 1.0,
95
+ "initializer_range": 0.02,
96
+ "intermediate_size": 2048,
97
+ "is_decoder": false,
98
+ "is_encoder_decoder": false,
99
+ "label2id": {
100
+ "LABEL_0": 0,
101
+ "LABEL_1": 1
102
+ },
103
+ "layer_norm_eps": 1e-05,
104
+ "length_penalty": 1.0,
105
+ "max_length": 20,
106
+ "max_position_embeddings": 77,
107
+ "min_length": 0,
108
+ "model_type": "clip_text_model",
109
+ "no_repeat_ngram_size": 0,
110
+ "num_attention_heads": 8,
111
+ "num_beam_groups": 1,
112
+ "num_beams": 1,
113
+ "num_hidden_layers": 12,
114
+ "num_return_sequences": 1,
115
+ "output_attentions": false,
116
+ "output_hidden_states": false,
117
+ "output_scores": false,
118
+ "pad_token_id": 1,
119
+ "prefix": null,
120
+ "problem_type": null,
121
+ "pruned_heads": {},
122
+ "remove_invalid_values": false,
123
+ "repetition_penalty": 1.0,
124
+ "return_dict": true,
125
+ "return_dict_in_generate": false,
126
+ "sep_token_id": null,
127
+ "task_specific_params": null,
128
+ "temperature": 1.0,
129
+ "tie_encoder_decoder": false,
130
+ "tie_word_embeddings": true,
131
+ "tokenizer_class": null,
132
+ "top_k": 50,
133
+ "top_p": 1.0,
134
+ "torchscript": false,
135
+ "transformers_version": "4.7.0.dev0",
136
+ "use_bfloat16": false,
137
+ "vocab_size": 49408
138
+ },
139
+ "text_config_dict": null,
140
+ "tie_encoder_decoder": false,
141
+ "tie_word_embeddings": true,
142
+ "tokenizer_class": null,
143
+ "top_k": 50,
144
+ "top_p": 1.0,
145
+ "torch_dtype": null,
146
+ "torchscript": false,
147
+ "transformers_version": "4.9.0.dev0",
148
+ "use_bfloat16": false,
149
+ "vision_config": {
150
+ "_name_or_path": "",
151
+ "add_cross_attention": false,
152
+ "architectures": null,
153
+ "attention_dropout": 0.0,
154
+ "bad_words_ids": null,
155
+ "bos_token_id": null,
156
+ "chunk_size_feed_forward": 0,
157
+ "decoder_start_token_id": null,
158
+ "diversity_penalty": 0.0,
159
+ "do_sample": false,
160
+ "dropout": 0.0,
161
+ "early_stopping": false,
162
+ "encoder_no_repeat_ngram_size": 0,
163
+ "eos_token_id": null,
164
+ "finetuning_task": null,
165
+ "forced_bos_token_id": null,
166
+ "forced_eos_token_id": null,
167
+ "gradient_checkpointing": false,
168
+ "hidden_act": "quick_gelu",
169
+ "hidden_size": 768,
170
+ "id2label": {
171
+ "0": "LABEL_0",
172
+ "1": "LABEL_1"
173
+ },
174
+ "image_size": 224,
175
+ "initializer_factor": 1.0,
176
+ "initializer_range": 0.02,
177
+ "intermediate_size": 3072,
178
+ "is_decoder": false,
179
+ "is_encoder_decoder": false,
180
+ "label2id": {
181
+ "LABEL_0": 0,
182
+ "LABEL_1": 1
183
+ },
184
+ "layer_norm_eps": 1e-05,
185
+ "length_penalty": 1.0,
186
+ "max_length": 20,
187
+ "min_length": 0,
188
+ "model_type": "clip_vision_model",
189
+ "no_repeat_ngram_size": 0,
190
+ "num_attention_heads": 12,
191
+ "num_beam_groups": 1,
192
+ "num_beams": 1,
193
+ "num_hidden_layers": 12,
194
+ "num_return_sequences": 1,
195
+ "output_attentions": false,
196
+ "output_hidden_states": false,
197
+ "output_scores": false,
198
+ "pad_token_id": null,
199
+ "patch_size": 32,
200
+ "prefix": null,
201
+ "problem_type": null,
202
+ "pruned_heads": {},
203
+ "remove_invalid_values": false,
204
+ "repetition_penalty": 1.0,
205
+ "return_dict": true,
206
+ "return_dict_in_generate": false,
207
+ "sep_token_id": null,
208
+ "task_specific_params": null,
209
+ "temperature": 1.0,
210
+ "tie_encoder_decoder": false,
211
+ "tie_word_embeddings": true,
212
+ "tokenizer_class": null,
213
+ "top_k": 50,
214
+ "top_p": 1.0,
215
+ "torchscript": false,
216
+ "transformers_version": "4.7.0.dev0",
217
+ "use_bfloat16": false
218
+ },
219
+ "vision_config_dict": null
220
+ },
221
+ "is_encoder_decoder": true,
222
+ "marian_config": {
223
+ "_name_or_path": "",
224
+ "activation_dropout": 0.0,
225
+ "activation_function": "swish",
226
+ "add_bias_logits": false,
227
+ "add_cross_attention": false,
228
+ "add_final_layer_norm": false,
229
+ "architectures": [
230
+ "MarianMTModel"
231
+ ],
232
+ "attention_dropout": 0.0,
233
+ "bad_words_ids": [
234
+ [
235
+ 65000
236
+ ]
237
+ ],
238
+ "bos_token_id": 0,
239
+ "chunk_size_feed_forward": 0,
240
+ "classif_dropout": 0.0,
241
+ "classifier_dropout": 0.0,
242
+ "d_model": 512,
243
+ "decoder_attention_heads": 8,
244
+ "decoder_ffn_dim": 2048,
245
+ "decoder_layerdrop": 0.0,
246
+ "decoder_layers": 6,
247
+ "decoder_start_token_id": 65000,
248
+ "diversity_penalty": 0.0,
249
+ "do_sample": false,
250
+ "dropout": 0.1,
251
+ "early_stopping": false,
252
+ "encoder_attention_heads": 8,
253
+ "encoder_ffn_dim": 2048,
254
+ "encoder_layerdrop": 0.0,
255
+ "encoder_layers": 6,
256
+ "encoder_no_repeat_ngram_size": 0,
257
+ "eos_token_id": 0,
258
+ "extra_pos_embeddings": 65001,
259
+ "finetuning_task": null,
260
+ "force_bos_token_to_be_generated": false,
261
+ "forced_bos_token_id": null,
262
+ "forced_eos_token_id": 0,
263
+ "gradient_checkpointing": false,
264
+ "id2label": {
265
+ "0": "LABEL_0",
266
+ "1": "LABEL_1",
267
+ "2": "LABEL_2"
268
+ },
269
+ "init_std": 0.02,
270
+ "is_decoder": false,
271
+ "is_encoder_decoder": true,
272
+ "label2id": {
273
+ "LABEL_0": 0,
274
+ "LABEL_1": 1,
275
+ "LABEL_2": 2
276
+ },
277
+ "length_penalty": 1.0,
278
+ "max_length": 512,
279
+ "max_position_embeddings": 512,
280
+ "min_length": 0,
281
+ "model_type": "marian",
282
+ "no_repeat_ngram_size": 0,
283
+ "normalize_before": false,
284
+ "normalize_embedding": false,
285
+ "num_beam_groups": 1,
286
+ "num_beams": 4,
287
+ "num_hidden_layers": 6,
288
+ "num_return_sequences": 1,
289
+ "output_attentions": false,
290
+ "output_hidden_states": false,
291
+ "output_scores": false,
292
+ "pad_token_id": 65000,
293
+ "prefix": null,
294
+ "problem_type": null,
295
+ "pruned_heads": {},
296
+ "remove_invalid_values": false,
297
+ "repetition_penalty": 1.0,
298
+ "return_dict": true,
299
+ "return_dict_in_generate": false,
300
+ "scale_embedding": true,
301
+ "sep_token_id": null,
302
+ "static_position_embeddings": true,
303
+ "task_specific_params": null,
304
+ "temperature": 1.0,
305
+ "tie_encoder_decoder": false,
306
+ "tie_word_embeddings": true,
307
+ "tokenizer_class": null,
308
+ "top_k": 50,
309
+ "top_p": 1.0,
310
+ "torch_dtype": null,
311
+ "torchscript": false,
312
+ "transformers_version": "4.9.0.dev0",
313
+ "use_bfloat16": false,
314
+ "use_cache": true,
315
+ "vocab_size": 65001
316
+ },
317
+ "model_type": "clip-vision-marian",
318
+ "seed": 42,
319
+ "transformers_version": null
320
+ }
logs/events.out.tfevents.1626630957.t1v-n-8499dd91-w-0.1328528.3.v2 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7de765433d5c33fdf34bad559fcb94c8dc8c0838e4ff0eb5bca138d7266c3e89
3
+ size 3187062