[论文解读] WatChat: Explaining perplexing programs by debugging mental models
WatChat 是一种通过诊断和纠正用户对语言语义的误解来解释 JavaScript 程序意外行为的系统。它使用逆向程序合成技术推断有缺陷的心理模型,并生成对比性、因果性和符合社会语境的解释——在解释诸如 `[] + []` 返回 "" 等意外行为方面表现出有效性。
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.
研究动机与目标
- 解决当前编程工具在解释非由代码错误引起、而是源于对语言语义理解有误的心理模型所导致的意外行为方面的空白。
- 设计一种系统,通过将用户的误解建模为反事实语义,生成类人、有帮助的解释。
- 创建一个支持解释生成与教学示例合成的框架,用于诊断误解。
- 将认知科学原则——对比性、选择性、因果性和社会语境——整合到编程的自动化解释系统中。
- 使编程环境能够作为协作性的认知伙伴,而非被动的调试器。
提出的方法
- 将用户的心理模型建模为 JavaScript 的反事实语义,表示对语言行为的错误解释。
- 应用逆向程序合成技术,推断可能导致程序意外行为的合理误解(即“误解解释器”)。
- 通过识别并修补这些反事实语义中的错误来生成解释,使其符合认知科学中对比性和选择性解释的原则。
- 使用 JavaScript 语义的形式化规范和符号执行引擎(Rosette),在毫秒内高效搜索 2^32 种潜在误解。
- 反转解释过程,以合成诊断性程序示例,用于测试和纠正学习者中的特定误解。
- 通过询问用户关于其预期结果(例如,“你是否期望得到一个空数组?”)来实现上下文敏感的解释生成,从而支持自适应、对话式的交互。

实验结果
研究问题
- RQ1编程工具如何解释非因代码错误引起的意外行为,而是通过诊断和纠正用户对语言语义的误解?
- RQ2哪些认知原则——如对比性、选择性和因果性——可以指导编程环境中类人化解释的生成?
- RQ3程序合成技术是否可以被反转,以推断并调试编程语言行为的有缺陷心理模型?
- RQ4此类系统在在多大程度上能够生成具有教学价值的诊断性示例,以针对特定误解?
- RQ5如何设计上下文敏感且社会适应性的解释系统,使其能根据用户预期和背景定制解释?
主要发现
- WatChat 通过识别和纠正关于类型强制转换和数组到字符串转换的误解,能够推断并解释诸如 `[] + []` 返回 "" 的令人惊讶的 JavaScript 行为。
- 该系统在不到一毫秒内高效搜索 2^32 种潜在心理模型,实现实时解释生成。
- WatChat 生成的解释具有对比性和选择性,聚焦于预期行为与实际行为之间的关键差异,例如数组字符串化过程中括号的缺失。
- 通过询问用户对输出的预期,系统成功建模了用户预期,从而实现自适应、对话式的心理模型调试。
- 该框架可被反转,以生成高精度的教学示例,用于诊断特定误解,如对数组连接或字符串转换的误解。
- WatChat 在解释质量上优于基线大语言模型(如 GPT-4),生成的解释具有对比性、因果性和社会适宜性,避免冗长或错误的逐步追踪。

阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。