LayerCake: Token-Aware Contrastive Decoding within Large Language Model Layers

Jingze Zhu, Yongliang Wu, Wenbo Zhu, Jiawang Cao, yanqiang zheng, Jiawei Chen, Xu Yang, Bernt Schiele, Jonas Fischer, Xinting Hu · Submission to ICLR 2026 · Rejected

TL;DR

LayerCake is a training-free decoding strategy that reduces hallucinations in Large Language Models (LLMs) by exploiting the relationship between transformer depth and token semantics. By selectively suppressing attention to specific token types—like punctuation in early layers and conceptual terms in middle layers—the authors induce controlled factual degradation, creating a "contrastive signal" that steers the final generation toward higher factual accuracy.

What Problem Does This Paper Address?

Despite their impressive fluency, LLMs remain prone to "hallucinations"—generating content that sounds plausible but is factually incorrect. Researchers have tried to fix this during the "decoding" phase (when the model picks the next word) by looking at internal signals.

However, previous methods usually look at these signals in silos: they either analyze how different layers contribute to truthfulness (layer-wise) or how specific tokens (like the "attention sink" at the start of a sentence) drive the model. The authors of LayerCake argue that these two dimensions are deeply intertwined. They set out to answer: How does the functional role of a token change as it moves through the depths of a transformer?

Methods

The researchers first conducted an empirical "attention analysis" to see where the model focuses its energy. They categorized tokens into three groups:

  1. Punctuation (P-type): Structural markers like commas, periods, and the <s> start token.
  2. Conceptual (C-type): Nouns, verbs, and adjectives that carry the core meaning.
  3. Functional (F-type): "Glue" words like "the," "is," or "which."

The "Layered Cake" Discovery

They found that LLMs process information in distinct stages:

  • Stage 1 (Layers 0–4): The model focuses heavily on Punctuation, establishing the structural skeleton of the sentence.
  • Stage 2 (Layers 5–16): Attention shifts toward Conceptual tokens, where the "heavy lifting" of semantic reasoning and factual grounding occurs.
  • Stage 3 & 4 (Layers 17–31): The model consolidates information and performs a final alignment before outputting a token.

The LayerCake Intervention

Using these insights, they developed a contrastive decoding method. The core idea of contrastive decoding is to compare a "strong" model with a "weakened" version; the difference between them highlights the most important features for a good output.

LayerCake creates this "weakened" version by intervening at specific depths:

  • It suppresses attention to P-type tokens in the early layers.
  • It suppresses attention to C-type tokens in the middle layers.

By subtracting the log-probabilities of this "messed-up" model from the original model's predictions, they amplify the factual signals that the model would have lost if those specific token-layer interactions were disrupted.

Datasets

The authors evaluated LayerCake across a massive battery of benchmarks to ensure it wasn't just a "one-trick pony":

  • Factuality: TruthfulQA, FACTOR (Expert), and HaluEval-Sum.
  • Reasoning: StrategyQA and GSM8K (math).
  • General Knowledge/QA: HellaSwag, OpenBookQA (OBQA), TriviaQA, HotpotQA, and Natural Questions (NQ).

They tested the method on several popular model families, including LLaMA 2 (7B/13B), LLaMA 3 (8B), Mistral-7B, and Qwen 3-8B.

Key Insights and Ideas

  • Functional Specialization: The most striking "aha" moment is that punctuation isn't just filler; in early layers, it acts as an "anchor" for the model's reasoning. If you mask a comma in Layer 2, the model’s factual accuracy plummets far more than if you mask it in Layer 20.
  • Targeted Sabotage: Instead of weakening the whole model (like using a smaller version or adding noise), LayerCake uses "surgical" strikes on attention. This makes the contrastive signal much cleaner and more relevant to the specific factual task at hand.
  • Training-Free Efficiency: Because this happens entirely at inference time, it requires zero extra GPU memory for training or fine-tuning, making it highly accessible for deployment.

Key Results

LayerCake consistently outperformed standard greedy decoding and state-of-the-art baselines like DoLa and SLED:

  • TruthfulQA: On the multiple-choice task, LayerCake improved accuracy by an average of 3.5% (MC1), 1.7% (MC2), and 6.4% (MC3) over the next best method.
  • Hallucination Reduction: On HaluEval-Sum, it showed a significant 7.73% improvement in accuracy compared to greedy decoding.
  • Robustness: The gains were consistent across different architectures (LLaMA, Mistral, Qwen), suggesting that the "Layered Cake" attention pattern is a fundamental characteristic of modern transformer-based LLMs.
  • Quality Control: Using GPT-5 Nano as a judge, the authors confirmed that LayerCake doesn't just produce facts—it maintains (and sometimes improves) the grammatical coherence and reduces repetition in the generated text.

Limitations and Future Work

  • Fixed Stages: Currently, the layer boundaries (e.g., 0–4 for punctuation) are manually defined based on observation. The authors suggest that future versions could be adaptive, automatically identifying these stages for any new model architecture.
  • Latency: Like all contrastive decoding methods, LayerCake requires two forward passes (one original, one intervened), which roughly doubles the time per token. While they introduced a "plausibility constraint" to speed things up, it remains slower than simple greedy decoding.
  • Granularity: The token categorization is currently based on broad Part-of-Speech tags. Refining this to account for word frequency or specific semantic roles could further sharpen the contrastive signal.

Summary updated

BibTeX
@misc{zhu2025layercake,
  author = {Jingze Zhu and Yongliang Wu and Wenbo Zhu and Jiawang Cao and yanqiang zheng and Jiawei Chen and Xu Yang and Bernt Schiele and Jonas Fischer and Xinting Hu},
  title = {{LayerCake: Token-Aware Contrastive Decoding within Large Language Model Layers}},
  year = {2025},
  eprint = {2507.04404},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.04404},
}
Figure