Hindsight Task Relabelling: Experience Replay for Sparse Reward Meta-RL

Charles Packer, Pieter Abbeel, Joseph E. Gonzalez

Introduction

Meta-Reinforcement Learning (Meta-RL) agents are designed to quickly adapt to new, unseen tasks by leveraging experience gained from previous tasks. However, these agents typically fail in environments with sparse rewards—where the agent only receives a reward upon successfully completing a task (e.g., +1 for reaching a goal, and 0 everywhere else). To overcome this, researchers often rely on hand-engineered dense proxy rewards. This paper introduces Hindsight Task Relabeling (HTR), an algorithm that adapts Hindsight Experience Replay (HER) to the Meta-RL setting, allowing agents to learn effective exploration and adaptation strategies using only sparse rewards.

The Challenge of Sparse Rewards in Meta-RL

In Meta-RL, the specific task is hidden from the agent. The agent must infer the task by exploring the environment and observing the rewards it collects. If rewards are sparse, a randomly initialized agent will almost never stumble upon a successful outcome, meaning it receives zero learning signal to figure out how to explore or infer the task.

To bypass this exploration bottleneck, existing Meta-RL algorithms typically "cheat" by using hand-shaped, dense reward functions during the meta-training phase. They only evaluate the agent on sparse rewards during meta-testing. However, designing dense reward functions is expensive, requires domain expertise, and can lead to unintended behaviors where the agent optimizes for the proxy reward rather than the true objective.

Hindsight Task Relabeling (HTR)

The authors propose HTR to bring the core concept of Hindsight Experience Replay (HER) into the Meta-RL domain. In standard HER, if an agent tries to reach Goal A but ends up at Goal B, the experience is relabeled as a successful attempt at Goal B. This provides a sparse reward signal that the agent can still learn from.

However, applying standard HER directly to Meta-RL fails. Meta-RL agents use a "context encoder" to infer the hidden task from a batch of recent transitions. If you independently relabel every transition in a batch with a different random goal, the context encoder gets confused because the transitions no longer represent a single, coherent task.

Comparison of relabeling in standard Goal-conditioned RL versus Meta-RL. Meta-RL requires context consistency across multiple trajectories.

To solve this, HTR ensures batch-level consistency using two proposed strategies, with the first being the most practical:

  1. Single Episode Relabeling (SER): The algorithm samples a single trajectory, generates a hindsight task based on where the agent actually ended up, and relabels a batch of transitions from that specific trajectory with the new task. This closely mimics how the agent will experience data during actual testing.
  2. Episode Clustering (EC): Trajectories that happen to satisfy similar hindsight tasks are clustered into new, distinct task replay buffers.

The authors implement HTR on top of PEARL (Probabilistic Embeddings for Actor-critic RL), a standard off-policy Meta-RL algorithm.

Experimental Setup and Key Results

The authors evaluated HTR on a suite of continuous control environments modified from prior Meta-RL benchmarks, including a 2D Point Robot navigation task, a Wheeled Locomotion task, and a complex Ant Locomotion task. Crucially, unlike prior work, these environments strictly used sparse rewards during both meta-training and meta-testing.

Exploration behavior in the Point Robot environment, showing the agent systematically sweeping the semicircle to find the hidden goal.

The experiments revealed several key insights:

  • Standard Meta-RL fails: Without HTR, the baseline PEARL algorithm completely fails to learn meaningful exploration strategies in all three sparse reward environments.
  • HTR matches dense-reward Oracles: PEARL equipped with HTR successfully learns to explore and adapt using only sparse rewards. Its performance (average sparse return) is virtually identical to an "oracle" PEARL agent trained with hand-engineered dense proxy rewards.
  • Systematic Exploration: Visualizations show that HTR agents learn to systematically search the task space—such as sweeping the perimeter of the semicircle in the Point Robot environment—just as effectively as agents trained with dense proxy rewards.
  • An implicit curriculum emerges: Early in training, the agent flails randomly. HTR relabels these random flails as successful tasks, teaching the agent basic mechanics. As the policy improves, it starts hitting actual sparse rewards, and the distribution of relabeled tasks naturally shifts toward the true ground-truth task distribution.
  • Less is more: While standard HER often relabels up to 80% of the data, HTR works best with a much lower relabeling probability (e.g., 10% to 30%). Relabeling too much biases the training data too far away from the ground-truth task distribution.

Limitations and Future Work

While highly effective, HTR assumes it is easy to map a state or trajectory to a task (e.g., "the agent ended up at coordinates X,Y, so the new task is navigating to X,Y"). This works perfectly for goal-reaching tasks but is much harder to define for complex, multi-step robotic manipulation. Additionally, HTR introduces a new hyperparameter—the relabeling probability—which requires tuning for optimal performance. Future work may extend HTR to broader families of tasks by integrating inverse RL to automatically learn how to relabel complex trajectories.

Summary updated

BibTeX
@inproceedings{packer2021hindsight,
  author = {Charles Packer and Pieter Abbeel and Joseph E. Gonzalez},
  title = {{Hindsight Task Relabelling: Experience Replay for Sparse Reward Meta-RL}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
}
Figure