AhmedSSabir commited on
Commit
4ae724e
·
verified ·
1 Parent(s): d49cad4

Add BERT-CNN reward caption reranker with evaluation

Browse files
README.md ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ library_name: pytorch
4
+ base_model: google-bert/bert-base-uncased
5
+ datasets:
6
+ - AhmedSSabir/Textual-Image-Caption-Dataset
7
+ tags:
8
+ - bert
9
+ - image-captioning
10
+ - caption-reranking
11
+ - reinforcement-learning
12
+ - visual-relatedness
13
+ - custom-code
14
+ ---
15
+ # BERT-CNN Reward Caption Reranker
16
+
17
+ A BERT-CNN caption reranker fine-tuned with a **listwise expected-CIDEr reward**.
18
+ Given the nine beam-search captions of an image and image-context words (objects,
19
+ scene labels), it picks the caption most likely to match human references.
20
+ The model does not read images or generate captions.
21
+
22
+ It starts from the BERT-CNN visual semantic relatedness model of
23
+ [Visual Semantic Relatedness Dataset for Image Captioning](https://openaccess.thecvf.com/content/CVPR2023W/O-DRUM/html/Sabir_Visual_Semantic_Relatedness_Dataset_for_Image_Captioning_CVPRW_2023_paper.html)
24
+ and adds a second training stage. **No new human annotation is used**: the reward
25
+ comes from existing COCO reference captions.
26
+
27
+ **It also improves a recent vision-language model.** Without any retraining, choosing
28
+ among Google's [Gemma 4 12B](https://huggingface.co/google/gemma-4-12B-it) nine beam
29
+ captions raises CIDEr from 0.9624 to 0.9783 (+0.0159 [+0.009, +0.023]) on 5,000 COCO
30
+ test images, and SPICE and BERTScore rise too. Details and examples are under
31
+ [Evaluation](#evaluation).
32
+
33
+ ## Training
34
+
35
+ ![Two-stage training process](training_process.png)
36
+
37
+ **Stage I: relatedness pre-training** (the paper's BERT-CNN). BERT-base with a CNN
38
+ head, trained with binary cross-entropy on the visual semantic relatedness dataset
39
+ (330,790 context/caption pairs, related if the similarity score is at least 0.3).
40
+
41
+ **Stage II: listwise reward fine-tuning** (this model).
42
+
43
+ 1. A frozen BLIP captioner (`Salesforce/blip-image-captioning-base`) writes nine
44
+ beam-search captions for 10,000 COCO training images.
45
+ 2. Each candidate gets a reward `r_k = CIDEr(c_k, references)` against that
46
+ image's COCO human captions.
47
+ 3. The reranking score is `s_k = b_k + w * f(v, c_k)`. Here `f` is the BERT-CNN
48
+ logit, `b_k` is a learned bonus for beam position k, and `w` is a learned weight.
49
+ 4. The model maximizes the exact expected reward over the nine candidates,
50
+ `E_{k ~ softmax(s)}[r_k]`, with the mean reward as baseline. This is a
51
+ policy-gradient objective computed without sampling.
52
+ 5. Training: 4 epochs, 5,000 steps, 8 images (72 captions) per step. Adam
53
+ learning rates are 1e-6 for BERT, 1e-5 for the CNN head and 1e-2 for `b, w`;
54
+ seed 42. It took 407 s on one RTX A5000.
55
+ 6. Selection is on 734 held-out validation images (best validation CIDEr, epoch 4).
56
+ The test sets were run once, after the choice was locked in `protocol_lock.json`.
57
+
58
+ Learned values: beam bonus `b = [2.58, -0.22, -2.62, -3.49, -4.01, -3.78, -5.26,
59
+ -5.89, -6.85]` and `w = 3.20`. The model keeps the first beam unless BERT-CNN is
60
+ confident another candidate is better. It replaces it for 39% of images.
61
+
62
+ ## Usage
63
+
64
+ ```python
65
+ from huggingface_hub import snapshot_download
66
+ import sys
67
+
68
+ path = snapshot_download("AhmedSSabir/BERT-CNN-Reward-Caption-Reranker")
69
+ sys.path.insert(0, path)
70
+ from inference import CaptionReranker
71
+
72
+ reranker = CaptionReranker(path, device="cpu") # "cuda" for a GPU
73
+ beams = [ # exactly nine captions, in beam-search order (best beam first)
74
+ "a white toilet sitting next to a white bath tub",
75
+ "a bathroom with a sink and a toilet",
76
+ "a bathroom with two sinks and a toilet",
77
+ "a white bath tub sitting next to a toilet",
78
+ "a bath room with a toilet and a bath tub",
79
+ "a white bath tub sitting next to a white toilet",
80
+ "a white toilet sitting next to a white sink",
81
+ "a bath room with a toilet a bath tub",
82
+ "a bath room with a toilet a sink and a mirror",
83
+ ]
84
+ best, scores = reranker.rerank("washbasin bathtub sink", beams)
85
+ print(beams[best]) # -> a bathroom with a sink and a toilet
86
+ ```
87
+
88
+ The beam bonus means `rerank` needs the nine captions **in the generator's beam
89
+ order**. For other inputs, `reranker.logits(context, captions)` returns the raw
90
+ BERT-CNN scores.
91
+
92
+ ## Evaluation
93
+
94
+ Paper benchmark: the paper's ViLBERT 9-beam candidates for **5,000 Karpathy test
95
+ images** (45,000 captions). All rows were scored with the same scorers. BERTScore
96
+ in this setup reads about 0.004 higher than the paper's, so compare B-S within
97
+ this table.
98
+
99
+ | Method | BLEU-4 | METEOR | ROUGE-L | CIDEr | SPICE | BERTScore |
100
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
101
+ | Best Beam (beam 1) | **0.3509** | 0.2741 | 0.5573 | 1.1150 | 0.2051 | 0.9406 |
102
+ | Retrained PyTorch BERT-CNN (stage I only) | 0.3258 | 0.2716 | 0.5486 | 1.0855 | 0.2056 | 0.9393 |
103
+ | **This model** | 0.3504 | **0.2794** | **0.5625** | **1.1475** | **0.2119** | **0.9413** |
104
+ <!-- | Paper, best reported row | 0.352 | 0.275 | 0.560 | 1.131 | 0.208 | 0.9366* | -->
105
+
106
+ The BERT-CNN row above chooses among all nine candidates. The two-candidate setting is shown below.
107
+
108
+ Gains over Best Beam, with paired bootstrap 95% intervals over images:
109
+
110
+ | Metric | Gain |
111
+ | --- | --- |
112
+ | CIDEr | **+0.0325 [+0.021, +0.044]** |
113
+ | SPICE | +0.0068 [+0.005, +0.009] |
114
+ | BERTScore | +0.0007 [+0.0004, +0.0010] |
115
+
116
+ Two retrainings with seeds 43 and 44 gave CIDEr 1.1418 and 1.1415. Both are
117
+ significantly above Best Beam.
118
+
119
+ **Two-candidate setting (first two beams only).** On the same 5,000 images, the retrained
120
+ BERT-CNN reaches CIDEr 1.1317 here, close to the paper's reported 1.131, but falls below
121
+ Best Beam with nine candidates. This model improves on Best Beam in both settings.
122
+
123
+ | Method | CIDEr, 2 candidates | CIDEr, 9 candidates |
124
+ | --- | ---: | ---: |
125
+ | Best Beam | 1.1150 | 1.1150 |
126
+ | Retrained PyTorch BERT-CNN | 1.1317 | 1.0855 |
127
+ | **This model** | **1.1383** | **1.1475** |
128
+
129
+ **Ablations on the same benchmark (CIDEr):**
130
+
131
+ | Variant | CIDEr |
132
+ | --- | ---: |
133
+ | Beam bonus only (BERT-CNN frozen, w = 0) | 1.1150 |
134
+ | No beam bonus | 1.1202 |
135
+ | Sentence-similarity reward instead of CIDEr | 1.1236 |
136
+ | CIDEr and similarity mix | 1.1341 |
137
+ | CIDEr reward plus relatedness BCE loss | 1.1384 |
138
+ | **CIDEr reward (this model)** | **1.1475** |
139
+
140
+ **In-domain test:** BLIP 9-beam candidates for the same 5,000 images.
141
+
142
+ | Method | CIDEr |
143
+ | --- | ---: |
144
+ | Best Beam | 1.0632 |
145
+ | This model | **1.1470** (+0.0838 [+0.073, +0.095]) |
146
+
147
+ **Gemma 4 12B candidates.** `google/gemma-4-12B-it`, prompted for a short COCO-style
148
+ caption with nine beams, on the same 5,000 images. This model was not retrained on them.
149
+
150
+ | Method | BLEU-4 | METEOR | ROUGE-L | CIDEr | SPICE | BERTScore |
151
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
152
+ | Gemma 4 12B, beam 1 of 9 | 0.2441 | 0.2739 | 0.5288 | 0.9624 | 0.2248 | 0.9438 |
153
+ | **Gemma 4 12B + this model** | **0.2458** | **0.2766** | **0.5314** | **0.9783** | **0.2267** | **0.9448** |
154
+
155
+ Gains: CIDEr +0.0159 [+0.009, +0.023], SPICE +0.0019 [+0.001, +0.003], BERTScore
156
+ +0.0009 [+0.0007, +0.0012].
157
+
158
+ Gemma 4 examples, CIDEr per caption. The model replaces Gemma's top caption on 1,298 of
159
+ 5,000 images: CIDEr improves on 751, drops on 543 and ties on 4. The rows below are the
160
+ first three improvements and the first drop in a random draw from those images.
161
+
162
+ | Image | Context words | Gemma 4 top caption | This model picks |
163
+ | --- | --- | --- | --- |
164
+ | COCO 27585 | wall clock analog tree | A large black and gold clock stands against a blue sky. (0.70) | **A large ornate clock stands in front of a building. (1.25)** |
165
+ | COCO 320370 | croquet ball soccer tree | A man in a red shirt stands on a green field. (0.61) | **A man in a red shirt stands on a green lawn. (0.70)** |
166
+ | COCO 300233 | mixing bowl corn food | Ingredients and a food processor are arranged on a gray surface. (0.40) | **Ingredients and a food processor are laid out on a table. (0.47)** |
167
+ | COCO 419228 (failure) | ice bear polar | **A white polar bear walks on rocks in an enclosure. (2.54)** | A large white polar bear walks on a rocky surface. (1.85) |
168
+
169
+ **Summary: gain over each captioner's own top beam (CIDEr).**
170
+
171
+ | Captioner | Top beam | + This model | Gain [95% CI] |
172
+ | --- | ---: | ---: | --- |
173
+ | BLIP-base (training captioner) | 1.0632 | 1.1470 | +0.0838 [+0.073, +0.095] |
174
+ | ViLBERT (paper's candidates) | 1.1150 | 1.1475 | +0.0325 [+0.021, +0.044] |
175
+ | Gemma 4 12B | 0.9624 | 0.9783 | +0.0159 [+0.009, +0.023] |
176
+
177
+ ## Examples (ViLBERT candidates, CIDEr per caption)
178
+
179
+ | Image | Best Beam | This model |
180
+ | --- | --- | --- |
181
+ | COCO 460621 | a white toilet sitting next to a white bath tub (0.39) | **a bathroom with a sink and a toilet (0.83)** |
182
+ | COCO 43680 | a group of cows that are standing in the dirt (0.64) | **a herd of cattle walking across a dry field (1.32)** |
183
+ | COCO 424432 | a white and brown dog laying on a bed (0.73) | **a dog laying on a bed with a blanket (0.86)** |
184
+ | COCO 365685 (failure) | **a woman is taking a bite out of a hot dog (0.92)** | a woman sitting at a table eating a hotdog (0.11) |
185
+
186
+ When the model changes the caption (1,948 of 5,000 images), the change improves
187
+ CIDEr 1,110 times and lowers it 838 times.
188
+
189
+ ## Limitations
190
+
191
+ - **Use it as a reranker, not a relatedness classifier.** Reward training shifts
192
+ the scores upward. On the paper's 41,849 held-out relatedness pairs, accuracy at
193
+ the 0.5 cutoff falls from 0.893 to 0.631, and ROC-AUC from 0.962 to 0.937. For
194
+ relatedness probabilities, use the stage I BERT-CNN.
195
+ - Agreement with Flickr8K expert ratings dropped slightly: Spearman 0.365, against
196
+ 0.380 for the stage I model on 5,822 pairs.
197
+ - The beam bonus was learned for 9-beam candidates. Other beam widths may need
198
+ retraining. It was trained on BLIP candidates; gains carry over to ViLBERT and
199
+ Gemma 4 12B candidates but are smaller there.
200
+ - A reranker can only choose among its candidates, so it does not replace a stronger
201
+ captioner. On the same images, COCO-tuned captioners score higher on their own
202
+ (single caption, CIDEr: Florence-2-large-ft 1.445, BLIP-2 OPT-2.7B COCO 1.369). This
203
+ model has not been tested on their candidates.
204
+ - CIDEr rewards exact wording ("hotdog" vs "hot dog"). The reranker cannot fix
205
+ errors shared by all nine candidates.
206
+ - The best validation epoch was the last epoch, so longer training was not explored.
207
+
208
+ The repository includes inference-only weights, the tokenizer, model and inference
209
+ code, training settings, and evaluation results (`evaluation/`).
210
+
211
+ ## Citation
212
+
213
+ ```bibtex
214
+ @InProceedings{Sabir_2023_CVPR,
215
+ author = {Sabir, Ahmed and Moreno-Noguer, Francesc and Padr{\'o}, Llu{\'i}s},
216
+ title = {Visual Semantic Relatedness Dataset for Image Captioning},
217
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
218
+ month = {June},
219
+ year = {2023},
220
+ pages = {5598--5606},
221
+ doi = {10.1109/CVPRW59228.2023.00592},
222
+ url = {https://openaccess.thecvf.com/content/CVPR2023W/O-DRUM/html/Sabir_Visual_Semantic_Relatedness_Dataset_for_Image_Captioning_CVPRW_2023_paper.html}
223
+ }
224
+ ```
config.json ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "VisualRelatednessModel"
4
+ ],
5
+ "model_type": "bert-cnn-caption-reranker",
6
+ "bert_config": {
7
+ "return_dict": true,
8
+ "output_hidden_states": false,
9
+ "dtype": "float32",
10
+ "chunk_size_feed_forward": 0,
11
+ "is_encoder_decoder": false,
12
+ "architectures": [
13
+ "BertForMaskedLM"
14
+ ],
15
+ "id2label": {
16
+ "0": "LABEL_0",
17
+ "1": "LABEL_1"
18
+ },
19
+ "label2id": {
20
+ "LABEL_0": 0,
21
+ "LABEL_1": 1
22
+ },
23
+ "problem_type": null,
24
+ "_name_or_path": "models/bert-base-uncased",
25
+ "transformers_version": "5.3.0",
26
+ "gradient_checkpointing": false,
27
+ "model_type": "bert",
28
+ "position_embedding_type": "absolute",
29
+ "pad_token_id": 0,
30
+ "is_decoder": false,
31
+ "add_cross_attention": false,
32
+ "bos_token_id": null,
33
+ "eos_token_id": null,
34
+ "tie_word_embeddings": true,
35
+ "vocab_size": 30522,
36
+ "hidden_size": 768,
37
+ "num_hidden_layers": 12,
38
+ "num_attention_heads": 12,
39
+ "hidden_act": "gelu",
40
+ "intermediate_size": 3072,
41
+ "hidden_dropout_prob": 0.1,
42
+ "attention_probs_dropout_prob": 0.1,
43
+ "max_position_embeddings": 512,
44
+ "type_vocab_size": 2,
45
+ "initializer_range": 0.02,
46
+ "layer_norm_eps": 1e-12,
47
+ "use_cache": true,
48
+ "classifier_dropout": null,
49
+ "output_attentions": false
50
+ },
51
+ "model_options": {
52
+ "architecture": "bert-cnn",
53
+ "seq_len": 64,
54
+ "cnn_filters": 32,
55
+ "cnn_kernel_size": 3,
56
+ "num_bert_layers": 12,
57
+ "tune_embeddings": false
58
+ },
59
+ "rank_prior": {
60
+ "bias": [
61
+ 2.5842955112457275,
62
+ -0.21887986361980438,
63
+ -2.617722511291504,
64
+ -3.491527795791626,
65
+ -4.005457878112793,
66
+ -3.7829275131225586,
67
+ -5.263741970062256,
68
+ -5.885319709777832,
69
+ -6.846593379974365
70
+ ],
71
+ "weight": 3.2007904052734375
72
+ },
73
+ "score": "bias[beam position] + weight * BERT-CNN logit; beam positions 1..9 in beam-search order"
74
+ }
evaluation/full_metrics.json ADDED
@@ -0,0 +1,440 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "results": {
3
+ "paper_vilbert/first-beam": {
4
+ "metrics": {
5
+ "BLEU_1": 0.7521088640033475,
6
+ "BLEU_4": 0.35091666039484937,
7
+ "METEOR": 0.2740649213423215,
8
+ "ROUGE_L": 0.55730837007525,
9
+ "CIDEr": 1.1149750812231705,
10
+ "SPICE": 0.2051467123007049,
11
+ "BERTScore_F1": 0.9405835866928101
12
+ }
13
+ },
14
+ "paper_vilbert/A2-cider": {
15
+ "metrics": {
16
+ "BLEU_1": 0.7543677420694943,
17
+ "BLEU_4": 0.35038564573334036,
18
+ "METEOR": 0.2794252054355059,
19
+ "ROUGE_L": 0.5624724309601203,
20
+ "CIDEr": 1.1474607323724648,
21
+ "SPICE": 0.2119032114095339,
22
+ "BERTScore_F1": 0.9412955045700073
23
+ },
24
+ "vs_first_beam": {
25
+ "CIDEr": {
26
+ "difference": 0.03248565114929445,
27
+ "ci95": [
28
+ 0.021273590435114172,
29
+ 0.04381817372846462
30
+ ]
31
+ },
32
+ "SPICE": {
33
+ "difference": 0.006756499108828964,
34
+ "ci95": [
35
+ 0.005064563632588412,
36
+ 0.008515563454492548
37
+ ]
38
+ },
39
+ "BERTScore": {
40
+ "difference": 0.0007119835257530212,
41
+ "ci95": [
42
+ 0.0003816543799638748,
43
+ 0.0010461517238616943
44
+ ]
45
+ }
46
+ }
47
+ },
48
+ "paper_vilbert/A2-cider-seed43": {
49
+ "metrics": {
50
+ "BLEU_1": 0.7541702331990072,
51
+ "BLEU_4": 0.34819763235786194,
52
+ "METEOR": 0.2787522418418623,
53
+ "ROUGE_L": 0.5608437344904296,
54
+ "CIDEr": 1.1418308401942123,
55
+ "SPICE": 0.21100101218968775,
56
+ "BERTScore_F1": 0.9412525296211243
57
+ },
58
+ "vs_first_beam": {
59
+ "CIDEr": {
60
+ "difference": 0.026855758971042053,
61
+ "ci95": [
62
+ 0.01573842950042596,
63
+ 0.03774575797807877
64
+ ]
65
+ },
66
+ "SPICE": {
67
+ "difference": 0.005854299888982864,
68
+ "ci95": [
69
+ 0.004230277004097649,
70
+ 0.007545450207437246
71
+ ]
72
+ },
73
+ "BERTScore": {
74
+ "difference": 0.0006690580606460571,
75
+ "ci95": [
76
+ 0.0003416048058867455,
77
+ 0.0010037949207425117
78
+ ]
79
+ }
80
+ }
81
+ },
82
+ "paper_vilbert/A2-cider-seed44": {
83
+ "metrics": {
84
+ "BLEU_1": 0.7536831546611341,
85
+ "BLEU_4": 0.3487910562683307,
86
+ "METEOR": 0.27876933022763234,
87
+ "ROUGE_L": 0.5611273923252967,
88
+ "CIDEr": 1.1415035816492287,
89
+ "SPICE": 0.21069880850916087,
90
+ "BERTScore_F1": 0.941270112991333
91
+ },
92
+ "vs_first_beam": {
93
+ "CIDEr": {
94
+ "difference": 0.026528500426058355,
95
+ "ci95": [
96
+ 0.015461564008056681,
97
+ 0.03719260043088689
98
+ ]
99
+ },
100
+ "SPICE": {
101
+ "difference": 0.005552096208455978,
102
+ "ci95": [
103
+ 0.003921174774884093,
104
+ 0.007217001777398386
105
+ ]
106
+ },
107
+ "BERTScore": {
108
+ "difference": 0.0006866474270820617,
109
+ "ci95": [
110
+ 0.00036229795545339585,
111
+ 0.0010176115068793294
112
+ ]
113
+ }
114
+ }
115
+ },
116
+ "paper_vilbert/A5-cider-bce": {
117
+ "metrics": {
118
+ "BLEU_1": 0.7574909938546143,
119
+ "BLEU_4": 0.3500147832234189,
120
+ "METEOR": 0.2774411435162455,
121
+ "ROUGE_L": 0.5613011089891018,
122
+ "CIDEr": 1.138433173459532,
123
+ "SPICE": 0.2094046320227589,
124
+ "BERTScore_F1": 0.9411762952804565
125
+ },
126
+ "vs_first_beam": {
127
+ "CIDEr": {
128
+ "difference": 0.02345809223636181,
129
+ "ci95": [
130
+ 0.012649300630465888,
131
+ 0.03436401651784764
132
+ ]
133
+ },
134
+ "SPICE": {
135
+ "difference": 0.004257919722053996,
136
+ "ci95": [
137
+ 0.002680062928676328,
138
+ 0.005822506461482289
139
+ ]
140
+ },
141
+ "BERTScore": {
142
+ "difference": 0.0005927220940589905,
143
+ "ci95": [
144
+ 0.0002773158437013626,
145
+ 0.0009150636693835257
146
+ ]
147
+ }
148
+ }
149
+ },
150
+ "paper_vilbert/A3-similarity": {
151
+ "metrics": {
152
+ "BLEU_1": 0.7567390153520221,
153
+ "BLEU_4": 0.34532203526619026,
154
+ "METEOR": 0.2746760806523903,
155
+ "ROUGE_L": 0.5581204003716966,
156
+ "CIDEr": 1.1236317100690412,
157
+ "SPICE": 0.20939972263298126,
158
+ "BERTScore_F1": 0.9409727454185486
159
+ },
160
+ "vs_first_beam": {
161
+ "CIDEr": {
162
+ "difference": 0.008656628845870942,
163
+ "ci95": [
164
+ -0.005240936708872434,
165
+ 0.022294550429155506
166
+ ]
167
+ },
168
+ "SPICE": {
169
+ "difference": 0.004253010332276365,
170
+ "ci95": [
171
+ 0.0021455036363641974,
172
+ 0.006455195285110698
173
+ ]
174
+ },
175
+ "BERTScore": {
176
+ "difference": 0.00038920217752456667,
177
+ "ci95": [
178
+ -5.482336878776545e-06,
179
+ 0.0007888154581189152
180
+ ]
181
+ }
182
+ }
183
+ },
184
+ "paper_vilbert/A4-mix": {
185
+ "metrics": {
186
+ "BLEU_1": 0.7548203516520693,
187
+ "BLEU_4": 0.34916432806093023,
188
+ "METEOR": 0.27727195666860444,
189
+ "ROUGE_L": 0.5599557599251835,
190
+ "CIDEr": 1.1340847222949046,
191
+ "SPICE": 0.20926844383712132,
192
+ "BERTScore_F1": 0.9410042762756348
193
+ },
194
+ "vs_first_beam": {
195
+ "CIDEr": {
196
+ "difference": 0.019109641071734386,
197
+ "ci95": [
198
+ 0.00842330897878974,
199
+ 0.029478617264110704
200
+ ]
201
+ },
202
+ "SPICE": {
203
+ "difference": 0.004121731536416366,
204
+ "ci95": [
205
+ 0.0025829483501072035,
206
+ 0.005695482341309813
207
+ ]
208
+ },
209
+ "BERTScore": {
210
+ "difference": 0.0004207610845565796,
211
+ "ci95": [
212
+ 0.00011979014217853545,
213
+ 0.0007201787564158439
214
+ ]
215
+ }
216
+ }
217
+ },
218
+ "paper_vilbert/A2b-cider-no-position": {
219
+ "metrics": {
220
+ "BLEU_1": 0.7349882653742538,
221
+ "BLEU_4": 0.3279217603767499,
222
+ "METEOR": 0.28095047529732425,
223
+ "ROUGE_L": 0.556251651422652,
224
+ "CIDEr": 1.1201967590087958,
225
+ "SPICE": 0.21534489968484521,
226
+ "BERTScore_F1": 0.9401296973228455
227
+ },
228
+ "vs_first_beam": {
229
+ "CIDEr": {
230
+ "difference": 0.005221677785625393,
231
+ "ci95": [
232
+ -0.010827136039780402,
233
+ 0.021138612213461378
234
+ ]
235
+ },
236
+ "SPICE": {
237
+ "difference": 0.010198187384140286,
238
+ "ci95": [
239
+ 0.007624108874537086,
240
+ 0.012760126964106425
241
+ ]
242
+ },
243
+ "BERTScore": {
244
+ "difference": -0.0004538540959358215,
245
+ "ci95": [
246
+ -0.0009028402432799339,
247
+ -9.768431782722619e-06
248
+ ]
249
+ }
250
+ }
251
+ },
252
+ "paper_vilbert/unchanged-bert-cnn": {
253
+ "metrics": {
254
+ "BLEU_1": 0.7402983239765452,
255
+ "BLEU_4": 0.3258168163635417,
256
+ "METEOR": 0.27156185747101835,
257
+ "ROUGE_L": 0.5485864278264938,
258
+ "CIDEr": 1.085457625454499,
259
+ "SPICE": 0.20556140379403381,
260
+ "BERTScore_F1": 0.9393018484115601
261
+ },
262
+ "vs_first_beam": {
263
+ "CIDEr": {
264
+ "difference": -0.029517455768671607,
265
+ "ci95": [
266
+ -0.045417418545184024,
267
+ -0.013603843796331073
268
+ ]
269
+ },
270
+ "SPICE": {
271
+ "difference": 0.00041469149332888405,
272
+ "ci95": [
273
+ -0.002018283043677736,
274
+ 0.0029015339359160126
275
+ ]
276
+ },
277
+ "BERTScore": {
278
+ "difference": -0.00128170405626297,
279
+ "ci95": [
280
+ -0.001723966481089592,
281
+ -0.0008351772513985635
282
+ ]
283
+ }
284
+ }
285
+ },
286
+ "blip_in_domain/first-beam": {
287
+ "metrics": {
288
+ "BLEU_1": 0.6972557211045558,
289
+ "BLEU_4": 0.338047272629492,
290
+ "METEOR": 0.25417657356781453,
291
+ "ROUGE_L": 0.5347548020857551,
292
+ "CIDEr": 1.0631640320236824,
293
+ "SPICE": 0.19848560541377797,
294
+ "BERTScore_F1": 0.9363407492637634
295
+ }
296
+ },
297
+ "blip_in_domain/unchanged-bert-cnn": {
298
+ "metrics": {
299
+ "BLEU_1": 0.6927075614451419,
300
+ "BLEU_4": 0.31308187825193373,
301
+ "METEOR": 0.24749698021813377,
302
+ "ROUGE_L": 0.5309808503782891,
303
+ "CIDEr": 1.0020373032616425,
304
+ "SPICE": 0.1886035723550942,
305
+ "BERTScore_F1": 0.9362419843673706
306
+ },
307
+ "vs_first_beam": {
308
+ "CIDEr": {
309
+ "difference": -0.06112672876203984,
310
+ "ci95": [
311
+ -0.07703248993243476,
312
+ -0.04466810364650549
313
+ ]
314
+ },
315
+ "SPICE": {
316
+ "difference": -0.009882033058683756,
317
+ "ci95": [
318
+ -0.012468651209439591,
319
+ -0.007370175182655841
320
+ ]
321
+ },
322
+ "BERTScore": {
323
+ "difference": -9.878027776721865e-05,
324
+ "ci95": [
325
+ -0.0006621658074436709,
326
+ 0.00047508578209090043
327
+ ]
328
+ }
329
+ }
330
+ },
331
+ "blip_in_domain/A2-cider": {
332
+ "metrics": {
333
+ "BLEU_1": 0.7451779342194806,
334
+ "BLEU_4": 0.36119635247762377,
335
+ "METEOR": 0.26878435097515646,
336
+ "ROUGE_L": 0.564238028759961,
337
+ "CIDEr": 1.1469812911562853,
338
+ "SPICE": 0.2090844645720823,
339
+ "BERTScore_F1": 0.9410110116004944
340
+ },
341
+ "vs_first_beam": {
342
+ "CIDEr": {
343
+ "difference": 0.08381725913260307,
344
+ "ci95": [
345
+ 0.07264195855986173,
346
+ 0.0950220839363521
347
+ ]
348
+ },
349
+ "SPICE": {
350
+ "difference": 0.010598859158304288,
351
+ "ci95": [
352
+ 0.008764631329274094,
353
+ 0.012371659436999622
354
+ ]
355
+ },
356
+ "BERTScore": {
357
+ "difference": 0.004670334048569202,
358
+ "ci95": [
359
+ 0.0042247722623869775,
360
+ 0.005140163039322942
361
+ ]
362
+ }
363
+ }
364
+ },
365
+ "blip_in_domain/A3-similarity": {
366
+ "metrics": {
367
+ "BLEU_1": 0.7270299442143029,
368
+ "BLEU_4": 0.3501662789530852,
369
+ "METEOR": 0.2629617379523437,
370
+ "ROUGE_L": 0.5606769902901408,
371
+ "CIDEr": 1.112112593182917,
372
+ "SPICE": 0.2037673968122235,
373
+ "BERTScore_F1": 0.9406426548957825
374
+ },
375
+ "vs_first_beam": {
376
+ "CIDEr": {
377
+ "difference": 0.04894856115923462,
378
+ "ci95": [
379
+ 0.03589291862594552,
380
+ 0.06221725785689125
381
+ ]
382
+ },
383
+ "SPICE": {
384
+ "difference": 0.005281791398445559,
385
+ "ci95": [
386
+ 0.0031942825409635583,
387
+ 0.007364935030469625
388
+ ]
389
+ },
390
+ "BERTScore": {
391
+ "difference": 0.004301912151277065,
392
+ "ci95": [
393
+ 0.003804747149115428,
394
+ 0.0048193004098720845
395
+ ]
396
+ }
397
+ }
398
+ },
399
+ "blip_in_domain/A5-cider-bce": {
400
+ "metrics": {
401
+ "BLEU_1": 0.7327806336397135,
402
+ "BLEU_4": 0.35607684672554313,
403
+ "METEOR": 0.26600139071984985,
404
+ "ROUGE_L": 0.5605545245545978,
405
+ "CIDEr": 1.1298572297403193,
406
+ "SPICE": 0.2070218030565185,
407
+ "BERTScore_F1": 0.940541684627533
408
+ },
409
+ "vs_first_beam": {
410
+ "CIDEr": {
411
+ "difference": 0.06669319771663691,
412
+ "ci95": [
413
+ 0.056269795137920055,
414
+ 0.07739607247334784
415
+ ]
416
+ },
417
+ "SPICE": {
418
+ "difference": 0.008536197642740549,
419
+ "ci95": [
420
+ 0.006805229287105627,
421
+ 0.010291442021231376
422
+ ]
423
+ },
424
+ "BERTScore": {
425
+ "difference": 0.004200989380478859,
426
+ "ci95": [
427
+ 0.0037530666100792586,
428
+ 0.004658673680387437
429
+ ]
430
+ }
431
+ }
432
+ }
433
+ },
434
+ "settings": {
435
+ "spice": "SPICE 1.0 with Stanford CoreNLP 3.6.0 jars from Maven Central (SHA1 verified)",
436
+ "bertscore": "bert-score 0.3.12 default lang=en (roberta-large, layer 17), no baseline rescaling",
437
+ "bootstrap": "Paired image bootstrap, 5,000 resamples, seed 42, vs BLIP/ViLBERT first beam",
438
+ "note": "BERTScore setup reads ~.0043 higher than the paper; compare only within measured rows"
439
+ }
440
+ }
evaluation/gemma_and_vlm_comparison.json ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metrics": {
3
+ "ViLBERT Best Beam": {
4
+ "BLEU_4": 0.35091666039484937,
5
+ "METEOR": 0.2740649213423215,
6
+ "ROUGE_L": 0.55730837007525,
7
+ "CIDEr": 1.1149750812231705,
8
+ "SPICE": 0.2051467123007049,
9
+ "BERTScore_F1": 0.9405835866928101,
10
+ "mean_words": 9.1796
11
+ },
12
+ "ViLBERT + A2 (ours)": {
13
+ "BLEU_4": 0.35038564573334036,
14
+ "METEOR": 0.2794252054355059,
15
+ "ROUGE_L": 0.5624724309601203,
16
+ "CIDEr": 1.1474607323724648,
17
+ "SPICE": 0.2119032114095339,
18
+ "BERTScore_F1": 0.9412955045700073,
19
+ "mean_words": 9.6274
20
+ },
21
+ "BLIP-2 OPT-2.7B COCO": {
22
+ "BLEU_4": 0.3862458128519228,
23
+ "METEOR": 0.3252341585718044,
24
+ "ROUGE_L": 0.6020429155974029,
25
+ "CIDEr": 1.3685444875585508,
26
+ "SPICE": 0.2641478228572063,
27
+ "BERTScore_F1": 0.9444411993026733,
28
+ "mean_words": 11.6696
29
+ },
30
+ "Florence-2-large-ft": {
31
+ "BLEU_4": 0.42243857648216,
32
+ "METEOR": 0.32188081326994167,
33
+ "ROUGE_L": 0.6207980047969944,
34
+ "CIDEr": 1.4448625795131615,
35
+ "SPICE": 0.2550894769489606,
36
+ "BERTScore_F1": 0.9556063413619995,
37
+ "mean_words": 10.055
38
+ },
39
+ "Gemma 4 E4B (zero-shot)": {
40
+ "BLEU_4": 0.109240804552885,
41
+ "METEOR": 0.2113076616746602,
42
+ "ROUGE_L": 0.38943483455116296,
43
+ "CIDEr": 0.560079221150841,
44
+ "SPICE": 0.16178991806070883,
45
+ "BERTScore_F1": 0.9236863255500793,
46
+ "mean_words": 10.772
47
+ },
48
+ "Qwen3-VL-8B (zero-shot)": {
49
+ "BLEU_4": 0.06354880080686207,
50
+ "METEOR": 0.18518010584127706,
51
+ "ROUGE_L": 0.3322120766909865,
52
+ "CIDEr": 0.5618697822651968,
53
+ "SPICE": 0.15514823383328552,
54
+ "BERTScore_F1": 0.9217654466629028,
55
+ "mean_words": 7.3616
56
+ },
57
+ "Gemma 4 12B (zero-shot, greedy)": {
58
+ "BLEU_4": 0.24380978792462132,
59
+ "METEOR": 0.27256350667214235,
60
+ "ROUGE_L": 0.5261398569037006,
61
+ "CIDEr": 0.9562139589487022,
62
+ "SPICE": 0.2214717292342159,
63
+ "BERTScore_F1": 0.9435825943946838,
64
+ "mean_words": 10.271
65
+ },
66
+ "Gemma 4 12B beam 1 of 9": {
67
+ "BLEU_4": 0.24409278788324099,
68
+ "METEOR": 0.2738550825613708,
69
+ "ROUGE_L": 0.5287699088241975,
70
+ "CIDEr": 0.9623679515257382,
71
+ "SPICE": 0.22482969816240064,
72
+ "BERTScore_F1": 0.943812906742096,
73
+ "mean_words": 10.3198
74
+ },
75
+ "Gemma 4 12B 9 beams + A2 (ours)": {
76
+ "BLEU_4": 0.24581472152086295,
77
+ "METEOR": 0.2766367555281066,
78
+ "ROUGE_L": 0.5314083384677266,
79
+ "CIDEr": 0.9783124903219313,
80
+ "SPICE": 0.22673098761384544,
81
+ "BERTScore_F1": 0.9447519779205322,
82
+ "mean_words": 10.3418
83
+ }
84
+ },
85
+ "comparisons": {
86
+ "Gemma 4 12B 9 beams + A2 (ours) minus Gemma 4 12B beam 1 of 9": {
87
+ "CIDEr": {
88
+ "difference": 0.015944538796193192,
89
+ "ci95": [
90
+ 0.009364214746043575,
91
+ 0.022649274661504473
92
+ ]
93
+ },
94
+ "SPICE": {
95
+ "difference": 0.0019012894514447694,
96
+ "ci95": [
97
+ 0.0005711566383379341,
98
+ 0.0032189657388873383
99
+ ]
100
+ },
101
+ "BERTScore": {
102
+ "difference": 0.0009390871855430305,
103
+ "ci95": [
104
+ 0.0007185192793258466,
105
+ 0.0011615596245974301
106
+ ]
107
+ }
108
+ },
109
+ "Gemma 4 12B 9 beams + A2 (ours) minus Gemma 4 12B (zero-shot, greedy)": {
110
+ "CIDEr": {
111
+ "difference": 0.022098531373229098,
112
+ "ci95": [
113
+ 0.013750467393457097,
114
+ 0.030295849759610863
115
+ ]
116
+ },
117
+ "SPICE": {
118
+ "difference": 0.0052592583796295354,
119
+ "ci95": [
120
+ 0.0035891084982392677,
121
+ 0.006910753706294941
122
+ ]
123
+ },
124
+ "BERTScore": {
125
+ "difference": 0.0011693264823406935,
126
+ "ci95": [
127
+ 0.000907752315106336,
128
+ 0.001438536663772538
129
+ ]
130
+ }
131
+ }
132
+ },
133
+ "a2_changed_beam1": 1298,
134
+ "bootstrap": "paired image bootstrap, 10,000 resamples, seed 42",
135
+ "note": "All systems scored with the same PTB tokenizer, pycocoevalcap 1.2, SPICE 1.0, bert-score 0.3.12 roberta-large"
136
+ }
evaluation/history.json ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "epoch": 0,
4
+ "step": 0,
5
+ "loss": null,
6
+ "validation": {
7
+ "images": 734,
8
+ "cider": 1.1346124596125913,
9
+ "first_position_fraction": 0.8160762942779292,
10
+ "similarity": 0.5949951588767467,
11
+ "bias": [
12
+ -1.8657495975494385,
13
+ -2.0072312355041504,
14
+ -2.1180338859558105,
15
+ -2.2044894695281982,
16
+ -2.1884660720825195,
17
+ -2.2376866340637207,
18
+ -2.351823329925537,
19
+ -2.4379560947418213,
20
+ -2.53885555267334
21
+ ],
22
+ "weight": 0.10000000149011612
23
+ }
24
+ },
25
+ {
26
+ "epoch": 1,
27
+ "step": 1250,
28
+ "loss": -0.1353437490489334,
29
+ "validation": {
30
+ "images": 734,
31
+ "cider": 1.1553391954544343,
32
+ "first_position_fraction": 0.782016348773842,
33
+ "similarity": 0.6018881397956236,
34
+ "bias": [
35
+ 1.1036248207092285,
36
+ -1.0918254852294922,
37
+ -2.418034553527832,
38
+ -2.864823818206787,
39
+ -3.2561841011047363,
40
+ -3.239999532699585,
41
+ -3.7660140991210938,
42
+ -4.425673007965088,
43
+ -4.671413898468018
44
+ ],
45
+ "weight": 1.2252278327941895
46
+ }
47
+ },
48
+ {
49
+ "epoch": 2,
50
+ "step": 2500,
51
+ "loss": -0.188206138927117,
52
+ "validation": {
53
+ "images": 734,
54
+ "cider": 1.1667432830358435,
55
+ "first_position_fraction": 0.7016348773841962,
56
+ "similarity": 0.6042576148923314,
57
+ "bias": [
58
+ 1.7062114477157593,
59
+ -0.7172172665596008,
60
+ -2.6066951751708984,
61
+ -3.059556245803833,
62
+ -3.646683692932129,
63
+ -3.4505269527435303,
64
+ -4.242111682891846,
65
+ -5.089768886566162,
66
+ -5.408341884613037
67
+ ],
68
+ "weight": 1.9742474555969238
69
+ }
70
+ },
71
+ {
72
+ "epoch": 3,
73
+ "step": 3750,
74
+ "loss": -0.21721196895763278,
75
+ "validation": {
76
+ "images": 734,
77
+ "cider": 1.1802293056274897,
78
+ "first_position_fraction": 0.6444141689373297,
79
+ "similarity": 0.6067765879797513,
80
+ "bias": [
81
+ 2.1147305965423584,
82
+ -0.6355664134025574,
83
+ -2.3752055168151855,
84
+ -3.2914059162139893,
85
+ -3.9347314834594727,
86
+ -3.4727468490600586,
87
+ -4.861271381378174,
88
+ -5.379321098327637,
89
+ -5.98567008972168
90
+ ],
91
+ "weight": 2.6366775035858154
92
+ }
93
+ },
94
+ {
95
+ "epoch": 4,
96
+ "step": 5000,
97
+ "loss": -0.23870838665664196,
98
+ "validation": {
99
+ "images": 734,
100
+ "cider": 1.1857390925346636,
101
+ "first_position_fraction": 0.5980926430517711,
102
+ "similarity": 0.6068402878046848,
103
+ "bias": [
104
+ 2.5842955112457275,
105
+ -0.21887986361980438,
106
+ -2.617722511291504,
107
+ -3.491527795791626,
108
+ -4.005457878112793,
109
+ -3.7829275131225586,
110
+ -5.263741970062256,
111
+ -5.885319709777832,
112
+ -6.846593379974365
113
+ ],
114
+ "weight": 3.2007904052734375
115
+ }
116
+ }
117
+ ]
evaluation/human_metrics.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dataset": "Original Flickr8K ExpertAnnotations.txt",
3
+ "pairs": 5822,
4
+ "images": 1000,
5
+ "checkpoint_sha256": "125a083e3258b7ee038b6fb3e9d40a2d6078e2a325fbc1c4ba9cd062e674daaf",
6
+ "metrics": {
7
+ "clipscore_vit_b32": {
8
+ "examples": 5822,
9
+ "spearman": 0.7273458253579359,
10
+ "kendall_tau_b": 0.5760866201430647,
11
+ "kendall_tau_c": 0.5631096474308253,
12
+ "pearson": 0.7484619266030074
13
+ },
14
+ "bert_cnn_resnet152": {
15
+ "examples": 5822,
16
+ "spearman": 0.23897661511730053,
17
+ "kendall_tau_b": 0.17511563484276757,
18
+ "kendall_tau_c": 0.17116331913460656,
19
+ "pearson": 0.20429245894996126,
20
+ "normalized_human_mae": 0.47293288321293026,
21
+ "empty_image_contexts": 218
22
+ },
23
+ "bert_cnn_clip_imagenet": {
24
+ "examples": 5822,
25
+ "spearman": 0.23477193485123116,
26
+ "kendall_tau_b": 0.1718365123138481,
27
+ "kendall_tau_c": 0.1679471771227406,
28
+ "pearson": 0.19951677072314783,
29
+ "normalized_human_mae": 0.5044658286184057,
30
+ "empty_image_contexts": 386
31
+ },
32
+ "bert_cnn_combined": {
33
+ "examples": 5822,
34
+ "spearman": 0.3646498307040494,
35
+ "kendall_tau_b": 0.2680415373382081,
36
+ "kendall_tau_c": 0.2620033341773608,
37
+ "pearson": 0.3111999615665536,
38
+ "normalized_human_mae": 0.4910941707480373,
39
+ "empty_image_contexts": 0
40
+ }
41
+ },
42
+ "protocol": "Original mean human ratings; three fixed image-only context policies; no tuning on human ratings",
43
+ "limitations": [
44
+ "Visual extractors differ from training-data extraction; not original-paper replication",
45
+ "Normalized-human MAE is descriptive; binary-trained outputs are not calibrated human ratings",
46
+ "Image-context ablations share test data and are not independent validation sets"
47
+ ]
48
+ }
evaluation/paper_benchmark_captions.json ADDED
The diff for this file is too large to render. See raw diff
 
