Autoregressive models like GPT-4 are masters of "next-token prediction," but they have a well-known Achilles' heel: compounding errors. Because they are trained to predict the next word given a perfect ground-truth history, they often don't know how to recover when they stumble during generation. One slightly "off" token can lead the model into a tailspin of gibberish or repetition.
A new paper from researchers at Stanford, "SequenceMatch: Imitation Learning for Autoregressive Sequence Modelling with Backtracking," proposes a clever fix. By reframing sequence generation as an imitation learning problem, the authors introduce a way for models to minimize distributional drift and—most importantly—learn how to use a "backspace" key to undo their own mistakes.
The Compounding Error Problem
Standard language models are trained using Maximum Likelihood Estimation (MLE). During training, the model always sees the correct "teacher" tokens. But during inference, the model is on its own; it feeds its own (potentially flawed) outputs back in as inputs.
This creates a mismatch: the model has never learned what to do when it is "out-of-distribution" (OOD). In the imitation learning literature, this is known as the compounding error problem. If a model makes a 1% error at every step, after 50 steps, it is likely in a state it never encountered during training. The result is "neural text degeneration"—the repetitive or nonsensical loops we often see in smaller or poorly tuned models.
Methods: SequenceMatch
SequenceMatch addresses this problem by treating text generation as an imitation learning task. It departs from standard training in three major ways:
1. From KL to $\chi^2$ Divergence
MLE is equivalent to minimizing the forward KL-divergence, which doesn't penalize the model for behaving strangely on sequences that don't exist in the training data (it is "OOD-blind"). SequenceMatch instead minimizes a $\chi^2$-divergence between the model's "occupancy measure" (how often it visits certain states) and the data's occupancy measure. This objective more heavily punishes the model for wandering into OOD territory.
2. The Backspace Action
Simply telling a model it's in a bad state isn't enough if there's no "good" way forward. The authors augment the model’s vocabulary with a special <bkspc> token. In their Markov Decision Process (MDP) formulation, taking the <bkspc> action deterministically removes the last token and returns the model to the previous state, providing a universal "escape hatch" to return to a known-good prefix.
3. Efficient Non-Adversarial Training
Unlike GANs, which are notoriously unstable, SequenceMatch uses a fully supervised loss derived from recent advances in "IQ-Learn." It uses a replay buffer of the model's own generated sequences to provide "on-policy" feedback without needing a discriminator network. To make this efficient for Transformers, they developed a novel masking scheme that allows the model to process sequences containing backspaces in a single parallel pass, maintaining the speed advantages of the architecture.
Key Insights and Results
To teach the model how to use the backspace, the authors inject "ground-truth noise" into the training data (e.g., inserting a wrong digit followed by a backspace). This acts as a form of expert demonstration for error recovery. The researchers evaluated SequenceMatch on several challenging tasks, including arithmetic (base-conversion math), text generation (fine-tuning Llama-2-7b on OpenWebText), and algorithmic tasks.
- Arithmetic Accuracy: On base-conversion math, SequenceMatch significantly outperformed MLE and Behavioral Cloning. Qualitatively, the model would often type a wrong digit, "realize" the mistake, hit
<bkspc>, and then provide the correct answer. - Higher Quality Text: In OpenWebText generation, SequenceMatch achieved higher MAUVE scores (a metric for how closely generated text distribution matches human text) compared to MLE and "Unlikelihood Training."
- Diversity: The model maintained high n-gram entropy (diversity) while reducing the "gibberish" typically associated with high-temperature sampling.
Limitations and Future Work
While promising, SequenceMatch comes with a few trade-offs:
- Computational Overhead: SequenceMatch is roughly 2-3x slower to train than MLE. This is because it requires "rolling out" the model to generate sequences for the replay buffer and uses a more complex masking pattern that prevents some GPU kernel optimizations.
- Heuristic Noise: The current method relies on injecting random noise to teach backtracking. The authors suggest that using a "mistake model" (e.g., common human typos or translation errors) could make the backtracking even more effective.
- Scaling: While tested on Llama-2-7b, it remains to be seen how this objective scales to 70B+ parameter models where the "base" model's OOD behavior is already much more robust.
Summary updated