TL;DR
Robots that learn from a success-or-failure signal get almost nothing to learn from, because nearly every attempt fails. Andrychowicz and co-authors show that an off-policy learner can reuse failed episodes by replaying them with goals the robot did reach, which turns misses into labelled examples. Their agent learned pushing, sliding and pick-and-place in simulation from binary rewards only, and a pick-and-place policy trained in simulation succeeded on a physical arm in 5 of 5 trials once it was retrained with observation noise.
Builds on: Hindsight Experience Replay, Deep Deterministic Policy Gradient (DDPG), Experience Replay · Leads to: Goal-Conditioned Reinforcement Learning
Why it mattered
The paper made goal-conditioned learning from sparse rewards a practical option for robot manipulation. Its core move, relabelling stored transitions with achieved goals, is now a common tool in this area, and it is the reason a sparse success signal is enough for many simulated manipulation tasks that would otherwise need a carefully shaped reward.
It also gave a concrete recipe others could copy: a known reward function, an off-policy actor-critic, and a choice of which goals to relabel with. The paper's ablations on that choice are the part most people reuse. The idea is also an early, clean example of sim-to-real transfer for a manipulation policy, where the policy trained entirely in simulation was run on a physical Fetch arm.
The problem
A standard RL agent learns from a reward signal that says how well it did. In a manipulation task the natural reward is binary: the object is within a tolerance of the goal, or it is not. A random policy almost never succeeds, so almost every stored transition has the same reward, and the learner gets no gradient toward success.
The usual fix is reward shaping, adding a term such as a distance to the goal. The authors argue that this needs domain knowledge and often gives the wrong incentives. In their experiments, shaped rewards did not help either algorithm on any of the three tasks. The paper asks whether an agent can learn from sparse, binary rewards directly.
Two background pieces are needed. Off-policy learners such as DQN and DDPG can learn from data generated by a different behaviour policy, which is what makes replay with new goals valid. Universal policies, as in Goal-Conditioned Reinforcement Learning, take the goal as an input, so one network can pursue many goals.
How it works
The pipeline runs in this order. Each stage is shown in the diagram.
- Pick a goal and an initial state for the episode.
- Run the behaviour policy for steps, which is the policy plus exploration noise, and store the episode.
- For each transition , compute the reward for the original goal, . This is the ordinary replay record.
- Choose extra goals from the same episode, using a strategy . The paper's simplest choice is the final achieved goal, .
- Store a second copy of the transition with goal and reward . This is the hindsight record.
- Sample minibatches from the buffer, mixing original and relabelled records, and update the critic and actor with an off-policy algorithm.
A tiny trace of steps 3 to 5 on a one-dimensional line, where the goal is position 5 and the agent ends at position 1 without reaching it:
- Step 3: the original goal is never reached, so every reward is .
- Step 4: with the final strategy, .
- Step 5: the transition that ends on position 1 gets reward with goal , and the others keep .
Each stored transition now carries one informative label where before it had none. Nothing about the environment changed. Only the goal written into the record changed.
flowchart LR A[Sample goal g and start s0] --> B[Run behaviour policy with noise] B --> C[Store transitions with original goal g] B --> D[Choose extra goals g' from the same episode] D --> E[Store copies with goal g' and reward r of s t, a t, g'] C --> F[Replay buffer] E --> F F --> G[Off-policy update of critic and actor] G --> A
Worked examples
Two bits, start at , and the goal is . Each action flips one bit, and a state satisfies a goal only when it equals the goal. The episode is , and the goal is never reached. The example is illustrative; the paper's bit-flipping setup, with up to 50 bits, is described in its Section 3.1.
- Original rewards: no visited state equals , so the three transitions get .
- Final strategy: , the last state.
- Transition : the next state is not , so .
- Transition : the next state is not , so .
- Transition : the next state equals , so .
- The relabelled copies contain one success where the original data had none.
Interpretation: the last transition now teaches the critic that moving to from is a successful move for the goal . That is a true fact about this environment.
Use the same episode , but relabel with the future strategy and one goal per transition (). Label the four states in the episode as , , , .
- Transition 0 (): sample a later state, , so . The next state is not , so .
- Transition 1 (): the only later state is , so . The next state is not , so .
- Transition 2 (): the only later state is , so . The next state equals , so .
- The future strategy gives the same single success as the final strategy here, because the only achieved goal available to each transition was .
Interpretation: with a longer episode, the future strategy would offer several different goals for the same transition, which is what gives it more variety than the final strategy. The paper found this variety valuable (Section 4.5).
The paper reports two numbers from its real-robot test. Before retraining the pick-and-place policy succeeded in 2 of 5 trials. After retraining with Gaussian observation noise (standard deviation 1 cm), it succeeded in 5 of 5 trials.
- Success rate before retraining: , which is 40 percent.
- Success rate after retraining: , which is 100 percent.
- Improvement: , which is 60 percentage points.
- Separately, the paper's replay accounting. Each transition is stored once with its original goal and times with relabelled goals, so the share of relabelled records is in that buffer. For this is , and for it is , about . The paper observed that raising above 8 degraded performance because the share of ordinary, unrelabelled data became very low.
- The 2-of-5 result is small, so it is a demonstration rather than a statistical study. The paper says the policy was not robust to small errors in the box position estimate, which is why the noise was added.
Interpretation: the real-robot result reflects both the value of training with HER and the gap that observation noise creates. The share calculation is our arithmetic from the paper's description, not a number the paper reports.
Try it: the paper's best setting used or for the future strategy. Using the share formula above, what is the ratio of relabelled to original records when , and does it match the share ? Answer: the ratio is , and it matches the share, because a share of means 8 relabelled records for every 1 original record.
The math
Step 2 in symbols: the sparse reward
Let be 1 when the state satisfies goal and 0 otherwise. For the object-position goals used in the robot tasks, is 1 when the object lies within a fixed tolerance of . The paper's sparse reward is
where is the state after action is taken in state . In words: the reward is on success and otherwise. The bracket is 1 when the condition is true and 0 when it is false.
Step 4 in symbols: the goal map
The paper assumes a mapping from states to goals, with for every state . In words: every state satisfies some goal, namely the one it represents. For the robot tasks, is the object's position in . The final-state strategy uses .
Step 5 in symbols: the relabelled record
A stored transition is written as , where means concatenation, and the reward is recomputed for the new goal:
Because the reward function is known, is computed exactly. No estimate is needed.
Step 6 in symbols: the critic target
With DQN, the Bellman target is . With DDPG, which the paper uses for all its robot results, it is , where is the actor. The paper uses and clips targets to , which for is . The clip matches the range of possible returns when every reward is or . The critic is trained to minimise the squared gap between and over minibatches. Relabelling is valid because the critic learns the value of acting toward from data gathered while the agent was pursuing , and that is an off-policy update.
The strategies in symbols
The paper compares four ways to choose for a transition at time in an episode of length :
- final: .
- future: for random indices from the same episode.
- episode: for random indices from anywhere in the same episode.
- random: is the goal of states sampled from anywhere in training.
The parameter is the number of relabelled goals per transition. The paper keeps the original goal in the buffer as well, so each transition is stored once with its original goal and times with relabelled goals.
Results
Bit-flipping (Section 3.1, Figure 1). The paper says that DQN without HER can only solve the task for bits, while DQN with HER solves it for up to 50. It also says standard RL is bound to fail for because it never sees any reward other than .
Multi-goal robot tasks (Section 4.2, Figure 3). DDPG without HER was unable to solve any of the three tasks, and DDPG with count-based exploration made some progress only on sliding. DDPG with HER solved all three almost perfectly. The paper counts an episode as successful when the object ends within 7 cm of the goal for pushing and pick-and-place, and within 20 cm for sliding. Results are averaged over 5 random seeds, with shaded areas showing one standard deviation.
Single-goal setting (Section 4.3, Figure 4). DDPG with HER performed much better than DDPG alone even when every episode had the same goal. The paper also finds HER learns faster when training episodes contain multiple goals, so it advises training on multiple goals even when only one matters.
Shaped rewards (Section 4.4, Figure 5). Neither DDPG nor DDPG with HER solved any task with any of the shaped rewards they tried. The best shaped reward was , and it still failed on all tasks. The authors give two reasons: the shaped reward differs from the success condition, and shaped rewards penalise behaviour that could help exploration.
Choice of goals (Section 4.5, Figure 6). Every strategy except random solved pushing and pick-and-place almost perfectly. The future strategy with or performed best and was the only one that nearly solved sliding. Raising above 8 degraded performance.
Physical robot (Section 4.6, Figure 7). The pick-and-place policy, trained in simulation with the future strategy and , succeeded in 2 of 5 trials on a Fetch arm without fine-tuning. After retraining with noise (standard deviation 1 cm) on observations, it succeeded in 5 of 5 trials.
Limits. The experiments use one simulated robot arm, three tasks, and a known object-position mapping. The paper's real-robot test is a single task with five trials. The method needs an achieved-goal mapping and a reward function that can be recomputed for a new goal. The paper does not claim HER helps when goals cannot be read off the state.
Reading guide
- Section 1, Introduction. Read after Hindsight Experience Replay and Sparse Reward Problem. The hockey example is the intuition behind relabelling.
- Section 2, Background. Needs Markov Decision Process, Bellman Equation, Deep Q-Network, and Deep Deterministic Policy Gradient (DDPG). Section 2.4 introduces universal value functions, which need Goal-Conditioned Reinforcement Learning.
- Section 3, Hindsight Experience Replay. The core of the paper. Read 3.1 with the bit-flipping example, then 3.2 and 3.3 for the algorithm. Needs Experience Replay and Q-Learning as background, and Reward Shaping for the comparison in 3.1.
- Section 4, Experiments. Read 4.1 for the environment, then 4.2 to 4.5 in order. Section 4.4 needs Reward Shaping. Section 4.6 is the real-robot test.
- Section 5, Related work. Mentions prioritised replay and curricula; useful after the lesson, not required.
Check yourself
QuestionIn one sentence, what does HER add to the replay buffer, and what does it leave unchanged?Show answer
It adds extra copies of each transition written with a different goal, usually a state the agent reached later in the episode, and recomputes the reward for that goal. It leaves the states, actions and environment unchanged, so the agent still visits the same states.
QuestionIn the tiny bit-string example, the episode is with goal . With the final strategy, how many relabelled transitions get reward 0, and why?Show answer
One. The final achieved goal is . Only the last transition ends in , so only its relabelled reward is 0. The other two end in and , which are not , so they get .
QuestionWhy does HER need an off-policy learner such as DDPG rather than an on-policy one?Show answer
The relabelled records were generated while the agent was pursuing the original goal, so for the new goal they are off-policy data. An off-policy critic can learn the value of acting toward the new goal from them. An on-policy method assumes the data came from the current policy pursuing the goal it is optimising, which the relabelled data violates.
QuestionThe paper reports 2 of 5 successful real-robot trials before retraining and 5 of 5 after. What were the two success rates, and what was the difference in percentage points?Show answer
Before retraining, percent. After retraining, percent. The difference is 60 percentage points. The paper attributes the early failures partly to the policy being trained on perfect simulated states and not being robust to small errors in the box position.
QuestionA new task rewards a robot only when a judged property of the scene holds, and the property is not a function of the robot's joint state. Can HER be applied directly? Give the reason.Show answer
Not directly. HER needs a map from each stored state to a goal that the state satisfies, and a reward that can be recomputed for any relabelled goal. If the property is not a function of the joint state, the goal a stored state achieves cannot be read off, so the relabelled rewards cannot be computed exactly. The options are to expose the property as a state function, or to use a different reward.