HistAlign: Improving Context Dependency in Language Generation by Aligning with History

David Wan, Shiyue Zhang, Mohit Bansal

Abstract

Language models (LMs) can generate hallucinations and incoherent outputs, which highlights their weak context dependency. Cache-LMs, which augment LMs with a memory of recent history, can increase context dependency and have shown remarkable performance in diverse language generation tasks. However, we find that even with training, the performance gain stemming from the cache component of current cache-LMs is suboptimal due to the misalignment between the current hidden states and those stored in the memory. In this work, we present HistAlign, a new training approach to ensure good cache alignment such that the model receives useful signals from the history. We first prove our concept on a simple and synthetic task where the memory is essential for correct predictions, and we show that the cache component of HistAlign is better aligned and improves overall performance. Next, we evaluate HistAlign on diverse downstream language generation tasks, including prompt continuation, abstractive summarization, and data-to-text. We demonstrate that HistAlign improves text coherence and faithfulness in open-ended and conditional generation settings respectively. HistAlign is also generalizable across different model families, showcasing its strength in improving context dependency of LMs in diverse scenarios.

Introduction

Modern Large Language Models (LLMs) are prone to "hallucinations" and incoherence, often because they struggle with context dependency. While self-attention helps, it is often limited by the softmax bottleneck: a mathematical constraint where the model's output layer lacks the rank to represent highly nuanced, multi-modal word distributions.

A classic solution is the Cache-LM, which equips the model with a "local memory" of recent hidden states and tokens, allowing it to "copy" directly from the history. However, research shows a critical gap: even when trained, these models often fail to align their current "query" state with the correct "key" state in the cache.

Comparison of HistAlign and Baseline Cache-LM predictions.

As illustrated in Figure 1, a standard model might mistakenly retrieve irrelevant words like "to" or "the" from the cache, or hallucinate a semantically related but incorrect word like "queen" from its internal vocabulary. HistAlign addresses this by ensuring the model receives useful signals from its history through better alignment.

HistAlign Methodology

The core contribution of this work is HISTALIGN, a training objective that forces the model to align its current hidden state with relevant historical memories. The approach consists of three primary steps:

  1. Get Local Cache: Hidden states and tokens from the recent history are stored. This is applicable to both decoder-only (e.g., GPT) and encoder-decoder (e.g., BART) architectures.
  2. Rank Memories by Embedding Similarity: HISTALIGN uses order-informed contrastive learning. Instead of treating all "negative" examples as equally wrong, it ranks them based on semantic similarity to the target word. For example, if the target is "housing," the model learns that "accommodations" is a "better" negative than "children."
  3. Align Cache with Margin Loss: This creates a more nuanced vector space where the model learns to prioritize semantically relevant history, effectively moving the model's hidden state toward a "neighborhood" of relevant concepts.
The three-step HistAlign training process: cache retrieval, ranking, and alignment.

By adding the cache logits to the standard softmax logits, the model can represent complex distributions that a standard parametric model cannot, effectively breaking the softmax bottleneck.

Experimental Results

The authors evaluated HISTALIGN across four distinct scenarios: synthetic ambiguous templates, open-ended story generation (WritingPrompts), abstractive summarization (XSum & CNN/DM), and data-to-text (LogicNLG).

  • Synthetic Success: On the Ambiguous Template task, HISTALIGN achieved nearly 100% accuracy in retrieving correct tokens, while previous state-of-the-art methods often failed to reach 1% accuracy in the same cache-only setting.
  • Improved Coherence: In open-ended generation, HISTALIGN improved coherence scores by up to 7.5 points on GPT2-small.
  • Higher Faithfulness: In summarization (XSum), HISTALIGN significantly outperformed baselines on faithfulness metrics like FactCC (+0.91) and DAE (+4.78).
  • Human Preference: Human evaluators significantly preferred HISTALIGN over the TRIME baseline for both fluency and coherence.

Conclusion

HISTALIGN demonstrates that the failure of previous Cache-LMs was not the cache itself, but the training methodology. By employing semantic ranking and margin-based loss, the model becomes robust and better aligned with its own history. Future work may explore scaling this approach to 70B+ parameter models and incorporating HISTALIGN into the initial pre-training phase of LLMs.

Summary updated

BibTeX
@inproceedings{wan2023histalign,
  author = {David Wan and Shiyue Zhang and Mohit Bansal},
  title = {{HistAlign: Improving Context Dependency in Language Generation by Aligning with History}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  url = {https://openreview.net/forum?id=oaNa4rNIpU},
}
Figure