Introduction to Reinforcement LearningPart 4 · Beyond value functions
Lecture 11Learning about many things
Learning more from the same stream of experience: general value functions, auxiliary tasks that shape a shared representation, trade-offs between tasks and PopArt, universal value functions, and distributional reinforcement learning.
Key ideas, one per episode
- Ep. 43Any useful knowledge can be a prediction.
- Ep. 44Extra questions build a better shared representation.
- Ep. 45Normalise the targets, and preserve the outputs.
- Ep. 46One number hides the shape of the future.
Based on: Deep Reinforcement Learning, Part 2, DeepMind × UCL Reinforcement Learning Lecture Series (2021), by Matteo Hessel. The slides follow that order of topics, in our own words, figures and examples; they are not official material of the original course.
Watch
4 short episodes of ACML Explains for this lecture. Pick one from the list, and open the transcript to read along: each timestamp plays the episode from there. The narration is generated with a voice clone of Teddy, used with his permission.
Episode 43 · 5:14
General value functions
Your state isn't what you see. It's what you expect to happen.
Any useful knowledge can be a prediction.
TranscriptEpisode 43
One number, a narrow picture
Module eleven: learning about many things. So far, our agents chased one number. One reward, one value, one policy. And a narrow goal gives you a narrow picture of the world. A narrow representation can't support good generalisation. The deadly triad and value leakage only make it worse. Think of a ship. If the only thing you ever practised is sailing in a straight line, you'll be lost the day someone asks for a circle. Better: first learn how a ship moves. Then a straight line, a circle, whatever you're asked. Rich knowledge first.
Knowledge as predictions
Remember the reward hypothesis, from the very first lecture? Any goal can be written as maximising a scalar reward. Push it one step further. Maybe all useful knowledge can be written as predictions. Not just about reward. About anything. That's a general value function. Sutton and colleagues, two thousand eleven. Swap the reward for a cumulant, c: any signal you care about. And make two more things flexible. The discount, gamma, can depend on the state. And the policy can be any policy, even a hypothetical one. You've noticed, I'm sure. This course started very mathematical, and slowly became more and more engineering. This is engineering.
Turning the knobs
Let's play with the knobs. Cumulant equals reward, under my own policy, with my usual gamma. That's plain policy evaluation. Nothing new. Cumulant equals reward, and gamma equals zero. Now I only predict the very next reward. Which object did that, earlier in the course? The model. Cumulant equals the next state, or a feature of it, with gamma zero. Given a state and an action, predict where you land. That's the dynamics. Same architecture, same learning rule. Just different questions. You get all of these as a gift, by turning a few knobs. And the policy knob: what would happen if I always walked left? You can learn that answer without ever walking left. That's off-policy learning, and we'll meet it again as an open problem.
A discount per state
Why would gamma depend on the state? Think chess. At the start of the game, how far do you want to look? Far. The game is long. Near the end, you want to finish the job. A short horizon. So a gamma that depends on the state can make sense. And a gamma of zero in some states means: this question ends here. Discount and termination are the same knob. Choose it wisely, and it helps. Choose it badly, and it hurts. And as usual, you mostly find out which one afterwards.
Our corridor, three questions
We tried it. A corridor of seven cells, an agent walking at random. One stream of experience, and three questions learned at the same time. Question one: how much reward is coming, from the right end of the corridor? Gamma point nine. Question two: will I touch the left wall on the very next step? Gamma zero. Question three: how soon will I reach it? Gamma point eight. Twenty thousand steps of plain TD learning, for all three at once. All three ended with an average error below a tenth. Two of them, far below. None of these questions is the task. But together, they say a lot about where the agent is.
Sub-goals, and a boxing story
Cumulants are also a way to add sub-goals. Back to the ship. The main reward: sail in a straight line. Add a few more signals. Don't capsize. Here's a good idea: stop capsizing. And if you sail in a zigzag, fine by me, I'm still happy. A story I like. Two simulated agents, trained to box against each other. One of them found a brilliant move: fall to the floor, and do nothing. The other one had never seen anything like it. It had no idea what to do, and it fell apart. The one lying on the floor won. The fix was a new signal: if you fall on the floor, I'm angry with you. A small cumulant, a very different agent.
Train on one, judge on another
Which brings an important habit. Agents are often trained on one reward, and evaluated on another. In the boxing example, when we evaluate, we only care who wins. Falling or not falling doesn't matter there. Usually the evaluation reward sits inside the training reward. You still want to train in the right direction. The extras are there to help, not to replace.
Predictions as the state
Now a bold idea, from predictive state representations. Littman, Sutton and Singh, two thousand two. Ask a large and diverse set of questions. If the set is rich enough, the answers say everything you need about the state. So use the predictions themselves as the state. Then learn the policy and the values as a simple, linear function of those predictions. Our corridor already shows the spirit. Will I touch the wall now? How soon? How much reward is coming? Three answers, and you can roughly tell where you are, without anyone telling you. Your state is no longer what you see. It's what you expect to happen.
Recap
So: a general value function predicts any cumulant, with any discount, under any policy. Reward prediction, dynamics, policy evaluation: all special cases. And asking many questions builds a richer picture of the world. Next time: put many questions into one network, and let them teach each other. Auxiliary tasks.
One body, many heads
Last time, many questions. Today, one network that answers them all. Look at the networks we met in this course. What goes in? Always the state, or the state and an action. Nothing else makes sense. Could a network take only an action? What would it learn? Nothing. We never defined a useful function from an action alone. So the input is the same. What changes between a policy network, a value network, and a Q network? Only the last layer. The head. Which means you can keep one body, and give it many heads. A multi-head network. Training is simple: add up the losses, maybe with a weight on each. And every weight is one more knob to tune.
Auxiliary tasks
That's the idea of auxiliary tasks, from Jaderberg and colleagues, two thousand sixteen. General value functions, as extra heads on a shared network. You minimise the main loss and the auxiliary losses together. You don't really care about the auxiliary answers. You care about what they do to the shared layers. They make the representation richer and more robust. You can even let the auxiliary losses train only the representation, and leave the layers above it alone.
Capture the flag
An example. Capture the flag. Find the other team's flag, and bring it home. The reward: win the game. Mathematically, if you work long enough, you'll find a good policy. Let me make it easier for the network. Add a task: find the flag. And another: when you have the flag, get back to base. Sub-tasks of winning, in the right order. I don't care much about either of them on their own. But on the way, the network learns a representation that serves all of them. And winning gets easier. These extra signals are called pseudo-rewards. Pseudo, not sudo. Nothing to do with Linux. That was a great joke, by the way.
Pixels, features, rewards
Two classic auxiliary tasks. Pixel control: learn to change the pixels on the screen as much as possible. Picture the screen cut into a grid of small squares. For each square, one question: which actions change this square the most? Lots of questions, and the screen answers them for free. Feature control: the same idea, but for the network's own hidden features. Learn to change them as much as possible. And reward prediction: from three recent frames, guess whether the next reward is positive, negative, or zero. Rewards are rare, so rewarding moments are replayed more often, about half the time. None of these is the game. All of them force the network to understand what it can change in its
Does it work?
world. Does it work? In their paper, on a suite of three D maze tasks called Labyrinth, the plain agent averaged fifty four percent of expert human performance. With all the auxiliary tasks together: eighty seven percent. And it learned about ten times faster on average. Same main reward. Same data. More questions on the side. And the extra rewards are only for learning. The agent is still judged on the game score alone.
The honest part
Now the honest part. Ask an engineer: what happens when a machine has more moving parts? More chances that one of them breaks. Every extra task can help, and every extra task is another point of failure. And not every task helps. Add a task called have a picnic, and the network will learn something about picnics. It won't help you capture the flag. Which tasks help? Like many things in this course: you try, you find out you were wrong, you try again. You only know afterwards. Partly because we, the world, not just this class, don't fully understand how neural networks work. We understand fully connected networks better every year. And we're already at transformers. And not every good idea is the newest. One of my favourites is the clockwork network: parts of its memory tick at different speeds, some every step, some only every few steps. Cheaper than an LSTM, and in my experience, great for physics, where signals have a rhythm.
The value improvement path
One more angle: the value improvement path. Dabney and colleagues, twenty twenty. While learning, the agent's policy keeps improving. So the network must represent a whole sequence of value functions, from the first poor policy to the best one. A good representation supports the entire path, not just the end. Auxiliary tasks can help keep it flexible along the way. A related idea: tasks that build on each other. Think of a game with levels. Win level one. Then levels one and two. Then one, two and three. A student suggested a nicer one: teach a language model a sentence, then a paragraph, then a whole article. Each task extends the one before.
Toolbox or staircase
The difference matters. Before, the extra tasks were just a list. If they happened to help each other, great. Here, each task deliberately extends the previous one, on the way to the final task. Your teacher builds the ladder, one rung at a time. The first is a toolbox. The second is a staircase.
Recap
So: one body, many heads. The heads ask extra questions. The body gets a better picture of the world. Choose the questions with care, and expect some trial and error. Next time: what happens when one task shouts much louder than the others?
Tasks compete
We want to learn as much as possible about the world. But capacity and compute are limited. And different tasks compete for them. There's always a trade-off. Even if you do nothing explicit about it, you've made a choice. The size of each task's updates to the shared weights grows with how big and how frequent its rewards are. A loud task pulls the representation its way. So some tasks shape the shared layers a lot, and some barely at all. Not because they matter more. Just because their numbers are bigger. A classic fix: the DQN agent on Atari clipped every reward to between minus one and one. Simple, and it keeps the scales tame. But in some games, a small pellet is worth ten points, and catching a ghost is worth hundreds. After clipping, both are plus one. The scale is fixed, and the task has quietly changed.
No full dataset
In supervised learning, you know the dataset in advance. So you normalise inputs and targets to sensible scales. Many deep models barely work without that. In reinforcement learning, you don't have the full dataset. Worse, the scale of the values you predict keeps changing as the agent improves. So the normalisation has to adapt, while you learn.
Normalise while you learn
Adaptive target normalisation, from van Hasselt and colleagues, twenty sixteen. Step one: see a target, like a Q-learning target. Step two: update a running mean of the targets, and a running average of their squares. That gives you a running variance, too. Step three: the network predicts the target minus the mean, divided by the standard deviation. Statisticians call that a z-score. Say the targets so far average a thousand, with a spread of a hundred. A target of eleven hundred becomes plus one. Nine hundred becomes minus one. Every task now speaks at the same volume. Step four: whenever you need the real value, for example to bootstrap, multiply back by the standard deviation and add the mean. These running estimates are approximations, and not great ones early on. But they fix the problem of scale.
Preserve the outputs
One catch. Every time the normalisation changes, every output of the network changes too. Even for states you never touched. That seems bad. We shouldn't change the values of unrelated states. The fix is neat. When the mean and the standard deviation move, rescale the last layer's weights and bias by exactly the opposite amount. The real outputs stay put. That's the name: PopArt. Preserving outputs precisely, while adaptively rescaling targets.
Our toy run
Our toy run. Two prediction tasks share one hidden layer. One target lives around one. The other around a thousand. Plain stochastic gradient descent, at the step size that suits the big task: the big task ends within ten percent. The small one stays at eighty three percent error. Drowned out. We tried five step sizes. The best compromise left both tasks above thirty percent error. With PopArt-style normalisation, one step size: both tasks end within about ten percent. The same idea, with one normalisation per game, let a single agent learn all fifty seven Atari games at once. Hessel and colleagues, twenty nineteen. One set of weights, above the median human score.
Open: off-policy
Now some open problems. If you want to write papers in this area, here are some questions. Some have been open for years. Off-policy learning. Can we learn about one cumulant while following a policy that maximises a different one? In one paper, called Unicorn, the agent must pick up a key, then a lock, then a door, then a chest, in that order. An agent trained only for the chest never did better than random. Learning about every step of the chain together, off-policy, from the same experience, got there. Learn about many things, to do the hard thing. Splitting a goal into sub-tasks is easy when you know the policy that collected the data. Off-policy, it's much less clear how.
Open: universal value functions
Generalisation. So far, each general value function is learned on its own. Can what we learn about one question help with another? One idea: feed the question itself into the network as an input. The cumulant, the discount. Then the network can generalise across goals. And since the name general value function was already taken, these were called universal value functions. Schaul and colleagues, twenty fifteen. Think of a maze where the goal can be anywhere. Train on some goal positions, and the network can make a sensible guess for a goal it has never trained on.
Open: discovery
And discovery. Which questions should an agent ask? Instead of choosing them by hand, learn them from experience, with meta-learning. Meta-learning means learning how to learn. A classic example: give a model a table, and let it tell you which learning algorithm will work best on it. It's a field I love. My own little corner is meta-learning for feature selection. Everyone needs their own little corner.
Recap
So: tasks compete, whether you like it or not. Normalise targets so no task drowns the others, and preserve the outputs while you do it. And the open questions: learning off-policy, generalising across questions, and discovering which questions to ask. Next time: stop predicting one number. Predict the whole distribution.
One number hides the shape
Everything so far predicted an expectation. One number: the average return. But the return is random. Roll a die. The average is three and a half. You will never, ever roll a three and a half. Remember the world from module nine? Minus a million once, plus a million once, and zero all the other times. The expectation is zero. Exactly like a world where nothing ever happens. Same average, very different worlds. One of them, you'd like to know about in advance. Same with the weather. Two millimetres of rain on average tells you less than: eighty percent dry, twenty percent storm.
The whole distribution
Distributional reinforcement learning: learn the whole distribution of returns, not just its mean. The value function takes a state, and instead of one number, it gives back a distribution of possible returns. A richer learning signal. And that can help the network learn more robust representations, the same story as auxiliary tasks. And there's a Bellman equation for it, too. The return is the reward, plus gamma times the next return. Not as averages this time, but as random variables, distribution and all.
The catch
What's the catch? It's harder. We have endless tools to predict a number: regression, classification, you name it. We, the world, are much less good at predicting distributions. There are tools, but far fewer, and they're harder to use. Regression gives you a number, maybe with an error bar. A full shape, with two humps, or a long tail? That's much harder.
C51: a comb
One way to do it: Categorical DQN, from Bellemare and colleagues, twenty seventeen. Fix a comb of possible returns. Say, fifty one points between minus ten and ten. For each point, the network outputs a probability. The distribution is the comb with those probabilities. To act, you still use the mean: each point times its probability, summed up. Fifty one points, a categorical distribution. That's why people call it C51.
Shift, shrink, project
Learning it looks like Q-learning, with a twist. Take the next state's distribution, for its best action. Shift it by the reward, and shrink it by gamma. Now the points don't sit on your comb anymore. So project them back onto the comb, splitting each point's probability between its two nearest neighbours. A tiny example. Say the comb has a point at every whole number. Reward one, gamma point nine, and a point sitting at five. It moves to five and a half. So half its probability goes to five, and half goes to six. Then make your current distribution closer to that target, by minimising the KL divergence. In practice, a cross-entropy loss.
Our die and coin
Our run. A one-step world: roll a die, get the number, game over. Fifty one points, a categorical learner, nothing else. It puts about one sixth of the probability near each face, one to six. Its mean: three point four five. The truth: three point five. Close, not perfect. It's still a learner, with a finite number of samples. Now a coin: plus ten or minus ten. Two clear spikes at the ends, nothing in the middle. The mean is about zero, but the picture says something completely different.
Quantiles
There are many other ways to model the distribution. Quantile regression, from Dabney and colleagues, flips the idea around. Instead of fixed points with learned probabilities, fix the probabilities and learn where the points go. Eleven quantiles, say, each one owning the same share of the probability. How does each point find its place? Take the point for the bottom ten percent. When a sample lands above it, nudge it up a little. When one lands below, nudge it down a lot. It settles where one sample in ten falls below it. On our die, most of the eleven points land right on the faces: two at one, two at two, one at three, and so on. A few are still on their way between faces. On the coin, five land at minus ten, five land at plus ten, and the middle one wanders somewhere in between. With a coin, that's honest.
Why bother
Why bother, if we act on the mean anyway? First, the richer signal shapes better representations. Second, you can see risk. Two actions with the same mean, one of them occasionally catastrophic. Now you can tell them apart. Two routes to work. One takes thirty minutes, every day. The other takes twenty five, but one day in five, it takes fifty. Same average. If you have a flight to catch, you know which one you want. Remember the bandit with a million dollar jackpot, and a hundred dollars in your pocket? The distribution is what tells you to walk away. Third, an agent can use the distribution to be careful: avoid actions with a long, bad tail, even when their average looks fine. And a beautiful twist. In twenty twenty, Dabney and colleagues found evidence for this in mice. Different dopamine neurons seem more optimistic or more pessimistic, and together they encode a whole distribution of rewards.
Module eleven, done
That's module eleven. Ask many questions, with general value functions. Share one network, with auxiliary tasks. Keep the loud tasks from drowning the quiet ones, with PopArt. And when one number isn't enough, learn the whole distribution. Next module: learning from humans. Demonstrations, preferences, and how language models got their manners.
5:14Episode 43General value functionsAny useful knowledge can be a prediction.
5:12Episode 44Auxiliary tasksExtra questions build a better shared representation.
5:21Episode 45When tasks competeNormalise the targets, and preserve the outputs.
5:22Episode 46Distributional RLOne number hides the shape of the future.
