Learning from demonstrations
One of the most common ways to teach a robot is to show it what to do. Learn how demonstrations are collected, what behaviour cloning is, and why copying goes wrong.
In 60 seconds
Learning from demonstrations
One of the most common ways to teach a robot is to show it what to do. Learn how demonstrations are collected, what behaviour cloning is, and why copying goes wrong.
How demonstration data is collected
| Method | How it works | Good and bad |
|---|---|---|
| Teleoperation | A person controls the robot from a distance, with a joystick, a handheld controller, a copy of the arm or a VR headset | Data matches the robot's own body; slow, needs trained people |
| Kinesthetic teaching | A person gently moves the robot's arm by hand while it records | Simple and direct; tiring, and the person's hand may appear in the camera view |
| Hand-held tools | A person does the task with a gripper tool that has a camera on it | Can be done in many places; the robot's body still differs a little |
| Human videos | Recordings of people doing tasks | Plenty of them; no forces, different hands and viewpoints |
Behaviour cloning: copy the expert
- 1
Record
Collect many pairs of (what the robot saw, what the expert did next). - 2
Train
Train a neural network to predict the expert's action from the observation. - 3
Run
On the real robot: take a camera image, ask the network for an action, do it, repeat many times a second. - 4
Check
Test on new starting positions and objects, not just the ones in the recordings.
Why copying drifts: distribution shift
Ways people reduce the problem
- Recovery demonstrations: deliberately show the robot starting from bad positions and fixing them.
- DAgger (dataset aggregation): let the robot act, record the situations it reaches, ask the expert what it should have done there, add that to the data, and train again.
- More variety: collect demonstrations with different objects, positions, lights and people.
- Predicting short chunks of actions rather than one tiny step at a time. Some methods do this to make movement smoother and more consistent.
Other problems with demonstrations
- People are not consistent. Two experts may do the same task in different ways. A simple network may average them into a movement nobody did, like going between two paths around an obstacle and hitting it.
- The robot only learns what it was shown. It does not know why the expert did something, so it cannot reason about a new goal.
- Bad demonstrations teach bad habits. Data quality matters as much as data amount.
- Every demo starts from the same position
- Only perfect runs are kept
- One person, one table, one kind of cup
- Test only on the training setups
- Many starting positions and object placements
- Includes corrections from small mistakes
- Different people, rooms, lights and objects
- Test on setups the robot never saw
Watch and read more
Lab
A paper experiment that shows distribution shift, plus a plan for a better demonstration dataset.
The problem
Draw a 6 x 6 grid on paper. Put a start square at the bottom-left and a goal at the top-right. Draw a short wall in the middle.
- Be the expert. Draw one clean path from start to goal. Write it as a table: square → move (up, down, left, right). This is your demonstration.
- Be the robot. The robot only knows moves for squares in your table. Start one square to the right of the start. What does the robot do? Write down what happens.
- Now imagine each move has a small chance of slipping one square sideways. Roll a die for each move: on a 1, slip right. Follow your table. How often do you reach a square with no rule?
- Fix it. Add rows to the table for squares next to your path, showing how to get back. This is like recovery demonstrations or DAgger.
- Write three rules you would follow if you were collecting real demonstrations for a robot that picks up cups.
You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Why does distribution shift get worse the longer a task is?Reveal
Each step has a small chance of error. In a long task there are many steps, so errors have more chances to happen and to build on each other. Once the robot is off course, later actions are made from situations the policy never trained on, so they are less reliable. That is why long, multi-step tasks are especially hard for pure behaviour cloning.
Q2A behaviour cloning policy scores well on a held-out test set of recorded demos, but fails on the real robot. How can both be true?Reveal
The held-out test checks: "given an observation the expert saw, does the policy predict the expert's action?" That only uses situations the expert reached. On the real robot, the policy's own small errors lead to new situations that are not in any recording. So accuracy on recorded data does not measure how well the robot recovers. You must test by actually running the policy.
Questions people ask
How many demonstrations does a robot need?
It depends a lot on the task, the robot and the method. Simple tasks in a fixed setting may need fairly few. Tasks with many objects and positions need many more. Rather than trusting a number, test the policy on new situations and see where it fails.
Is behaviour cloning the same as reinforcement learning?
No. Behaviour cloning copies an expert's actions and needs no reward. Reinforcement learning, covered in the next lesson, learns from rewards by trying things. The two are often combined: start by copying, then improve with practice.
Why not just write rules instead?
For simple, fixed tasks, hand-written rules and classic control work very well and are still widely used. Learning helps when the task has too much variety to write rules for, like grasping many different soft or oddly shaped objects.
What is teleoperation used for besides data?
People also teleoperate robots to do work directly, for example where it is unsafe for a person to be present. In demos, remember that a robot may be teleoperated rather than acting by itself.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.