Abstract
Standard autoregressive (AR) language models generate text in a strictly linear, irrevocable fashion. Once a token is sampled, it remains fixed, even if it leads the model into logical inconsistencies or coding errors. This paper introduces Resample-Previous-Tokens (RPT), a novel sampling and training framework that allows models to "proofread" and replace recently generated tokens by leveraging future context. By fine-tuning an 8B parameter model to perform Previous-Token-Prediction (PTP), we achieve a ~10% relative improvement in reasoning and coding tasks. Our results suggest that allowing models a mechanism for local correction significantly mitigates the compounding error problem inherent in AR generation.
1. Introduction
Autoregressive language models generate sequences token-by-token from left to right. While effective, this process is fundamentally limited by its irrevocability: a single sub-optimal choice or "slip of the tongue" early in a sequence can derail the entire generation, leading to logical fallacies or software bugs. Unlike humans, who often pause to revise a sentence mid-thought, standard LLMs are trapped in a continuous stream of consciousness.
Existing search strategies like Beam Search attempt to explore multiple paths but often suffer from semantic collapse or repetitive outputs. To address this, we propose Resample-Previous-Tokens (RPT), a method that grants models a "delete" key, enabling them to revisit and refine their recent output based on the tokens that follow.
2. Methodology
2.1 Resample-Previous-Tokens (RPT)
The core of our approach is the transition from simple Next-Token-Prediction (NTP) to a framework that includes Previous-Token-Prediction (PTP). In PTP, the model calculates the probability of a past token $x_i$ given both the preceding context $x_{<i}$ and the subsequent token $x_{i+1}$:
$$p(x_i | x_{<i}, x_{i+1})$$
During inference, the model maintains a small sliding window (typically $w=2$ or $3$). As the model generates, it iteratively revisits the tokens within this window, asking if the previously selected token still makes sense in light of the newly generated "future" token. If a more probable candidate is found, the token is replaced.
2.2 Permutation Training
To enable this capability without changing the underlying Transformer architecture, we utilize Permutation Training. We fine-tuned a pretrained 8B parameter model on 100 billion tokens (approximately 10% of its original training duration). During this phase, we occasionally swap the order of tokens in the input sequence. This forces the model to learn how to "fill in the blank" for a skipped token once the subsequent context is revealed.
3. Experimental Setup
3.1 Training Data
The models were trained on a massive corpus of 1 trillion language tokens, with the RPT-specific fine-tuning occurring on a 100B token subset.
3.2 Evaluation Benchmarks
We evaluated the RPT framework across several high-stakes domains:
- Coding: HumanEval+, MBPP, and multi-language benchmarks covering C++, C#, PHP, Bash, Java, and TypeScript.
- Reasoning: GSM8K (Grade-school math word problems).
- Validation: Error analysis and total variation distance measurements were conducted using the DCLM dataset.
4. Key Insights
4.1 The Hindsight Advantage
Our analysis reveals that PTP (predicting the past given the future) has significantly lower entropy than standard NTP. In essence, it is mathematically easier for a model to refine a choice with the benefit of hindsight than it is to predict the future from scratch. This lower entropy allows RPT to effectively prune erroneous generation paths before they propagate.
4.2 The Training Bonus
Interestingly, we observed that models trained with RPT objectives perform better even when using standard sampling (without the iterative correction step). This suggests that learning to predict tokens out-of-order improves the model's internal representations and overall robustness.
5. Results
5.1 Performance Gains
Fine-tuning with RPT yielded a ~10% relative improvement across reasoning and coding benchmarks compared to standard autoregressive baselines. These gains were consistent across all tested programming languages, demonstrating the generalizability of the approach.
5.2 Temperature Robustness
RPT is particularly effective at higher sampling temperatures. While standard models often become incoherent when "creativity" (stochasticity) is increased, RPT acts as a stabilizer, correcting high-variance guesses that would otherwise derail the sequence.
6. Limitations and Future Work
The primary trade-off for RPT is computational cost. Because the model must iteratively resample tokens, inference is inherently slower than standard one-pass generation. While we mitigated this using a small window size ($w=2$), future work will explore more efficient ways to scale the correction window. Additionally, we aim to move beyond greedy decoding for the correction step, potentially incorporating more sophisticated local search strategies.
7. Conclusion
By introducing a mechanism for hindsight-based correction, RPT bridges the gap between the rigid linearity of AR models and the iterative nature of human writing. The resulting improvements in coding and reasoning suggest that "proofreading" is a vital component for the next generation of robust language models.
Summary updated