REINFORCEMENT
Trust Region Policy Optimization (TRPO)
policy gradient 기법에서 step-sizing이 매우 중요하다. 왜냐하면, supervised learning에서는 그 다음 update 할 때 어느정도 보완할 수 있지만, 강화학습에서는 step이 너무 커서 policy가 이상하게 변하면 그 이상한 policy 아래에서 다음 batch를 수집하게 된다. (계속 반복됨) 그래서 이를 해결하기 위해 등장한 것이 [yellow]TRPO[/yellow] 이다.
TRPO는 policy update가 너무 많이 되지 않도록 KL divergence를 penalty로 준다.
위의 수식을 constraint 대신에 penalty항을 추가해서 풀게 되면 아래와 같은 꼴이 된다.
하지만, 하나의 $\beta$를 고르는게 어려워서 $\beta = 1$로 사용한다.
Proximal Policy Optimization Algorithm (PPO)
결국 TRPO는 아래 수식을 최대화 하는 방향으로 학습한다. (위의 식에서 $\beta = 1$ 이라서 무시된 것 같음) 따라서, probability ratio 라고 하는 $r(\theta_{old})$ 가 매우 커질 수 있다.
그래서 PPO는 [yellow]clipping[/yellow]을 통해서 policy update가 너무 커지지 않도록 한다.
이런 저런 loss를 붙여주면 최종 로스는 아래와 같고, 이를 최대화 하는 방향으로 policy를 학습한다.
위의 수식에서 $L_t^{VF}$는 $(V_{\theta}(S_t) - V_t^{targ})^2$이고, $S[\pi_{\theta}]$는 entropy-bonus 항으로 exploration을 많이 하도록 한다.
이를 알고리즘으로 표현하면 아래와 같다.
value function은 따로 계산해줘야 한다. (아래 필기 참고)
Deep Reinforcement Learning from Human Preferences
2개의 비디오를 보고 어떤 것이 더 좋은지 선택하도록 했다. human feedback으로 부터 reward function을 학습하고, reward function을 optimize 한다.
이 논문에서는 well-specified reward function 없이 아래 4가지 조건을 만족하는 solution을 찾고 싶어한다.
- only recognize the desire behavior (not necessarily demonstrate)
- non-expert user에 의해서 모델이 학습될 수 있어야 하고
- large problem으로 확장 가능해야하며
- user feedback에 대해 economic 해야한다.
각 time 마다 policy $\pi: \mathcal{O} \rightarrow \mathcal{A}$, reward function estimate $\hat{r}: \mathcal{O} \times \mathcal{A} \rightarrow \mathbb{R}$
- policy $\pi$가 set of trajectories $\{\tau^1, ..., \tau^i\}$ 생성, sum of predicted rewards $r_t = \hat{r}(o_t, a_t)$를 최대화 하는 방향으로 policy $\pi$의 파라미터가 업데이트 됨 (traditional RL)
- pairs of segments ($\sigma^1$, $\sigma^2$) 선택 (from the trajectores $\{\tau^1, ..., \tau^i\}$)
- parmeters of mapping $\hat{r}$이 supervised learning으로 학습됨 (사람의 비교를 맞추도록)
$\sigma^1$을 $\sigma^2$보다 선호할 확률은 위와 같다. 이 때, 두 예측 reward의 차이는 어떤 하나를 다른 하나보다 더 선호할 확률을 의미한다. (아래 필기 참고)
위에서 구한 특정 segments를 선호할 확률값 (예측값)과 human label 사이의 cross-entropy loss를 최소화 하는 $\hat{r}$을 선택한다. (reward function 학습)
Fine-Tuning Language Models from Human Preferences
reward learning이란 human judgement로 reward를 정의한 RL이다. 이 논문에서는 4가지 task(continuation, summarization)를 independent 하게 학습한다. Human feedback을 기반으로 reward function을 구하고, 그 reward를 최대로 만드는 policy를 구한다.
사람에게 4개의 option 중 하나를 고르도록 하는데, reward model이 사람의 선택을 예측할 수 있도록 하는 loss이다.
policy $\pi$를 fine-tune할 때 사용되는 loss이다. 두번째 항은 KL divergence 역할을 하는데 $\pi$가 $\rho$와 너무 멀어지지 않도록 방지하는 역할을 하며, 그 중 분자항은 entropy bonus 역할을 한다.
- $(x, y_0, y_1, y_2, y_3)$ 데이터를 수집하고 ($x$는 prompt dataset에서, $y$는 original GPT $\rho$를 통해서 생성) human에게 가장 좋은 $y_i$를 선택하도록 한다.
- reward model $r$을 original GPT $\rho$로 초기화 하고, human sample에 대해서 loss 1을 이용해서 학습시킨다.
- policy $\pi$를 PPO 알고리즘을 통해 최대 reward를 만들 수 있도록 학습시킨다.
- online data collection case인 경우, 추가적인 sample을 계속 수집하고 주기적으로 reward model $r$을 재학습시킨다.
Training language models to follow instructions with human feedback
언어 모델이 untruthful, toxic, not helpful한 output을 생성하는 경우가 있는데 이를 user와 model이 [yellow]not align[/yellow] 되어 있다고 표현한다. human feedback으로 모델을 fine-tuning해서 align 하는 것이 목표이다.
총 3가지 단계로 이루어져 있다: 1) Supervised fine-tuning 2) Reward modeling 3) Reinforcement Learning
1. SFT: 데이터 수집 및 수집한 데이터를 가지고 supervised learning 방식으로 fine-tuning
OpenAI API에 제출된 prompt와 labeler-written prompt에 대해서 human-written demonstration을 생성하고 supervised learning을 이용해서 labeler demonstration에 대해 GPT3을 fine-tune한다. 이때, validation set의 RM score를 기반으로 SFT model을 선택한다.
2. RM: human-labeled comparison을 수집하고, comparison data에 대해 reward model을 학습
prompt에 대해서 모델이 output을 뱉으면 labeler가 랭킹을 매겨 human-labeled comparison 데이터를 만든다. 아래 loss를 통해서 labeler가 어떤 output을 선호하는지 예측하도록 reward model을 학습한다. (SFT model with the final unembedding layer removed에서 시작해서 prompt와 response를 input으로 받아서 reward를 산출한다.)
3. RL (PPO): 학습된 reward model을 reward function으로 이용하여 policy가 최대 reward를 만들도록 PPO 알고리즘으로 학습
value-function은 RM으로 초기화하고, PPO 알고리즘을 통해 아래 objective를 최대화 하도록 policy를 학습시킨다. $E_{x ~ D_{pretrain}}$은 public NLP dataset에 대한 성능 저하 방지를 위한 term이다.
InstructGPT 저자들은 아래의 8가지 결과를 얻었다.
- Labelers significantly prefer InstructGPT outputs over outputs from GPT-3.
- Our models generalize to the preferences of "held-out" labelers that did not produce any training data.
- Public NLP datasets are not reflective of how our language models are used.
- InstructGPT models show improvements in truthfulness over GPT-3.
- InstructGPT shows small improvements in toxicity over GPT-3, but not bias.
- We can minimize performance regressions on public NLP datasets by modifying our RLHF fine-tuning procedure.
- InstructGPT models show promising generalization to instructions outside of the RLHF finetuning distribution.
- InstructGPT still makes simple mistakes.
[1] Schulman, John, et al. "Trust region policy optimization." International conference on machine learning. PMLR, 2015.
[2] Schulman, John, et al. "Proximal policy optimization algorithms." arXiv preprint arXiv:1707.06347 (2017).
[3] Christiano, Paul F., et al. "Deep reinforcement learning from human preferences." Advances in neural information processing systems 30 (2017).
[4] Ziegler, Daniel M., et al. "Fine-tuning language models from human preferences." arXiv preprint arXiv:1909.08593 (2019).
[5] Ouyang, Long, et al. "Training language models to follow instructions with human feedback." Advances in Neural Information Processing Systems 35 (2022): 27730-27744.