Large language models are becoming increasingly practical for translating code across programming languages, a process known as $transpiling$. Even though automated transpilation significantly boosts developer productivity, a key concern is whether the generated code is correct. Existing work initially used manually crafted test suites to test the translations of a small corpus of programs; these test suites were later automated. In contrast, we devise the first approach for automated, functional, property-based testing of code translation models. Our general, user-provided specifications about the transpiled code capture a range of properties, from purely syntactic to purely semantic ones. As shown by our experiments, this approach is very effective in detecting property violations in popular code translation models, and therefore, in evaluating model quality with respect to given properties. We also go a step further and explore the usage scenario where a user simply aims to obtain a correct translation of some code with respect to certain properties without necessarily being concerned about the overall quality of the model. To this purpose, we develop the first property-guided search procedure for code translation models, where a model is repeatedly queried with slightly different parameters to produce alternative and potentially more correct translations. Our results show that this search procedure helps to obtain significantly better code translations.
翻译:大型语言模型在跨编程语言代码翻译(即“转译”)中日益实用。尽管自动化转译显著提升了开发效率,但生成代码的正确性成为关键问题。现有研究最初使用人工构建的测试套件对少量程序进行翻译测试,后续实现了测试套件的自动化。相比之下,我们提出了首个面向代码翻译模型的自动化、功能性、基于属性的测试方法。用户提供的通用规范可捕获转译代码的各类属性,从纯句法属性到纯语义属性。实验表明,该方法能有效检测主流代码翻译模型中的属性违规行为,从而评估模型在特定属性上的质量。更进一步,我们探索了用户仅需针对某些属性获取正确翻译代码(无需关注模型整体质量)的使用场景。为此,我们开发了首个面向代码翻译模型的属性引导搜索程序,通过反复调用模型微调参数,生成替代性且可能更正确的翻译。结果表明,该搜索程序能显著提升代码翻译的正确性。