Contrastive Abstraction for Reinforcement Learning

Vihang Patil, Markus Hofmarcher, Elisabeth Rumetshofer, Sepp Hochreiter

TL;DR

Learning policies in complex reinforcement learning (RL) environments is notoriously sample-inefficient when dealing with vast state spaces and long horizons. This paper introduces Contrastive Abstraction Learning, a reward-free framework that first clusters temporally proximal states using self-supervised contrastive learning, and then condenses them into discrete abstract states using the fixed points of Modern Hopfield Networks (MHNs). By tuning an inverse temperature parameter via a learned neural network, the agent flexibly controls its level of abstraction to enable rapid downstream policy learning and graph-based planning.

What Problem Does This Paper Address?

In reinforcement learning, tasks become drastically simpler if an agent can plan over high-level "abstract states" (e.g., “in the office” vs. “on the street”) rather than raw, noisy observations. However:

  1. Learning state abstractions end-to-end via RL objectives is notoriously unstable.
  2. Standard reward-dependent abstractions fail to generalize across different tasks in the same environment.
  3. Bisimulation and clustering methods can be computationally prohibitive when searching through vast state spaces.

The authors address how to learn reusable, reward-free state abstractions purely from trajectory data by leveraging self-supervised representations and associative memory dynamics.

Methods

The proposed approach operates in three main stages:

  1. Contrastive Learning of Sequential Proximity: Trajectories (from random exploration, replays, or demonstrations) are sampled to create positive pairs of states that are close in time. Using an InfoNCE objective, the encoder maps sequentially adjacent states closer together in representation space while pushing non-adjacent states apart.
  2. State Abstraction via Modern Hopfield Networks (MHNs): Continuous MHNs store state representations as associative memories. The update rule iteratively converges queries to fixed-point attractors (meta-stable states). All representations falling into the same attractor basin collapse to the same fixed point, which defines an abstract state.
  3. Controlling Abstraction Granularity ($\beta$-Network): The inverse temperature $\beta$ of the MHN determines granularity: low $\beta$ yields coarse clusters (averaging stored patterns), while high $\beta$ yields fine-grained states. The authors train an auxiliary feed-forward network to predict state-dependent $\beta$ values using a contrastive masking setup (random feature dropout).
  4. Downstream Execution Modes:
  5. Abstract Policy: A policy directly selects primitive actions conditioned on the abstract state.
  6. Meta Policy: A high-level policy selects meta-actions (sub-policies trained via behavior cloning to transition between adjacent abstract states).
  7. Graph-based Planning: A connectivity graph is built across abstract states using cosine similarity. Path planning (e.g., shortest path) finds routes to the goal, executed via learned sub-policies.

Datasets

The authors evaluated their method across simulated domains of varying complexity:

  • CifarEnv: A custom benchmark using CIFAR-100 images where 10 classes serve as semantic rooms/states with deterministic transitions.
  • Maze2D (Medium & Large): Continuous navigation benchmarks from the D4RL offline RL suite.
  • RedBlueDoor: A partially observable gridworld from the MiniGrid environment suite.
  • MineRL: Trajectories of human demonstrations from the Minecraft-based MineRL competition dataset.

Key Insights and Ideas

  • Laplace Temporal Sampling is Optimal for Abstraction: Choosing the right temporal sampling distribution matters. Uniform sampling yields muddy representations, while Gaussian sampling mirrors the geometry too closely without forming discrete clusters. A Laplace distribution effectively clusters states that belong together while pulling overlapping trajectories into shared spaces.
  • MHN Attractors Act as Natural State Aggregators: Instead of running $k$-means or setting hard cluster boundaries, the continuous associative memory dynamics naturally map continuous representations into stable fixed points.
  • Learned Temperature Automatically Discovers Latent Structure: Training the $\beta$-network allows the model to dynamically find the correct number of abstract states (e.g., recovering exactly the 10 ground-truth classes in CifarEnv), avoiding tedious manual tuning of cluster counts.

Key Results

  • Downstream RL: In CifarEnv navigation tasks (GoSchool, GoOffice, GoMarket, GoHouse), the Meta Policy learned faster and achieved higher cumulative returns than an Abstract Policy, pre-trained contrastive representations without abstraction (ATC-style), or standard PPO on raw states.
  • Graph Planning Success: Evaluating zero-shot graph-based planning with behavior-cloned sub-policies over 1,000 sampled start-goal pairs achieved strong task success rates:
  • 86% on CifarEnv
  • 88% on Maze2D-Large
  • 92% on Maze2D-Medium
  • Qualitative Clustering: In Maze2D and RedBlueDoor, MHN fixed points reliably mapped distinct geometric corridors, rooms, and door status conditions (open vs. closed) into coherent abstract states.

Limitations and Future Work

  • Action Uniformity Assumption: The Abstract Policy paradigm assumes that all raw states mapped to a single abstract state share the same optimal primitive action—an assumption that often breaks down in fine-grained control tasks.
  • Dependence on Trajectory Coverage: Constructing meaningful transitions requires offline trajectories with adequate state-space coverage, whether gathered via random policies or demonstrations.
  • Heuristic Graph Pruning: Connecting abstract states for planning relies on cosine similarity thresholding; although data-driven pruning is discussed, errors in the connectivity graph can cause planning failures.
  • Fixed Hopfield Weights: The Hopfield network in these experiments used fixed memory states without end-to-end learnable internal memory weights.

Summary updated

BibTeX
@inproceedings{patil2023contrastive,
  author = {Vihang Patil and Markus Hofmarcher and Elisabeth Rumetshofer and Sepp Hochreiter},
  title = {{Contrastive Abstraction for Reinforcement Learning}},
  booktitle = {GenPlan @ NeurIPS},
  year = {2023},
  url = {https://openreview.net/forum?id=oMkUQKfsCU},
}
Figure