一句话:提出首个自动定位神经代码翻译后语义错误的方法,实现 Python 到 JavaScript 的 TransMap 工具。
神经代码翻译可减少学习新语言或迁移代码的人工成本,Codex 等模型在翻译任务上表现有效,但生成代码常含语义错误。由于神经翻译器是黑盒,难以解释和控制,这些错误难以从翻译器本身消除。本文提出首个自动定位神经代码翻译后语义错误的方法,并实现原型工具 TransMap,用于 Python 到 JavaScript 翻译。它旨在指出需要修复的正确位置,通常仅高亮 1–2 行供用户检查。在包含 648 个语义错误的 Python 微基准上,TransMap 对 87.96% 的错误准确定位修复位置;作者还翻译了 5 个最多 1k 行的 Python 库,初步用户研究显示,相比使用带调试器的标准 IDE,修复语义错误的时间减少约 70%。
Automated code translation between programming languages can greatly reduce the human effort needed in learning new languages or in migrating code. Recent neural machine translation models, such as Codex, have been shown to be effective on many code generation tasks including translation. However, code produced by neural translators often has semantic mistakes. These mistakes are difficult to eliminate from the neural translator itself because the translator is a black box, which is difficult to interpret or control compared to rule-based transpilers. We propose the first automated approach to pinpoint semantic mistakes in code obtained after neural code translation. Our techniques are implemented in a prototype tool called TransMap which translates Python to JavaScript, both of which are popular scripting languages. On our created micro-benchmarks of Python programs with 648 semantic mistakes in total, TransMap accurately pinpoints the correct location for a fix for 87.96%, often highlighting 1-2 lines for the user to inspect per mistake. We report on our experience in translating 5 Python libraries with up to 1k lines of code with TransMap. Our preliminary user study suggests that TransMap can reduce the time for fixing semantic mistakes by around 70% compared to using a standard IDE with debuggers.