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

Jingze Zhu, Yongliang Wu, Wenbo Zhu, Jiawang Cao, Yanqiang Zheng +5 more
7/6/2025
cs.AI

No confident code implementation found for this paper.

Abstract

Large language models (LLMs) excel at natural language understanding and generation but remain vulnerable to factual errors, limiting their reliability in knowledge-intensive tasks. While decoding-time strategies provide a promising efficient solution without training, existing methods typically treat token-level and layer-level signals in isolation, overlooking the joint dynamics between them. In this work, we introduce a token-aware, layer-localized contrastive decoding method that aligns specific token types with their most influential transformer layers to improve factual generation. Through empirical attention analysis, we identify two key patterns: punctuation tokens receive dominant attention in early layers, while conceptual tokens govern semantic reasoning in intermediate layers. By selectively suppressing attention to these token types at their respective depths, we achieve the induction of controlled factual degradation and derive contrastive signals to guide the final factual decoding. Our method requires no additional training or model modification, and experiments demonstrate that our method consistently improves factuality across multiple LLMs and various benchmarks.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{zhu2025layercake,
  title  = {LayerCake: Token-Aware Contrastive Decoding within Large Language Model Layers},
  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},
  year   = {2025},
  eprint = {2507.04404},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2507.04404v2}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2507.04404.svg)](https://codeofpaper.com/paper/2507.04404)

Discussion