Preparare i dati per l'RLHF

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Insiemi di dati di preferenze vs. prompt

Il processo RLHF completo.

Reinforcement Learning from Human Feedback (RLHF)

Insiemi di dati di preferenze vs. prompt

Il processo RLHF completo con dataset iniziale di prompt.

Reinforcement Learning from Human Feedback (RLHF)

Insiemi di dati di preferenze vs. prompt

Il processo RLHF completo con dataset iniziale di prompt e dataset di preferenze che alimenta il modello di ricompensa.

Reinforcement Learning from Human Feedback (RLHF)

Dataset di prompt

  • Domande per il modello
  • Reperibili negli insiemi di dati su 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?'
  • Potresti dover estrarre il prompt
  • Cerca marcatori come: Input=, {{Text}}:, ###Human:
Reinforcement Learning from Human Feedback (RLHF)

Esplorare il dataset di preferenze

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

Elaborare il dataset di preferenze

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'])}
)
  • Il modo di estrarre i prompt è diverso tra i vari dataset
Reinforcement Learning from Human Feedback (RLHF)

Dataset di preferenze finale

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)

Esercitiamoci!

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...