Generation Probabilities Are Not Enough: Uncertainty Highlighting in AI Code Completions

Helena Vasconcelos, Gagan Bansal, Adam Fourney, Q. Vera Liao, Jennifer Wortman VaughanarXiv 2023 · DOI

TL;DR

Current AI code assistants often highlight "uncertain" code based on how likely the model was to generate it, but a new study reveals this approach doesn't actually help developers. Instead, highlighting code based on an "edit model"—which predicts what a human is likely to change—significantly speeds up debugging and leads to more targeted fixes.

What Problem Does This Paper Address?

AI-powered code completion tools like GitHub Copilot and Amazon CodeWhisperer have revolutionized software development, but they are notorious for generating code that looks plausible but contains subtle bugs or security flaws. To prevent developers from blindly accepting these errors (a phenomenon known as automation bias), researchers have suggested highlighting "uncertain" parts of the generated code.

However, there is a fundamental disconnect in how we define "uncertainty." Most systems rely on generation probability—the statistical likelihood of a token being produced by the model. This paper tackles a critical question: Does showing generation probabilities actually help programmers find bugs, or should we be predicting what a human will actually need to edit?

Fig. 1. Overview of two approaches to uncertainty highlighting explored in our study: directly predicting the likelihood of an edit (top path), and using generation probabilities (bottom path). In this example, edit model-based highlighting points the programmer to the location of a necessary change (the list comprehension which erroneously has “1” in place of “-1”). The generation probability-based highlighting points the programmer to the function name, which, while being high variance, does not necessarily have any errors.

Methods

The authors conducted a mixed-methods, within-subjects user study with 30 professional programmers. They compared three user interface conditions:

  1. No Highlights: The baseline code completion alone.
  2. Generation Probability Highlighting: Highlighting tokens where the language model had low confidence during generation.
  3. Edit Model Highlighting: Highlighting tokens predicted to have a high likelihood of being modified or deleted by a human.

To build the edit model, the researchers first ran a data-collection phase with 9 separate programmers, tracking exactly which tokens they edited on the same tasks. They then set thresholds to ensure both highlighting methods flagged a comparable number of characters across the study.

Datasets

The evaluation utilized three "easy" standalone programming tasks sourced from LeetCode:

  • Ugly Number: A task where the AI generated correct overall logic but introduced numerous Python syntax errors.
  • Base 7: A task where the AI code was syntactically perfect but contained a minor conceptual error (appending an extra "0").
  • Most Common Word: A task with minimal syntax errors but a logical flaw involving an in-place dictionary modification.

The initial code completions were generated using OpenAI's code-davinci-002 (Codex) model.

Key Insights and Ideas

  • Low Probability $\neq$ Incorrect: Generation probability is a poor proxy for bugs. A language model might assign low probability to a token simply because there are many valid ways to write that line (e.g., choosing a variable name or initiating a loop structure), leading to harmless code being flagged as "uncertain."
  • Language Models Can Be Confidently Wrong: Conversely, models can generate logical bugs with extremely high confidence, meaning generation probability highlights will completely miss them.
  • Programmers Want Actionable Insights: Developers don't care about the model's internal statistical variances; they want the UI to point them directly to what needs fixing.
  • The "Sea of Color" Problem: Programmers strongly dislike cluttered UIs. They prefer subtle, granular shading (like multi-level opacity) over raw numerical percentages, and they want tooltips explaining why something is highlighted.

Key Results

The quantitative results strongly favored the edit-model approach over traditional generation probabilities:

  • Faster Completion Times: Participants in the Edit Model condition completed tasks significantly faster (averaging 8.59 minutes) compared to the Generation Probability condition (9.61 minutes) and the No Highlights baseline (9.27 minutes).
  • Reduced Effort: Developers added significantly fewer characters to fix the code in the Edit Model condition (92.2 characters) than in the baseline (148.9 characters), indicating more targeted editing.
  • Higher Engagement with Highlights: Tokens highlighted by the edit model had a survival rate of only 35.3% (meaning 64.7% were edited or deleted), compared to a 73.9% survival rate for tokens highlighted by generation probability. This proves developers actually found the edit-model highlights worth acting upon.
  • Subjective Preference: Participants rated the utility of the edit model significantly higher and found generation probability highlights to be distracting "noise."

Limitations and Future Work

While promising, the edit model used in this study was "closed-world," meaning it was trained specifically on the exact tasks the participants evaluated. To make this practical, future work must scale this to an "open-world" setting by training general-purpose edit models on large-scale telemetry data (such as user edit logs from commercial tools like Copilot).

Additionally, the authors note that highlighting cannot solve errors of omission—if the AI completely forgets to include a necessary edge case, a token-highlighting interface has nothing to flag. Exploring margin annotations or placeholder text for missing logic remains an open design challenge.

Summary updated

BibTeX
@misc{vasconcelos2023generation,
  author = {Helena Vasconcelos and Gagan Bansal and Adam Fourney and Q. Vera Liao and Jennifer Wortman Vaughan},
  title = {{Generation Probabilities Are Not Enough: Uncertainty Highlighting in AI Code Completions}},
  year = {2023},
  eprint = {2302.07248},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2302.07248},
}
Figure