0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09A robot with no map and no teacher
Dev has a new delivery robot. It doesn't have a map, and nobody is going to tell it the right moves. It only gets feedback: every step costs it a little, and reaching the customer's door earns a big reward. Watch its first attempt. It wanders back and forth, bumps into the end of the street, and finally stumbles onto the door after twenty-two steps. On its very next attempt, it drives straight there in four. No labelled examples. No teacher. Just actions, consequences and memory. This is reinforcement learning, the third way machines learn, the one behind game-playing champions and robots, and, as we'll see in Season Three, part of how chatbots learned to be helpful.
Season One, Module Six: reinforcement learning. First stop: agents, rewards and Q-learning.
1:07The reinforcement learning loop
Every reinforcement learning problem has the same loop. An agent, here the robot, observes the state of its environment: which block of the street it's on. It chooses an action: move left or right. The environment responds with a reward and a new state. And around it goes. Each step costs minus one, to encourage speed. Reaching the door earns plus ten and ends the episode, one complete delivery. Notice how different this is from supervised learning. Nobody ever tells the robot "the right move here is right". It only learns how good things turned out, and often only at the end.
The big reward arrives at the door, but which of the earlier moves deserve the credit? That's called the credit assignment problem, and solving it is the heart of reinforcement learning.
1:59Return, discounting and policy
What is the robot actually trying to maximise? Not the next reward, but the total reward it collects from now on, called the return. We usually discount future rewards. With a discount factor gamma of zero point nine, a reward one step away counts ninety percent, two steps away eighty-one percent, and so on. Rewards sooner are worth more than rewards later, and discounting also keeps the total finite if an episode never ends. Let's compute the return from the first block if the robot always drives right. Three steps at minus one, then plus ten at the door: minus one, minus zero point nine, minus zero point eight one, plus seven point two nine.
Total: four point five eight. The robot's strategy, which action to take in each state, is called its policy. Our goal is to find the policy with the highest expected return.
3:01Value functions: V and Q
To choose good actions, the robot needs to know how good each situation is. The value of a state, V of s, is the return it can expect from there. With the best policy, the block next to the door is worth ten, the one before eight, then six point two, then four point five eight at the start. The values glow brighter as the door gets closer. Even more useful is the Q-value, Q of s and a: how good it is to take a particular action in a particular state, and act well afterwards. Here's the robot's Q-table: one row per block, one column per action.
On the first block, going right is worth four point five eight, and going left, bumping the wall and wasting a step, is worth only three point one two. Once you have a Q-table, acting is easy: in every state, pick the action with the higher Q-value. Here that's "right" everywhere. So the whole problem comes down to learning those numbers.
4:05The Bellman equation
Those numbers obey a beautifully simple relationship called the Bellman equation. The value of taking an action equals the immediate reward, plus the discounted value of the best move from wherever you land. Let's check it. From block two, going right costs minus one and lands on block three, whose best value is ten. Minus one plus zero point nine times ten: eight. Exactly the table's value. From the first block, going left bumps the wall and leaves you where you were: minus one plus zero point nine times four point five eight gives three point one two.
Correct again. Notice how value flows backwards from the reward: ten at the door, then eight, then six point two, then four point five eight. That's credit assignment solved, step by step.
4:57Q-learning: learning the table
The robot doesn't know these values at the start. It learns them from experience with an algorithm called Q-learning. Every time it takes an action and sees the result, it forms a target: the reward it just got, plus the discounted best Q-value of the new state. Then it nudges its old estimate a fraction of the way towards that target. The fraction is the learning rate, alpha. If that shape looks familiar, it should: move a step from your current guess towards a better one, exactly like gradient descent. Let's do the very first update.
Every Q-value starts at zero. The robot, on the first block, moves right, and pays minus one. The target is minus one plus zero point nine times zero: minus one. So the Q-value moves halfway from zero towards minus one: minus zero point five. Now watch it train. The first delivery takes twenty-two wandering steps. Over the next nine deliveries, it takes the shortest route, four steps, six times, and six steps the other three times. We'll see why in a moment. And the Q-table settles on exactly the values the Bellman equation predicted.
6:13Exploration vs exploitation
Why does the trained robot still sometimes take extra steps? Because we told it to keep experimenting. Every learning agent faces a dilemma. Exploit: take the action you currently believe is best. Or explore: try something different, in case it's even better. It's like always ordering your favourite dish versus trying something new on the menu. Never explore, and you might never discover something better. Explore all the time, and you never benefit from what you've learned. A simple, popular solution is epsilon-greedy.
With probability epsilon, here thirty percent, take a random action. Otherwise, take the best-known one. Those occasional random moves are the extra steps. In practice, epsilon is often reduced over time: explore a lot early on, then exploit more as the robot becomes confident. Without exploration, an agent can lock onto the first route that happened to work, and never find the shortcut that was there all along.
7:19From tables to deep reinforcement learning
A table works for a street with five blocks. But a city with ten thousand intersections already needs tens of thousands of entries, and for a game like chess, or a robot seeing the world through a camera, the number of possible states is astronomically large. No table could ever hold them, and the agent would never visit most of them. The breakthrough was to replace the table with a neural network that takes in a state and estimates the Q-values, generalising from situations it has seen to ones it hasn't. That's deep reinforcement learning.
A famous example: a system from DeepMind learned to play dozens of classic Atari games directly from the screen pixels. And in two thousand and sixteen, DeepMind's AlphaGo, which combined neural networks, reinforcement learning and search, defeated Lee Sedol, one of the world's best Go players. We'll learn how neural networks work in Season Two. Next episode, though, we'll meet a different approach that skips Q-values entirely and learns the policy directly.
8:31Try it yourself: watch values flow back
Let's watch value flow backwards, by hand, in a simplified first episode where the robot drives straight to the door. Every Q-value starts at zero. In that first episode, moving right from block zero costs minus one, and the next block looks worthless so far, so the Q-value becomes minus zero point five. The same happens at blocks one and two. But when the robot steps from block three into the door, it earns ten, and that Q-value jumps to five. In the second episode, the robot moves right from block two into block three, which now looks valuable.
Its old value is minus zero point five. Pause and compute the update: add half of the gap between the target, minus one plus zero point nine times five, and that old value. The target is three and a half; the gap is four; half of it is two; so the new value is one point five. The reward at the door has started to flow backwards, one block at a time, exactly the wave we saw in the Bellman equation. With more episodes, every value converges to the numbers in our table.
9:49The discount factor: how far ahead to look
The discount factor gamma decides how far ahead the agent looks. With gamma at zero point nine, the return from the first block is plus four point five eight: the reward at the door is worth the three-step walk. With gamma at a half, the same walk is worth minus zero point five. The door is so heavily discounted that the step costs outweigh it. So gamma is a design choice. Close to one, the agent is patient and plans for the long term. Small, and it becomes short-sighted. Match it to the task: a delivery robot should care about reaching the customer, even if it takes a while.
10:32Model-free vs model-based
Q-learning is called model-free: it never builds a map of how the world works. It just learns values from experience. Model-based methods learn, or are given, a model of the world, like "moving right takes you one block further", and use it to plan, imagining possible routes before acting. Planning can make learning far more efficient, but if the model of the world is wrong, the plans are wrong. Some of the most famous systems, like AlphaGo, combine learned values with planning by search.
11:09Reinforcement learning in business
Where does reinforcement learning appear in business? In sequential decisions: which promotion to show a customer now, given how they reacted before; how to dispatch a fleet of delivery vans; when to restock inventory; how much to bid for an ad. Often the simplest version is enough: a multi-armed bandit, which chooses between a few options, like three email subject lines, learning which works best while still occasionally trying the others, the explore-exploit balance again. One caution: learning by trial and error in the real world can be costly or risky.
Practitioners train in simulators, learn from logged past decisions, and put strict limits on what an agent is allowed to try.
11:58Common pitfalls
Reinforcement learning has its own pitfalls. Reward hacking, which we'll see next. Rewards so rare that the agent never stumbles onto success, which tempts designers to add intermediate rewards, carefully, or they create new loopholes. Environments that change over time. Agents that master a simulator but fail in the real world. And instability when neural networks replace the Q-table, which deep Q-networks tamed with tricks like replaying past experiences and slowly updating a separate copy of the network for the targets.
12:36Reward design and reward hacking
One more lesson, and it's one of the most important in all of AI. An agent will optimise exactly what you reward, not what you meant. Suppose we'd rewarded the robot plus one for every block it moved, thinking movement means progress. It would quickly discover that the best strategy is to drive back and forth forever, collecting rewards and never delivering anything. This is called reward hacking, and it happens surprisingly often in practice. That's why our rewards were designed around the outcome we actually want, the delivery, with a small cost for every step to encourage speed.
Keep this in mind for Season Three, when we see how chatbots are trained with rewards based on human preferences.
13:24Myth vs Fact
Myth: a reinforcement learning agent understands its goal. Fact: it learns numbers that predict future reward, and acts to make that reward large. The "goal" exists only in the reward function that we design, which is why designing it carefully matters so much.
13:43Recap
Let's recap. In reinforcement learning, an agent acts in an environment and learns from rewards. It aims to maximise the discounted return. Q-values say how good each action is in each state, and they obey the Bellman equation: the reward now, plus the discounted best value next. Q-learning learns them from experience by nudging estimates towards targets, while epsilon-greedy keeps it exploring. Big problems replace the table with a neural network. And agents optimise exactly what we reward, so we design rewards carefully.
One sentence to remember: value flows backwards from the reward.
14:27Next: policy gradients
Mission complete. With no map and no teacher, the robot learned the fastest route after a single wandering delivery, and its Q-table says exactly why. Next, the final episode of Season One. Instead of scoring every action and picking the best, what if the robot directly learned how likely it should be to take each action, and simply made good actions more likely? That's the policy gradient, a short step from the way modern chatbots are fine-tuned. See you on the map.