Idan commited on
Commit
57fe27a
·
verified ·
1 Parent(s): 098eb4c

Add Factor Graph Attention weights (VisDial v1.0, MRR 66.01)

Browse files
Files changed (3) hide show
  1. README.md +138 -0
  2. config.json +56 -0
  3. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: transformers
4
+ pipeline_tag: visual-question-answering
5
+ tags:
6
+ - visual-dialog
7
+ - visdial
8
+ - multimodal
9
+ - attention
10
+ - factor-graph-attention
11
+ - ndcg
12
+ datasets:
13
+ - Idan/visdial-fga-preprocessed
14
+ metrics:
15
+ - recall
16
+ - mrr
17
+ - ndcg
18
+ model-index:
19
+ - name: fga-ndcg
20
+ results:
21
+ - task:
22
+ type: visual-question-answering
23
+ name: Visual Dialog
24
+ dataset:
25
+ type: visdial
26
+ name: VisDial v1.0 val
27
+ metrics:
28
+ - type: ndcg
29
+ value: 69.07
30
+ name: NDCG
31
+ - type: mrr
32
+ value: 49.03
33
+ name: MRR
34
+ - type: recall
35
+ value: 34.27
36
+ name: R@1
37
+ - type: recall
38
+ value: 66.15
39
+ name: R@5
40
+ - type: recall
41
+ value: 80.13
42
+ name: R@10
43
+ ---
44
+
45
+ # Factor Graph Attention — NDCG variant
46
+
47
+ * A general multimodal attention approach inspired by probabilistic graphical models.
48
+ * Achieves a state-of-the-art performance (MRR) on visual dialog task.
49
+
50
+ This is [Factor Graph Attention](https://arxiv.org/abs/1904.05880) (CVPR'19) finetuned
51
+ on the **dense relevance annotations**, which optimizes NDCG. Code:
52
+ [idansc/fga](https://github.com/idansc/fga).
53
+
54
+ For the MRR-oriented model, see [`Idan/fga`](https://huggingface.co/Idan/fga).
55
+
56
+ ## Why there are two models
57
+
58
+ The sparse training label calls one of the 100 candidates correct and the other 99
59
+ equally wrong. That is what MRR measures. But for "is it daytime?" the candidate list
60
+ contains *yes*, *yeah*, *it is* and *yes it is*, and the label picks one arbitrarily.
61
+ NDCG instead scores against the graded relevance five annotators assigned to every
62
+ candidate.
63
+
64
+ Training on the graded signal moves NDCG a long way and costs MRR, because the two
65
+ metrics genuinely disagree about what a good ranking is. That tension is the subject of
66
+ the 2020 challenge submission, https://github.com/idansc/mrr-ndcg.
67
+
68
+ ## Results
69
+
70
+ On VisDial v1.0 val. The baseline is the MRR model this was finetuned from:
71
+
72
+ | Model | NDCG | MRR | R@1 | R@5 | R@10 | Mean rank |
73
+ | --- | --- | --- | --- | --- | --- | --- |
74
+ | [`Idan/fga`](https://huggingface.co/Idan/fga) (sparse) | 56.46 | **66.01** | 52.46 | 82.95 | 90.97 | 3.92 |
75
+ | **This model** (dense only) | **69.07** | 49.03 | 34.27 | 66.15 | 80.13 | 6.68 |
76
+ | dense + sparse, weight 0.5 | 68.00 | 61.93 | 49.55 | 76.59 | 86.14 | 5.07 |
77
+ | dense + sparse, weight 1.0 | 66.61 | 63.27 | 50.69 | 78.33 | 87.38 | 4.78 |
78
+
79
+ This checkpoint is the pure-dense end of that trade-off: the best NDCG, and the worst
80
+ MRR. If you want one model that is respectable at both, the `sparse_weight=1.0` row
81
+ gives up 2.5 NDCG to recover 14 MRR, and is reproducible with `--sparse_weight 1.0`.
82
+
83
+ Trained for 5 epochs at lr 1e-4 on the 2,000-image dense subset of **train**. The val
84
+ annotations are never trained on — they are the evaluation set.
85
+
86
+ ### On the objective
87
+
88
+ The loss is a soft-label cross entropy: the relevance vector is normalized into a
89
+ distribution and matched against the model's log-softmax over the candidates,
90
+
91
+ ```
92
+ loss = -sum_i p_i log q_i, p = relevance / sum(relevance)
93
+ ```
94
+
95
+ which is the cross entropy the sparse loss already computes, generalized from a one-hot
96
+ target to a graded one.
97
+
98
+ A smooth approximation of NDCG itself (ApproxNDCG, Qin et al.) was also tried and is
99
+ implemented in the repo. It is worse on this task — +6.0 NDCG against +12.6, while
100
+ losing more MRR — most likely because it concentrates its gradient on the few positions
101
+ the discount rewards, whereas the soft cross entropy draws signal from all 100
102
+ candidates, which matters when there are only 2,000 training examples.
103
+
104
+ ## Usage
105
+
106
+ ```python
107
+ from fga import FGAForVisualDialog
108
+
109
+ model = FGAForVisualDialog.from_pretrained("Idan/fga-ndcg")
110
+ outputs = model(**batch)
111
+ ranking = outputs.logits.argsort(dim=-1, descending=True)
112
+ ```
113
+
114
+ Install with `pip install git+https://github.com/idansc/fga.git`.
115
+
116
+ Reproduce with:
117
+
118
+ ```bash
119
+ python scripts/finetune_dense.py \
120
+ --model_name_or_path <sparse checkpoint> \
121
+ --train_dense_path data/visdial_1.0_train_dense_annotations.json \
122
+ --output_dir models/fga-ndcg \
123
+ --loss soft_ce --sparse_weight 0.0 \
124
+ --learning_rate 1e-4 --num_train_epochs 5
125
+ ```
126
+
127
+ ## Citation
128
+
129
+ Please cite Factor Graph Attention if you use this work in your research:
130
+ ```
131
+ @inproceedings{schwartz2019factor,
132
+ title={Factor graph attention},
133
+ author={Schwartz, Idan and Yu, Seunghak and Hazan, Tamir and Schwing, Alexander G},
134
+ booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},
135
+ pages={2039--2048},
136
+ year={2019}
137
+ }
138
+ ```
config.json ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "FGAForVisualDialog"
4
+ ],
5
+ "classifier_dropout": 0.5,
6
+ "dtype": "float32",
7
+ "empty_token_id": 11321,
8
+ "hidden_ans_dim": 512,
9
+ "hidden_cap_dim": 128,
10
+ "hidden_hist_dim": 128,
11
+ "hidden_img_dim": 2048,
12
+ "hidden_ques_dim": 512,
13
+ "initializer_type": "he",
14
+ "legacy_unary_dropout": false,
15
+ "lstm_initializer_type": "he",
16
+ "model_type": "fga",
17
+ "num_history_rounds": 9,
18
+ "num_options": 100,
19
+ "pad_token_id": 0,
20
+ "sharing_factor_weights": {
21
+ "4": [
22
+ 9,
23
+ [
24
+ 0,
25
+ 1
26
+ ]
27
+ ],
28
+ "5": [
29
+ 9,
30
+ [
31
+ 0,
32
+ 1
33
+ ]
34
+ ]
35
+ },
36
+ "size_force": false,
37
+ "stop_token_id": 11320,
38
+ "text_encoder_type": "lstm",
39
+ "transformers_version": "5.14.1",
40
+ "unary_dropout": 0.5,
41
+ "use_cache": false,
42
+ "use_pairwise": true,
43
+ "use_prior": true,
44
+ "use_self": true,
45
+ "use_unary": true,
46
+ "utility_sizes": [
47
+ 100,
48
+ 21,
49
+ 41,
50
+ 37,
51
+ 21,
52
+ 21
53
+ ],
54
+ "vocab_size": 11322,
55
+ "word_embed_dim": 200
56
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c0005e59451850afbed219efd39c8b462822cca4f55c4dbf270d76f4a41fa66e
3
+ size 209755804