使用大型语言模型进行人类对齐的代码可读性评估
Human-Aligned Code Readability Assessment with Large Language Models
AI总结:
本文提出 CoReEval 大规模基准,系统评估 10 个 LLM 在多语言、多提示和解码设置下的代码可读性判断,揭示开发者引导提示可提升人类对齐与解释质量。
摘要:
代码可读性对软件理解和维护至关重要,但难以大规模评估。传统静态指标往往无法捕捉人类判断的主观性和情境敏感性。大型语言模型(LLM)提供了一种可扩展的替代方案,但其作为可读性评估者的行为仍未得到充分研究。我们推出 CoReEval,这是首个用于评估基于 LLM 的代码可读性评估的大规模基准,包含针对 10 个最先进 LLM 的超过 140 万次模型-代码片段-提示评估。该基准涵盖 3 种编程语言(Java、Python、CUDA)、2 种代码类型(功能代码和单元测试)、4 种提示策略(ZSL、FSL、CoT、ToT)、9 种解码设置,以及面向初级和高级角色定制的开发者引导提示。我们将 LLM 输出与人类标注和经过验证的静态模型进行比较,分析数值一致性(MAE、Pearson、Spearman)和理由质量(情感、方面覆盖、语义聚类)。研究结果表明,基于人类定义的可读性维度的开发者引导提示在结构化情境中提升了一致性,增强了解释质量,并能通过角色框架实现轻量级个性化。然而,分数变异性的增加凸显了一致性、稳定性和可解释性之间的权衡。CoReEval 为提示工程、模型对齐研究和人在回路评估提供了坚实基础,并可应用于教育、入职培训和 CI/CD 流水线,在这些场景中 LLM 可充当可解释、可适应的评审者。
英文摘要:
Code readability is crucial for software comprehension and maintenance, yet difficult to assess at scale. Traditional static metrics often fail to capture the subjective, context-sensitive nature of human judgments. Large Language Models (LLMs) offer a scalable alternative, but their behavior as readability evaluators remains underexplored. We introduce CoReEval, the first large-scale benchmark for evaluating LLM-based code readability assessment, comprising over 1.4 million model-snippet-prompt evaluations across 10 state of the art LLMs. The benchmark spans 3 programming languages (Java, Python, CUDA), 2 code types (functional code and unit tests), 4 prompting strategies (ZSL, FSL, CoT, ToT), 9 decoding settings, and developer-guided prompts tailored to junior and senior personas. We compare LLM outputs against human annotations and a validated static model, analyzing numerical alignment (MAE, Pearson's, Spearman's) and justification quality (sentiment, aspect coverage, semantic clustering). Our findings show that developer-guided prompting grounded in human-defined readability dimensions improves alignment in structured contexts, enhances explanation quality, and enables lightweight personalization through persona framing. However, increased score variability highlights trade-offs between alignment, stability, and interpretability. CoReEval provides a robust foundation for prompt engineering, model alignment studies, and human in the loop evaluation, with applications in education, onboarding, and CI/CD pipelines where LLMs can serve as explainable, adaptable reviewers.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。