# [Training language models to follow instructions with human feedback](https://arxiv.org/abs/2203.02155) ## 1. Introduction 1. Large language models (LMs) can be prompted to perform a range of natural language processing(NLP) tasks, given some examples of the task as input. However, these models often express unintended behaviors such as making up facts, generating biased or toxic text, or simply not following user instructions 2. This is because the language modeling objective used for many recent large LMs—predicting the next token on a webpage from the internet—is different from the objective “follow the user’s instructions helpfully and safely” 3. Thus, we say that the language modeling objective is misaligned :::info misaligned是指LLM產生的內容沒有被法解決或有效幫助人類所提出來的問題 ::: 4. We make progress on aligning language models by training them to act in accordance with the user’s intention. 5. This encompasses both explicit intentions such as following instructions and implicit intentions such as staying truthful, and not being biased, toxic, or otherwise harmful. :::info Alignment指的是LLM產生的結果: 1. 能有效地幫助使用者解決問題,不會答非所問 2. 不會出現untruthful、biase or harmful的內容 ::: :::success 總結來說,OpenAI團隊提出使用人類反饋的強化學習方法(Reforcement Learn Human Feedback)來fine-tune語言模型,使其行為更符合人類的意圖。 ::: ## 2. Methods and Methodology ### Step 1: Supervised fine-tuning via collected demonstration #### 1.1 一開始OpenAI團隊拿自家內部API的prompt,叫人來回答。換句話說就是人認為LLM應該要怎麼回答這個問題,請人寫下來(human-written desired output)。 ![截圖 2023-11-24 09.53.53](https://hackmd.io/_uploads/ByO74t6Vp.png =60%x) #### 1.2 而這樣一個prompt加上一個人的回答我們就稱做一個demonstration。 ![截圖 2023-11-24 09.54.12](https://hackmd.io/_uploads/By6UEYpEp.png =80%x) #### 1.3 接下來因為要訓練資料,所以我們蒐集了一堆的demonstratons。另外為了避免人撰寫output時帶入自己個人主觀的意見,因此OpenAI請了不同的承包商的不同人來參與這個工作。 ![截圖 2023-11-24 09.54.38](https://hackmd.io/_uploads/SJxuNFaVa.png =70%x) #### 1.4 之後我們將蒐集的demonstrations丟到GPT-3進行訓練,這邊一堆的demonstrations就是dataset。 ![截圖 2023-11-24 09.54.57](https://hackmd.io/_uploads/HJ0FNFpN6.png =80%x) :::success 到這邊就完成Step 1了,而訓練完demonstrations的模型我們稱作supervised fine-tuning model,簡稱SFT model。 ::: ### Step 2: Reward Model Training #### 2.1 之後我們將prompt丟進剛才訓練好的SFT model,讓他產生output。但我們知道每次輸入相同的input,卻會得到不同的output(因為LLM內部要產生下一個token是靠機率),因此下面的圖片說明的是同一個prompt(也就是input)產生了A,B,C,D四種不同的回答。 ![截圖 2023-11-24 09.56.04](https://hackmd.io/_uploads/rknkHFTET.png =60%x) #### 2.2 之後我們會再請人對這4個答案做一個排序,如果覺得LLM回答得好就排前面一點;反之就牌後面一點。 ![截圖 2023-11-24 09.56.30](https://hackmd.io/_uploads/ryYeBYaV6.png =60%x) #### 2.3 之後我們會將人的排序丟進Reward model裡面進行訓練。而這個Reward model可以對LLM產生的output進行一個評分,如果Reward model覺得LLM產生的結果不錯,那就會得到比較高的分數(reward value),反之就會得比較低的分數。 :::info 也可以把Reward model假設為老師,SFT model是學生。而sampled prompt是考題,model outputs表示學生的答案。之後學生會把答案給老師,老師會對你的答案給出一個分數 ::: ![截圖 2023-11-24 09.56.52](https://hackmd.io/_uploads/Sy6Wrt6Ea.png =90%x) :::info 接下來我們進一步探討Reward model裡面是怎麼運作的: 1. 橘色內部大張的紙表示input;小張的紙表示output。而小張的紙右下方的i , j表示LLM產生的不同output,也可以說output i和output j。 2. 之後會將產生的output丟進Reward model(綠色圖示)內進行評分。(在這邊雖然畫了兩個Reward model,但其實是指同一個)。 3. 經過Reward model後會分別產生評分ri , rk。 4. 接著我們根據Reward model訓練完的解果來逐步調整loss,下方會進一步的解釋: * 下方紫色的區塊表示Reward model訓練完的解果,也就是output j回答得比output k好。 * 之後我們將剛剛從Reward model得出的評分進行運算,也就是把值丟進loss=log(...)。 * 假設rj>rk,則經過運算後loss會很小;如果rj<rk,則經過運算後loss會很大。那loss如果太大就表示跟尋練出來的結果相差太大,因此我們會根據算出來的loss進行調整(也就是虛線箭頭部分)。 ![截圖 2023-11-24 09.58.15](https://hackmd.io/_uploads/SyPEHY6Np.png =35%x) ![截圖 2023-11-24 09.58.50](https://hackmd.io/_uploads/HJ_LSK6Np.png =60%x) * 上面的公式其實只是在計算loss。x表示input,y表示output,D表示dataset(指的是LLM產生各種結果的dataset) * 另外Reward model產生的分數是經過Normalize的,也就是模型對所有output評分,平均就是0分,所以分數可能有正有負。 ::: ### Step 3: Reinforcement learning via PPO 1. 我們丟一個新的prompt,然後讓SFT model來回答並產生output。 2. 然後把output丟到Reward model裡面打分數得到rk,rk可能是正或負。 3. 接下來會把得到的分數feedback給SFT model(也稱作generation model)進行強化是學習(Refocement learning)。這裡做強化式學習簡單來說就是對model產生下一個token這個行為做調整。 4. 這裡PPO是強化式學習的一種方法,跟policy gradient有關。 ![截圖 2023-11-24 09.59.22](https://hackmd.io/_uploads/BJVOStTEp.png ) :::success 這邊有使用到強化式學習的技術,這邊不多介紹。但可以參考下方網址: [概述增強式學習 (Reinforcement Learning, RL) (一) ](https://www.youtube.com/watch?v=XWukX-ayIrs) [概述增強式學習 (Reinforcement Learning, RL) (二) ](https://www.youtube.com/watch?v=US8DFaAZcp4) [概述增強式學習 (Reinforcement Learning, RL) (三) ](https://www.youtube.com/watch?v=kk6DqWreLeU&t=100s) ::: 將上方三個步驟結合的完整流程圖: ![螢幕擷取畫面 2023-11-23 101347](https://hackmd.io/_uploads/HJN2HeRVp.png) :::success 上面的流程就是在介紹RLHF(Reforcement Learning form Human Feedback)這個技術,而整個模型我們稱作InstructionGPT。 ::: ## 3. Results 下圖是顯示出各種調整的模型在各方面的比較: :::info * GPT:這邊指的是GPT-3。 * GPT(prompted):也是使用GPT-3,但使用時會加入一些prompts/guide去引導模型有更好的生成。 * SFT:這是前面只完成Step 1的模型 * PPO/PPO-ptx:就是上述加入Reforcement Learning的模型。PPO-ptx是又有去考慮到pre-train model 的distribution ::: ![螢幕擷取畫面 2023-11-23 111739](https://hackmd.io/_uploads/rkp4PxC4p.png) 上圖必較特別的是在幻覺(Hallucination)的比較,最低的是SFT模型。這可能是因為訓練的資料都是人寫的,所以在生成文字時比較不容易產生幻覺(Hallucination)。但這樣的模型多樣性(diverse)就會比較差。 所以有時候產生幻覺不一定是壞事,模型適當的產生幻覺,其實能給我們更多的補充資料。:+1: :::success 論文中提到其他的觀察(細節部分請自行看論文說明): * Labelers significantly prefer InstructGPT outputs over outputs from GPT-3. * 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. * 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 promising generalization to instructions outside of the RLHF finetuning distribution. * InstructGPT still makes simple mistakes. ::: ## 4. Discussion 1. Implications for alignment research * This suggests that right now increasing investments in alignment of existing language models is more cost-effective than training larger models. 2. Limitation * Our models are neither fully aligned nor fully safe; they still generate toxic or biased outputs, make up facts, and generate sexual and violent content without explicit prompting.