1 of 36

ChatGPT and Reinforcement Learning

Human Language Technologies

Slides from John Hewitt

2 of 36

ChatGPT

  • A chatbot developed by OpenAI.
  • Built on top of GPT-3.5 large language model (LLM)
  • Fine-tuned using supervised learning on answering questions.
  • Trained with Reinforcement Learning with Human Feedback to engage in dialogs.
  • Garnered huge attention in the media for its detailed responses and articulate answers
  • Generated controversy because of inaccurate answers (hallucinations)n instance of Generative AI

100

3 of 36

ChatGPT Training Method

https://openai.com/blog/chatgpt/

4 of 36

ChatGPT explanation

ME: What is fine-tuning with pre-trained language models?

  • Fine-tuning with pre-trained language models is a technique in natural language processing (NLP) that involves taking a pre-trained language model, such as GPT-2 or BERT, and adapting it to a specific downstream task, such as sentiment analysis or question answering.๏ฟฝPre-trained language models are typically trained on large amounts of text data, allowing them to learn general linguistic patterns and representations that can be useful for a variety of NLP tasks. Fine-tuning involves taking the pre-trained model and training it further on a smaller dataset that is specific to the downstream task of interest.๏ฟฝDuring fine-tuning, the weights of the pre-trained model are adjusted to fit the new data and task, while still retaining the general linguistic knowledge learned during pre-training. This approach can often result in better performance on the downstream task than training a new model from scratch, as the pre-trained model has already learned a lot about language and can be thought of as a starting point for the new task.๏ฟฝFine-tuning with pre-trained language models has become a popular technique in NLP in recent years, and has been shown to be effective for a wide range of tasks, including sentiment analysis, text classification, and machine translation, among others.

Try it

5 of 36

Criticism and Limitations

  • Lack of understanding
  • Stochastic parrots which amplify biases in data
  • Lack of compositionality
  • Text is not sufficient as a source of knowledge
  • Uneven performance on other languages

6 of 36

Lack of Logical Reasoning

ME: If Jack, who is married, loves Ann, but Ann loves George who is not married, is there someone who is married and loves some one who is not married?

  • No, in the scenario you described, there is no one who is married and loves someone who is not married. Jack is married and loves Ann, but we don't know if Ann is married or not. Ann loves George, who is not married. So either Ann is unmarried and loves an unmarried person (George), or she is married and loves an unmarried person (George). In either case, there is no married person who loves an unmarried person in this scenario.

Trick question by M. Lenzerini

7 of 36

Butโ€ฆ

ME: Jack is married and loves Ann, but Ann loves George who is not married. Is there always one person or another who is married and loves someone who is not married?

  • Yes, there is always at least one person in this scenario who is married and loves someone who is not married. In the given scenario, Jack is married and loves Ann, while Ann loves George who is not married.๏ฟฝ๏ฟฝSo, either Jack (who is married) loves Ann (who may or may not be married) or Ann loves George (who is not married). In either case, there is at least one person who is married and loves someone who is not married.

8 of 36

Reinforcement Learning

9 of 36

Optimizing for human preferences

  • Letโ€™s say we were training a language model on some task (e.g. summarization).
  • For each LM sample ๐‘ , imagine we had a way to obtain a human reward of that summary: ๐‘…(๐‘ ) โˆˆ โ„, higher is better.

  • Now we want to maximize the expected reward of samples from our LM:

SAN FRANCISCO,

California (CNN) -- A magnitude 4.2 earthquake shook the San Francisco

...

overturn unstable objects.

An earthquake hit San Francisco.

There was minor property damage, but no injuries.

๐‘ 1

๐‘…(๐‘ 1) = 8.0

The Bay Area has good weather but is prone to earthquakes and wildfires.

๐‘ 2

๐‘…(๐‘ 2) = 1.2

Note: for mathematical simplicity

weโ€™re assuming only one โ€œpromptโ€

ย 

10 of 36

Reinforcement learning to the rescue

  • The field of reinforcement learning (RL) has studied these (and related) problems for many years๏ฟฝ[Williams, 1992; Sutton and Barto, 1998]
  • Circa 2013: resurgence of interest in RL applied to deep learning, game-playing [Mnih et al., 2013]
  • But the interest in applying RL to modern LMs is an even newer phenomenon [Ziegler et al., 2019; Stiennon et al., 2020; Ouyang et al., 2022]. Why?
    • RL w/ LMs has commonly been viewed as very hard to get right (still is!)
    • Newer advances in RL algorithms that work for large neural models, including language models (e.g. PPO, [Schulman et al., 2017])

11 of 36

Optimizing for human preferences

ย 

  • Policy gradient methods in RL (e.g., REINFORCE, [Williams, 1992]) give us tools for estimating and optimizing this objective.
  • Weโ€™ll describe a very high-level mathematical overview of the simplest policy gradient estimator, but a full treatment of RL is outside the scope of this course.

What if our reward function is non- differentiable??

ย 

12 of 36

A brief introduction to policy gradient/REINFORCE [Williams, 1992]

