From games to the real world
How the same ideas are used for robots, recommendations and training chatbots with human feedback, and why safety matters more outside a game.
In 60 seconds
From games to the real world
How the same ideas are used for robots, recommendations and training chatbots with human feedback, and why safety matters more outside a game.
Games: where RL made its name
Robots
Recommendations and apps
Language models: learning from human feedback
- 1
Collect comparisons
People see two answers to the same prompt and pick the better one. - 2
Train a reward model
A model learns to give a score that matches which answers people prefer. - 3
Optimise the chatbot
The chatbot is trained with RL to write answers the reward model scores highly. - 4
Hold it close
A penalty keeps it from drifting too far from its starting behaviour, which limits reward hacking. - 5
Test and repeat
Check the new model on safety and quality tests before using it.
import math
# Four answers. People compared pairs: (winner, loser).
answers = ["polite and correct", "correct but rude", "polite but wrong", "rude and wrong"]
prefs = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3), (0, 1), (1, 3), (2, 3), (0, 2)]
score = [0.0] * 4
for _ in range(300): # simple gradient steps
for w, l in prefs:
p_win = 1 / (1 + math.exp(score[l] - score[w])) # chance the model says w wins
score[w] += 0.05 * (1 - p_win)
score[l] -= 0.05 * (1 - p_win)
for s, a in sorted(zip(score, answers), reverse=True):
print(f"{s:6.2f} {a}")
Safety outside the game
- Mistakes cost nothing; press restart
- The reward is the real goal (the score)
- Exploring randomly is fine
- The world never changes its rules
- Mistakes can hurt people, money or trust
- The reward is only a stand-in for what we want
- Exploring must stay inside safe limits
- People and places change, so a policy can go out of date
- Hard limits outside the policy: a robot's speed limit or emergency stop should not depend on what it learned.
- Test in simulation and small trials first, with a person watching and able to stop it.
- Watch behaviour, not only the score. Reward hacking shows up in what the system does.
- Think about who is affected, especially when the "environment" is real people, such as app users or students.
Watch and read more
Lab
A one-page design card for an RL system in the real world: state, actions, reward, loopholes and safety limits.
The problem
Choose one of these, or your own idea: (a) traffic lights at a busy junction in your city; (b) a study app that picks which practice question to show a student next; (c) a small farm robot that waters plants only where the soil is dry.
- State: what information does the agent see? What must it not see (for example, private data)?
- Actions: list the choices. Which actions are never allowed, whatever the policy says?
- Reward: write it as simply as a formula or a sentence. Is it the real goal or a stand-in?
- Loopholes: write at least two ways a strong agent could collect reward without doing the real job, and change the reward to close one.
- Learning safely: where will it practise first (a simulator, past data, a small trial)? Who watches, and how can they stop it?
- Who is affected: name the people, and one way you would check the system is fair and helpful to them.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1For the study app, why is "questions answered correctly" a risky reward?Reveal
The easiest way to get many correct answers is to show only easy questions the student already knows. The agent would look successful while the student learns nothing new. A better reward looks at learning over time, for example improvement on a separate check later, and a person should review what the app does with real students.
Q2An RLHF-trained chatbot starts agreeing with whatever the user says. How could the training have caused this?Reveal
If people rating answers tended to prefer answers that agreed with them, the reward model learns "agreeing scores well", and RL makes the chatbot do more of it. The chatbot is optimising the learned reward, which differs from real helpfulness. Fixes include better rating instructions, tests that check for agreeing with false statements, and mixing in other training signals.
Questions people ask
Do chatbots learn from me in real time with RL?
Usually not in the moment. Training normally happens separately, with collected feedback, and new versions are tested before release. Some apps ask you to rate answers; how that feedback is used depends on the company. Check the app's privacy settings and policy.
Is RLHF the only way to make a chatbot helpful?
No. Training on good example answers (instruction tuning) comes first, and there are other methods such as direct preference optimisation and rule-based feedback. Developers often combine several.
Can I try RL on bigger games at home?
Yes. Open-source toolkits such as Gymnasium provide many ready-made environments with the same step idea you used here. Deep RL needs more computing power, so start with small environments and check the toolkit's current documentation.
Why is RL used less than supervised learning in everyday products?
It needs a lot of trial and error, a reward that really matches the goal, and a safe way to explore. When good labelled data exists, learning from examples is usually simpler and safer. RL shines when you can simulate, or when the task is to make a sequence of decisions.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.