Contrastive Difference Predictive Coding

Chongyi Zheng, Ruslan Salakhutdinov, Benjamin Eysenbach

TL;DR

Researchers have developed TD InfoNCE, a new approach that combines contrastive representation learning with temporal difference (TD) updates. By "stitching together" fragments of different experiences, this method learns to predict future states up to 1500× more efficiently than standard techniques, significantly boosting performance in goal-conditioned reinforcement learning.

What Problem Does This Paper Address?

In reinforcement learning (RL), a "goal-conditioned" agent needs to understand which actions will lead it to a specific future state. Traditionally, this is done using Contrastive Predictive Coding (CPC), which learns representations by comparing "positive" examples (states that actually happened together) against "negative" examples (random states).

However, standard CPC relies on Monte Carlo (MC) estimation. This means the model needs to see an entire sequence of events to learn the relationship between a start and a finish. This is data-hungry and inefficient because it can't easily learn from "off-policy" data—it can't realize that a piece of Trajectory A could be combined with a piece of Trajectory B to find a shortcut. This paper tackles the challenge of learning long-term temporal dependencies without requiring massive amounts of data or perfectly continuous demonstrations.

Methods

The authors introduce Temporal Difference InfoNCE (TD InfoNCE). The "secret sauce" is applying the logic of TD learning—the backbone of algorithms like Q-learning—to the InfoNCE (Information Noise Contrastive Estimation) loss function.

TD InfoNCE Concept

Key technical highlights include:

  • The TD Update: Instead of waiting for a trajectory to end (Monte Carlo), the model updates its current estimate based on the very next state and its own internal prediction of what follows that state.
  • Non-parametric Successor Representation: The authors prove that their method is essentially a non-parametric version of the "Successor Representation," a classic RL concept that encodes how often states are visited in the future.
  • Importance Weighting: To handle off-policy data (data collected by a different agent or policy), they derive a specific importance weight that allows the model to "re-weight" past experiences to fit the current goal.

Datasets

The researchers evaluated TD InfoNCE across several demanding benchmarks:

  1. Fetch Robotics (OpenAI Gym): Tasks like reach, push, pick & place, and slide, using both raw coordinates (state-based) and 64x64 RGB images.
  2. AntMaze (D4RL): A standard offline RL benchmark where an "ant" robot must navigate complex mazes to reach a goal.
  3. Tabular Gridworld: A controlled 5x5 environment used to precisely measure sample efficiency and "stitching" capabilities.

Key Insights and Ideas

  • Stitching is Power: The most striking insight is the ability to "stitch." If the robot knows how to get from A to B, and from B to C, TD InfoNCE allows it to infer the path from A to C even if it has never seen that full sequence. Monte Carlo methods fail here because they only learn from completed A-to-C runs.
  • Latent Space Planning: The authors found that linear interpolation in their learned representation space actually corresponds to a form of planning. Moving between two points in the "embedding" space naturally follows the causal path the robot should take.
  • Robustness to Noise: Unlike state-of-the-art methods like Quasimetric RL (QRL), which often assume deterministic environments, TD InfoNCE handles stochasticity (randomness) much better because it is grounded in a probabilistic framework.

Key Results

  • Massive Efficiency: In tabular settings, TD InfoNCE was 1500× more sample efficient than the standard Monte Carlo version of InfoNCE and 20× more efficient than the traditional Successor Representation.
  • Robotics Success: On challenging Fetch tasks like pick & place and slide, TD InfoNCE achieved a 2× median improvement in success rates over the strongest baselines.
Performance on Fetch Tasks
  • Image-Based Mastery: It was the only method tested that achieved non-negligible success rates on the most difficult image-based manipulation tasks.
  • Offline Performance: On the AntMaze benchmark, it outperformed specialized offline RL algorithms like IQL and TD3+BC on 5 out of 6 tasks.

Limitations and Future Work

Despite its strengths, the authors note that TD InfoNCE is computationally complex. It requires more hyperparameters than its Monte Carlo counterpart, making it harder to tune. Additionally, while it performs well on images, it still struggles with the most high-dimensional, visually complex control tasks.

Future research directions include applying this TD-based contrastive learning to other domains like Natural Language Processing (NLP) or video modeling, where temporal dependencies are crucial but data efficiency remains a bottleneck.

Summary updated

BibTeX
@inproceedings{zheng2024contrastive,
  author = {Chongyi Zheng and Ruslan Salakhutdinov and Benjamin Eysenbach},
  title = {{Contrastive Difference Predictive Coding}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=0akLDTFR9x},
}
Figure