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)

선호(preference) 데이터셋 탐색

from datasets import load_dataset
preference_data = load_dataset("trl-internal-testing/hh-rlhf-helpful-base-trl-style", 
                               split="train")

Hugging Face 플랫폼에서 hh-rlhf 데이터셋을 보여주는 스크린샷.

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...