Guide · AI & Machine Learning

How Reinforcement Learning Works

Reinforcement learning (RL) is the branch of machine learning where a system learns by trial and error instead of from labelled examples. It is the machinery behind game-playing agents, robot control, recommendation tuning and the alignment step used to train modern chatbots.

The core loop: agent, environment, reward

An agent observes the state of an environment, picks an action, and receives a numeric reward plus a new state. Repeating this loop, the agent learns a policy — a mapping from states to actions that maximises total reward over time rather than the immediate payoff.

  • State — what the agent can see right now (board position, sensor readings, a prompt).
  • Action — what it can do (a move, a motor command, the next token).
  • Reward — the scalar feedback signal that defines the goal.
  • Discount factor — how much future reward counts relative to immediate reward.

Exploration vs exploitation

The central tension in RL: exploiting the best known action earns reward now, but exploring unknown actions is the only way to find something better. Practical systems balance the two with strategies such as epsilon-greedy randomness, entropy bonuses, or optimistic value initialisation.

The main families of algorithms

Value-based methods

These learn how good each state-action pair is. Q-learning and its deep variant, DQN, estimate a Q-value for every action and then act greedily on it. They work well when the action space is small and discrete.

Policy-gradient methods

Instead of scoring actions, these adjust the policy directly in the direction that raises expected reward. REINFORCE, A2C/A3C and PPO (Proximal Policy Optimization) live here. PPO became the default workhorse because it constrains how far the policy can move in one update, which keeps training stable.

Model-based RL

The agent learns a predictive model of the environment and plans inside it. It is far more sample efficient — valuable when real-world trials are slow or expensive, as in robotics.

RLHF: how RL trains chatbots

Reinforcement learning from human feedback turns subjective preference into a reward signal. Humans rank model responses, a reward model is trained to reproduce those rankings, and the language model is then optimised against that reward — usually with PPO, or with simpler preference-optimisation methods such as DPO. Newer reasoning models extend this with verifiable rewards, where correctness of a maths proof or unit test provides the signal instead of a human rater.

Where reinforcement learning is used

  • Games — the classic proving ground, from Atari to Go and StarCraft.
  • Robotics — locomotion and manipulation policies trained in simulation, then transferred to hardware.
  • Operations — data-centre cooling, energy scheduling, traffic and inventory control.
  • Recommendations and ads — optimising long-term engagement rather than a single click.
  • Language models — alignment, tool use, and multi-step reasoning.

Why RL is hard in practice

  • Sample hunger — millions of interactions may be needed; simulation is often the only affordable option.
  • Reward hacking — agents optimise the reward you wrote, not the outcome you meant.
  • Instability — small hyperparameter changes can collapse training.
  • Sim-to-real gap — a policy perfected in simulation can fail on physical hardware.

A sensible learning path

  1. Understand Markov decision processes and the Bellman equation.
  2. Implement tabular Q-learning on a grid world.
  3. Move to DQN on a classic control task such as CartPole.
  4. Learn policy gradients, then PPO.
  5. Read about RLHF and preference optimisation to connect RL to today's language models.

Keep following AI coverage in our AI & Machine Learning section, or see the live tech feed for breaking updates.

Frequently asked questions

What is reinforcement learning in simple terms?

Reinforcement learning is machine learning by trial and error: an agent observes a state, takes an action, receives a reward, and gradually learns a policy that maximises total reward over time instead of learning from labelled examples.

How is reinforcement learning different from supervised learning?

Supervised learning trains on input-output pairs labelled by humans. Reinforcement learning has no correct answer per step — only a reward signal — so the agent must explore actions and credit long-term outcomes to earlier decisions.

What is the difference between Q-learning and PPO?

Q-learning is value-based: it estimates how good each state-action pair is and acts greedily on those values, which suits small discrete action spaces. PPO is a policy-gradient method that adjusts the policy directly while limiting how far it can change per update, which keeps training stable in large or continuous action spaces.

What is RLHF and why do chatbots use it?

Reinforcement learning from human feedback turns human preference rankings into a reward model, then optimises a language model against that reward with PPO or a preference-optimisation method such as DPO. It aligns model output with what people actually judge to be helpful.

Why is reinforcement learning hard to use in production?

RL is sample hungry, unstable across hyperparameters, prone to reward hacking, and policies trained in simulation often fail on real hardware because of the sim-to-real gap.

How should a beginner start learning reinforcement learning?

Start with Markov decision processes and the Bellman equation, implement tabular Q-learning on a grid world, move to DQN on CartPole, then learn policy gradients and PPO before reading about RLHF.