Counterfactual Explanations for Models of Code
Not on the map. Why?
Abstract (arXiv)
Machine learning (ML) models play an increasingly prevalent role in many software engineering tasks. However, because most models are now powered by opaque deep neural networks, it can be difficult for developers to understand why the model came to a certain conclusion and how to act upon the model's prediction. Motivated by this problem, this paper explores counterfactual explanations for models of source code. Such counterfactual explanations constitute minimal changes to the source code under which the model "changes its mind". We integrate counterfactual explanation generation to models of source code in a real-world setting. We describe considerations that impact both the ability to find realistic and plausible counterfactual explanations, as well as the usefulness of such explanation to the user of the model. In a series of experiments we investigate the efficacy of our approach on three different models, each based on a BERT-like architecture operating over source code.
Key facts. Cited by 25 papers in the map (data through 14 Oct 2026). Builds on 35 of its 49 references that are in the map. First posted on arXiv 10 Nov 2021.
Builds on
35 of 49 references.
References · 35
- 2017Attention Is All You Needcited by 60,361
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,399
- 2016"Why Should I Trust You?": Explaining the Predictions of Any Classifiercited by 5,070
- 2017Axiomatic Attribution for Deep Networkscited by 3,384
- 2017Towards A Rigorous Science of Interpretable Machine Learningcited by 1,416
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2017Explanation in Artificial Intelligence: Insights from the Social Sciencescited by 1,206
- 2019What Does BERT Look At? An Analysis of BERT's Attentioncited by 1,003
- 2019Attention is not Explanationcited by 929
- 2018code2vec: Learning Distributed Representations of Codecited by 250
- 2020Algorithmic Recourse: from Counterfactual Explanations to Interventionscited by 250
- 2019FACE: Feasible and Actionable Counterfactual Explanationscited by 233
23 more
- 2016Understanding Neural Networks through Representation Erasurecited by 224
- 2021Polyjuice: Generating Counterfactuals for Explaining, Evaluating, and Improving Modelscited by 222
- 2015Visualizing and Understanding Neural Models in NLPcited by 200
- 2017Visualizing Deep Neural Network Decisions: Prediction Difference Analysiscited by 166
- 2018Pathologies of Neural Models Make Interpretations Difficultcited by 140
- 2020A Transformer-based Approach for Source Code Summarizationcited by 133
- 2018Automated Vulnerability Detection in Source Code Using Deep Representation Learningcited by 114
- 2019Learning to Deceive with Attention-Based Explanationscited by 111
- 2020Explaining NLP Models via Minimal Contrastive Editing (MiCE)cited by 106
- 2019Attention in Natural Language Processingcited by 101
- 2020General Pitfalls of Model-Agnostic Interpretation Methods for Machine Learning Modelscited by 75
- 2020Generate Your Counterfactuals: Towards Controlled Counterfactual Generation for Textcited by 75
- 2019Attention Interpretability Across NLP Taskscited by 71
- 2018DeepBugs: A Learning Approach to Name-based Bug Detectioncited by 65
- 2019Adversarial Examples for Models of Codecited by 63
- 2017Interpretable & Explorable Approximations of Black Box Modelscited by 54
- 2020Semantic Robustness of Models of Source Codecited by 45
- 2019TypeWriter: Neural Type Prediction with Search-based Validationcited by 32
- 2021Understanding Neural Code Intelligence Through Program Simplificationcited by 22
- 2020Learning Autocompletion from Real-World Datasetscited by 20
- 2020Probing Model Signal-Awareness via Prediction-Preserving Input Minimizationcited by 14
- 2021Generative Counterfactuals for Neural Networks via Attribute-Informed Perturbationcited by 11
- 2017Navigate, Understand, Communicate: How Developers Locate Performance Bugscited by 2
Built on by
Citing papers per year: 2022: 2; 2023: 10; 2024: 7; 2025: 6.
25 papers.
Sort:
By area:
- 2024NExT: Teaching Large Language Models to Reason about Code Executioncited by 63
- 2023Stealthy Backdoor Attack for Code Modelscited by 49
- 2024Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicatescited by 14
- 2023Toward a Theory of Causation for Interpreting Neural Code Modelscited by 12
- 2024Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanationcited by 12
- 2024Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanationscited by 11
- 2023Towards Causal Deep Learning for Vulnerability Detectioncited by 9
- 2024PromptExp: Multi-granularity Prompt Explanation of Large Language Modelscited by 6
- 2025Neuron-Guided Interpretation of Code LLMs: Where, Why, and How?cited by 5
- 2023ExplainableFold: Understanding AlphaFold Prediction with Explainable AIcited by 4
- 2024A Critical Study of What Code-LLMs (Do Not) Learncited by 4
- 2023Study of Distractors in Neural Models of Codecited by 2
13 more
- 2023xASTNN: Improved Code Representations for Industrial Practicecited by 2
- 2023On a Foundation Model for Operating Systemscited by 2
- 2024A Systematic Literature Review on Explainability for Machine/Deep Learning-based Software Engineering Researchcited by 2
- 2025CodeSCM: Causal Analysis for Multi-Modal Code Generationcited by 2
- 2025Analyzing Latent Concepts in Code Language Modelscited by 2
- 2022Learning to Learn to Predict Performance Regressions in Production at Metacited by 1
- 2023COMET: Neural Cost Model Explanation Frameworkcited by 1
- 2023Redundancy and Concept Analysis for Code-trained Language Modelscited by 1
- 2023T-COL: Generating Counterfactual Explanations for General User Preferences on Variable Machine Learning Systemscited by 1
- 2025Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generationcited by 1
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactualscited by 1
- 2022A Retrospective on ICSE 2022cited by 0
- 2025Mapping the Trust Terrain: LLMs in Software Engineering -- Insights and Perspectivescited by 0
- 2025Neuron-Guided Interpretation of Code LLMs: Where, Why, and How?23 Dec 2025
- 2025Analyzing Latent Concepts in Code Language Models1 Oct 2025
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactuals20 May 2025
- 2025Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generation21 Mar 2025
- 2025Mapping the Trust Terrain: LLMs in Software Engineering -- Insights and Perspectives18 Mar 2025
- 2025CodeSCM: Causal Analysis for Multi-Modal Code Generation7 Feb 2025
- 2024PromptExp: Multi-granularity Prompt Explanation of Large Language Models16 Oct 2024
- 2024Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanations12 Jul 2024
- 2024A Critical Study of What Code-LLMs (Do Not) Learn17 Jun 2024
- 2024Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanation24 Apr 2024
- 2024NExT: Teaching Large Language Models to Reason about Code Execution23 Apr 2024
- 2024Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicates8 Feb 2024
13 more
- 2024A Systematic Literature Review on Explainability for Machine/Deep Learning-based Software Engineering Research26 Jan 2024
- 2023On a Foundation Model for Operating Systems13 Dec 2023
- 2023Towards Causal Deep Learning for Vulnerability Detection12 Oct 2023
- 2023T-COL: Generating Counterfactual Explanations for General User Preferences on Variable Machine Learning Systems28 Sep 2023
- 2023Redundancy and Concept Analysis for Code-trained Language Models1 May 2023
- 2023xASTNN: Improved Code Representations for Industrial Practice13 Mar 2023
- 2023Study of Distractors in Neural Models of Code3 Mar 2023
- 2023COMET: Neural Cost Model Explanation Framework14 Feb 2023
- 2023Toward a Theory of Causation for Interpreting Neural Code Models7 Feb 2023
- 2023ExplainableFold: Understanding AlphaFold Prediction with Explainable AI27 Jan 2023
- 2023Stealthy Backdoor Attack for Code Models6 Jan 2023
- 2022Learning to Learn to Predict Performance Regressions in Production at Meta8 Aug 2022
- 2022A Retrospective on ICSE 202226 Jul 2022
- 2023Stealthy Backdoor Attack for Code Modelscited by 49
- 2023Stealthy Backdoor Attack for Code Models6 Jan 2023
- 2024Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicatescited by 14
- 2023Toward a Theory of Causation for Interpreting Neural Code Modelscited by 12
- 2024Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanationcited by 12
- 2024Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanationscited by 11
- 2023Towards Causal Deep Learning for Vulnerability Detectioncited by 9
- 2024PromptExp: Multi-granularity Prompt Explanation of Large Language Modelscited by 6
- 2025Neuron-Guided Interpretation of Code LLMs: Where, Why, and How?cited by 5
- 2023ExplainableFold: Understanding AlphaFold Prediction with Explainable AIcited by 4
- 2024A Critical Study of What Code-LLMs (Do Not) Learncited by 4
- 2023Study of Distractors in Neural Models of Codecited by 2
- 2023xASTNN: Improved Code Representations for Industrial Practicecited by 2
- 2023On a Foundation Model for Operating Systemscited by 2
12 most cited of 23 All 23 (JSON)
- 2025Neuron-Guided Interpretation of Code LLMs: Where, Why, and How?23 Dec 2025
- 2025Analyzing Latent Concepts in Code Language Models1 Oct 2025
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactuals20 May 2025
- 2025Enabling Global, Human-Centered Explanations for LLMs:From Tokens to Interpretable Code and Test Generation21 Mar 2025
- 2025Mapping the Trust Terrain: LLMs in Software Engineering -- Insights and Perspectives18 Mar 2025
- 2025CodeSCM: Causal Analysis for Multi-Modal Code Generation7 Feb 2025
- 2024PromptExp: Multi-granularity Prompt Explanation of Large Language Models16 Oct 2024
- 2024Towards More Trustworthy and Interpretable LLMs for Code through Syntax-Grounded Explanations12 Jul 2024
- 2024A Critical Study of What Code-LLMs (Do Not) Learn17 Jun 2024
- 2024Graph Neural Networks for Vulnerability Detection: A Counterfactual Explanation24 Apr 2024
- 2024Do Large Code Models Understand Programming Concepts? Counterfactual Analysis for Code Predicates8 Feb 2024
- 2024A Systematic Literature Review on Explainability for Machine/Deep Learning-based Software Engineering Research26 Jan 2024
12 newest of 23 All 23 (JSON)