###### tags: `Paper Notes`
# ERNIE-ViL
* 原文:Knowledge Enhanced Vision-Language Representations Through Scene Graph
* 機構:Baidu
* 時間:2020 年
### Introduction
* 仿照 BERT,現在 V+L 模型也開始了pre-train + fine-tune 的做法。也就是先將 V+L 模型 pre-train 在 image-text alignment 資料集上(eg. Conceptual Captions、SBU),然後在 fine-tune 到 downstream task 上(eg. VCR、VQA、image capioning)。知名的作法有 OSCAR、UNITER 等。
* 然而,如果只是像 BERT 一樣隨機的蓋住 token,那模型將無法精準學到 image 與 text 之間的關係。
* 因此,ERNIE-ViL 提出了依據 Scene Graph 選擇要蓋掉哪些 token 的 pre-training 方法。簡單的說就是「更合理的 masking 方式」。
### Scene Graph
* Scene Graph 包含了 visual scenes 的 structure knowledge,如 Figure 2 所示,Scene Graph 是由 object、attribute、relationship 三種 node 所組成的 graph。
* 簡單的說就是 text 的結構化表示。
<center><img src="https://i.imgur.com/kyyU5XP.png" width=700></center>
### Input Embedding
* **Sentence Embedding**:
* 做法與 BERT 相同,先用 WordPiece 將 input sentecnce 切分成很多個 token。
* 並且加入兩個 special token:[CLS]、[SEP]。
* 每個 token 最後的 embedding 都是由各自的 word embedding、segment embedding、position embedding 所組成。
* sentence embedding 的最終結果為:$\{ [CLS], w_1, ..., w_T, [SEP] \}$。
* **Image Embedding**:
* 先用 pre-trained object detector 將 visual features 提取出來。
* 再將每個 object 的 focation features $(\frac{x_1}{W}, \frac{y_1}{H}, \frac{x_2}{W}, \frac{y_2}{H}, \frac{(x_2 - x_1)(y_2 - y_1)}{WH})$ 加進去。
* 定義一個特殊 feature,[IMG],其值為 object detector 輸出的整個 feature map 的 mean pooling。
* image embedding 的最終結果為:$\{ [IMG], v_1, ..., v_t \}$。
* **Visual-Language Encoder**:
* 綜上所述,joint model 的輸入為:$\{ [IMG], v_1, ..., v_t, [CLS], w_1, ..., w_T;[SEP] \}$。
* ERNIE-ViL 的 joint model 為 two-stream cross -model Transformers。
* image、sentence embedding 的輸出為 $h_{v_i}, h_{w_i}, h_{[IMG]}, h_{[CLS]}, h_{[SEP]}$。
### Scene Graph Predection
* 如 Figure 2 所示,Scene Graph 是從 text 解析而得。而 Scene Graph Predection 任務可分成三個部分:Object Prediction、Attribute Predicton、Relationship Prediction,分別對應到 Scene Graph 中的三種 node。
* 注意,這裡的 object 是指 Scene Graph 裡的 object node,而不是 image 中的 object。
* Scene Graph Parsing:
* ERNIE-ViL 的 Scene Graph Parser 來自於 [29]。
* **Object Prediction**:
* 在每次訓練的過程中都隨機挑出 Scene Graph 裡 30% 的 object node,$w_{o_i}$。被挑出的 object node 有 80% 的機率被換成 [MASK],有 10% 的機率被換成 random token,有 10% 的機率保持原狀。
* 所謂的 object prediction 就是要根據 image region 與其它未被挑中的 token 去預測 $w_{o_i}$。
* loss function 如下:
$$
L_{obj}(\theta) = -E_{(w,v) \sim D} \log (P(w_{o_i} | w_{\backslash \_ o_i}))
$$
* **Attribute Prediction**:
* 與 object prediction 相同,每次都挑出 30% 的 attribute node,$w_{a_i}$。並要去預測被選中的人是誰。
* 不一樣的地方是,被挑出的 attribute node 其對應的 object node,$w_{o_i}$,不會被選中。
* loss function 如下:
$$
L_{attr}(\theta) = -E_{(w,v) \sim D} \log (P(w_{a_i} | w_{o_i}, w_{\backslash \_ a_i}, v))
$$
* **Relationship Prediction**:
* 與 object prediction 相同,每次都挑出 30% 的 relationship node,$w_{r_i}$。並要去預測被選中的人是誰。
* 不一樣的地方是,被挑出的 relationship node 其周圍的兩個的 object node,$w_{o_{i1}}, w_{o_{i2}}$,不會被選中。
* loss function 如下:
$$
L_{rel}(\theta) = -E_{(w,v) \sim D} \log (P(w_{r_i} | w_{o_{i1}}, w_{o_{i2}}, w_{\backslash \_ r_i}, v))
$$
### Pre-training with Scene Graph Predection
* 從上面可以看到,Scene Graph Predection 其實就是一種 Masked Model Modelling (MLM) 的改進方法。
* 除了 MLM 外,ERNIE-ViL 還用了 Masked Region Prediction、Image-Text Matching 做 pre-training。
### Experiemnts
* Pre-training Data:
* out-of-domain:Conceptual Captions (CC)、SBU。
* in-domain:Visual Genome、MSCOCO。
* Implementation Details:
* ERNIE-ViL 可分成 base、large 兩種尺寸,主要差在 joint model,細節如 Table 2 所示。
* object detetor 採用 Faster R-CNN。
<center><img src="https://i.imgur.com/0IzAIkD.png" width=700></center>
* 實驗結果如 Table 3 所示。
<center><img src="https://i.imgur.com/qvVBPVA.png" width=700></center>
* Visual Question Answering (VQA) 實驗細節:
> The VQA task requires answering natural language questions about images. VQA 2.0 dataset [11] contains 204k images and 1.1M questions about these images. Following [34], we treat VQA as a multi-label classification task – assigning a soft target score to each answer based on its relevancy to the 10 human answer responses. We take dot product (根據 trace code 的結果應該是 elementwise multiplication 的意思) of final hidden state of h~[CLS]~ and h~[IMG]~ to map this representation into 3,129 possible answers with an additional two layer MLP. The model is optimized with a binary cross-entropy loss on the soft target scores. Additional question-answer pairs from Visual Genome are used for data augmentation as in [10]. We fine-tune VQA model over 12 epochs with a batch size of 256 and initial learning rate of 1e-4 which decays by 0.1 at the end of epoch 6 and epoch 9. At inference, we simply take a softmax.
### References
[23] Unified visualsemantic embeddings: Bridging vision and language with structured meaning representations.
[29] Spice: Semantic propositional image caption evaluation.