evaluation/protocol_lock.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "primary": "A2-cider",
3
+ "chosen_by": "Highest validation CIDEr among A1-A5 (seed 42)",
4
+ "validation": {
5
+ "A1-position-only": 1.0956471906954763,
6
+ "A2-cider": 1.1857390925346636,
7
+ "A2b-cider-no-position": 1.1615941578373485,
8
+ "A3-similarity": 1.1592443408076532,
9
+ "A4-mix": 1.1657679601285866,
10
+ "A5-cider-bce": 1.1711880370556262,
11
+ "A2-cider-seed43": 1.1881012105843036,
12
+ "A2-cider-seed44": 1.1880342239140615
13
+ },
14
+ "checkpoint_sha256": {
15
+ "A1-position-only": "c3278c3aa61f17418d29c9b2c0ba696b3d74f16074fcc54340268f668592d9b8",
16
+ "A2-cider": "125a083e3258b7ee038b6fb3e9d40a2d6078e2a325fbc1c4ba9cd062e674daaf",
17
+ "A2b-cider-no-position": "3720f77ee52582b874abffa9938985cfa2d91dcd0020deeb316ef626d05e58ba",
18
+ "A3-similarity": "61036c2c8bd26b7435b377b5f292164b1b6b3e49873a039d50c7438dbc946568",
19
+ "A4-mix": "b2667143f649eef812d08feee3152d18a12e5a0707cdad415254093134842c12",
20
+ "A5-cider-bce": "cda5ffe3d0922b59a8416337ea5ee17a611f24e78c3690529048bd887e8a0571",
21
+ "A2-cider-seed43": "44f2511e10b1f6563a9a60e467910ccde6d79ebce9a9efce69cc9b5b8b8ae080",
22
+ "A2-cider-seed44": "06035f683b04f457af3afbd0bc2ed7610e91aa5a98db60c651d84ec30117ac52"
23
+ },
24
+ "locked_before_test": true,
25
+ "time": "2026-11-07 19:59:47 UTC"
26
+ }
evaluation/relatedness_test.metrics.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "examples": 41849,
3
+ "accuracy": 0.6314368324213243,
4
+ "precision": 0.6065205171444632,
5
+ "recall": 0.9989899840080801,
6
+ "f1": 0.7547853736089031,
7
+ "roc_auc": 0.9372219351550691,
8
+ "binary_cross_entropy": 1.308156706740762,
9
+ "threshold": 0.5,
10
+ "confusion_matrix": [
11
+ [
12
+ 2687,
13
+ 15400
14
+ ],
15
+ [
16
+ 24,
17
+ 23738
18
+ ]
19
+ ]
20
+ }
evaluation/test_results.json ADDED
@@ -0,0 +1,445 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "primary": "A2-cider",
3
+ "tests": {
4
+ "paper_vilbert": {
5
+ "images": 5000,
6
+ "oracle_cider": 1.6182621834020914,
7
+ "metrics": {
8
+ "first-beam": {
9
+ "BLEU_1": 0.7521088640033475,
10
+ "BLEU_2": 0.591623450790047,
11
+ "BLEU_3": 0.4557287535721338,
12
+ "BLEU_4": 0.35091666039484937,
13
+ "CIDEr": 1.1149750812231705,
14
+ "first_position_fraction": 1.0
15
+ },
16
+ "unchanged-bert-cnn": {
17
+ "BLEU_1": 0.7402983239765452,
18
+ "BLEU_2": 0.5757457487950892,
19
+ "BLEU_3": 0.4342284148485376,
20
+ "BLEU_4": 0.3258168163635417,
21
+ "CIDEr": 1.0854576254544988,
22
+ "first_position_fraction": 0.1234
23
+ },
24
+ "A1-position-only": {
25
+ "BLEU_1": 0.7521088640033475,
26
+ "BLEU_2": 0.591623450790047,
27
+ "BLEU_3": 0.4557287535721338,
28
+ "BLEU_4": 0.35091666039484937,
29
+ "CIDEr": 1.1149750812231705,
30
+ "first_position_fraction": 1.0
31
+ },
32
+ "A2-cider": {
33
+ "BLEU_1": 0.7543677420694943,
34
+ "BLEU_2": 0.5953936138426826,
35
+ "BLEU_3": 0.4569996763225077,
36
+ "BLEU_4": 0.35038564573334036,
37
+ "CIDEr": 1.1474607323724648,
38
+ "first_position_fraction": 0.6104
39
+ },
40
+ "A2b-cider-no-position": {
41
+ "BLEU_1": 0.7349882653742538,
42
+ "BLEU_2": 0.574064632808988,
43
+ "BLEU_3": 0.4349227793617935,
44
+ "BLEU_4": 0.3279217603767499,
45
+ "CIDEr": 1.1201967590087958,
46
+ "first_position_fraction": 0.0792
47
+ },
48
+ "A3-similarity": {
49
+ "BLEU_1": 0.7567390153520221,
50
+ "BLEU_2": 0.5967878186289933,
51
+ "BLEU_3": 0.4553340280166201,
52
+ "BLEU_4": 0.34532203526619026,
53
+ "CIDEr": 1.1236317100690412,
54
+ "first_position_fraction": 0.4184
55
+ },
56
+ "A4-mix": {
57
+ "BLEU_1": 0.7548203516520693,
58
+ "BLEU_2": 0.5943072626591133,
59
+ "BLEU_3": 0.4557471546473046,
60
+ "BLEU_4": 0.34916432806093023,
61
+ "CIDEr": 1.1340847222949046,
62
+ "first_position_fraction": 0.6976
63
+ },
64
+ "A5-cider-bce": {
65
+ "BLEU_1": 0.7574909938546143,
66
+ "BLEU_2": 0.5972567267723976,
67
+ "BLEU_3": 0.45769277436880385,
68
+ "BLEU_4": 0.3500147832234189,
69
+ "CIDEr": 1.138433173459532,
70
+ "first_position_fraction": 0.6734
71
+ },
72
+ "A2-cider-seed43": {
73
+ "BLEU_1": 0.7541702331990072,
74
+ "BLEU_2": 0.594308423725063,
75
+ "BLEU_3": 0.4552943668707535,
76
+ "BLEU_4": 0.34819763235786194,
77
+ "CIDEr": 1.141830840194212,
78
+ "first_position_fraction": 0.6404
79
+ },
80
+ "A2-cider-seed44": {
81
+ "BLEU_1": 0.7536831546611341,
82
+ "BLEU_2": 0.5939024570607181,
83
+ "BLEU_3": 0.4554360547642447,
84
+ "BLEU_4": 0.3487910562683307,
85
+ "CIDEr": 1.1415035816492287,
86
+ "first_position_fraction": 0.649
87
+ }
88
+ },
89
+ "paired_cider": {
90
+ "A1-position-only": {
91
+ "first-beam": {
92
+ "difference": 0.0,
93
+ "ci95": [
94
+ 0.0,
95
+ 0.0
96
+ ]
97
+ },
98
+ "unchanged-bert-cnn": {
99
+ "difference": 0.029517455768671607,
100
+ "ci95": [
101
+ 0.013393474718649963,
102
+ 0.045857509258577636
103
+ ]
104
+ }
105
+ },
106
+ "A2-cider": {
107
+ "first-beam": {
108
+ "difference": 0.03248565114929444,
109
+ "ci95": [
110
+ 0.021257191765305255,
111
+ 0.043816346383125496
112
+ ]
113
+ },
114
+ "unchanged-bert-cnn": {
115
+ "difference": 0.06200310691796606,
116
+ "ci95": [
117
+ 0.04885120969712054,
118
+ 0.07502684445185444
119
+ ]
120
+ }
121
+ },
122
+ "A2b-cider-no-position": {
123
+ "first-beam": {
124
+ "difference": 0.005221677785625393,
125
+ "ci95": [
126
+ -0.010528698602534392,
127
+ 0.021006286338626806
128
+ ]
129
+ },
130
+ "unchanged-bert-cnn": {
131
+ "difference": 0.03473913355429701,
132
+ "ci95": [
133
+ 0.022716135169115907,
134
+ 0.04680816402302316
135
+ ]
136
+ }
137
+ },
138
+ "A3-similarity": {
139
+ "first-beam": {
140
+ "difference": 0.008656628845870939,
141
+ "ci95": [
142
+ -0.005162178870035752,
143
+ 0.022361781396491313
144
+ ]
145
+ },
146
+ "unchanged-bert-cnn": {
147
+ "difference": 0.03817408461454255,
148
+ "ci95": [
149
+ 0.026284460869596557,
150
+ 0.050244014037753415
151
+ ]
152
+ }
153
+ },
154
+ "A4-mix": {
155
+ "first-beam": {
156
+ "difference": 0.01910964107173439,
157
+ "ci95": [
158
+ 0.008700685679583426,
159
+ 0.02960173203844372
160
+ ]
161
+ },
162
+ "unchanged-bert-cnn": {
163
+ "difference": 0.048627096840406,
164
+ "ci95": [
165
+ 0.03582370057655935,
166
+ 0.0611321669986398
167
+ ]
168
+ }
169
+ },
170
+ "A5-cider-bce": {
171
+ "first-beam": {
172
+ "difference": 0.02345809223636181,
173
+ "ci95": [
174
+ 0.012693902384894774,
175
+ 0.03436222518224583
176
+ ]
177
+ },
178
+ "unchanged-bert-cnn": {
179
+ "difference": 0.05297554800503342,
180
+ "ci95": [
181
+ 0.04007371819842809,
182
+ 0.06584487452205912
183
+ ]
184
+ }
185
+ },
186
+ "A2-cider-seed43": {
187
+ "first-beam": {
188
+ "difference": 0.026855758971042046,
189
+ "ci95": [
190
+ 0.015854291701270503,
191
+ 0.037843832407025886
192
+ ]
193
+ },
194
+ "unchanged-bert-cnn": {
195
+ "difference": 0.05637321473971365,
196
+ "ci95": [
197
+ 0.04363054530483112,
198
+ 0.06932505081453445
199
+ ]
200
+ }
201
+ },
202
+ "A2-cider-seed44": {
203
+ "first-beam": {
204
+ "difference": 0.02652850042605835,
205
+ "ci95": [
206
+ 0.01569128166699668,
207
+ 0.03741393660479623
208
+ ]
209
+ },
210
+ "unchanged-bert-cnn": {
211
+ "difference": 0.056045956194729955,
212
+ "ci95": [
213
+ 0.04295636498490685,
214
+ 0.0689257872719245
215
+ ]
216
+ }
217
+ }
218
+ }
219
+ },
220
+ "blip_in_domain": {
221
+ "images": 5000,
222
+ "oracle_cider": 1.5192155611503675,
223
+ "metrics": {
224
+ "first-beam": {
225
+ "BLEU_1": 0.6972557211045558,
226
+ "BLEU_2": 0.5589953953306551,
227
+ "BLEU_3": 0.4375854037004591,
228
+ "BLEU_4": 0.338047272629492,
229
+ "CIDEr": 1.0631640320236821,
230
+ "first_position_fraction": 1.0
231
+ },
232
+ "unchanged-bert-cnn": {
233
+ "BLEU_1": 0.6927075614451419,
234
+ "BLEU_2": 0.5467138200318495,
235
+ "BLEU_3": 0.41722106465653414,
236
+ "BLEU_4": 0.31308187825193373,
237
+ "CIDEr": 1.0020373032616423,
238
+ "first_position_fraction": 0.1024
239
+ },
240
+ "A1-position-only": {
241
+ "BLEU_1": 0.6972557211045558,
242
+ "BLEU_2": 0.5589953953306551,
243
+ "BLEU_3": 0.4375854037004591,
244
+ "BLEU_4": 0.338047272629492,
245
+ "CIDEr": 1.0631640320236821,
246
+ "first_position_fraction": 1.0
247
+ },
248
+ "A2-cider": {
249
+ "BLEU_1": 0.7451779342194806,
250
+ "BLEU_2": 0.602038711524827,
251
+ "BLEU_3": 0.47015388585036233,
252
+ "BLEU_4": 0.36119635247762377,
253
+ "CIDEr": 1.1469812911562853,
254
+ "first_position_fraction": 0.597
255
+ },
256
+ "A2b-cider-no-position": {
257
+ "BLEU_1": 0.7492076721661279,
258
+ "BLEU_2": 0.6001318679611358,
259
+ "BLEU_3": 0.4626851747509669,
260
+ "BLEU_4": 0.3497497264938604,
261
+ "CIDEr": 1.1210157484672216,
262
+ "first_position_fraction": 0.1508
263
+ },
264
+ "A3-similarity": {
265
+ "BLEU_1": 0.7270299442143029,
266
+ "BLEU_2": 0.5884846320744176,
267
+ "BLEU_3": 0.4578148682664639,
268
+ "BLEU_4": 0.3501662789530852,
269
+ "CIDEr": 1.1121125931829168,
270
+ "first_position_fraction": 0.419
271
+ },
272
+ "A4-mix": {
273
+ "BLEU_1": 0.7241440818235776,
274
+ "BLEU_2": 0.5832507254587247,
275
+ "BLEU_3": 0.4542950873251976,
276
+ "BLEU_4": 0.3483276836523094,
277
+ "CIDEr": 1.1075998944881613,
278
+ "first_position_fraction": 0.6734
279
+ },
280
+ "A5-cider-bce": {
281
+ "BLEU_1": 0.7327806336397135,
282
+ "BLEU_2": 0.5927275276644527,
283
+ "BLEU_3": 0.46321467684746426,
284
+ "BLEU_4": 0.35607684672554313,
285
+ "CIDEr": 1.1298572297403193,
286
+ "first_position_fraction": 0.649
287
+ },
288
+ "A2-cider-seed43": {
289
+ "BLEU_1": 0.7432503976837088,
290
+ "BLEU_2": 0.6010193575130967,
291
+ "BLEU_3": 0.46965775473868077,
292
+ "BLEU_4": 0.3607841801407428,
293
+ "CIDEr": 1.1461092136840518,
294
+ "first_position_fraction": 0.6182
295
+ },
296
+ "A2-cider-seed44": {
297
+ "BLEU_1": 0.7419365512853906,
298
+ "BLEU_2": 0.5997652510833471,
299
+ "BLEU_3": 0.46847684409748,
300
+ "BLEU_4": 0.35962784991833674,
301
+ "CIDEr": 1.1420322976633694,
302
+ "first_position_fraction": 0.62
303
+ }
304
+ },
305
+ "paired_cider": {
306
+ "A1-position-only": {
307
+ "first-beam": {
308
+ "difference": 0.0,
309
+ "ci95": [
310
+ 0.0,
311
+ 0.0
312
+ ]
313
+ },
314
+ "unchanged-bert-cnn": {
315
+ "difference": 0.06112672876203984,
316
+ "ci95": [
317
+ 0.04461033866764987,
318
+ 0.07732889442325831
319
+ ]
320
+ }
321
+ },
322
+ "A2-cider": {
323
+ "first-beam": {
324
+ "difference": 0.08381725913260307,
325
+ "ci95": [
326
+ 0.0727875544504028,
327
+ 0.0952077601843989
328
+ ]
329
+ },
330
+ "unchanged-bert-cnn": {
331
+ "difference": 0.1449439878946429,
332
+ "ci95": [
333
+ 0.13123145918065157,
334
+ 0.1584672668531495
335
+ ]
336
+ }
337
+ },
338
+ "A2b-cider-no-position": {
339
+ "first-beam": {
340
+ "difference": 0.057851716443539314,
341
+ "ci95": [
342
+ 0.04271872527034004,
343
+ 0.07325111089796867
344
+ ]
345
+ },
346
+ "unchanged-bert-cnn": {
347
+ "difference": 0.11897844520557917,
348
+ "ci95": [
349
+ 0.1065857808370289,
350
+ 0.13147903804945957
351
+ ]
352
+ }
353
+ },
354
+ "A3-similarity": {
355
+ "first-beam": {
356
+ "difference": 0.04894856115923461,
357
+ "ci95": [
358
+ 0.035741020466093225,
359
+ 0.06260445814702015
360
+ ]
361
+ },
362
+ "unchanged-bert-cnn": {
363
+ "difference": 0.11007528992127445,
364
+ "ci95": [
365
+ 0.09785163686033818,
366
+ 0.1229914533939251
367
+ ]
368
+ }
369
+ },
370
+ "A4-mix": {
371
+ "first-beam": {
372
+ "difference": 0.04443586246447917,
373
+ "ci95": [
374
+ 0.03405757119093585,
375
+ 0.05511339311451561
376
+ ]
377
+ },
378
+ "unchanged-bert-cnn": {
379
+ "difference": 0.105562591226519,
380
+ "ci95": [
381
+ 0.09213401867542881,
382
+ 0.11889410360514222
383
+ ]
384
+ }
385
+ },
386
+ "A5-cider-bce": {
387
+ "first-beam": {
388
+ "difference": 0.06669319771663693,
389
+ "ci95": [
390
+ 0.05628127853231627,
391
+ 0.07764260246364937
392
+ ]
393
+ },
394
+ "unchanged-bert-cnn": {
395
+ "difference": 0.12781992647867677,
396
+ "ci95": [
397
+ 0.11451074580965637,
398
+ 0.14125596300371077
399
+ ]
400
+ }
401
+ },
402
+ "A2-cider-seed43": {
403
+ "first-beam": {
404
+ "difference": 0.0829451816603695,
405
+ "ci95": [
406
+ 0.07194278777091113,
407
+ 0.09434764973335309
408
+ ]
409
+ },
410
+ "unchanged-bert-cnn": {
411
+ "difference": 0.14407191042240938,
412
+ "ci95": [
413
+ 0.1303761099103887,
414
+ 0.15753553193319397
415
+ ]
416
+ }
417
+ },
418
+ "A2-cider-seed44": {
419
+ "first-beam": {
420
+ "difference": 0.07886826563968741,
421
+ "ci95": [
422
+ 0.0679104338592083,
423
+ 0.09013364703943051
424
+ ]
425
+ },
426
+ "unchanged-bert-cnn": {
427
+ "difference": 0.13999499440172725,
428
+ "ci95": [
429
+ 0.12623425125883314,
430
+ 0.15353143250912157
431
+ ]
432
+ }
433
+ }
434
+ }
435
+ }
436
+ },
437
+ "uncertainty": "Paired image bootstrap, 10,000 resamples, fixed reference IDF; not training-seed variation",
438
+ "not_evaluated_here": [
439
+ "METEOR",
440
+ "ROUGE_L",
441
+ "SPICE",
442
+ "BERTScore"
443
+ ],
444
+ "published": false
445
+ }
inference.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Inference for the reward-fine-tuned BERT-CNN caption reranker."""
2
+ import json
3
+ from pathlib import Path
4
+
5
+ import torch
6
+ from safetensors.torch import load_file
7
+ from transformers import AutoTokenizer
8
+
9
+ from modeling import VisualRelatednessModel, backbone_config_from_dict
10
+
11
+
12
+ class CaptionReranker:
13
+ """Pick the best of nine beam-search captions: score_k = bias[k] + weight * BERT-CNN logit."""
14
+
15
+ def __init__(self, model_path, device="cpu"):
16
+ path = Path(model_path)
17
+ if not path.is_dir():
18
+ from huggingface_hub import snapshot_download
19
+ path = Path(snapshot_download(str(model_path), allow_patterns=["config.json", "model.safetensors", "tokenizer/*"]))
20
+ config = json.loads((path / "config.json").read_text())
21
+ self.device = torch.device(device)
22
+ self.model = VisualRelatednessModel(backbone_config_from_dict(config["bert_config"]), **config["model_options"])
23
+ self.model.load_state_dict(load_file(str(path / "model.safetensors")))
24
+ self.model.to(self.device).eval()
25
+ self.tokenizer = AutoTokenizer.from_pretrained(path / "tokenizer", local_files_only=True, use_fast=True)
26
+ self.tokenizer.padding_side = "right"
27
+ self.seq_len = config["model_options"]["seq_len"]
28
+ self.bias = config["rank_prior"]["bias"]
29
+ self.weight = config["rank_prior"]["weight"]
30
+
31
+ @torch.inference_mode()
32
+ def logits(self, visual_context, captions, batch_size=16):
33
+ if not isinstance(visual_context, str) or not visual_context.strip():
34
+ raise ValueError("Provide image-context words, such as dog, ball, grass")
35
+ if not captions or any(not isinstance(c, str) or not c.strip() for c in captions):
36
+ raise ValueError("Provide at least one nonempty caption")
37
+ values = []
38
+ for start in range(0, len(captions), batch_size):
39
+ selected = captions[start:start + batch_size]
40
+ batch = self.tokenizer([visual_context] * len(selected), selected, padding="max_length",
41
+ truncation="longest_first", max_length=self.seq_len,
42
+ return_tensors="pt").to(self.device)
43
+ values.extend(self.model(**batch).float().cpu().tolist())
44
+ return values
45
+
46
+ def rerank(self, visual_context, beams):
47
+ """beams: the nine captions in beam-search order (best beam first). Returns (index, scores)."""
48
+ if len(beams) != len(self.bias):
49
+ raise ValueError(f"Expected exactly {len(self.bias)} captions in beam-search order")
50
+ scores = [b + self.weight * x for b, x in zip(self.bias, self.logits(visual_context, beams))]
51
+ best = max(range(len(scores)), key=lambda i: (scores[i], -i)) # earliest beam wins ties
52
+ return best, scores
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55b8e8a84c8708c788db7b389e7622d1e745c2a871e54766140290f8da39f37c
3
+ size 435889108
modeling.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Original BERT heads/masking and explicit ModernBERT comparison variants."""
2
+
3
+ import torch
4
+ from torch import nn
5
+ from transformers import BertConfig, BertModel, ModernBertConfig, ModernBertModel, ModernBertForSequenceClassification
6
+
7
+
8
+ def backbone_config_from_dict(values):
9
+ kind = values.get("model_type", "bert")
10
+ classes = {"bert": BertConfig, "modernbert": ModernBertConfig}
11
+ if kind not in classes:
12
+ raise ValueError(f"Unsupported checkpoint backbone: {kind}")
13
+ return classes[kind].from_dict(values)
14
+
15
+
16
+ class VisualRelatednessModel(nn.Module):
17
+ def __init__(self, bert_config, architecture="bert-cnn", seq_len=64,
18
+ cnn_filters=32, cnn_kernel_size=3, num_bert_layers=None,
19
+ tune_embeddings=None, backbone=None):
20
+ super().__init__()
21
+ if architecture not in {"bert", "bert-cnn", "modernbert", "modernbert-cnn"}:
22
+ raise ValueError("Unsupported model architecture")
23
+ modern = architecture.startswith("modernbert")
24
+ if modern != (bert_config.model_type == "modernbert"):
25
+ raise ValueError("Architecture and pretrained backbone type do not match")
26
+ if not 3 <= seq_len <= bert_config.max_position_embeddings:
27
+ raise ValueError("seq_len must be between 3 and BERT's positional embedding limit")
28
+ layers = bert_config.num_hidden_layers if num_bert_layers is None else num_bert_layers
29
+ if not 0 <= layers <= bert_config.num_hidden_layers:
30
+ raise ValueError("num_bert_layers is outside this BERT model's layer range")
31
+ if cnn_filters < 1 or cnn_kernel_size < 1:
32
+ raise ValueError("CNN filter count and kernel size must be positive")
33
+ self.options = dict(architecture=architecture, seq_len=seq_len,
34
+ cnn_filters=cnn_filters, cnn_kernel_size=cnn_kernel_size,
35
+ num_bert_layers=layers,
36
+ tune_embeddings=architecture in {"bert", "modernbert"} if tune_embeddings is None else tune_embeddings)
37
+ if modern:
38
+ # Let the outer training loop control compilation explicitly.
39
+ bert_config.reference_compile = False
40
+ bert_config._attn_implementation = "sdpa"
41
+ model_class = ModernBertForSequenceClassification if architecture == "modernbert" else ModernBertModel
42
+ self.bert = backbone if backbone is not None else model_class(bert_config)
43
+ else:
44
+ self.bert = backbone if backbone is not None else BertModel(
45
+ bert_config, add_pooling_layer=architecture == "bert")
46
+ hidden = bert_config.hidden_size
47
+ if architecture == "bert":
48
+ self.dropout = nn.Dropout(.1)
49
+ self.classifier = nn.Linear(hidden, 2)
50
+ nn.init.normal_(self.classifier.weight, std=.02)
51
+ nn.init.zeros_(self.classifier.bias)
52
+ elif architecture != "modernbert":
53
+ pooled_length = (seq_len - cnn_kernel_size + 1) // 2
54
+ if pooled_length < 1:
55
+ raise ValueError("seq_len must be at least cnn_kernel_size + 1")
56
+ self.conv = nn.Conv1d(hidden, cnn_filters, cnn_kernel_size)
57
+ self.pool = nn.MaxPool1d(2, stride=2)
58
+ self.classifier = nn.Linear(pooled_length * cnn_filters, 1)
59
+ # Keras Glorot initialization for the original CNN and dense head.
60
+ nn.init.xavier_uniform_(self.conv.weight)
61
+ nn.init.zeros_(self.conv.bias)
62
+ nn.init.xavier_uniform_(self.classifier.weight)
63
+ nn.init.zeros_(self.classifier.bias)
64
+ self.configure_finetuning()
65
+
66
+ @classmethod
67
+ def from_pretrained(cls, source, revision=None, **options):
68
+ architecture = options.get("architecture", "bert-cnn")
69
+ if architecture.startswith("modernbert"):
70
+ model_class = ModernBertForSequenceClassification if architecture == "modernbert" else ModernBertModel
71
+ extra = {"num_labels": 2} if architecture == "modernbert" else {}
72
+ bert = model_class.from_pretrained(source, revision=revision, reference_compile=False,
73
+ attn_implementation="sdpa", **extra)
74
+ else:
75
+ bert = BertModel.from_pretrained(source, revision=revision, add_pooling_layer=architecture == "bert")
76
+ return cls(bert.config, backbone=bert, **options)
77
+
78
+ def configure_finetuning(self):
79
+ self.bert.requires_grad_(False)
80
+ modern = self.options["architecture"].startswith("modernbert")
81
+ encoder = self.bert.model if self.options["architecture"] == "modernbert" else self.bert
82
+ if self.options["tune_embeddings"]:
83
+ encoder.embeddings.requires_grad_(True)
84
+ count = self.options["num_bert_layers"]
85
+ if count:
86
+ layers = encoder.layers if modern else encoder.encoder.layer
87
+ for layer in layers[-count:]:
88
+ layer.requires_grad_(True)
89
+ if modern:
90
+ encoder.final_norm.requires_grad_(True)
91
+ if self.options["architecture"] == "modernbert":
92
+ self.bert.head.requires_grad_(True)
93
+ self.bert.classifier.requires_grad_(True)
94
+ if self.options["architecture"] == "bert" and self.bert.pooler is not None:
95
+ self.bert.pooler.requires_grad_(True)
96
+
97
+ def forward(self, input_ids, attention_mask, token_type_ids=None):
98
+ if self.options["architecture"].startswith("modernbert"):
99
+ output = self.bert(input_ids=input_ids, attention_mask=attention_mask, return_dict=True)
100
+ if self.options["architecture"] == "modernbert":
101
+ return output.logits
102
+ else:
103
+ output = self.bert(input_ids=input_ids, attention_mask=attention_mask,
104
+ token_type_ids=token_type_ids, return_dict=True)
105
+ if self.options["architecture"] == "bert":
106
+ return self.classifier(self.dropout(output.pooler_output))
107
+ if input_ids.shape[1] != self.options["seq_len"]:
108
+ raise ValueError("BERT-CNN requires fixed padding to the checkpoint's seq_len")
109
+ # The old BertLayer zeroed padded token vectors BEFORE the convolution.
110
+ sequence = output.last_hidden_state * attention_mask.unsqueeze(-1).to(output.last_hidden_state.dtype)
111
+ pooled = self.pool(torch.relu(self.conv(sequence.transpose(1, 2))))
112
+ # Keras Flatten traverses time then filters, rather than filters then time.
113
+ flat = pooled.transpose(1, 2).contiguous().flatten(1)
114
+ return self.classifier(flat).squeeze(-1)
115
+
116
+ def probabilities(self, logits):
117
+ return logits.softmax(-1)[:, 1] if self.options["architecture"] in {"bert", "modernbert"} else logits.sigmoid()
118
+
119
+ def loss(self, logits, labels):
120
+ if self.options["architecture"] in {"bert", "modernbert"}:
121
+ return nn.functional.cross_entropy(logits, labels.long())
122
+ return nn.functional.binary_cross_entropy_with_logits(logits, labels.float())
provenance.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "source_checkpoint": "outputs/reward-v2/runs/A2-cider/model.pt",
3
+ "source_sha256": "125a083e3258b7ee038b6fb3e9d40a2d6078e2a325fbc1c4ba9cd062e674daaf",
4
+ "warm_start_sha256": "3790215706a0ecad5e3db7f3052bdbe3c549e853f10a2b22e6cfd7c568fc3b4b",
5
+ "weights_sha256": "55b8e8a84c8708c788db7b389e7622d1e745c2a871e54766140290f8da39f37c",
6
+ "caption_generator_for_training": "Salesforce/blip-image-captioning-base (frozen)"
7
+ }
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch>=2.6,<3
2
+ transformers==5.3.0
3
+ safetensors>=0.4
4
+ huggingface_hub>=1,<2
tokenizer/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_lower_case": true,
5
+ "is_local": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "pad_token": "[PAD]",
9
+ "sep_token": "[SEP]",
10
+ "strip_accents": null,
11
+ "tokenize_chinese_chars": true,
12
+ "tokenizer_class": "BertTokenizer",
13
+ "unk_token": "[UNK]"
14
+ }
training_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "data": null,
3
+ "checkpoint": "PyTorch BERT-CNN (sha256 3790215706a0ecad5e3db7f3052bdbe3c549e853f10a2b22e6cfd7c568fc3b4b)",
4
+ "output": null,
5
+ "beta": 0.0,
6
+ "position_prior": true,
7
+ "student_weight": 0.1,
8
+ "freeze_student": false,
9
+ "bce_weight": 0.0,
10
+ "bce_data": null,
11
+ "bce_batch": 32,
12
+ "epochs": 4,
13
+ "patience": 2,
14
+ "batch_images": 8,
15
+ "learning_rate": 1e-06,
16
+ "head_learning_rate": 1e-05,
17
+ "prior_learning_rate": 0.01,
18
+ "seed": 42,
19
+ "threads": 8,
20
+ "device": "cuda",
21
+ "precision": "bf16",
22
+ "max_steps": 0,
23
+ "smoke_images": 0,
24
+ "source_checkpoint_sha256": "3790215706a0ecad5e3db7f3052bdbe3c549e853f10a2b22e6cfd7c568fc3b4b",
25
+ "train_images": 10000,
26
+ "validation_images": 734,
27
+ "reward": "CIDEr",
28
+ "reward_statistics": {
29
+ "teacher_score": {
30
+ "mean": 0.9767111133008491,
31
+ "std": 0.7337384584946552
32
+ }
33
+ },
34
+ "initial_bias": [
35
+ -1.8657496056651226,
36
+ -2.007231122881001,
37
+ -2.1180337737350685,
38
+ -2.2044893876466585,
39
+ -2.1884659635972477,
40
+ -2.237686544090907,
41
+ -2.3518232877103324,
42
+ -2.4379562051795007,
43
+ -2.5388554661206517
44
+ ],
45
+ "initial_weight": 0.1,
46
+ "bce_examples": 0,
47
+ "input_hashes": {
48
+ "train_pairs.csv": "52cc6aac967de7ce5b213b6fd1c9c8b5c53e50119487716207fd6c1f81894741",
49
+ "train_scored.csv": "93e69b3423b4a702f858d31d80ab50f1597ebfc53c4f420ee46c51ac425703cf",
50
+ "validation_pairs.csv": "e2e299803b689690501b85e99844c4976f94fc08da8824824952e5c58f3974e6",
51
+ "validation_scored.csv": "da48e0e2cfa11b784ebd751ae88a6a756cccad0713ec3a9f00a1c4c76c439b37"
52
+ },
53
+ "selection": "Highest validation CIDEr of the selected caption, including epoch zero; earliest beam wins ties",
54
+ "score": "bias[beam position] + weight * BERT-CNN logit"
55
+ }
training_process.png ADDED