Can Perplexity Serve as a Cognitive Signal for Code Understandability?
Xiaokai Rong, Mohammadali Sefidi Esfahani, Aashish Yadavally, Rigby Peter, Tien N. Nguyen
Abstract
Recent work suggests that token-level perplexity from large language models can align with localized human confusion during code comprehension. This raises a natural question: can perplexity also serve as a snippet-level signal for code understandability? We conduct an empirical study of this question across multiple human-grounded datasets, including method-level understandability judgments, output-prediction tasks, and accepted understandability-improvement patches. Despite prior token-level evidence, we find that simple snippet-level aggregations of token perplexity, such as average, median, or peak perplexity, do not reliably correlate with human understandability. We then investigate why this happens. First, token perplexity is highly skewed and heavy-tailed across code structures; extreme spikes arise not only from semantically meaningful constructs, but also from identifiers, literals, types, separators, and tokenization artifacts. Second, human understandability labels often lack consensus, making whole-snippet difficulty a noisy target. Third, perplexity distributions and their alignment with human difficulty vary substantially across models and tokenizers. These findings explain why prior token-level perplexity--confusion alignment does not directly transfer to snippet-level understandability. Overall, our study positions perplexity as a promising but delicate cognitive signal: useful for localized code confusion, but requiring code-aware aggregation, consensus-aware evaluation, and model-sensitivity analysis before it can support reliable code-understandability measurement.
Create a lesson
Related papers
ProgramDistill: From Interactive Web Apps to Verifiable Reference-Guided SWE Tasks
Jeonghye Kim, Minseon Kim, Young Jin Kim et al.
Evaluating the Health of Open-Source Smart City Platforms
Rodrigo Bravo Simões, Fernando Brito e Abreu, Vasco Amaral
From Component Snapshots to Lifecycle Traces: Agent-Based Software Composition Analysis
Chaofan Li, Zhengduo Xue, Chengxiang Li et al.
A Study on the Impact of Natural Language Differences in Prompts on Automatic Code Generation Using LLMs
Haruka Tokumasu, Masanari Kondo, Alexander Serebrenik et al.
A Study of the Reliability of Agentic AI-Generated Programs
Ayesha Shafique, Barton P. MIller, Elisa R. Heymann
Relationally Guided Use Case Modeling with LLMs
Guangyu Wang, Bangqi Li, Ji Wu et al.