Transpilation, or code translation, aims to convert source code from one programming language (PL) to another. It is beneficial for many downstream applications, from modernizing large legacy codebases to augmenting data for low-resource PLs. Recent large language model (LLM)-based approaches have demonstrated immense potential for code translation. Among these approaches, training-based methods are particularly important because LLMs currently do not effectively adapt to domain-specific settings that suffer from a lack of knowledge without targeted training. This limitation is evident in transpilation tasks involving low-resource PLs. However, existing training-based approaches rely on a pairwise transpilation paradigm, making it impractical to support a diverse range of PLs. This limitation is particularly prominent for low-resource PLs due to a scarcity of training data. Furthermore, these methods suffer from suboptimal reinforcement learning (RL) reward formulations. To address these limitations, we propose CodePivot, a training framework that leverages Python as an intermediate representation (IR), augmented by a novel RL reward mechanism, Aggressive-Partial-Functional reward, to bootstrap the model's multilingual transpilation ability without requiring parallel corpora. Experiments involving 10 PLs show that the resulting 7B model, trained on Python-to-Others tasks, consistently improves performance across both general and low-resource PL-related transpilation tasks. It outperforms substantially larger mainstream models with hundreds of billions more parameters, such as Deepseek-R1 and Qwen3-235B-A22B-Instruct-2507, on Python-to-Others tasks and Others-to-All tasks, respectively. In addition, it outperforms its counterpart trained directly on Any-to-Any tasks on general transpilation tasks. The code and data are available at https://github.com/lishangyu-hkust/CodePivot.


翻译:代码翻译旨在将源代码从一种编程语言转换为另一种编程语言。它在多种下游应用中具有重要价值,从现代化大型遗留代码库到为资源匮乏的编程语言扩充数据。近期基于大语言模型的方法在代码翻译中展现出巨大潜力。在这些方法中,基于训练的方法尤为重要,因为大语言模型目前无法有效适应缺乏针对训练知识的领域特定设置——这一局限性在涉及低资源编程语言的翻译任务中尤为明显。然而,现有基于训练的方法依赖成对翻译范式,难以支持多样的编程语言。这种局限性在低资源编程语言中尤为突出,原因是缺乏训练数据。此外,这些方法还存在强化学习奖励公式设计欠佳的问题。为克服这些局限,我们提出CodePivot——一种以Python为中间表示的训练框架,并通过新型强化学习奖励机制(激进-部分-功能奖励)增强,使其能在无需平行语料的情况下引导模型的多语言翻译能力。涉及10种编程语言的实验表明,在Python到其他语言任务上训练得到的7B模型,在通用和低资源编程语言相关的翻译任务中均实现了一致性的性能提升。该模型在Python到其他语言任务及其他语言到所有语言任务上,分别超越了参数规模达数千亿的主流大模型,例如Deepseek-R1和Qwen3-235B-A22B-Instruct-2507。此外,在通用翻译任务上,其性能也优于直接进行任意语言间训练的同级模型。代码与数据已开源:https://github.com/lishangyu-hkust/CodePivot。

0
下载
关闭预览

相关内容

人们为了让计算机解决各种棘手的问题,使用编程语言 编写程序代码并通过计算机运算得到最终结果的过程。
通过强化学习增强代码生成中的代码大语言模型:综述
专知会员服务
29+阅读 · 2025年1月1日
《大型语言模型代码生成》综述
专知会员服务
70+阅读 · 2024年6月4日
《深度学习代码智能》综述、基准和工具集
专知会员服务
56+阅读 · 2024年1月2日
RecInterpreter:架起大语言模型与传统推荐模型的桥梁
专知会员服务
54+阅读 · 2023年11月9日
【翻译技术速递】入门教程:Trados 翻译记忆库工具
翻译技术沙龙
38+阅读 · 2019年11月28日
《机器翻译与译后编辑教学指南》于WITTA年会正式发布
翻译技术沙龙
32+阅读 · 2019年6月17日
【干货】深入理解自编码器(附代码实现)
清华大学:刘洋——基于深度学习的机器翻译
人工智能学家
12+阅读 · 2017年11月13日
神经网络机器翻译原理:LSTM、seq2seq到Zero-Shot
北京思腾合力科技有限公司
11+阅读 · 2017年8月10日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
认知战与交战性质的改变:神经战略视角
专知会员服务
5+阅读 · 5月8日
人工智能如何变革军事C5ISR作战
专知会员服务
12+阅读 · 5月8日
相关基金
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员