Selective Prompt Anchoring for Code Generation

Yuan Tian, Tianyi Zhang
2/12/2026

No official code found. Best implementation: magic-YuanTian/Selective-Prompt-Anchoring (100 stars, Apache-2.0, last commit 2026-04-24).

Abstract

Recent advances in large language models (LLMs) have transformed software development by automatically generating code from natural language. Yet challenges remain in generating fully correct code that aligns with user intent. Our study reveals that LLMs tend to pay less attention to user prompts as more code tokens are generated. We hypothesize that this attention dilution issue is an important reason for code generation errors. To mitigate this issue, we propose Selective Prompt Anchoring (SPA) to guide code LLMs to pay more attention to user intent when generating code. We evaluate SPA using six base LLMs across six benchmarks. Our results demonstrate that SPA enhances Pass@1 by up to 12.9%, consistently outperforming SOTA code generation methods in all settings. Our code is available at https://github.com/magic-YuanTian/Selective-Prompt-Anchoring.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Selective Prompt Anchoring

1003PythonMay 22, 20245 months agoApache-2.0

Similar Papers

Cite this paper

@article{tian2026selective,
  title  = {Selective Prompt Anchoring for Code Generation},
  author = {Yuan Tian and Tianyi Zhang},
  year   = {2026},
  eprint = {2408.09121},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2408.09121},
  journal = {ICML 2024 2024}
}

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/2408.09121.svg)](https://codeofpaper.com/paper/2408.09121)

Discussion