Do Large Language Models Pay Similar Attention Like Human Programmers When Generating Code?
Bonan Kou, Shengmai Chen, Zhijie Wang, Lei Ma, Tianyi Zhang
摘要
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.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 6 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models 引用了 Grounded Copilot: How Programmers Interact with Code-Generating Models
- Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models 引用了 Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
- Grounded Copilot: How Programmers Interact with Code-Generating Models 引用了 Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
- Enhancing Code Generation via Bidirectional Comment-Level Mutual Grounding 引用了 Grounded Copilot: How Programmers Interact with Code-Generating Models
- Code-MUE: Measuring Code LLMs’ Uncertainty through Execution-Based Semantic Interaction Graphs 引用了 Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models
- PromptCharm: Text-to-Image Generation through Multi-modal Prompting and Refinement 引用了 Grounded Copilot: How Programmers Interact with Code-Generating Models
引用它的顶会 Paper6
- PromptCharm: Text-to-Image Generation through Multi-modal Prompting and RefinementZhijie Wang, Yuheng Huang, Da Song, Lei Ma 等CHI 2024 · 111 次引用
- Towards Understanding the Characteristics of Code Generation Errors Made by Large Language ModelsZhijie Wang, Zijie Zhou, Da Song, Yuheng Huang 等ICSE 2025 · 12 次引用
- Enhancing Code Generation via Bidirectional Comment-Level Mutual GroundingYifeng Di, Tianyi ZhangICSE 2025 · 3 次引用
- Write Your Own Code Checker: An Automated Test-Driven Checker Development Approach with LLMsJun Liu, Yuanyuan Xie, Jiwei Yan, Jinhao Huang 等ICSE 2026
- Code-MUE: Measuring Code LLMs’ Uncertainty through Execution-Based Semantic Interaction GraphsXiaoning Ren, Yinxing Xue, Lei Ma, Yuheng HuangISSTA 2026
它引用的 Paper29
- GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng 等ICLR 2021 · 1,644 次引用
- 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 次引用
- Aligning AI With Shared Human ValuesDan Hendrycks, Collin Burns, Steven Basart, Andrew Critch 等ICLR 2021 · 878 次引用
- Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code ContributionsHammond Pearce, Baleegh Ahmad, Benjamin Tan, Brendan Dolan-Gavitt 等S&P 2022 · 725 次引用
- Grounded Copilot: How Programmers Interact with Code-Generating ModelsShraddha Barke, Michael B. James, Nadia PolikarpovaOOPSLA 2023 · 408 次引用
相关 Paper
- Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language ModelsYanlin Wang, Tianyue Jiang, Mingwei Liu, Jiachi Chen 等FSE 2025 · 6 次引用
- 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 等ACL 2025
- Impeding LLM-assisted Cheating in Introductory Programming Assignments via Adversarial PerturbationSaiful Islam Salim, Rubin Yuchan Yang, Alexander Cooper, Suryashree Ray 等EMNLP 2024 · 4 次引用
- Oracle-Guided Program Selection from Large Language ModelsZhiyu Fan, Haifeng Ruan, Sergey Mechtaev, Abhik RoychoudhuryISSTA 2024 · 4 次引用
