머신러닝 및 딥러닝/자연어처리

Vision-Language Model | self-attention vs cross-attention

viamemine 2023. 8. 1. 13:39
728x90
반응형

A Survey of Vision-Language Pre-Trained Models

 

📍 Summary

 

Pre-training은 처음에 computer vision에서 유용하다고 밝혀졌는데,

Transformer와 BERT의 등장 이후 NLP에서도 만연하게 사용되었다.

 

이는 Transformer가 long range dependency를 model하는 강력한 능력 덕분에

Pretrained Language Models (PLM)의 backbone이 되었다.

 

이후, vision과 language modalities를 모두 model하는 Vision-Language Pre-Trained Models이 연구되었다. 

 

 

📍 VL-PTM의 3단계

1. image와 text의 의미를 유지한 채 latent representation으로 encode

2. image와 text 사이의 상호작용을 model하는 architecture를 design

3. VL-PTMs를 효과적으로 학습하는 pre-training task를 고안

 

 

 

💥 1. image와 text의 의미를 유지한 채 latent representation으로 encode

- 거의 모든 VL-PTM이 Transformer-based PTM을 text encoder로 사용한다.

 

대부분의 text encoder는 BERT를 따른다.

 

- Text sequence는 토큰으로 잘린 후 [CLS]와 [SEP] 토큰과 concat한다.

- 각 token이 word embedding으로 map된다.

- Position을 나타내는 positional embedding과 modality type를 나타내는 segment embedding도

word embedding에 더해져 최종 embedding을 만든다.

 

- Image도 paired text의 sequence of embeddings과 align하기 위해 sequence of embedding vectors로 표현해야 한다.

- Image 내 visual concepts 간 relationship이 중요하지만, 포착하기 어렵다. 

( 때문에 많은 연구들이 다양한 vision encoder를 사용하여 relationship과 사물의 attributes를 포착하려고 한다. )

 

- ViT는 transformer를 사용하여 vision feature를 추출한다.

- 이미지를 여러 flattened 2D patches로 자르고, image patches의 embedidngs가 sequence로 arrange된다.

- ALBEF, SimVLM은 vision feature를 위해 ViT encoder를 사용하였다. 

 

 

 

💥 2. image와 text 사이의 상호작용을 model하는 architecture를 design

: 두 modalities의 정보를 통합하는 것이다.

 

통합하는 방법에 따라 Fusion-Encoder, Dual-Encoder, Combination of both로 나눌 수 있다.

 

 

💥💥 1. Fusion-Encoder

Fusion Encoder는 text embeddings과  image features를 받아 fusion approach를 취한다.

 

self-attention이나 cross-attention operation 이후,

last layer의 hidden state가 여러 modalities를 합친 fused representation으로 취급된다.

cross-modal interaction을 model하는 fusion scheme는 두 가지 종류(single stream / dual stream)가 있다.

 

- Single stream

두 modalities 간 potential correlation과 alignment가 single transformer encoder로 학습될 수 있을 정도로 간단하다.

= text embeddings과 image features이 concat되고,

position과 modality를 의미하는 special embeddings을 더한 후, transformer-based encoder에 input으로 들어간다.

 

서로 다른 Vision-Language task가 서로 다른 input format을 요구하지만,

single-stream은 transforemer attention의 unordered representation nature 덕분에

task를 unified framework로 처리할 수 있다.

 

single-stream architecture은 두 modalities에 직접 self-attention을 수행하기 때문에,

intra-modality interaction을 무시할 수도 있다.

 

따라서 몇몇의 연구는 Vision-Language model을 하기 위해 dual-stream architecture를 사용한다. 

 

 

- Dual stream

Vision-Language interaction을 model하기 위해 cross-attention mechanism을 적용한다.

= query vectors는 한 modality에서 오고, key와 value vectors는 다른 modality에서 온다.

 

cross-attention layer는 주로 두 unidirectional  cross-attention sub-layes를 포함한다.

하나는 language to vision이고, 다른 하나는 vision to language이다. 

 

이들은 두 modalities 사이의 정보를 교환하고, semantics를 aligning하는 역할을 한다.

 

Dual stream architecture는 better multimodal representation을 얻기 위해서라면,

