Abstract
Offline reinforcement learning (RL) aims to derive optimal policies from fixed, often suboptimal, datasets. A critical requirement for success in this domain is "stitching"—the ability to combine segments of suboptimal trajectories to form an optimal path. While Decision Transformers (DT) have shown promise by framing RL as sequence modeling, they fundamentally lack this stitching capability. We present Context-Former, a framework that replaces traditional scalar reward conditioning with latent expert representations. By employing a supervised "divergent expert matching" objective, Context-Former enables DT to effectively stitch trajectories, outperforming existing DT variants and state-of-the-art imitation learning baselines on complex tasks like Maze2d and Gym-Mujoco.
Introduction
In offline reinforcement learning (RL), the goal is to learn a high-performing policy from a fixed dataset of past experiences, which are often collected by mediocre or suboptimal agents. A hallmark of a successful offline RL algorithm is stitching: the capacity to synthesize an optimal path from fragments of suboptimal trajectories. For example, if a dataset contains one path from point A to B and another from B to C, the algorithm should be able to "stitch" them together to find the path from A to C, even if no single trajectory in the data ever completed the full trip.
While the Decision Transformer (DT) has been successful by treating RL as a sequence modeling problem—predicting actions based on a target "Return-to-Go" (RTG)—it famously lacks this stitching capability. Previous attempts to rectify this, such as the Q-learning Decision Transformer (QDT), rely on conservative value functions that often make the agent too timid or prone to errors when encountering out-of-distribution data.
Methodology: The Context-Former Framework
Context-Former shifts the paradigm from reward-matching to expert matching in a latent space, addressing the information bottleneck of scalar rewards.
Latent Conditioning
Instead of conditioning the Transformer on a scalar RTG, Context-Former conditions on a latent embedding $z$. This $z$ represents the "context" or "intent" of the trajectory, providing a much richer description of behavior than a single numerical value.
Divergent Sequential Expert Matching
The core innovation is the Divergent Sequential Expert Matching objective. The model is trained to optimize $z$ such that it moves toward the representations of expert trajectories and away from suboptimal ones. This "divergence" ensures the model extracts the most useful "expert-like" features even from messy, suboptimal data.
Architecture
- Encoder: Uses a BERT-style architecture to extract Hindsight Information (HI) from trajectories.
- Policy: A modified Decision Transformer that takes the latent context $z$ as an input instead of the traditional reward-based RTG.
Context-Former is trained using fully supervised learning, which provides greater stability and avoids the "conservatism" trap typical of off-policy RL methods.
Experimental Results
The researchers evaluated Context-Former using the standard D4RL benchmark, focusing on Gym-Mujoco tasks and the Maze2d domain, which specifically tests stitching abilities.
Key Insights
- Stitching as Representation Matching: Stitching doesn't have to be a value-estimation problem. If trajectory fragments can be mapped into a latent space where high-quality fragments cluster together, the Transformer can learn to transition between them naturally.
- Moving Beyond Scalars: Scalar rewards (e.g., +10) don't explain how a model succeeded. A latent vector $z$ provides a richer description, allowing for better generalization.
- The Power of Divergence: By explicitly telling the model to be unlike bad trajectories while mimicking good ones, the authors could extract expert-level information even when actual expert data was scarce.
Performance Highlights
- Superior Stitching: In the
maze2denvironment, Context-Former achieved a score of 363.4, significantly outperforming standard DT (237.9) and the specialized QDT (291.7). - Outperforming DT Variants: Context-Former showed a 25.7% improvement over the Generalized Decision Transformer (GDT) across several Mujoco tasks.
- Imitation Learning Excellence: Compared against state-of-the-art Imitation Learning (IL) baselines like CEIL or IQ-Learn, Context-Former achieved the highest aggregate scores in both "Learning from Demonstration" (LfD) and "Learning from Observation" (LfO) settings.
Conclusion and Future Work
Context-Former successfully introduces stitching capabilities to the Decision Transformer architecture through latent expert matching. While its performance is currently tied to the quality of expert demonstrations, future work may explore Optimal Transport to reduce this reliance, potentially allowing the model to learn optimal behaviors with even less guidance.
Summary updated