{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/watchat-explaining-perplexing-programs-by","title":"WatChat: Explaining perplexing programs by debugging mental models","arxiv_id":"2403.05334","date":"2024-03-08","proceeding":null,"authors":["Kartik Chandra","Katherine M. Collins","Will Crichton","Tony Chen","Tzu-Mao Li","Adrian Weller","Rachit Nigam","Joshua Tenenbaum","Jonathan Ragan-Kelley"],"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.","url_abs":"https://arxiv.org/abs/2403.05334v2","url_pdf":"https://arxiv.org/pdf/2403.05334v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"watchat-explaining-perplexing-programs-by","repo_url":"https://github.com/kach/watchat","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":null}],"tasks":[{"task_slug":"language-modelling","task_name":"Language Modelling"},{"task_slug":"misconceptions","task_name":"Misconceptions"},{"task_slug":"program-synthesis","task_name":"Program Synthesis"},{"task_slug":null,"task_name":"counterfactual"}],"methods":[],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":null,"mcp":null,"developers":"https://syntology.ai/developers"},"arxiv_metadata":null,"syntology_extracted_results":null}