Do Large Language Models Pay Similar Attention Like Human Programmers When Generating Code?
Bonan Kou, Shengmai Chen, Zhijie Wang, Lei Ma, Tianyi Zhang
Abstract
Large Language Models (LLMs) have recently been widely used for code generation. Due to the complexity and opacity of LLMs, little is known about how these models generate code. We made the first attempt to bridge this knowledge gap by investigating whether LLMs attend to the same parts of a task description as human programmers during code generation. An analysis of six LLMs, including GPT-4, on two popular code generation benchmarks revealed a consistent misalignment between LLMs’ and programmers’ attention. We manually analyzed 211 incorrect code snippets and found five attention patterns that can be used to explain many code generation errors. Finally, a user study showed that model attention computed by a perturbation-based method is often favored by human programmers. Our findings highlight the need for human-aligned LLMs for better interpretability and programmer trust.
Ask about this paper
Your agent reads all of it.
Lune indexed this paper to the last equation, along with the top-tier papers that cite it. Ask a question and the answer quotes them.
Your agent calls
Luneget_paper_fulltext
Free to start. No credit card required.
Terminal
Install the CLIlune papers fulltext 5983443f-15cf-4ba5-a360-882affdac533Cited by top-tier papers6
- PromptCharm: Text-to-Image Generation through Multi-modal Prompting and RefinementZhijie Wang, Yuheng Huang, Da Song, Lei Ma et al.CHI 2024 · 111 citations
- Towards Understanding the Characteristics of Code Generation Errors Made by Large Language ModelsZhijie Wang, Zijie Zhou, Da Song, Yuheng Huang et al.ICSE 2025 · 12 citations
- Enhancing Code Generation via Bidirectional Comment-Level Mutual GroundingYifeng Di, Tianyi ZhangICSE 2025 · 3 citations
- Write Your Own Code Checker: An Automated Test-Driven Checker Development Approach with LLMsJun Liu, Yuanyuan Xie, Jiwei Yan, Jinhao Huang et al.ICSE 2026
- Code-MUE: Measuring Code LLMs’ Uncertainty through Execution-Based Semantic Interaction GraphsXiaoning Ren, Yinxing Xue, Lei Ma, Yuheng HuangISSTA 2026
Builds on28
- GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
- Aligning AI With Shared Human ValuesDan Hendrycks, Collin Burns, Steven Basart, Andrew Critch et al.ICLR 2021 · 878 citations
- Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code ContributionsHammond Pearce, Baleegh Ahmad, Benjamin Tan, Brendan Dolan-Gavitt et al.S&P 2022 · 725 citations
- Grounded Copilot: How Programmers Interact with Code-Generating ModelsShraddha Barke, Michael B. James, Nadia PolikarpovaOOPSLA 2023 · 408 citations
Related papers
- Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language ModelsYanlin Wang, Tianyue Jiang, Mingwei Liu, Jiachi Chen et al.FSE 2025 · 6 citations
- Selective Prompt Anchoring for Code GenerationYuan Tian, Tianyi ZhangICML 2025
- Personality-Guided Code Generation Using Large Language ModelsYaoqi Guo, Zhenpeng Chen, Jie M. Zhang, Yang Liu et al.ACL 2025
- Impeding LLM-assisted Cheating in Introductory Programming Assignments via Adversarial PerturbationSaiful Islam Salim, Rubin Yuchan Yang, Alexander Cooper, Suryashree Ray et al.EMNLP 2024 · 4 citations
- Oracle-Guided Program Selection from Large Language ModelsZhiyu Fan, Haifeng Ruan, Sergey Mechtaev, Abhik RoychoudhuryISSTA 2024 · 4 citations
