Abstract
Standard Transformer language models trained with next-token prediction often suffer from the "Clever Hans" effect, where they rely on local statistical patterns rather than global reasoning. This paper introduces Semformer, a model architecture that incorporates "semantic planning" by predicting a compressed, latent representation of the future response before generating text. By utilizing trainable planning tokens supervised by an auxiliary autoencoder, Semformer demonstrates superior performance in tasks requiring lookahead, such as graph path-finding, and shows improved generalization across language modeling and summarization benchmarks.
1. Introduction
The prevailing paradigm for training Large Language Models (LLMs) is next-token prediction with teacher forcing. While this approach has yielded impressive results, it incentivizes models to exploit local cues in the training prefix rather than developing a coherent internal plan for the entire response. This phenomenon, often referred to as the "Clever Hans" shortcut, is particularly problematic in tasks requiring significant lookahead. For instance, in a graph path-finding task, the validity of the first node in a sequence depends entirely on the final destination. Standard Transformers often fail these tests because they do not "think ahead" before they begin generating tokens.
Semformer addresses this limitation by forcing the model to formulate a "semantic plan"—an abstract representation of the intended answer—prior to the generation of the first output token.
2. Methodology
Semformer is a decoder-only Transformer that explicitly models the semantics of the target response through a multi-stage process involving latent space prediction.
2.1 The Semantic Autoencoder
During the training phase, an auxiliary autoencoder is employed to process the target response. This autoencoder compresses the text into a sequence of low-dimensional latent vectors ($Z$). These vectors serve as the ground-truth "semantic plan" that the model must learn to anticipate.
2.2 Planning Tokens and Dual Objective
The architecture inserts $k$ trainable "planning tokens" between the input prompt (prefix) and the target answer. The model is then trained with a dual objective:
- Next-Token Prediction: The standard cross-entropy loss for generating the target text.
- Latent Prediction: The hidden states of the planning tokens are supervised via an $L_2$ loss to predict the latent vectors $Z$ generated by the autoencoder.
2.3 Inference
At test time, the autoencoder is discarded. The model generates the planning tokens based on the prompt. Because these tokens have been trained to predict the latent semantics of a valid response, they act as an internal guide. The subsequent text generation is then conditioned on these informative planning states.
3. Experimental Results
The authors evaluated Semformer (125M parameters) against vanilla Transformers and "Pause Transformers" (which use dummy tokens for extra computation without explicit semantic supervision).
3.1 Graph Path-Finding
In synthetic star-path graph benchmarks, which require perfect lookahead, Semformer achieved near 100% accuracy. In contrast, standard Transformers and Pause Transformers struggled significantly, often hovering between 5% and 50% accuracy. This suggests that the explicit supervision of planning tokens is necessary for the model to utilize extra computation effectively for reasoning.
3.2 General Language Modeling and Summarization
Semformer demonstrated robust performance across several standard NLP benchmarks:
- Wikitext: Achieved a perplexity of 35.6, outperforming the vanilla baseline (37.5).
- Summarization (XSum, SAMSum, DialogSum): Showed consistent improvements in ROUGE scores, indicating better global coherence in long-form generation.
- In-Context Learning (SST-2): In a 4-shot setting, Semformer reached 66.1% accuracy, compared to 57.0% for the standard Transformer.
4. Discussion and Insights
Several key findings emerged from the ablation studies:
- The Role of Compression: Low-dimensional latent spaces (32 or 64 dimensions) proved more effective than higher-dimensional ones. This indicates that a plan is most useful when it serves as an abstract summary rather than a verbatim reconstruction of the future.
- Attention Dynamics: Visualization of attention weights revealed that Semformer's planning tokens focus heavily on relevant constraints in the prompt (e.g., graph edges). The generated answer tokens then attend strongly to these planning tokens, confirming that the model is indeed conditioning its output on the internal plan.
- Convergence: Semformer reached peak performance on reasoning tasks in fewer training steps than models using simpler objectives like Bag-of-Words (BoW) prediction.
5. Conclusion and Future Work
Semformer provides a promising framework for mitigating the shortcuts inherent in teacher-forcing. By supervising the model's internal planning process, it achieves a level of logical consistency that standard next-token predictors lack. Future research will focus on scaling this architecture to larger parameter counts (1B+) and exploring hierarchical planning structures for more complex, multi-step reasoning tasks in domains like mathematics and software engineering.
Summary updated