WatChat: Explaining perplexing programs by debugging mental models

Kartik Chandra,Katherine M. Collins,Will Crichton,Tony Chen,Tzu-Mao Li,Adrian Weller,Rachit Nigam,Joshua Tenenbaum,Jonathan Ragan-Kelley
2024-10-03
Abstract:Often, a good explanation for a program's unexpected behavior is a bug in the programmer's code. But sometimes, an even better explanation is a bug in the programmer's mental model of the language or API they are using. Instead of merely debugging our current code ("giving the programmer a fish"), what if our tools could directly debug our mental models ("teaching the programmer to fish")? In this paper, we apply recent ideas from computational cognitive science to offer a principled framework for doing exactly that. Given a "why?" question about a program, we automatically infer potential misconceptions about the language/API that might cause the user to be surprised by the program's behavior -- and then analyze those misconceptions to provide explanations of the program's behavior. Our key idea is to formally represent misconceptions as counterfactual (erroneous) semantics for the language/API, which can be inferred and debugged using program synthesis techniques. We demonstrate our framework, WatChat, by building systems for explanation in two domains: JavaScript type coercion, and the Git version control system. We evaluate WatChatJS and WatChatGit by comparing their outputs to experimentally-collected human-written explanations in these two domains: we show that WatChat's explanations exhibit key features of human-written explanation, unlike those of a state-of-the-art language model.
Programming Languages,Artificial Intelligence,Human-Computer Interaction
What problem does this paper attempt to address?
The problem that this paper attempts to solve is how to provide effective explanations of program behavior, especially when programmers have misunderstandings in their understanding of programming languages or APIs. Specifically, the paper proposes a framework named WatChat, which aims to explain unexpected program behavior by debugging users' mental models. WatChat can automatically infer potential misunderstandings in the mental models that may cause users to be surprised by program behavior, and analyze these misunderstandings to provide behavior explanations. The paper demonstrates the effectiveness of this framework by building systems in two areas, JavaScript type conversion and the Git version control system, and proves that the explanations provided by WatChat have similar key features to those written by humans, rather than just simple technical descriptions or error messages. This helps improve programmers' problem - solving abilities and reduce programming errors caused by misunderstandings.