RLHF를 위한 데이터 준비

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

선호도 데이터셋 vs. 프롬프트 데이터셋

전체 RLHF 프로세스

Reinforcement Learning from Human Feedback (RLHF)

선호도 데이터셋 vs. 프롬프트 데이터셋

초기 프롬프트 데이터셋이 포함된 전체 RLHF 프로세스

Reinforcement Learning from Human Feedback (RLHF)

선호도 데이터셋 vs. 프롬프트 데이터셋

초기 프롬프트 데이터셋과 보상 모델에 입력되는 선호도 데이터셋이 포함된 전체 RLHF 프로세스

Reinforcement Learning from Human Feedback (RLHF)

프롬프트 데이터셋

  • 모델을 위한 질문
  • Hugging Face 데이터셋에서 확인 가능
prompt_data = load_dataset("center-for-humans-and-machines/rlhf-hackathon-prompts", 
                           split="train")
prompt_data['prompt'][0]
'How important is climate change?'
  • 프롬프트 추출이 필요할 수 있음
  • Input=, {{Text}}:, ###Human:와 같은 마커 확인
Reinforcement Learning from Human Feedback (RLHF)

선호도 데이터셋 살펴보기

from datasets import load_dataset
preference_data = load_dataset("qgallouedec/hh-rlhf-helpful-base-trl-style", 
                               split="train")
Reinforcement Learning from Human Feedback (RLHF)

선호도 데이터셋 처리하기

def extract_prompt(text):
    # Extract the prompt as the first element in the list
    prompt = text[0]["content"]
    return prompt
# Apply the extraction function to the dataset
preference_data_with_prompt = preference_data.map(
    lambda example: {**example, 'prompt': extract_prompt(example['chosen'])}
)
  • 프롬프트 추출 방식은 데이터셋마다 다름
Reinforcement Learning from Human Feedback (RLHF)

최종 선호도 데이터셋

sample = preference_data_with_prompt.select(range(1))
sample['prompt']
'What vitamins are essential for the body to function?'
sample['chosen']
[ { "content": "What vitamins are essential for the body to function?", "role": 
   "user" }, { "content": "There are some very important vitamins that ensure the 
   proper functioning of the body, including Vitamins A, C, D, E, and K along ...}]
Reinforcement Learning from Human Feedback (RLHF)

연습해 봅시다!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...