RLHF: Reinforcement Learning from Human Feedback

RLHF uses methods from reinforcement learning to directly optimize a language model with human feedback.

Verified

On this page

Definition

Reinforcement Learning from Human Feedback (RLHF) uses methods from reinforcement learning to directly optimize a language model with human feedback. It involves training multiple models and different deployment stages. RLHF starts from a language model that has already been pretrained with the classical pretraining objectives. The process needs a model that responds well to a range of instructions.

At a glance

Hugging Face’s official post divides the training process it describes into three parts: pretraining a language model, collecting data to train a reward model, and fine-tuning the language model with reinforcement learning.

Diagram: Pretraining a language model (LM) > Gathering data and training a reward model > Fine-tuning the LM with reinforcement learning1Pretraining a language model (LM)2Gathering data and training a reward model3Fine-tuning the LM with reinforcement learning

How it works

The initial model can be fine-tuned on additional text or conditions, but this is not a required step. A reward model takes a sequence of text and returns a scalar reward intended to represent human preference. The reward system can be an end-to-end language model or a modular design, such as ranking outputs and converting the ranking to a reward.

Prompts are passed through the initial language model to generate new text. Human annotators rank the language model’s generated text. When people assign scalar scores directly to text, differing values make the scores poorly calibrated and noisy.

The post instead describes comparing and ranking outputs from multiple models to produce a better regularized dataset. One method used in the source is to have users compare text generated by two models from the same prompt. Pairwise comparisons of outputs can feed an Elo system to rank models and outputs relative to each other.

These different methods of ranking are normalized into a scalar reward signal for training. Reinforcement learning then optimizes the original language model using the reward model. The policy is a language model that takes in a prompt and returns a sequence of text, or just probability distributions over text.

The reward function is a combination of the preference model and a constraint on policy shift. In the PPO approach described by the post, a copy of the initial language model is fine-tuned by updating some or all parameters. PPO updates the parameters using reward metrics from the current batch. PPO is a trust region optimization algorithm that uses constraints on the gradient to ensure the update step does not destabilize the learning process.

Whether to freeze parameters, and how many, remains an open research question. Online iteration is optional: updating the reward model and policy together requires a deployed dialogue agent with access to an engaged user base so users can keep ranking outputs from different versions.

Example

The post uses InstructGPT as an example: OpenAI used a smaller version of GPT-3 for its first popular RLHF model. OpenAI used prompts submitted by users to the GPT API. In the reward function, given a prompt, x, from the dataset, the text y is generated by the current iteration of the fine-tuned policy.

The generated text is joined with the original prompt and passed to the preference model, producing a scalar preference score. The approach described in the post compares per-token probability distributions from the RL policy and initial model, using scaled KL divergence to construct a penalty. Without this penalty the optimization can start to generate text that is gibberish but fools the reward model to give a high reward.

Here the RL policy generates the text, which is then fed to the initial model to obtain relative probabilities for the KL penalty. Gradient updates do not touch this initial model during training. Gathering human preference data is quite expensive when deploying a system using RLHF, because other human workers are integrated directly outside the training loop.

RLHF performance depends on annotation quality. The annotations include human-written text and preference labels comparing model outputs. Human annotators can often disagree, adding a substantial potential variance to the training data without ground truth. To check this example against the post’s reward flow, follow the policy-generated text, preference score, initial-model probabilities used for the KL penalty, and policy update.

Common misconceptions

The post explicitly warns that RLHF models can still produce harmful or factually inaccurate text without expressing uncertainty. PPO is an optimization approach discussed by the post. It also notes that other algorithms may offer benefits or variants for RLHF.

Sources

This page is written from the official sources below. Open them to check the original text.

Verified ·

This page is written by AI from the official sources above and checked automatically. This site has not tested it. Found a mistake? Tell us.