ViLBERT: Pretraining Task-Agnostic Visiolinguistic Representations for Vision-and-Language Tasks
2020-03-12 23:10:53
Paper: NeurIPS 2019
Code: https://github.com/facebookresearch/vilbert-multi-task
1. Background and Motivation:
本文將 NLP 中非常火熱的 BERT 模型拓展為了 多模態的版本,即:Vision + Language,稱為 ViLBERT。如圖 1 所示,該模型包含兩個並行的流,分別用於編碼 image 和 language,並且加入了 co-attention transform layer 來增強兩者之間的交互,得到 pretrained model。作者在多個 vision-language 任務上得到了多個點的提升。
2. Approach Details:
本文首先對 BERT 模型進行了簡要的介紹,然后介紹如何將 BERT 拓展到多模態領域,聯合的進行學習視覺和語言的表達。
2.1. Preliminaries: Bidirectional Encoder Representations from Transformers (BERT):
BERT 模型是一種基於 attention 的雙向語言模型。當在大型語料庫上進行訓練時,已經驗證該方法可以取得非常有效的學習效果,並且在多個 NLP 的任務上取得了非常有效的遷移學習能力。BERT 模型在 word tokens $w_0, ... , w_T$ 上進行操作,這些 tokens 被映射到學習到的編碼上,通過 L “encoder-style” transformer blocks 來產生最終的表示:$h_0, ... , h_T$。假設我們用 $H^{(l)}$ 來表示一個矩陣,其中的第 l 行 $h_0^{(l)}, ... , h_T^{(l)}$ 對應了第 l 層的中間表示。該中間層的表示 $H^{(l)}$ 用於計算三個度量 Q,K 和 V,分別對應的是:用於引導多頭注意力模塊的 queries, keys, and values。具體來說,queries 和 keys 之間 dot-product similarity 決定了 attentional distributions over value vectors。按照這種方式得到的 weighted-averaged value vector 構成了 attention block 的輸出。作者將這種 query-conditioned key-value attention mechanism 來開發一種多模態 co-attention transformer 模型 ViLBERT。
Text Representation:BERT 處理的是離散的符號,包括 vocabulary words 以及 少量特殊的符號:SEP, CLS, 以及 MASK。對於一個給定的符號,輸入的表示是 a sum of a token-specific learned embedding 以及 encodings for position(句子中符號的索引) 和 segment(如果存在多個,就標記符號句子的索引,the index of the token's sentence)。
Training Tasks and Objectives:BERT 模型在大型語料庫中訓練,有如下兩種設定:masked language modelling 和 next sentence prediction。作者給出了如下的介紹:
2.2. ViBERT: Extending BERT to Jointly Represent Images and Text:
受到上述 BERT 的啟發,作者將該模型拓展成可以處理多模態的版本,來聯合的從 paired data 上來學習表示。
一種直觀的方法是最少的改動 BERT:簡單的通過聚類方法來離散化視覺輸入,將這些 visual “tokens” 看成是 text inputs,然后從一個 pre-trained BERT model。但是這種結構有如下的缺點:
1). initial clustering may result in discretization error and lose important visual details;
2). it treats inputs from both modalities identically, ignoring that they may need different levels of processing due to either their inherent complexity or the initial level of abstration of their input representations.
3). Forcing the pretrained weights to accommodate the large set of additional visual "tokens" may damage the learned BERT language model.
所以,作者研究了一種雙流結構來分別建模每一種模態,然后將其通過一組基於 attention 的交互來融合這些信息。這種方法允許每一種模態的網絡深度不同,確保了可以在不同的深度進行跨模態的聯系。
如圖 1 所示,ViLBERT 由兩個 BERT-style 的模塊構成,分別用於處理 image regions 和 text segments。每一個流的是一系列的 transformer blocks(TRM)和 novel co-attention transformer layers (Co-TRM),確保不同模態進行信息交換。給定圖像 I,表示為一系列的 region features v1, ... , vT 以及 文本輸入 w0, ... , wT,本文提出的模型輸出最終的表示 hv0, ... , hvT 以及 hw0, ... , hwT。注意到兩個流的交換被限制在特定的層,the text stream 明顯在與視覺特征進行交互之前得到了更多的處理 --- 這樣就和作者的直覺理解相匹配了,即:the chosen visual features are already fairly high-level and require limited context-aggregation compared to words in a sentence。
Co-Attentional Transformer Layers:
如圖 2b 所示,作者引入了一個 co-attentional transformer layer,給定中間視覺和語言的表示,該模塊計算 query,key,and value metrices 作為其他模態 多頭注意力模塊的輸入。所以,注意力模塊在產生 attention-pooled features 的時候,是依賴於其他模態的 --- 后續的 mimics common atteniton mechansims 是從其他 vision-and-language models 上得到的。剩下的 transformer 模塊像之前一樣,包含一個殘差。總體來說,co-attention 對於 vision-and-language 來說並不是一個新的 idea。
Image Representation:利用物體檢測網絡得到 instance-level 的 object proposal。不像文本數據,圖像中並不存在自然的序列。作者從空間位置的角度進行編碼,構建一個 5-d 的向量。作者將圖像中的區域序列開始的部分記為 IMG 來表示整個圖像。
Training Tasks and Objectives:像之前章節描述的那樣,作者考慮兩個預訓練的任務:masked multi-modal modelling and multi-modal alignment prediction.
The masked multi-modal modelling task 跟標准的 BERT 訓練方式一樣 --- 大約遮擋 15% 的 word 和 image region inputs,然后用這個模型來重構這部分的內容。但是作者這里不是直接回歸出 masked feature values,該模型是預測對應圖像區域的語義類別的分布。為了在這部分利用監督信息,作者從同一個預訓練的物體檢測模型中獲得該 region 的輸出分布。利用這兩個分布之間的 KL散度來訓練該模型。這個選擇反正了這么一個事實:自然語言經常被當做是視覺內容的高層語義表達,而不是用於重構確切的圖像特征(the language often only identifies high-level semantics of visual content and is unlikely to be able to reconstruct exact image features)。此外,利用回歸損失函數也會使得 masked image 和 text inputs 之間不平衡的損失。
在多模態對其任務中,模態被表示為一個 image-text pair {IMG, v1, ... , vT, CLS, w1, ... , wT, SEP} 然后去預測給定的圖像和文本對是否匹配,即:給定的文本是否和圖像的內容相符合。作者利用一個 linear layer 來進行二分類。然而,本文所用的數據集 Conceptual Captions dataset 僅僅包含對其的 image-caption pairs。為了產生負樣本對,作者隨機的替換對應的圖像或者文本描述。
3. Experimental Results: