Introduction à RLHF

Reinforcement Learning from Human Feedback (RLHF)

Mina Parham

AI Engineer

Bienvenue dans le cours !

 

  • Formateur : Mina Parham

 

  • Ingénieure en IA
  • Large Language Models (LLMs)
  • Reinforcement Learning from Human Feedback (RLHF)

 

  • Sujet : Reinforcement Learning from Human Feedback (RLHF)

Schéma d'un modèle d'IA avec une étape supplémentaire où une personne intervient.

Reinforcement Learning from Human Feedback (RLHF)

Bienvenue dans le cours !

 

  • Formateur : Mina Parham

 

  • Ingénieure en IA
  • Large Language Models (LLMs)
  • Reinforcement Learning from Human Feedback (RLHF)

 

  • Sujet : Reinforcement Learning from Human Feedback (RLHF)

Schéma d'un modèle d'IA avec une étape additionnelle où une personne intervient, menant à de meilleurs résultats.

Reinforcement Learning from Human Feedback (RLHF)

Rappel sur l'apprentissage par renforcement

Schéma montrant un agent, une action et une politique de récompense en cycle, représentant l'apprentissage par renforcement.

Reinforcement Learning from Human Feedback (RLHF)

Rappel sur l'apprentissage par renforcement

Schéma montrant un agent, une action et une politique de récompense en cycle, représentant l'apprentissage par renforcement.

Reinforcement Learning from Human Feedback (RLHF)

Rappel sur l'apprentissage par renforcement

Schéma montrant un agent, une action et une politique de récompense en cycle, représentant l'apprentissage par renforcement.

Reinforcement Learning from Human Feedback (RLHF)

Rappel sur l'apprentissage par renforcement

Schéma montrant un agent, une action et une politique de récompense en cycle, représentant l'apprentissage par renforcement.

Reinforcement Learning from Human Feedback (RLHF)

Du RL au RLHF

 

  Schéma montrant une icône d'un LLM, une sortie textuelle et une personne évaluatrice, représentant une partie du cycle de l'apprentissage par renforcement avec rétroaction humaine.

Reinforcement Learning from Human Feedback (RLHF)

Du RL au RLHF

 

  Schéma montrant une icône d'un LLM, une sortie textuelle et une personne évaluatrice, représentant une partie du cycle de l'apprentissage par renforcement avec rétroaction humaine.

Reinforcement Learning from Human Feedback (RLHF)

Du RL au RLHF

  • Entraîner le reward model
  • Aligner sur les préférences humaines

Schéma montrant une icône d'un LLM, une sortie textuelle et une personne évaluatrice, représentant une partie du cycle de l'apprentissage par renforcement avec rétroaction humaine.

Reinforcement Learning from Human Feedback (RLHF)

Ajustement d'un LLM dans RLHF

 

Icône d'un grand modèle de langue.

Reinforcement Learning from Human Feedback (RLHF)

Ajustement d'un LLM dans RLHF

  • Entraîner le LLM initial

Icône d'un grand modèle de langue ajusté avec un jeu de données d'entrée.

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » envoyée à un LLM.

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » avec un LLM répondant : « a 16th Century author ».

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » avec un LLM répondant : « a 16th Century author », et un modèle additionnel, un modèle de politique, recevant l'invite.

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » avec un LLM répondant : « a 16th Century author », et un modèle additionnel, un modèle de politique, recevant l'invite et étant entraîné avec un reward model.

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » avec un LLM répondant : « a 16th Century author », et un modèle additionnel, un modèle de politique, entraîné avec un reward model, donnant la réponse « William Shakespeare ».

Reinforcement Learning from Human Feedback (RLHF)

Processus RLHF complet

Invite « Who wrote Romeo and Juliet » avec un LLM répondant : « a 16th Century author », et un modèle additionnel, un modèle de politique, entraîné avec un reward model, donnant la réponse « William Shakespeare », avec une comparaison des deux résultats.

Reinforcement Learning from Human Feedback (RLHF)

Interagir avec des LLM réglés par RLHF

  • Modèles RLHF préentraînés sur Hugging Face 🤗
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)

Interagir avec des LLM réglés par RLHF

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)

Passons à la pratique !

Reinforcement Learning from Human Feedback (RLHF)

Preparing Video For Download...