NLP/Paper Review

[NLP / paper review ] Prefix Tuning and Prompt Tuning 차이

joannekim0420 2023. 4. 15. 16:07
728x90

Prefix Tuning / Prompt Tuning 모두 2021년에 각각 Stanford University 와 Google research 에서 발표 하였다. 

논문의 모든 내용을 포함하고 있지 않으며, 전체적인 내용의 이해를 위한 정리본이다. 

■ Prefix-Tuning: Optimizing Continuous Prompts for Generation

A. Prior Methods

  • Fine-tuning updates all Transformer parameters and requires storing a full model copy for each task.
  • 각 task에 따라 모델의 모든 파라미터를 update한다

 

 

 

 

  • Adapter Tuning inserts additional task-specific layers between the layers of pre-trained language models.
  • 어댑터 튜닝은 task specific 한 트랜스포머 레이어들을 사전학습된  모델 안에 추가한다. 

 

 

B. Prefix-Tuning

prefix tuning

  • Freezes the Transformer parameters and only optimizes the prefix, which is a prepended sequence of continuous task-specific vectors to the input.
  • Only needs to store the prefix for each task, making prefix-tuning modular and space-efficient.
  • Consequently, this only needs to store one copy of the large transformer and a learned task-specific prefix. By having a separate prefix for each task, it can avoid data cross-contamination.
  • 트랜스포머의 파라미터들을 freeze 하고 인풋의 task-specific 한 벡터 sequence인 prefix 에 해당하는 블록의 파라미터만 update 한다. 
  • task 에 따른 prefix 들만 저장하기 때문에 space efficient하고 모듈화함.
  • 하나의 큰 트랜스포머만 저장하고 태스크에 맞게 각각의 prefix들이 존재하여 데이터간 오염(서로의 도메인에 침범한는 것)을 방지한다. 

 

C. Two models(AR, Encoder-Decoder)

Autoregressive Model gpt2
Encoder-Decoder model BART

  • Decoder only model 인 GPT2와, Encoder-Decoder 구조인 BART 을 사용하여, 각각 table-to-text, summarization 에 training함. 
  • x,y는 각각 source, target을 의미하고, P_idx 는 prefix, H_i 는 activation을 의미한다. 

 

D. Results

  • These are the results of table-to-text generation. If the adapter tuning model and prefix model train on the same percentage of parameters, you can see prefix does much better and it also outperforms most of the datasets.
  • gpt2 의 table-to-text generation의 결과를 보면, adapter tuning과 prefix tuning에서 같은 파라미터 퍼센티지만큼 training 시켰을 때, fine-tuning이 더 성능이 좋았으며, adapter tuning 의 파라미터 퍼센티지를 3% 보다도 outperform 한 것 존재.
  • 대체적으로 prefix tuning을 사용했을 때가 adapter tuning이나 fine tuning보다 좋은 결과를 내보이지만 항상 모든 metric에 대해서 그런 것을 아님. 

  • 오른쪽 그래프의 위 2개는 summarization task 에 대한 평가이고, 아래 2개는 table-to-text task에 대한 평가이다. 
  • 오렌지 라인(prefix) 이 블루라인(finetuning)보다 같거나 더 좋은 결과를 보인다. 

 

E. Ablation Study

  • Performance increases as the prefix length increases up to a threshold (200 for summarization and 10 for table-to-text) and then a slight performance drop occurs.
  • prefix 길이에 대해서 ablation study의 결과를 보면, 대체적으로 prefix 의 길이이가 길어질수록 더 좋은 점수를 냈지만, 너무 길어지면 살짝 downgrade 된다. 
  • 여기서 rouge-1,-2, bleu 는 모두 높을수록 좋은 점수이고, TER(Translation Edit Rate)만 candidate 문장이 reference 과 같아지기 위해 몇 번의 수정을 거쳐야하는지 나타내는 점수로 낮을수록 좋다. 

 

  • Initializing the prefix with activations of real words significantly outperforms random initialization.
  • Using task-relevant words obtains slightly better performance than task-irrelevant words.
  • prefix 는 랜덤 initialization보다는 모두 task와 관련된 단어로 초기화하는게 더 유의미한 결과를 보인다. 
  • 그리고 task에 맞게 summarization, table-to-text 등 실질적 relevant 한 단어들을 사용하는게 banana, elephant 와 같이 상관 없는 단어들을 선택하는 것보다 더 좋다. 

 

 

■ The Power of Scale for Parameter-Efficient Prompt Tuning

 

A. Model Tuning

  • Model tuning requires making a task-specific copy of the entire pre-trained model for each downstream task and inference must be performed in separate batches.
  • 기존 모델 튜닝 방식은 각각의 task에 맞게 pre-trained 된 모델들을 모두 fine-tuning하는 방식이었음.

 

