> For the complete documentation index, see [llms.txt](https://byeolhee-kim.gitbook.io/paper-review/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://byeolhee-kim.gitbook.io/paper-review/paper-review/vlm/simvlm-simple-visual-language-model-pretraining-with-weak-supervision.md).

# SimVLM: Simple Visual Language Model Pretraining with Weak Supervision

https\://arxiv.org/pdf/2108.10904.pdf

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2FfW1VaS0SlGuhsHpg1Hkk%2Fimage.png?alt=media&amp;token=9892f262-e0ed-4e92-a88d-e32478b05546" alt=""><figcaption></figcaption></figure>

## <mark style="color:blue;">1. Introduction</mark>

해당 논문 이전의 모델들은 MLM, ITM 등 다양한 auxiliary loss들을 사용하여 pretraining 자체가 복잡함\
⇒ 복잡한 technique이나 auxiliary loss 없이 end-to-end로 학습할 수 있는 모델을 만들고자 함

* **Objective**
  * Prefix Language Modeling
* **Architecture**
  * Encoder-Decoder 구조
  * ViT 처럼 raw image를 input으로 넣는 방식 사용
* **Data**
  * large-scale weakly labeled dataset을 사용해 zero-shot generalization 성능을 확보하고자 함

## <mark style="color:blue;">3. SimVLM</mark>

### 3.1 Background

**Masked Language Modeling (MLM)**

* Encoder 구조 모델에서 사용하는 pretraining objective
* 마스킹 된 토큰의 앞 뒤 시퀀스를 바탕으로 양방향 attention을 통해 마스킹 토큰 예측
  * 문맥적인 부분을 이해하고 문맥에 맞춰 masking 된 단어 예측

**Language Modeling (LM)**

* Decoder 구조 모델에서 사용하는 pretraining objective
* 이전 시퀀스 기반 다음 토큰 예측
* 이전 시퀀스만 참조하기 때문에 단방향이라는 특징
  * generation에 특화

### 3.2 Proposed Objective: Prefix Language Modeling

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2F7KUl6DY4v8xS2BzotVqD%2Fimage.png?alt=media&amp;token=b3fe38ac-4e6b-4cee-91f6-1cd175b2d451" alt="" width="563"><figcaption><p><a href="https://www.youtube.com/watch?v=XU4ZHUnnbpg">https://www.youtube.com/watch?v=XU4ZHUnnbpg</a></p></figcaption></figure>

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2F763ET5CEflWI6LZ5dC4s%2Fimage.png?alt=media&amp;token=699efbc6-cec6-4946-93fc-e21b4d54f1a5" alt=""><figcaption></figcaption></figure>

* **Prefix Language Modeling이란?**

  * Language Modeling과 비슷한데 이제 이전 시퀀스를 Prefix로 사용한다고 보면 됨\
    즉, prefix를 given으로 주고 나머지 부분을 예측
  * $$T\_p$$ : prefix length 는 랜덤하게 설정하나 이미지 sequence 보다는 길게 설정해서 loss가 text에 대해서만 계산

* Prefix Language modeling은 sequence-to-sequence framework를 사용하기 때문에 다음과 같은 이점을 얻을 수 있다.
  * prefix가 미리 주어지기 때문에 그 내에서 bi-directional attention 계산으로 문맥 이해가 가능
  * LM처럼 다음 토큰을 예측하면서 generation에도 강점
  * 이후의 논문인 Flamingo도 일종의 prefix LM으로 볼 수 있음

### 3.3 Architecture

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2FEOmtrV2OBI7aZ1D1VQbI%2Fimage.png?alt=media&amp;token=8f04ac1e-b97a-4667-913f-f15ef7f26ef9" alt="" width="563"><figcaption></figcaption></figure>

* Encoder-Decoder 구조
* Contextualized한 정보를 담은 patch를 생성하기 위해 ResNet 상위 3개의 block을 사용해 이미지에 대한 1D embedding
* 저자는 modality type embedding은 성능 향상에 도움이 되지 않았다고 함
* Transformer 인코더의 last layer에서 cross attention하는 co-attention 방식

### 3.4 Datasets

* Large-scale nosiy image-text data
  * zero-shot 성능에 도움이 됨
* ALIGN에서 사용한 데이터 (1.8B) + C4 (test-only data) (300M)

## <mark style="color:blue;">4. Experiments</mark>

### 4.1 Set up

* ViT setup을 참고
  * Base : ResNet101 사용
  * Large : ResNet152 사용
  * Huge : ResNet152 with more channel 사용
* Image Resolution: 224x224
* Patch-size: 16x16
* Max sequence length: 256
* Random crop augmentation
* 512 TPU

### 4.2 Comparision with existing approaches

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2Fwbuk6dBJGWoAW2kR1wjd%2Fimage.png?alt=media&amp;token=de722af1-d374-4a3f-848d-84202ad6105e" alt="" width="563"><figcaption></figcaption></figure>

* 특히 NLVR2, SNLI-VE에서 높은 향상을 보임
* Encoder 모델 + Prefix + 많은 데이터의 강점

### 4.3 Zero-shot generalization

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2F0B7QskKWzygQl0oB89z9%2Fimage.png?alt=media&amp;token=5ee8ee52-5f44-410d-b1ba-96fe03794591" alt=""><figcaption></figcaption></figure>

* 다른 모델들을 supervised 한 경우와 SimVLM을 few-shot 한 것이 성능이 비슷함
  * 여기서 few-shot은 prompt learning이 아니라 1%의 데이터만 가지고 supervised 한 것임<br>

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2FKutC1FDSVi92ChnYH1pW%2Fimage.png?alt=media&amp;token=ebc5d20d-0fc9-432a-b8d8-816c22445ba3" alt="" width="347"><figcaption></figcaption></figure>

* Classification task에서는 <mark style="background-color:blue;">**다른 모델**</mark>들이 <mark style="background-color:red;">**SimVLM**</mark>에 비해 성능이 좋음
* 가장 성능이 높은 ALIGN은 dual encoder의 dot product로 fusion 함에 비해\
  SimVLM은 token by token으로 fusion하는 더 복잡한 방식임에도 성능이 더 낮음\
  **⇒ SimVLM의 architecture가 좋다고는 못하겠음**

<figure><img src="https://3767995091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcninPVWTJ93eLnFjFB7B%2Fuploads%2FFGUww3GGdsgpgLlynO6z%2Fimage.png?alt=media&amp;token=21e3bfdd-2e7e-4067-926a-37eb841fc6fa" alt="" width="350"><figcaption></figcaption></figure>

* <mark style="background-color:yellow;">**w/o Image2Text**</mark>
  * Align data가 없을 때 성능이 크게 하락
  * Align data가 중요하다!
* <mark style="background-color:green;">**w/o Text2Text**</mark>
  * text 데이터만으로 학습해도 2점 정도 올릴 수 있다.
* <mark style="background-color:blue;">**w/o conv stage**</mark>
  * 이미지 tokenization 할 때 linear 보다는 conv가 더 도움됨
  * ViT 논문에서도 conv가 더 advantage가 있다고 했었음

본 논문은 pretrain부터 처음부터 다시 했는데,\
요새는 vision encoder block을 이미 image-text align 되어있는 CLIP이나 ALIGN의 vision encoder를 가져와서 사용하는 추세이다.

⇒ 좀 더 fusion 하기 용이함

## <mark style="color:blue;">5. Conclusion 및 생각</mark>

* VLM을 위한 encoder-decoder 구조의 아키텍쳐 제시
  * Encoder에서 prefix로 image token과 text token(prefix token length까지의)을 input으로 받아서 Decoder에서 auto-regressive하게 text 생성
* 이전 논문들의 모델들은 Objective detector 형태의 vision encoder로 visual feature를 추출하지만\
  SimVLM은 ViT처럼 raw image를 patch로 잘라서 사용
* MLM, ITM 등 여러개의 pretraining objective로 훈련시키는 ALBEF와 달리 simple한 Prefix LM objective만을 사용
  * Prefix LM objective는 zero/few shot 성능에 도움이 됨
* large-scale의 weakly labeled dataset도 성능 향상에 도움이 되었을 것
* 더 복잡한데도 Classification에서 성능이 안나오는 것을 보면 굳이 Encoder-Decoder 구조를 사용해야할까 싶다.
* 하지만 generation task에서는 Prefix LM이 더 적합해보이기는 한다.

## Reference

* <https://ar5iv.labs.arxiv.org/html/2210.09263>
* <https://www.youtube.com/watch?v=XU4ZHUnnbpg>
* <https://www.youtube.com/watch?v=OMDu5r-Rm-c>
* <https://openreview.net/forum?id=GUrhfTuf_3>