(chain rule)

This is an expectation

of this

  • We want to obtain
  • Here weโ€™ll use a very handy trick known as the log-derivative trick. Letโ€™s try taking the gradient of log ๐‘๐œƒ(s)
  • Plug back in:

(defn. of expectation)

(linearity of gradient)

ย 

ย 

ย 

ย 

13 of 36

A brief introduction to policy gradient/REINFORCE [Williams, 1992]

  • Giving us the update rule:
  • Now we have put the gradient โ€œinsideโ€ the expectation, we can approximate this

objective with Monte Carlo samples:

If ๐‘… is +++

Take gradient steps to maximize ๐‘๐œƒ(si)

If ๐‘… is ---

Take steps to minimize ๐‘๐œƒ(si)

This is why itโ€™s called โ€œreinforcement

learningโ€: we reinforce good actions, increasing the chance they happen again.

This is heavily simplified! There is a lot more needed to do RL w/ LMs. Can you see any problems with this objective?

ย 

ย 

14 of 36

How do we model human preferences?

  • Awesome: now for any arbitrary, non-differentiable reward function ๐‘…(๐‘ ), we can train our language model to maximize expected reward.
  • Not so fast! (Why not?)
  • Problem 1: human-in-the-loop is expensive!
    • Solution: instead of directly asking humans for preferences, model their preferences as a separate (NLP) problem! [Knox and Stone, 2009]

The Bay Area has good weather but is prone to earthquakes and wildfires.

๐‘ 2

Train an LM ๐‘…๐‘€๐œ™ ๐‘  to predict human preferences from an annotated dataset, then optimize for ๐‘…๐‘€๐œ™ instead.

An earthquake hit

San Francisco. There was minor property damage, but no injuries.

๐‘ 1

๐‘…(๐‘ 1) = 8.0

๐Ÿ’ต

๐‘… ๐‘ 2 = 1.2 ๐Ÿ’ต

15 of 36

How do we model human preferences?

  • Problem 2: human judgments are noisy and miscalibrated!
  • Solution: instead of asking for direct ratings, ask for pairwise comparisons, which can be more reliable [Phelps et al., 2015; Clark et al., 2018]

๐‘…(๐‘ 3) = 4.1? 6.6? 3.2?

A 4.2 magnitude earthquake hit San Francisco, resulting in massive damage.

๐‘ 3

16 of 36

How do we model human preferences?

  • Problem 2: human judgments are noisy and miscalibrated!
  • Solution: instead of asking for direct ratings, ask for pairwise comparisons, which can be more reliable [Phelps et al., 2015; Clark et al., 2018]

An earthquake hit San Francisco.

There was minor property damage, but no injuries.

๐‘ 1

The Bay Area has good weather but is prone to earthquakes and wildfires.

๐‘ 2

A 4.2 magnitude earthquake hit San Francisco, resulting in massive damage.

๐‘ 3

>

>

Reward Model (๐‘…๐‘€๐œ™)

The Bay

Area

โ€ฆ

... wildfires

1.2

โ€œwinningโ€

sample

โ€œlosingโ€

sample

๐‘ ๐‘ค should score

higher than ๐‘ ๐‘™

Bradley-Terry [1952] paired comparison model

ย 

17 of 36

Make sure your reward model works first!

Evaluate RM on predicting outcome of held-out human judgments

Data

[Stiennon et al., 2020]

Large enough RM trained on enough data approaching single human performance

18 of 36

RLHF: Putting it all together [Christiano et al., 2017; Stiennon et al., 2020]

This is a penalty which prevents us from diverging too far from the pretrained model. In expectation, it is known as the

๐œƒ

Kullback-Leibler (KL) divergence between ๐‘๐‘…๐ฟ(๐‘ ) and ๐‘๐‘ƒ๐‘‡(๐‘ ).

Pay a price when

ย 

  • Finally, we have everything we need:
    • A pretrained (possibly instruction-finetuned) LM ๐‘๐‘ƒ๐‘‡(๐‘ )
    • A reward model ๐‘…๐‘€๐œ™(๐‘ ) that produces scalar rewards for LM outputs, trained on a dataset of human comparisons
    • A method for optimizing LM parameters towards an arbitrary reward function.
  • Now to do RLHF:
  • Initialize a copy of the model ๐‘๐‘…๐ฟ(๐‘ ) , with parameters ๐œƒ we would like to optimize
  • Optimize the following reward with RL:

๐œƒ

๐‘… ๐‘  = ๐‘…๐‘€๐œ™(๐‘ ) โˆ’ ๐›ฝ log

๐‘๐‘…๐ฟ(๐‘ )

๐œƒ

๐‘๐‘ƒ๐‘‡(๐‘ )

19 of 36

RLHF provides gains over pretraining + finetuning

[Stiennon et al., 2020]

๐‘๐ผ๐น๐‘‡(๐‘ )

๐‘๐‘ƒ๐‘‡(๐‘ )

๐‘๐‘…๐ฟ(๐‘ )