intra-model interaction과 cross-modal interaction이 분리되어야 한다고 가정한다.

 

이런 식의 architecture는 input을 더 comprehensive하게 encode하게 해주나,

extra feature encoder로 인해 parameter-inefficient하다. 

 

 

 

📍 self-attention과 cross-attention의 차이

self-attention: query = key = value 

cross-attention: query  key = value

(같다는 것은 vector의 값이 같다는 것이 아니라, vector의 출처가 같다는 의미)

 

 

 

📍 Fusion Encoder와 Dual Encoder의 단점

- Fusion Encoder

Fusion Encoder가 cross-modal interaction을 model하여 여러 VL task에서 SOTA를 냈지만,

heavy transformer network에 의존한다는 단점이 있다.

 

Fusion Encoder는 모든 가능한 image text pairs를 encode해야 하고, 결국 inference speed도 느리다.

 

- Dual Encoder

Dual Encoder는 두 single-modal encoders를 사용하여 두 modality를 분리해 각각 encode한다.

이후 shallow attention layer나 dot product 같은 간단한 방법을 사용하여,

image embedding과 text embedding을 VL similarity scores를 계산하기 위한 동일한 semantic space에 project한다.

 

Transformer 내에 complex cross-attention 없이도 dual encoder의 VL interaction modeling strategy가 훨씬 효율적이다.

 

따라서 images, texts의 feature vectors가 pre-computed되어 stored될 수 있고,

fusion encoder보다 retrieval tasks에 대해 더 효율적이다.

 

CLIP 같은 dual encoder model이 image-text retrieval tasks에 놀라운 성능을 보였지만,

NLVR 같은 hard VL understanding task에는 실패하기도 한다. 이는 두 modalities 사이의 shallow interaction 때문이다.

 

 

📍  Fusion Encoder + Dual Encoder

Fusion Encoder가 VL understanding task에 뛰어나고,

Dual Encoder가 retrieval task에 뛰어나다는 결과를 바탕으로 두 architecture를 조합한 방식이 세 번째 encoder이다.

 

- FLAVA는 먼저 dual encoder로 single-modal representations을 얻고,

single-modal embeddings을 fusion encoder로 보내 cross-modal representation을 얻는다. 

 

- VLMo는 Mixtureof-Modality-Expert(MoME)를 도입해 dual encoder와 fusion encoder를 single framework로 합친다.

단계별로 images, texts, image-text pairs에 pre-trained한 후

VLMo는 VL understanding task 뿐만 아니라 efficient image-text retrieval에도 적용 가능하다.

 

 

 

💥 3. VL-PTMs를 효과적으로 학습하는 pre-training task를 고안

Designed pre-trained tasks는 VL-PTM이 data에서 무엇을 배울 수 있는지에 큰 영향을 준다.

널리 사용되는 task들은 다음과 같다.

 

📍 Pre-training tasks

1. Cross-Modal Masked Language Modeling (MLM)

2. Cross-Modal Masked Region Prediction (MRP)

2.1 Masked Region Classification (MRC)

2.2 Masked Region Feature Regression (MRF)

3. Image-Text Matching (ITM)

4. Cross-Modal Contrastive Learning (CMCL)

 

📍 Downstream tasks

1. Cross-Modal Matching

1.1 Image Text Retrieval (ITR)

1.2 Vision Referring Expression (VRE)

2. Cross-Modal Reasoning

2.1 Visual Question Answering (VQA)

2.2 Natural Language for Visual Reasoning (NLVR)

2.3 Visual commonsense Reasoning (VCR)

3. Vision and Language Generation

3.1 Text-to-Image Generation

3.2 Multimodal Text Generation

 

VL-PTMs의 향후 발전 방향은 다음과 같다.

1. Unified Model Architecture 

2. Model Compression and Acceleration

3. Advanced Pre-training Methods

4. Reaching the Limit of VL-PTMs

728x90

'머신러닝 및 딥러닝 > 자연어처리' 카테고리의 다른 글

In-Context Learning ・PEFT  (0) 2024.05.08
Batch size와 Learning rate의 상관 관계  (0) 2023.11.18
Transfer Learning & Fine-tuning  (2) 2023.11.18
Contrastive Learning  (0) 2023.07.26
Self-supervised Learning  (0) 2023.07.26