Skip to main content
QUICK REVIEW

[Paper Review] Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanations

David N. Palacio, Daniel Rodríguez-Cárdenas|arXiv (Cornell University)|Jul 12, 2024
Access Control and TrustSocial Sciences3 citations
TL;DR

This paper introduces AST rust, a method that enhances trustworthiness and interpretability of LLMs for code by grounding model confidence scores in syntactic structures from Abstract Syntax Trees (ASTs). By mapping confidence to terminal and non-terminal AST nodes, AST rust enables fine-grained, human-understandable explanations of model predictions, demonstrating a causal link between syntax categories and model performance across 12 LLMs.

ABSTRACT

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.

Motivation & Objective

  • To address the lack of fine-grained, interpretable explanations for LLM predictions in code generation tasks.
  • To improve model trustworthiness by linking model confidence to familiar programming language constructs via AST structures.
  • To develop a visualization framework that maps model confidence scores to syntactic categories in ASTs for both local and global analysis.
  • To empirically validate AST rust’s effectiveness through quantitative analysis and human evaluation on 12 LLMs.
  • To demonstrate that syntax categories causally influence cross-entropy loss, revealing deeper insights into LLM behavior across different models and datasets.

Proposed method

  • AST rust extracts model confidence scores from LLM outputs and maps them to syntactic categories derived from Abstract Syntax Trees (ASTs).
  • It segments tokens into terminal and non-terminal AST nodes, assigning confidence scores to these well-known programming language constructs.
  • The method aggregates confidence scores across syntax categories and visualizes them using sequence, heat-map, and graph-based representations.
  • A structural causal model is employed to assess the causal relationship between syntax categories and cross-entropy loss, controlling for code confounders.
  • Bootstrapping and placebo refutations are used to ensure statistical robustness in causal inference.
  • The approach is evaluated on a curated dataset of GitHub repositories and validated through a human study with practitioners.

Experimental results

Research questions

  • RQ1To what extent can model confidence be meaningfully grounded in syntactic structures of code to improve interpretability?
  • RQ2How do different syntax categories in ASTs influence the cross-entropy loss of LLMs across diverse models and datasets?
  • RQ3Can AST rust’s visualizations help practitioners understand the trustworthiness and error patterns of LLM-generated code?
  • RQ4Is there a causal relationship between specific AST syntax categories and model prediction confidence after controlling for code-level confounders?
  • RQ5How usable and informative are AST rust’s visualizations in real-world code completion tasks?

Key findings

  • AST rust reveals a significant causal influence of AST syntax categories on cross-entropy loss, even after controlling for code confounders, indicating that model errors are systematically linked to specific syntactic structures.
  • The method successfully segments model confidence into interpretable syntax categories, enabling practitioners to understand which code constructs trigger higher uncertainty or errors.
  • A human study confirmed that participants found AST rust’s visualizations useful for diagnosing model behavior and identifying error-prone code patterns in code-completion tasks.
  • The approach uncovers that model performance varies meaningfully across syntax categories, with certain constructs (e.g., function definitions, conditionals) consistently showing higher loss, suggesting structural biases in LLMs.
  • Aggregated metrics like accuracy obscure these patterns, but AST rust exposes them, advocating for granular reporting in AI4SE evaluation.
  • The open-source release of datasets, code, and statistical analysis supports reproducibility and future adoption in industry and research.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.