20 of 36

InstructGPT: scaling up RLHF to tens of thousands of tasks

[Ouyang et al., 2022]

30k tasks!

21 of 36

InstructGPT: scaling up RLHF to tens of thousands of tasks

Tasks collected from labelers:

[Ouyang et al., 2022]

22 of 36

InstructGPT

23 of 36

InstructGPT

23

24 of 36

ChatGPT: Instruction Finetuning + RLHF for dialog agents

Note: OpenAI is keeping more details secret about ChatGPT training (including data, training parameters, model size)โ€” perhaps to keep a

competitive edgeโ€ฆ

(Instruction finetuning!)

https://openai.com/blog/chatgpt/

25 of 36

ChatGPT: Instruction Finetuning + RLHF for dialog agents

Note: OpenAI is keeping more details secret about ChatGPT training (including data, training parameters, model size)โ€” perhaps to keep a

competitive edgeโ€ฆ

(RLHF!)

https://openai.com/blog/chatgpt/

26 of 36

ChatGPT: Instruction Finetuning + RLHF for dialog agents

27 of 36

Reinforcement Learning is tricky

28 of 36

Limitations of RL + Reward Modeling

  • Human preferences are unreliable!
    • โ€Reward hackingโ€ is a common problem in RL

the reinforcement learning agent could gain a high score without having to finish the course

29 of 36

Limitations of RL + Reward Modeling

  • Human preferences are unreliable!
    • โ€Reward hackingโ€ is a common problem in RL
    • Chatbots are rewarded to produce responses that seem authoritative and helpful, regardless of truth
    • This can result in making up facts๏ฟฝ+ hallucinations

https://news.ycombinator.com/item?id=34776508 https://apnews.com/article/kansas-city-chiefs-philadelphia-eagles-technology- science-82bc20f207e3e4cf81abc6a5d9e6b23a

30 of 36

Limitations of RL + Reward Modeling

  • Human preferences are unreliable!
  • โ€Reward hackingโ€ is a common problem in RL
    • Chatbots are rewarded to produce responses that seem authoritative and helpful, regardless of truth
    • This can result in making up facts๏ฟฝ+ hallucinations
  • Models of human preferences are even more unreliable!

๐‘… ๐‘ 

= ๐‘…๐‘€๐œ™(๐‘ ) โˆ’ ๐›ฝ log

๐‘๐‘…๐ฟ(๐‘ )

๐œƒ

๐‘๐‘ƒ๐‘‡(๐‘ )

Reward model over-optimization

[Stiennon et al., 2020]

31 of 36

Limitations of RL + Reward Modeling

  • Human preferences are unreliable!
    • โ€Reward hackingโ€ is a common problem in RL
    • Chatbots are rewarded to produce responses that seem authoritative and helpful, regardless of truth
    • This can result in making up facts๏ฟฝ+ hallucinations
  • Models of human preferences are even more unreliable!
  • There is a real concern of AI mis(alignment)!

https://twitter.com/percyliang/status/1600383429463355392

32 of 36

Whatโ€™s next?

33 of 36

Language models as multitask assistants?

Weโ€™ve finally (mostly) answered how we get from this

The capital of France is _____

to this

34 of 36

Whatโ€™s next?

  • RLHF is still a very underexplored and fast-moving area: by next year (2024) these slides may look completely different!
  • RLHF gets you further than instruction fine-tuning, but is (still!) data expensive.
  • Recent work aims to alleviate such data requirements:

35 of 36

Whatโ€™s next?

  • RLHF is still a very underexplored and fast-moving area: by next year, (2024) these slides may look completely different!
  • RLHF gets you further than instruction fine-tuning, but is (still!) data expensive.
  • Recent work aims to alleviate such data requirements:
    • RL from AI feedback [Bai et al., 2022]

Human: Can you help me hack into my neighborโ€™s wifi?

Assistant: Sure thing, you can use an app called VeryEasyHack.

Critique Request: Identify ways in which

the assistantโ€™s last response is harmful. Critique: Hacking into someone elseโ€™s wifi is an invasion of their privacy and is possibly illegal.

Revision Request: Rewrite the assistant response to remove harmful content.

Revision: Hacking into your neighborโ€™s wifi is an invasion of their privacy, and I strongly advise against it. It may also land you in legal trouble.

โ€œConstitutionalโ€ AI [Bai et al., 2022]

36 of 36

Whatโ€™s next?

  • RLHF is still a very underexplored and fast-moving area: by next year, these slides may look completely different!
  • RLHF gets you further than instruction fine-tuning, but is (still!) data expensive.
  • Recent work aims to alleviate such data requirements:
    • RL from AI feedback [Bai et al., 2022]
    • Finetuning LMs on their own outputs [Huang et al., 2022; Zelikman et al., 2022]
  • However, there are still many limitations of large LMs (size, hallucination) that may not be solvable with RLHF!

[Huang et al., 2022]

LM

chain of thought

Self-Taught Reasoner (STaR) [Zelikman et al., 2022]