ICML 2025poster8 citations

Selective Prompt Anchoring for Code Generation

Yuan Tian, Tianyi Zhang

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 ***S**elective **P**rompt **A**nchoring* (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.

Large Language Models (LLMs)PromptCode GenerationSelf-attentionTaylor expansionLogitsAnchoring
BibTeX
@inproceedings{
tian2025selective,
title={Selective Prompt Anchoring for Code Generation},
author={Yuan Tian and Tianyi Zhang},
booktitle={Forty-second International Conference on Machine Learning},
year={2025},
url={https://openreview.net/forum?id=aEnkBIhYvO}
}
Selective Prompt Anchoring for Code Generation · ICML 2025