Préparer les données pour le RLHF

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Jeux de préférences vs. jeux d'invites

Le processus RLHF complet.

Reinforcement Learning from Human Feedback (RLHF)

Jeux de préférences vs. jeux d'invites

Le processus RLHF complet avec jeu initial d'invites.

Reinforcement Learning from Human Feedback (RLHF)

Jeux de préférences vs. jeux d'invites

Le processus RLHF complet avec jeu initial d'invites et un jeu de préférences alimentant le modèle de récompense.

Reinforcement Learning from Human Feedback (RLHF)

Jeu d'invites

  • Questions pour le modèle
  • Disponibles dans les jeux de données 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?'
  • L'invite peut devoir être extraite
  • Repérez des marqueurs comme : Input=, {{Text}}:, ###Human:
Reinforcement Learning from Human Feedback (RLHF)

Explorer le jeu de préférences

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

Capture d'écran de la plateforme Hugging Face montrant le jeu de données hh-rlhf.

Reinforcement Learning from Human Feedback (RLHF)

Traiter le jeu de préférences

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'])}
)
  • La méthode d'extraction des invites varie selon le jeu de données
Reinforcement Learning from Human Feedback (RLHF)

Jeu de préférences final

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)

Passons à la pratique !

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...