Paper commentary
Hindsight Experience Replay
Relabelled failed episodes teach RL from sparse rewards
- Problem Off-policy RL learns little from sparse binary rewards in manipulation tasks. Shaped rewards that would help need hand-built terms and domain knowledge that are hard to design.
- Method Hindsight Experience Replay stores each episode again with goals it actually reached, instead of the goal it was pursuing. It recomputes the reward for each copy, so an off-policy learner like DDPG gets a useful signal.
- Results DDPG with HER solved pushing, sliding and pick-and-place almost perfectly, while DDPG without HER solved none of the three tasks.
Why sparse binary rewards stall learning
Robotic manipulation policies are usually trained with a carefully shaped reward, and building that reward is itself a bottleneck. The example given is a stacking policy whose cost has five relatively complicated terms, each of which must be weighted by hand. This dependence on domain expertise limits where RL can be applied, especially when the admissible behaviour is not known in advance, which is why learning from a binary success signal matters.
The authors draw on a human comparison: a player who misses the net still learns where the shot should have gone. A standard RL learner reading the same miss would only conclude that the action sequence failed, and would learn little from it.
Exploration bonuses do not fix this in the toy task, because the difficulty comes from the size of the state space rather than from a lack of visited diversity.
Relabelling episodes with goals they reached
The setting is multi-goal: the policy and value function take both the state and a goal as input, and each goal defines a predicate that a state either satisfies or does not. A mapping \\( m \\) from states to goals is assumed so that every state satisfies the goal assigned to it, i.e. \\( f_{m(s)}(s) = 1 \\). Relabelling uses this mapping to reinterpret an episode that failed for its own goal as a successful episode for a different goal.
After an episode is collected, each transition is stored in the replay buffer once with the goal the episode was pursuing and again with goals drawn from the episode by a strategy S. The simplest choice for S is the goal achieved in the final state of the episode, \\( m(s_T) \\). Each stored copy receives a reward recomputed for its own goal, \\( r(s_t,a_t,g') \\), rather than the reward from the original goal.
The goal changes what the agent is trying to do but not how the environment responds, so the same transitions remain valid for an off-policy learner such as DQN, DDPG, NAF or SDQN.
The goals used for replay start from states the agent reaches even by chance and move toward harder ones, which the authors call an implicit curriculum. Unlike an explicit curriculum, this does not require control over the distribution of initial environment states.
Toy bit-flipping task
The environment has n bits, and its action space has n actions, where action i flips bit i.
DQN without HER solved the task only up to 13 bits, whereas DQN with HER solved it up to 50 bits. The two curves differ only in the replay step, which makes the gain attributable to relabelling in this setting. A shaped distance reward would also solve this toy problem, but the authors note that such rewards are hard to design for more complicated tasks.
Manipulation environments and learner
All manipulation experiments use a 7-DOF Fetch Robotics arm with a two-fingered parallel gripper, simulated in MuJoCo. Training happens entirely in simulation, and the trained policies are later run on hardware.
Pushing locks the fingers and moves a box to a target on the table, sliding hits a puck that must stop at a target beyond the robot's reach, and pick-and-place moves the box to a target in the air. For pick-and-place, half of the training episodes start from a recorded state in which the box is already grasped.
The learner is DDPG with Adam as the optimizer, with policies represented as MLPs using ReLU activations. Eight workers run in parallel and average their parameters after every update.
A goal is a 3-dimensional target position for the object, counted as achieved when the object lies within a tolerance \\( \\epsilon \\) of it. The mapping used by HER takes a state to the object's position, \\( m(s) = s_{object} \\). Rewards are binary and sparse unless stated otherwise.
The policy sees the absolute gripper position, the object and target positions relative to the gripper, and the distance between the fingers, while the Q-function also receives velocities. The policy inputs were kept limited so that deployment on the physical robot would be easier.
Does HER help DDPG across the three tasks?
The comparison covers DDPG alone, DDPG with count-based exploration, and DDPG with HER using the final strategy. An episode counts as successful when the object ends within 7cm of the goal for pushing and pick-and-place, and within 20cm for sliding. The curves average 5 random seeds, and each epoch is 800 episodes.
Without HER, DDPG solved none of the three tasks, and count-based exploration made some progress only on sliding. With HER, DDPG solved all three tasks almost perfectly, which the authors take as evidence that HER is what makes learning from sparse, binary rewards possible. The best goal-sampling version from the later ablation is shown as an additional curve for comparison.
DQN without HER was also run on these tasks and solved none of them. The count-based baseline used an intrinsic reward of the form \\( \\alpha/\\sqrt{N} \\) over a grid of the relative box-target position, and the reported run used \\( \\alpha = 1 \\) and a grid step of 1cm, chosen by search.
One goal and shaped rewards
When every episode uses the same goal, DDPG with HER still performs much better than DDPG alone. Training episodes with several goals made HER learn faster, so the authors suggest training on multiple goals even when only one matters.
The shaped rewards tested have the form \\( \\lambda |g - s_{object}|^p - |g - s'_{object}|^p \\), with \\( \\lambda \\in \\{0, 1\\} \\) and \\( p \\in \\{1, 2\\} \\). Neither DDPG nor DDPG with HER solved any task with any of these rewards, and the best of them was the negative squared distance. Rescaling the distances, clipping large ones and adding gripper-motion terms were also tried without successful training.
The authors offer two possible causes: a large gap between the shaped objective and the success condition, and penalties for moving the box in a wrong direction that may hinder exploration. In some runs the agent learned not to touch the box at all, since it could not manipulate it precisely. The authors conclude that domain-agnostic reward shaping did not work well in the simple forms they tried.
Which goals to replay with
Besides final, the study compares episode, which draws states from the same episode, future, which draws states from the same episode observed after the transition, and random, which draws from everything seen in training. Each strategy has a k that sets how much HER data enters the buffer relative to normal replay. The sweep covers 1, 2, 4, 8, 16 and all additional goals.
All strategies except random solve pushing and pick-and-place almost perfectly, whatever the value of k. Future with k equal to 4 or 8 performs best and is the only strategy that solves sliding almost perfectly. Raising k above 8 degrades performance, which the authors attribute to too little normal replay data in the buffer.
The authors read this as showing that the most valuable replay goals are those achieved in the near future. A variant that replays goals close to near-future ones did not perform better than future.
Transfer to the physical robot
The deployed policy is the pick-and-place policy trained in simulation with the future strategy and k equal to 4. It is deployed without fine-tuning, and the box position is estimated by a separately trained CNN from raw head-camera images.
Initially the policy succeeded in 2 out of 5 trials. The authors attribute the weakness to training on perfect simulated state, which left the policy sensitive to small errors in the box position. After retraining with Gaussian noise of standard deviation 1cm added to observations, the success rate rose to 5/5.
The Q-function was trained on exact observations, since it is not used during deployment on the physical robot.
Relation to replay variants and curricula
Prioritized experience replay changes which transitions are sampled, and the authors regard it as orthogonal to HER, so the two can be combined. Learning several tasks at once has been studied in policy search and hierarchical reinforcement learning, and automatic curriculum generation has been approached through program search, PowerPlay and self-play task setters.
The authors note that curricula in the literature are almost always hand-crafted, whereas the goal curriculum produced by HER emerges from the replay choices.
Limits of the evidence
The physical robot test covers one pick-and-place policy and 5 trials before and after noisy retraining. Shaped rewards were tried only in the forms the authors examined, so the negative result is limited to those forms. The bit-flipping result comes from a toy setting using DQN. The manipulation experiments use DDPG, and DQN appears there only as a baseline without HER.
Learning curves summarise variation across the 5 seeds with shaded standard deviation rather than per-seed results.
Paper info
- Authors
- Marcin Andrychowicz, Filip Wolski, Alex Ray, Jonas Schneider, Rachel Fong, Peter Welinder, Bob McGrew, Josh Tobin, Pieter Abbeel, Wojciech Zaremba
- Venue
- arXiv · Preprint
- First published
- 2017-7-5
- Added
- 2026-11-6
- Updated
- 2018-2-23
- Version
- v3
- arXiv
- 1707.01495
- Category
- cs.LG · cs.AI · cs.NE · cs.RO
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Marcin Andrychowicz, Filip Wolski, Alex Ray, Jonas Schneider, Rachel Fong, Peter Welinder, Bob McGrew, Josh Tobin, Pieter Abbeel, Wojciech Zaremba (2017). Hindsight Experience Replay. arXiv:1707.01495v3. https://arxiv.org/abs/1707.01495v3
BibTeX
@misc{andrychowicz2017hindsight,
title = {{Hindsight Experience Replay}},
author = {Marcin Andrychowicz and Filip Wolski and Alex Ray and Jonas Schneider and Rachel Fong and Peter Welinder and Bob McGrew and Josh Tobin and Pieter Abbeel and Wojciech Zaremba},
year = {2017},
eprint = {1707.01495},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1707.01495v3}
}