Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Key Ideas in RL

TLDR

RL Overview

The foundational ideas of Reinforcement Learning have been developing for at least 40 years, finding applications in diverse fields like robotics or drug discovery. Over that time there are many sub fields and algorithms in RL that are optimized for each one of the challenges. In the last 4 years, interest in Reinforcement Learning has increased substantially with the rise of Large Language Models (LLMs). Models like ChatGPT brought Reinforcement Learning from Human Feedback (RLHF) to widespread attention, while earlier models like GPT-3 also used RL to achieve frontier levels of performance. These days, RL is a key tool when shaping LLMs, particularly in the later stages referred to as post-training. Now, because what works for winning at the game of Go won’t necessarily work for solving cancer, many different approaches to reinforcement learning have been developed. However the fundamental concepts are similar.

A Straightforward Idea with Many Nuances

When reading through Reinforcement Learning literature, it can be easy to miss the forest for the trees. With many specific terms and mathematical formulae, it can be easy to get lost. This guide will cover the high-level ideas and basic terminology before we move on. Use it as a reference as you move through the subsequent notebooks.

The RL Loop

The concept of reinforcement learning is quite simple, with direct parallels to everyday life. An agent takes actions, and it receives rewards. Some rewards are immediate; others take time to result in the final outcome.

Basic RL Loop from SpinningUp

Figure 1:Basic RL Loop from SpinningUp

In this diagram, here are the definitions from Sutton and Barto:

These five simple concepts are at the core of billions of dollars of funding and compute resources. They’re at the core of self-driving cars, recommendation systems in deployed web apps, Nobel Prize-level breakthroughs such as AlphaFold, and many other real-world systems.

Of course, this means there is a lot of reinforcement-specific jargon that comes with this domain, so let’s get into it!

The Terms and Key Concepts

We’ll cover the most common terms that will be part of this guide. Described in just words, these terms can be confusing. If later on you are confused by these terms, come back to this page to reference the simple implementation before going back.

Environment(s)

In addition to the textbook definition of “environment,” I personally make these two distinctions:

State Terminology

Reward Terminology

Action Terminology and Policy

Challenges with RL

However, while conceptually simple, reinforcement learning comes with a host of challenges:

NameConceptChallenge
Explore vs. ExploitDeciding whether to stick with known successful actions or try new ones to find better rewards.Over-exploring wastes computation; over-exploiting leads to rigid models that fail in new situations.
Bias-Variance TradeoffBalancing the stability of policy updates against the flexibility to adapt to new data.High bias provides stability but lacks flexibility; high variance makes updates erratic and sensitive to noise.
Environment SpecificationDefining the rules, states, and boundaries of the world the agent operates in.Simple for games like chess; extremely complex for real-world applications like autonomous driving.
Sample EfficiencyMaximizing the amount of learning achieved from every interaction with the environment.RL often requires millions of trials; learning effectively from a limited number of “loops” is costly and slow.
Non-StationarityManaging environments where the rules, dynamics, or goals change over time.An agent may become obsolete if the environment shifts (e.g., user preference drift or changing market conditions).
Curse of DimensionalityDealing with the exponential growth of possibilities as more state/action variables are added.It becomes mathematically infeasible to explore or map every possible combination as complexity increases.
ObservabilityThe degree to which the agent can see the entire state of the environment at any given time.In “Partial Observability,” the agent must make decisions based on incomplete or noisy information.
Reward Function DesignTranslating complex human goals into a mathematical scalar reward.Reward Hacking: The agent may find unintended shortcuts to maximize rewards without actually solving the task e.g. editing the timer rather than making a task faster.
Credit AssignmentDetermining which specific action in a long sequence was responsible for the final outcome. Includes balancing between process(intermediate step) rewards, and outcome (completed output) rewardsIt is difficult to distinguish “good” actions from “bad” ones when the reward is delayed (e.g., a move in the beginning of a game).
Sim-to-Real TransferTraining an agent in a simulation and then deploying it in the physical world.The Reality Gap: Minor differences in physics or sensors between sim and reality can cause the agent to fail.
Catastrophic ForgettingThe tendency of a model to lose previous knowledge when exposed to new information.Learning a new task can cause the agent to completely “forget” how to perform a previously mastered task.
GeneralizationThe ability of the agent to perform well in environments it did not see during training.Agents often “overfit” to specific training scenarios, making them fragile when small environmental details change.
Safety & ConstraintsEnsuring the agent avoids dangerous or prohibited actions during the learning process.In robotics or healthcare, “exploratory” mistakes can lead to physical damage, injury, or ethical breaches.

LLM Focus

In this guide, we are focusing solely on LLMs, which means we focus on the algorithms on the far left of the diagram below. This includes algorithms such as PPO, and some not present on the diagram, such as GRPO.

Why focus on LLMs? Well, at least for two reasons:

  1. To focus our foundational learning on a smaller set of concepts, for example actions taken in a discrete space.

  2. Highlighting challenges specific to modern LLM deployments, such as the ambiguous nature of correctness in natural language.

Various RL Algorithms

Figure 2:Various RL Algorithms

Before getting to LLMs though, we’ll focus on a classic problem in RL to solidify the core concepts. Let’s get started in the next section!

Suggested Prompts

References