Contrastive Example-Based Control

Kyle Beltran Hatch, Benjamin Eysenbach, Rafael Rafailov, Tianhe Yu, Ruslan Salakhutdinov, Sergey Levine, Chelsea Finn

Abstract: While many real-world problems might benefit from reinforcement learning, these problems rarely fit into the MDP mold: interacting with the environment is often expensive and specifying reward functions is challenging. Motivated by these challenges, prior work has developed data-driven approaches that learn entirely from samples from the transition dynamics and examples of high-return states. These methods typically learn a reward function from high-return states, use that reward function to label the transitions, and then apply an offline RL algorithm to these transitions. While these methods can achieve good results on many tasks, they can be complex, often requiring regularization and temporal difference updates. In this paper, we propose a method for offline, example-based control that learns an implicit model of multi-step transitions, rather than a reward function. We show that this implicit model can represent the Q-values for the example-based control problem. Across a range of state-based and image-based offline control tasks, our method outperforms baselines that use learned reward functions; additional experiments demonstrate improved robustness and scaling with dataset size.

Introduction

Reinforcement Learning (RL) has shown immense potential in simulated environments, yet its application to complex real-world behaviors—such as folding laundry or packing a box—remains limited by the difficulty of reward engineering. Manually coding a reward function that captures the nuances of success is notoriously error-prone and time-consuming.

Example-based control offers a compelling alternative: instead of writing code, a user provides images or states representing a successful outcome. However, existing offline methods for this paradigm typically rely on a two-stage pipeline: training a classifier to distinguish success examples from random states and then using that classifier as a reward function for standard offline RL. This approach is often unstable, sensitive to hyperparameters, and prone to failure when success examples are scarce.

Methodology: Learning to Achieve Examples Offline (LAEO)

We introduce LAEO (Learning to Achieve Examples Offline), a method that simplifies offline example-based control by moving from "reward learning" to "implicit dynamics modeling." Instead of learning a binary success classifier, LAEO learns a model of the discounted state occupancy measure.

Essentially, the model estimates the probability that taking action $a$ in state $s$ will lead to visiting a target state $s^*$ at any point in the future. To train this without the computational burden of generating high-dimensional images, we utilize a contrastive loss. The model learns to assign high scores to actual future states (positive pairs) and low scores to random states sampled from the dataset (negative pairs).

The Geometric Perspective

Mathematically, the score from this contrastive model is equivalent (up to a constant) to the Q-value of the behavioral policy. This allows LAEO to effectively learn a shared embedding space where control becomes a geometric retrieval problem. A state-action pair is assigned a high Q-value if its "predicted future" embedding is close to the embedding of a success example.

LAEO learns a shared embedding space where state-action pairs are mapped close to success examples.

By deriving Q-values directly from the data distribution, we can employ a "one-step" RL approach. We update the policy to maximize these Q-values while utilizing a behavioral cloning regularizer to stay close to the original data distribution, thereby avoiding the common pitfalls of distribution shift and the instabilities of temporal difference (TD) learning.

Experimental Evaluation

We evaluated LAEO across six simulated robotic manipulation tasks, including state-based and image-based versions of FetchReach and FetchPush, as well as SawyerWindowOpen and SawyerDrawerClose. To test robustness, we utilized datasets ranging from "medium-quality" (45-50% success) to "low-quality" (8-12% success).

Success rates of LAEO compared to baselines across six robotic manipulation tasks.

As shown in the results, LAEO consistently outperforms state-of-the-art baselines like ORIL and PURL. Notably, LAEO demonstrates superior scaling; as the size of the offline dataset increases, its performance continues to improve while baseline methods often plateau. Furthermore, LAEO is remarkably sample-efficient, maintaining high performance even when provided with only a single success state, a scenario where classifier-based methods typically collapse.

Discussion and Conclusion

The success of LAEO highlights a key insight: learning how the world evolves (dynamics) provides a denser and more useful signal for control than binary success labels. By avoiding the complexities of TD-learning and reward classification, LAEO offers a more stable and easier-to-tune framework for offline control.

However, the method is not without limitations. Because LAEO performs only one step of policy improvement, it is fundamentally constrained by the quality of the behavioral data; it cannot easily discover strategies that are significantly better than the best trajectories already present in the dataset. Future work may explore extending this to a multi-step actor-critic framework to allow for further policy improvement, provided the associated instabilities can be managed. Nevertheless, LAEO represents a significant step toward making example-based control practical for complex, real-world robotic tasks.

Summary updated

BibTeX
@inproceedings{hatch2023contrastive,
  author = {Kyle Beltran Hatch and Benjamin Eysenbach and Rafael Rafailov and Tianhe Yu and Ruslan Salakhutdinov and Sergey Levine and Chelsea Finn},
  title = {{Contrastive Example-Based Control}},
  booktitle = {L4DC},
  year = {2023},
  url = {https://openreview.net/forum?id=JgrYIKytRx},
}
Figure