B. Prompt Tuning

  • Freeze the entire pre-trained model and only allow an additional k tunable tokens per downstream task to be prepended to the input text.
  • Prompt tuning only requires storing a small task-specific prompt for each task and enables mixed-task inference using the original pre-trained model
  • Removes the restriction that the prompt P be parameterized by the same frozen parameter as the pre-trained model(GPT3)
  • input text 의 앞부분에 추가된 additional k 토큰들만 downstream 태스크에서 학습함.
  • 각 태스크마다 prompt 들을 저장하여 인퍼런스에서 mixed-task 로 사용.
  • GPT3 의 prompt와 달리 기존 트랜스포머 모델 파라미터는 froze 해놓고, prompt 파라미터 update 할 수 있음. 

 

C. T5 Span corruption objective

Text: “Thank you for inviting me to your party last week”
Pre-training input :“Thank you <X> me to your party <Y> week”
Output :  “<X> for inviting <Y> last <Z>

T5 에는 span corruption objective 이라는 기존 LM 모델들과 다른 object function 이 존재.

예를 들어, text에 원 문장이 위와 같다면, pre-training 시에는 setinel 토큰 <x> <y> 등으로 몇몇 단어들을 대체하여 입력으로 넣어주고 output을 <x> <y> <z>와 같이 input text에서 mask 하지 않았던 단어들을 대신함. 

즉, t5 모델은 pre-training시 제대로 된 문장을 온전히 보지 못했다는 문제가 존재. 

 

이에 맞춰주기 위해서 prompt tuning 시 저자는 3가지로 경우를 나누어서 실험함.

Prompt Tuning T5 model settings:
1) Span Corruption: T5 frozen model
2) Span Corruption + sentinel : T5 frozen model + sentinel
(resembles the pretraining targets)
3) LM Adaption: Uses “LM” objective

 

D. Setting Comparison

  • 여기서 model parameters의 각각은 t5-small/base/large/xl/xxl 을 의미함.
  • Standard model tuning of T5 achieves strong performance but requires storing separate copies of the model for each end task.
  • Prompt tuning of T5 matches the quality of model tuning as size increases while enabling the reuse of a single frozen model for all tasks.
  • Prompt tuning significantly outperforms few-shot prompt design(GPT-3)
  • 더 큰 모델에 prompt tuning을 도입할수록 model tuning과 비슷한 성능의 점수를 낼 수 있음.

 

 default configuration 으로, 

 LM adaption, class label initialization, prompt length of 100 tokens 을 선택했는데, 그 이유로는 ablation study 를 했을 때 각각이 가장 성능이 좋았음.

 

▶ prompt length comparison

  • Increasing to 20+ tokens generally confers a large boost, but XXL model performs well even with single-token prompts.
  • XXL model performs well even with single token prompts.
  • In general, the performance gets better with the increase of model size and prompt length.
  • token 길이를 100으로 하는 것이 가장 좋았다.
  • 대체적으로 1이나 5 토큰은 모델이 작을 때 좋은 결과를 얻지 못했고, 20 이상부터는 비슷하지만 좋은 결과를 보임.
  • 그러나 1이나 5 길이의 prompt 길이도 모델의 크기가 완전히 크면 좋은 결과를 보임.

 

 

▶ Prompt initialization, Pre-training method comparison

  • Random uniform initialization lags behind using sampled vocabulary or class-label embedding.
  • The difference vanishes at XXL size.
  • span corruption” objective is not well-suited for training frozen models to be later conditioned by prompts.
  • LM adaptation adds value across all model sizes.
  • XXL model is the most forgiving and gives strong results even with span corruption.
  • sampled vocab 방식이나 class-label embedding을 이용하는 것이 랜덤 초기화보다 결과가 더 좋고, class-label 이나 sampled vocab 방식이 큰 차이를 보이지는 않음. (그래서 class label로 초기화 할 수 있는 단어가 부족하면 sample vocab 방식으로 대신 채워넣는다고 함)
  • LM adaption을 이용하는 것이 나머지 둘 보다 항상 더 좋은 결과를 보였고, 전 모델에 대해 좋은 결과를 보임. 
  • span corruption은 얼려놓은 모델 파라미터들을 prompt로 조정하는 것이 역시 좋지 않음. 
  • 역시 마찬가지로 XXL 모델에서는 어떤 방식이든 다 좋은 결과를 보임
  • 즉, 모델 사이즈가 엄청 크면 걍 모든 것에서 뛰어남. 

 

Prefix Tuning vs Prompt Tuning

많은 사람들은 prefix 나 prompt를 같은 개념으로 보고 심지어 전문가들도 크게 구분하지 않지만 논문 상 둘의 차이를 비교하자면... 

  • encoder의 layer들에 들어간 prefix. input에만 들어간 prompt
  • task마다 다른 prefix 를 갖는 prefix tuning과 달리, prompt tuning은 여러 태스크가 통합된 하나의 prompt를 갖는다.
  • 둘 다 pre-trained 된 모델을 freeze 하고 새롭게 추가한 prefix와 prompt 의 파라미터만 update 함

 

실제로는 prompt tuning의 개념은 더 다양하게 사용되고 있으며 prefix tuning의 의미를 포함해서 사용하는 경우도 있음. 이 글에서 두 개의 비교는 각 개념을 위주로 다루는 논문을 요약한 것이기 때문에 다른 논문에서는 다른 의미로 해석/사용 되기도 함.