Semformer: Transformer Language Models with Semantic Planning

Yongjing Yin, Junran Ding, Kai Song, Yue Zhang

Abstract

Next-token prediction serves as the dominant component in current neural language models. During the training phase, the model employs teacher forcing, which predicts tokens based on all preceding ground truth tokens. However, this approach has been found to create shortcuts, utilizing the revealed prefix to spuriously fit future tokens, potentially compromising the accuracy of the next-token predictor. In this paper, we introduce Semformer, a novel method of training a Transformer language model that explicitly models the semantic planning of response. Specifically, we incorporate a sequence of planning tokens into the prefix, guiding the planning token representations to predict the latent semantic representations of the response, which are induced by an autoencoder. In a minimal planning task (i.e., graph path-finding), our model exhibits near-perfect performance and effectively mitigates shortcut learning, a feat that standard training methods and baseline models have been unable to accomplish. Furthermore, we pretrain Semformer from scratch with 125M parameters, demonstrating its efficacy through measures of perplexity, in-context learning, and fine-tuning on summarization tasks.

Introduction

Modern Large Language Models (LLMs) are primarily trained using the next-token prediction objective with teacher forcing. While this paradigm has enabled unprecedented scaling, it suffers from a fundamental limitation: shortcut learning. Because the model is always provided with the ground-truth prefix during training, it often learns to exploit local statistical patterns to "guess" the next token rather than developing a deep understanding of the underlying logic required for a task.

This issue is particularly evident in tasks requiring global planning, such as graph path-finding. In these scenarios, models often exhibit the "Clever Hans" phenomenon: they become proficient at predicting the end of a sequence (where the prefix provides significant information) but fail at the critical first steps that require lookahead.

The 'Clever Hans' phenomenon in graph path-finding: standard models fail at the first token which requires global planning.

Methodology: The Semformer Architecture

To address these limitations, we propose Semformer, a Transformer architecture that incorporates an explicit semantic planning stage. The core idea is to force the model to compute an abstract representation of the entire future response before generating the first token of that response.

Semantic Planning Tokens

Semformer introduces a sequence of $k$ trainable "planning tokens" between the input prefix and the target response. These tokens serve as a computational bottleneck, encouraging the model to perform global reasoning before outputting tokens.

Latent Representation Prediction

During training, we employ an auxiliary Autoencoder (AE) to compress the target response into $k$ latent vectors ($Z$). The language model is then trained with a dual objective:

  1. Next-token prediction for the target response.
  2. Latent Representation Prediction ($L_{RP}$): Ensuring the hidden representations of the planning tokens match the latent vectors $Z$ produced by the AE via an $L_2$ loss.
The Semformer architecture: integrating a Language Model with an Autoencoder-guided semantic planning stage.

At inference time, the Autoencoder is discarded. The model generates the planning tokens, which have internalized the planning behavior during training, and then proceeds to generate the response based on these internal "plans."

Experimental Evaluation

Synthetic Reasoning: Graph Path-Finding

We evaluated Semformer on a graph path-finding task where the model must find a path between two nodes given an adjacency list. In complex settings (e.g., graphs with high branching factors), standard GPT-2 models achieved a mere ~3% accuracy, primarily failing at the first node. In contrast, Semformer achieved 100% accuracy, demonstrating its ability to mitigate shortcut learning and perform effective global planning.

General Language Modeling

To test scalability, we pretrained a 125M parameter Semformer from scratch on the OpenWebText corpus. Semformer achieved a lower perplexity (35.6) on Wikitext compared to a standard Transformer baseline (37.5). Furthermore, it showed superior performance in in-context learning tasks (SST-2, MRPC) and abstractive summarization (XSum, SAMSum, DialogSum), suggesting that semantic planning is broadly beneficial for language understanding and generation.

Conclusion

Semformer represents a significant step toward moving beyond simple linear next-token prediction. By forcing models to "think ahead" through a latent semantic space, we can mitigate the pitfalls of teacher forcing and shortcut learning. Future work will explore scaling Semformer to larger parameter counts and applying it to more complex reasoning domains like mathematics and code generation.

Summary updated

BibTeX
@inproceedings{yin2024semformer,
  author = {Yongjing Yin and Junran Ding and Kai Song and Yue Zhang},
  title = {{Semformer: Transformer Language Models with Semantic Planning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  url = {https://openreview.net/forum?id=RJgTy6tRsu},
}
Figure