[论文解读] Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanations
本文提出 AST rust,一种通过将模型置信度分数基于抽象语法树(AST)中的语法结构来增强大语言模型(LLM)在代码生成任务中可信度与可解释性的方法。通过将置信度映射到终端和非终端 AST 节点,AST rust 实现了细粒度、人类可理解的模型预测解释,展示了语法类别与模型性能之间的因果关系,涵盖 12 种 LLM。
Trustworthiness and interpretability are inextricably linked concepts for LLMs. The more interpretable an LLM is, the more trustworthy it becomes. However, current techniques for interpreting LLMs when applied to code-related tasks largely focus on accuracy measurements, measures of how models react to change, or individual task performance instead of the fine-grained explanations needed at prediction time for greater interpretability, and hence trust. To improve upon this status quo, this paper introduces ASTrust, an interpretability method for LLMs of code that generates explanations grounded in the relationship between model confidence and syntactic structures of programming languages. ASTrust explains generated code in the context of syntax categories based on Abstract Syntax Trees and aids practitioners in understanding model predictions at both local (individual code snippets) and global (larger datasets of code) levels. By distributing and assigning model confidence scores to well-known syntactic structures that exist within ASTs, our approach moves beyond prior techniques that perform token-level confidence mapping by offering a view of model confidence that directly aligns with programming language concepts with which developers are familiar. To put ASTrust into practice, we developed an automated visualization that illustrates the aggregated model confidence scores superimposed on sequence, heat-map, and graph-based visuals of syntactic structures from ASTs. We examine both the practical benefit that ASTrust can provide through a data science study on 12 popular LLMs on a curated set of GitHub repos and the usefulness of ASTrust through a human study.
研究动机与目标
- 解决代码生成任务中 LLM 预测缺乏细粒度、可解释性解释的问题。
- 通过将模型置信度与 AST 结构中的熟悉编程语言构造关联,提升模型可信度。
- 开发一种可视化框架,将模型置信度分数映射到 AST 中的语法类别,以支持局部与全局分析。
- 通过在 12 种 LLM 上进行定量分析与人工评估,实证验证 AST rust 的有效性。
- 证明语法类别对交叉熵损失具有因果影响,揭示不同模型与数据集下 LLM 行为的深层洞察。
提出的方法
- AST rust 从 LLM 输出中提取模型置信度分数,并将其映射到源自抽象语法树(AST)的语法类别。
- 它将标记分割为终端与非终端 AST 节点,为这些熟悉的编程语言构造分配置信度分数。
- 该方法对语法类别聚合置信度分数,并使用序列、热力图与基于图的表示进行可视化。
- 采用结构因果模型评估语法类别与交叉熵损失之间的因果关系,同时控制代码混淆因素。
- 使用自助法与虚假反事实检验,确保因果推断的统计稳健性。
- 该方法在精选的 GitHub 代码库数据集上进行评估,并通过开发人员参与的人工研究进行验证。
实验结果
研究问题
- RQ1在多大程度上可将模型置信度有意义地建立在代码的语法结构之上,以提升可解释性?
- RQ2在不同模型与数据集上,AST 中的不同语法类别如何影响 LLM 的交叉熵损失?
- RQ3AST rust 的可视化是否有助于开发人员理解 LLM 生成代码的可信度与错误模式?
- RQ4在控制代码层面混淆因素后,特定 AST 语法类别与模型预测置信度之间是否存在因果关系?
- RQ5在真实世界的代码补全任务中,AST rust 的可视化在可用性与信息量方面表现如何?
主要发现
- AST rust 揭示了 AST 语法类别对交叉熵损失具有显著因果影响,即使在控制代码混淆因素后依然成立,表明模型错误系统性地与特定语法结构相关。
- 该方法成功地将模型置信度分割为可解释的语法类别,使开发人员能够理解哪些代码结构会引发更高不确定性或错误。
- 人工研究证实,参与者认为 AST rust 的可视化在诊断模型行为与识别代码补全任务中的易错代码模式方面非常有用。
- 该方法揭示了模型性能在不同语法类别间存在显著差异,某些结构(如函数定义、条件语句)持续表现出更高损失,表明 LLM 中存在结构性偏差。
- 聚合指标如准确率会掩盖这些模式,而 AST rust 则揭示了它们,倡导在 AI4SE 评估中采用更细粒度的报告方式。
- 数据集、代码与统计分析的开源发布支持可复现性,并推动其在工业界与学术界的未来应用。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。