RLHF 入門

Reinforcement Learning from Human Feedback(RLHF)

Mina Parham

AI Engineer

歡迎加入本課程!

 

  • 講師:Mina Parham

 

  • AI 工程師
  • 大型語言模型(LLMs)
  • 從人類回饋中強化學習(RLHF)

 

  • 主題:從人類回饋中強化學習(RLHF)

一張圖示,呈現 AI 模型加入人類參與的額外步驟。

Reinforcement Learning from Human Feedback(RLHF)

歡迎加入本課程!

 

  • 講師:Mina Parham

 

  • AI 工程師
  • 大型語言模型(LLMs)
  • 從人類回饋中強化學習(RLHF)

 

  • 主題:從人類回饋中強化學習(RLHF)

一張圖示,呈現 AI 模型加入人類參與的額外步驟,帶來更佳結果。

Reinforcement Learning from Human Feedback(RLHF)

強化學習複習

一張圖示:代理、動作與獎勵策略構成循環,代表強化學習流程。

Reinforcement Learning from Human Feedback(RLHF)

強化學習複習

一張圖示:代理、動作與獎勵策略構成循環,代表強化學習流程。

Reinforcement Learning from Human Feedback(RLHF)

強化學習複習

一張圖示:代理、動作與獎勵策略構成循環,代表強化學習流程。

Reinforcement Learning from Human Feedback(RLHF)

強化學習複習

一張圖示:代理、動作與獎勵策略構成循環,代表強化學習流程。

Reinforcement Learning from Human Feedback(RLHF)

從 RL 到 RLHF

 

  一張圖示:LLM、文字輸出與人類評估者,代表從人類回饋中強化學習的部分循環。

Reinforcement Learning from Human Feedback(RLHF)

從 RL 到 RLHF

 

  一張圖示:LLM、文字輸出與人類評估者,代表從人類回饋中強化學習的部分循環。

Reinforcement Learning from Human Feedback(RLHF)

從 RL 到 RLHF

  • 訓練 獎勵模型(reward model)
  • 與人類偏好對齊

一張圖示:LLM、文字輸出與人類評估者,代表從人類回饋中強化學習的部分循環。

Reinforcement Learning from Human Feedback(RLHF)

RLHF 中的 LLM 微調

 

大型語言模型的圖示。

Reinforcement Learning from Human Feedback(RLHF)

RLHF 中的 LLM 微調

  • 訓練 初始 LLM

以輸入資料集微調的大型語言模型圖示。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

一個提示「Who wrote Romeo and Juliet」輸入 LLM。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

提示「Who wrote Romeo and Juliet」,LLM 回答:「a 16th Century author」。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

提示「Who wrote Romeo and Juliet」,LLM 回答:「a 16th Century author」,並有額外的策略模型接收該提示。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

提示「Who wrote Romeo and Juliet」,LLM 回答:「a 16th Century author」,另有策略模型接收提示,並以獎勵模型進行訓練。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

提示「Who wrote Romeo and Juliet」,LLM 回答:「a 16th Century author」,策略模型經獎勵模型訓練後,給出答案「William Shakespeare」。

Reinforcement Learning from Human Feedback(RLHF)

完整的 RLHF 流程

提示「Who wrote Romeo and Juliet」,LLM 回答:「a 16th Century author」,策略模型經獎勵模型訓練後給出「William Shakespeare」,並比較兩個結果。

Reinforcement Learning from Human Feedback(RLHF)

與 RLHF 微調後的 LLM 互動

  • 在 Hugging Face 上的 RLHF 預訓練模型 🤗
from transformers import pipeline

text_generator = pipeline('text-generation', model='lvwerra/gpt2-imdb-pos-v2')
# Provide a review prompt review_prompt = "This is definitely a" # Generate the continuation output = text_generator(review_prompt, max_length=50) #Print the generated text print(output[0]['generated_text'])
This is definitely a crucial improvement.
Reinforcement Learning from Human Feedback(RLHF)

與 RLHF 微調後的 LLM 互動

from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer


# Instantiate the pre-trained model and tokenizer model = AutoModelForSequenceClassification.from_pretrained("lvwerra/distilbert-imdb") tokenizer = AutoTokenizer.from_pretrained("lvwerra/distilbert-imdb")
# Use pipeline to create the sentiment analyzer sentiment_analyzer = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer) # Pass the text to the sentiment analyzer and print the result sentiment = sentiment_analyzer("This is definitely a crucial improvement.")
print(f"Sentiment Analysis Result: {sentiment}")
positive
Reinforcement Learning from Human Feedback(RLHF)

一起來練習吧!

Reinforcement Learning from Human Feedback(RLHF)

Preparing Video For Download...