Machine Learning paper/NLP

Improving Language Understanding by Generative Pre-Training (GPT) Paper Review / 논문 리뷰

Sion1225 2023. 10. 24. 00:13

첫 논문 리뷰입니다.
항상 논문을 읽고 개인적으로 논문을 정리하거나, 발표를 위해 슬라이드쇼 자료를 만들고 있는데, 내부적으로만 쓰고 남겨두기보다는 공개하는 것이 좋을 것 같아서 작성하기로 했습니다.

개인적으로 논문을 제대로 읽거나 리뷰할 때, 기본 템플릿을 유지한 채, 순서대로 읽는 편입니다. 그 이유는, 그렇게 해야 저자들의 생각과 시야를 최대한 따라갈 수 있고, 논문의 구성과 형식을 익히는데도 도움이 된다고 생각하기 때문입니다.
개인적 자료를 옮기는 것에 불과하기 때문에, 개인적 판단에 따라 크게 중요치 않은 내용은 생략됩니다.
한국어 자료를 늘리기 위하여 한글해석도 붙힐 생각입니다.
지적, 의견 환영합니다.


ChatGPT로 잘 알려진 GPT모델의 시발점이 되는 논문입니다. Pre-train과 Fine-tuning의 개념이 제시됐으며, 라벨링 되지 않은 다량의 데이터를 Transformer decoder 모델의 training data 로써 쓰는 방법을 제시한, 처음으로 제시된 Pre-trained Transformer인 중요한 논문입니다.


논문 원문에 포함되어있지 않지만, 이해를 돕기위한 자료입니다.

Attention is all you need (Ashish Vaswani et al., 2017)

붉은 사각형 부분이 Decoder 블록이고, Encoder가 없기 때문에, Encoder로부터 정보를 받아와 Attention을 수행하는 블록이 제거됐습니다. 그리고 Decoder블록을 N개 쌓은 구조가 GPT의 아키텍처입니다.


Improving Language Understanding by Generative Pre-Training (Radford et al., 2018)
원문링크


Abstruct

  • Labeling 되지 않은 데이터들을 이용하여 학습 (Unsupervised pre-training)

필자 개인적인 의견으로는 엄밀히 Unsupervised는 아니라고 봅니다. 이유는 후술 합니다.

  • 상기의 Pre-training을 함으로써, 적은 데이터셋으로부터도 우수한 성능을 끌어내는 것이 가능. (Fine-tuning)

Introduction

  • Leveraging more than word-level information from unlabeled text, however, is challenging.
    라벨링 되지 않은 데이터에서 단어 수준 이상의 정보를 활용하는 것은 어려운 일이다.
    • It is unclear what type of optimization objectives are most effective.
      어떤 종류의 목적함수가 가장 효과적인지 불분명하기 때문.
    • There is no consensus on the most effective way to transfer these learned representations to the target task.
      학습된 표현을 특정 task에 대해 적용하는 가장 효과적인 방법에 대해 합의된 바가 없다.

Related Work

하기 항목들에 관한 다양한 선행연구들이 있다.

  • Semi-supervised learning for NLP
  • Unsupervised pre-training
  • Auxiliary training objectives

Framework

Unsupervised pre-training

  • Unsupervised corpus of tokens $\mathcal{U}=\{u_1,⋯,u_n\}$, we use a standard language modeling objective to maximize the following likelihood:
    비지도 학습되는 코퍼스의 토큰들을 $\mathcal{U}=\{u_1,⋯,u_n\}$ 로 정의하고, 이하의 식과 같은 표준적인 언어모델 목적 함수를 최대화한다.
    $$
    L_{1}(\mathcal{U})=\sum_{i} \log P(u_i|u_{i-k},\cdots ,u_{i-1};\Theta)
    $$
    k: size of the context window, Θ: nn(신경망)’s parameter

위에서 말한, 엄밀히 Unsupervised(비지도학습) 이 아니라고 생각한다고 한 이유는, 사람이 labeling 한 라벨은 없지만, 원문인 corpus에서 각각의 토큰 하나하나를 라벨로써 사용하는 것이기 때문.

즉, 매 시점 토큰을 하나씩 예측해 가며, 원래 문장의 토큰과 동일하면 정답, 틀렸다면 오답이 된다. 틀렸을 경우, 후속 예측에 영향을 끼칠 수 있지 않냐는 질문에는, 원래 Transformer 논문인, Attention is all you need에서도 Decoder구조의 Training에 사용하는 Teacher forcing 기법을 사용하여 해결한다. 다시 말해, 매 시점의 예측이 다음의 예측에 영향을 주지 않는다.

처음 보면 수식이 복잡해 보일 수 있지만, 현재시점 i에서, window의 크기만큼의 이전 토큰들을 고려하여, 현재 시점에 나올 토큰의 확률을 로그스케일링 한 후, 처음부터 현재시점까지의 이러한 확률을 모두 더한다는 것이다.

  • We use a multi-layer Transformer decoder.
    멀티레이어 트랜스포머 디코더를 사용했다. 즉, 디코더 레이어(블록)를 적층 하여 사용했다. (Original Transformer랑 동일)
    $$
    h_0=UW_e+W_p
    $$
    $$
    h_l=\text{transforemr_block}(h_{l-1}) \forall i \in [1,n]
    $$
    $$
    P(u)=\text{softmax}(h_n W^T_e)
    $$
    $𝑈=(u_{(−k)},⋯,u_{(−1)})$: the context vector of tokens, $n$: the number of layers, $W_e$: token embedding matrix, $W_p$: position embedding matrix

