← All courses

Course 9 · Reinforcement Learning · about 10 min

Learning by trial and error

By the end of this course you can explain how agents learn from rewards, why exploring matters, and how Q-learning finds a route to a goal.

In reinforcement learning (RL), nobody provides the right answers. An agent acts in an environment, receives a reward (or penalty), and gradually learns which actions lead to the most reward over time.

It's how you'd train a dog with treats, except the agent may need thousands or millions of attempts.

Try itReinforcement or supervised learning?

CheckWhat does an RL agent learn from?

Step 2

Be careful what you reward

Agents optimise exactly the reward you give them, not what you meant. If there's a loophole, they find it. This is called reward hacking.

In 2016, OpenAI trained an agent on a boat-racing game, rewarding it for hitting targets along the course. The agent discovered it could circle in a small lagoon, hitting the same respawning targets over and over, scoring higher than finishing the race.

PredictA cleaning robot gets +1 for every piece of rubbish it picks up. What might it learn?

CheckWhat is reward hacking?

Step 3

Explore or exploit?

Every agent faces a dilemma: exploit the best option it knows, or explore something new that might be better. Only exploiting can lock it into a mediocre choice that got lucky early. Only exploring wastes time.

A common fix is epsilon-greedy: usually pick the best-known action, but every so often (say 10% of the time) try a random one.

Try itThree slot machines, 20 pulls

Each machine wins at a different hidden rate. Try to win as often as possible.

MachinePullsWins

CheckWhy should an agent sometimes try actions that don't look best?

Step 4

Q-learning: a value for every move

Q-learning keeps a score, called a Q-value, for every action in every situation: "how much total reward do I expect if I do this here?" After each move it updates the score towards the reward it just got plus the best score of where it landed. Over many episodes, good routes get high scores and the agent simply follows the highest one.

Try itTrain an agent

The agent starts at S and must reach the flag (+10). The hole costs −10, and each step costs −1. Arrows show its current best move.

CheckWhat does a Q-value estimate?

Step 5

Reinforcement learning in the real world

In 2016, DeepMind's AlphaGo beat world champion Lee Sedol at Go, 4 games to 1. A year later, AlphaZero learned chess, shogi and Go purely by playing against itself. RL also helps shape chatbots through human feedback (Course 6) and has been used to cut the energy Google's data centres spend on cooling.

Because RL needs huge numbers of attempts, robots usually train in simulation first, where mistakes are free and fast.

Try itA good fit for reinforcement learning?

CheckWhy do robots usually learn in simulation first?

Step 6 · Recap

What you learned

Quick reviewThree questions from memory. No scrolling back.

Course 10 brings everything together: building AI products people actually use. Mark this course complete below when you're ready.