Curriculum Β· Unit 3 Β· Learning from rewards
Can a machine get good at something just by being told 'good' or 'bad'?
Nobody showed these programs the right move. They tried things, got a score, and slowly learned which choices led to winning. It's called reinforcement learning, and it took machines from checkers in 1959 to beating a world-class Go player in 2016. Today it helps shape how chatbots behave, along with its favorite failure: gaming the score.
Nib says: Press Next to go once around the learning loop. Then train me in the corridor below: press Train and I'll wander until I find the coin. Keep pressing and watch the values creep backward from the coin, until I march straight there.
Train a goblin in a corridor
Six cells, a goblin at one end, a coin at the other. Reaching the coin pays 1 point; every other step pays nothing. Nib doesn't know which way to go, and has to find out.
Steps to reach the coin, one bar per episode (dashed line: the best possible, 5).
The update, after every step: value(cell, move) β value + 0.5 Γ (reward + 0.9 Γ best value of the next cell β value). This is called Q-learning. The 0.9 makes a coin far away worth a bit less than one close by, and 10% of moves are random so Nib keeps exploring.
The idea in plain words
Reinforcement learning is learning from a score instead of from answers. An agent looks at its situation, picks an action, and the world responds with a new situation and sometimes a reward: a number saying good or bad. Nobody tells it the right move. It has to find out which choices tend to lead to reward, and the reward often arrives long after the moves that earned it. Working out which earlier move deserves the credit is the heart of the problem.
Arthur Samuel at IBM built one of the first programs to do this, for checkers, and described it in 1959. It kept a scoring formula for board positions and adjusted that formula as it played, partly against copies of itself, so its quick judgment of a position came to agree better with what deeper look-ahead showed. Samuel is widely credited with popularizing the phrase "machine learning" for this kind of work.
In 1992 Gerald Tesauro, also at IBM, gave the idea a neural network. TD-Gammon played backgammon against itself over and over, and after each move nudged its estimate of the previous position toward its estimate of the next one, a method called temporal-difference learning. That's the same trick the corridor uses: value leaks backward one step at a time. It reached a strong level, and later versions played close to the best humans. Then in 2016 DeepMind's AlphaGo combined deep networks, trained first on expert games and then by self-play, with a search through possible moves, and beat Lee Sedol, one of the world's top Go players, four games to one.
The catch is that the agent learns whatever the reward actually pays for, not what you meant. Reward a goblin for coins and it may learn to farm a respawning coin instead of finishing the level. That is reward hacking, and you can watch it happen in the Coin-Loop Goblin. Chatbots meet the same trap: RLHF rewards answers people prefer, which is a little different from answers that are true. Keep this goblin in mind for Unit 9.
Three games, one idea
-
1959 Β· Arthur Samuel
Checkers
A scoring formula for positions, tuned by playing, partly against itself.
-
1992 Β· Gerald Tesauro
Backgammon
A neural network that taught itself through self-play with temporal-difference learning.
-
2016 Β· DeepMind
Go
Deep networks plus tree search, trained on expert games and then self-play; beat Lee Sedol 4β1.
Self-play is the common thread: an opponent that is always exactly your level, available for millions of games. A 2017 successor, AlphaGo Zero, skipped the human games entirely and learned Go from self-play alone.
Three things to keep
- 1
Act, get scored, adjust, repeat. Reinforcement learning needs no answer key, only a reward and lots of tries.
- 2
Credit flows backward. The reward comes at the end; learning spreads it back to the moves that led there, one step at a time.
- 3
It learns the reward, not your wish. If the score has a loophole, a good learner will find it. That's reward hacking.
Check yourself
In the corridor, why does the cell next to the coin learn a high value before the first cell does?
Each update only looks one step ahead. The cell beside the coin sees the reward directly; the cell before it only learns once its neighbor's value has grown. So value spreads backward from the coin, one cell per lesson.
What did Samuel, TD-Gammon and AlphaGo all use to get enough practice?
Self-play. Each program played against itself or copies of itself, so it always had an opponent at its own level and could play far more games than any human teacher could supply.
You reward a cleaning robot for every piece of trash it picks up. What could go wrong?
It might learn to tip trash out and pick it up again, scoring forever without cleaning anything. The reward paid for pickups, not for a clean room. That's reward hacking.
Go deeper
- β Paper Β· 1959 Β· Arthur Samuel
Some Studies in Machine Learning Using the Game of Checkers
Two ways to learn, memorizing positions and tuning a scoring formula, tested on a real game.
Read the paper β - β Paper Β· 1992 Β· Gerald Tesauro
Practical Issues in Temporal Difference Learning (TD-Gammon)
A network that learned backgammon from self-play and surprised its author with how good it got.
Read the paper β - Paper Β· 2016 Β· David Silver et al. (DeepMind)
Mastering the Game of Go with Deep Neural Networks and Tree Search
The AlphaGo paper: policy and value networks, self-play and search, working together.
Read the paper β - Essay Β· 2024 Β· Lilian Weng
Reward Hacking in Reinforcement Learning
A long, clear survey of how agents game their rewards, from simple games to language models.
Read the essay β - Paper Β· 2016 Β· Amodei, Olah et al.
Concrete Problems in AI Safety
Reward hacking listed as one of five practical safety problems, with the cleaning-robot examples that made it famous.
Read the paper β - Play
The Coin-Loop Goblin
Reward a goblin for coins and watch it learn to farm them instead of finishing the level.
Play it - Glossary
Reward hacking
The one-line definition, and where it shows up in the news.
Look it up - Timeline
Machines that learn
Samuel's checkers and TD-Gammon on the Goblin Candy timeline. AlphaGo is in the next era.
Open the timeline - π Lecture hall Β· free
Three lectures for this unit
Learning by Playing Β· Learning from Itself (TD-Gammon) Β· The Move No Human Would Play (AlphaGo).
See the lectures - Next Β· Unit 4
Machines that talk
Why do people believe a machine understands them? From ELIZA to a modern model passing Turing's test.
On to Unit 4