Lune

FSE2024Top-tier venue

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 Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

6 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models cites Grounded Copilot: How Programmers Interact with Code-Generating Models
  • Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • Grounded Copilot: How Programmers Interact with Code-Generating Models cites Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions
  • Enhancing Code Generation via Bidirectional Comment-Level Mutual Grounding cites Grounded Copilot: How Programmers Interact with Code-Generating Models
  • Code-MUE: Measuring Code LLMs’ Uncertainty through Execution-Based Semantic Interaction Graphs cites Towards Understanding the Characteristics of Code Generation Errors Made by Large Language Models
  • PromptCharm: Text-to-Image Generation through Multi-modal Prompting and Refinement cites Grounded Copilot: How Programmers Interact with Code-Generating Models
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers6

  1. PromptCharm: Text-to-Image Generation through Multi-modal Prompting and RefinementZhijie Wang, Yuheng Huang, Da Song, Lei Ma et al.CHI 2024 · 111 citations
  2. 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
  3. Enhancing Code Generation via Bidirectional Comment-Level Mutual GroundingYifeng Di, Tianyi ZhangICSE 2025 · 3 citations
  4. 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
  5. Code-MUE: Measuring Code LLMs’ Uncertainty through Execution-Based Semantic Interaction GraphsXiaoning Ren, Yinxing Xue, Lei Ma, Yuheng HuangISSTA 2026

Builds on29

  1. GraphCodeBERT: Pre-training Code Representations with Data FlowDaya Guo, Shuo Ren, Shuai Lu, Zhangyin Feng et al.ICLR 2021 · 1,644 citations
  2. 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
  3. Aligning AI With Shared Human ValuesDan Hendrycks, Collin Burns, Steven Basart, Andrew Critch et al.ICLR 2021 · 878 citations
  4. 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
  5. Grounded Copilot: How Programmers Interact with Code-Generating ModelsShraddha Barke, Michael B. James, Nadia PolikarpovaOOPSLA 2023 · 408 citations

Related papers

  1. Beyond Functional Correctness: Investigating Coding Style Inconsistencies in Large Language ModelsYanlin Wang, Tianyue Jiang, Mingwei Liu, Jiachi Chen et al.FSE 2025 · 6 citations
  2. Selective Prompt Anchoring for Code GenerationYuan Tian, Tianyi ZhangICML 2025
  3. Personality-Guided Code Generation Using Large Language ModelsYaoqi Guo, Zhenpeng Chen, Jie M. Zhang, Yang Liu et al.ACL 2025
  4. 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
  5. Oracle-Guided Program Selection from Large Language ModelsZhiyu Fan, Haifeng Ruan, Sergey Mechtaev, Abhik RoychoudhuryISSTA 2024 · 4 citations
Dusk over the sea between two cliffs drawn in fine vertical lines