각 시점의 토큰들이 블록들을 통과하여 최종적으로 확률로써 나타내어지는 것을 수식으로 표현한 것이다.

Supervised fine-tuning

  • We adapt the parameters to the supervised target task. We assume a labeled dataset $C$, where each instance consists of a sequence of input tokens, $𝑥^1,⋯,𝑥^𝑚$, along with a label $𝑦$.
    파라미터들을 지도학습된 (라벨이 있는) task에 맞춘다. 즉, 모델을 downstream task에 대해 적응시킨다(최적화한다, fine-tuning). 라벨링 된 데이터셋을 $C$ 라 하고, 각 예제는 입력토큰 $𝑥^1,⋯,𝑥^𝑚$ 으로 구성된 문장으로 되어있으며, 라벨 $𝑦$ 가 붙여져 있다.
  • The inputs are passed through the pre-trained model to obtain the final transformer block’s activation $ℎ_𝑙^𝑚$, which is then fed into an added linear output layer with parameter $𝑊_𝑦$ to predict $𝑦$:
    입력들은 사전학습된(pre-trained) 모델을 통과하여 마지막 transformer 블록에서 활성화$ℎ_𝑙^𝑚$를 얻는다. 그 후, 이 활성화는 파라미터$𝑊_𝑦$의 선형레이어에 입력되어 y를 예측한다.

'활성화'라는 것은, 블록의 출력을 의미함.

$$
𝑃(y│x^1,⋯,x^m )=𝑠𝑜𝑓𝑡𝑚𝑎𝑥(h_l^m W_y)
$$

  • This gives us the following objective to maximize:
    상기 수식으로부터 하기의 최대화할 목적함수를 얻을 수 있다.
    $$
    L_2(C)=\sum_{(x,y)}\log ⁡P(y|x^1,⋯,x^m)
    $$

Addition

    • We additionally found that including language modeling as an objective to the fine-tuning helped learning by
      추가적으로, fine-tuning에 언어 모델링을 포함시키는 것이 도움이 된다는 것을 발견했다.
      • Improving generalization of the supervised model
        지도학습 모델의 일반화 향상
      • Accelerating convergence
        수렴을 가속화
상기의 두 목적함수를 합쳐서 Fine-tuning 한다. 즉, task에 대해 학습하면서, fine-tuning 되는 데이터의 텍스트에 대해서도 동시에 학습되는 것이다. $L_1$의 학습률 가중치는 $\lambda$로 조정되어진다. (일반적으로 텍스트는 덜 학습)

$$
L_3(C)=L_2(C)+\lambda * L_1(C)
$$

Task-specific input transformations

상기 그림과 같이 각 task에 대해 모델설계 가이드라인을 제시. Similarity down stream task에 Text를 전치하여 입력하고 결과를 합해서 Linear로 보내는 이유가 설명되지 않았지만, 실험에 의한 경험론적 방법으로 추측.
Multiple Choice의 최우측 그림은 softmax를 의미. Likelihood를 산출.

Experiments

  • Unsupervised pre-training
    • BooksCorpus (contains over 7,00 unique unpublished books)
      BooksCorpus (출판되지 않은 7,000권의 각기 다른 책들)
    • 1B Word Language Model Benchmark which used by a similar approach, ELMo
      ELMo와 유사한 접근방식을 이용하여 1B Word Language Model Benchmark 시행
  • Model specifications
    • 12-layers(768 dimensional states and 12 attention heads)
    • FFN's dimension size: 3072
    • Adam lr: 2.5e-4 (increased linearly from 0 over the 2000 updates and annealed to 0)
    • 100 epochs on minibatches of 64 randomly sampled, contiguous sequences of 512 tokens.
    • A simple weight initialization of 𝑁(0,0.02)
    • BPE with 40,000 merges
    • Dropouts rate 0.1
    • L2 regularization 𝑤=0.01
    • GELU
  • Fine-tuning details
    • Dropout rate: 0.1
    • Learning rate: 6.25e-5 & batchsize 32
    • 3 epochs
    • Lr decay schedule with warmup over 0.2%
    • $\lambda = 0.5$

 

  • Supervised fine tuning

 

  • Natural Language Inference

 

  • Question & Answering

 

  • Semantic Similarity & Classification

Analysis

  • Impact of number of layers transferred
    레이어 수와 pre-training updates에 따른 성능

  • Ablation studies
    절제(융삭) 연구들
번역하기 힘들지만, 요소를 하나씩 깎아가며 실험을 했다는 의미를 함축하고 있는 듯.
  • The trend suggests that larger datasets benefit from the auxiliary objective but smaller datasets do not
    큰 데이터셋은 보조 목적(downstream task specific 한 튜닝/training)이 도움이 되는 경향을 보이지만, 작은 데이터셋은 그렇지 않다.
즉, 작은 데이터셋에 대해서는 fine-tuning 없이 pre-trained 모델만으로 사용하는 것이 더 성능이 좋았다.
  • LSTM only outperforms the Transformer on one dataset
    LSTM (ELMo)는 오직 하나의 데이터셋에서만 GPT보다 성능이 좋았다.
RTE를 의미.