arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2510.09400cs.SE
收藏

TIT:一种面向基于大语言模型的代码翻译的树结构指令微调方法

TIT: A Tree-Structured Instruction Tuning Approach for LLM-Based Code Translation

Dalian University of Technology(大连理工大学);Liaoning Normal University(辽宁师范大学)

He Jiang, Yufu Wang, Hao Lin, Peiyu Zou, Zhide Zhou, Ang Jia, Xiaochen Li, Zhilei Ren

AI总结:

提出TIT树结构指令微调方法,通过语法表示、数据增强和双阶段微调,解决LLM代码翻译中的语法混淆与语义错位,成功率提升1.22-1.75倍。

摘要:

大型语言模型(LLMs)通过在广泛代码语料库上的预训练,在自动化源到目标代码翻译方面展现了强大性能。然而,主流的基于LLM的代码翻译方法存在两个关键局限性。首先,它们对语言特定特征高度敏感,这常常将源语言的语法或词汇引入输出中,导致语法混淆。其次,由于过度依赖函数级并行数据集,它们缺乏细粒度的语义对齐,导致翻译代码与原始源代码之间出现语义错位。为克服这些局限性,我们提出了TIT,一种用于基于LLM的代码翻译的树结构指令微调范式。具体而言,TIT包含三个模块。首先,为缓解语法混淆,语法信息表示模块通过结构化解析整合了与语言无关的语法特征。然后,为生成高质量细粒度并行数据,细粒度并行数据集增强模块通过语句级分割和对比匹配将节点与代码段对齐。最后,我们利用双阶段树指令微调模块来减轻因引入语法信息而给LLM带来的上下文处理负担。第一阶段采用语法感知微调,使LLM能够自主理解结构化语法信息,而第二阶段利用代码生成微调,引导模型基于函数级语法依赖生成准确的目标代码。实验结果表明,所提出的方法在多个LLM上显著优于现有方法,在代码翻译中实现了1.22倍至1.75倍更高的成功率,同时显著减少了语法混淆。

英文摘要:

Large Language Models (LLMs) have shown strong performance in automated source-to-target code translation through pretraining on extensive code corpora. However, mainstream LLM-based code translation methods suffer from two critical limitations. First, they are highly sensitive to language-specific features, which often introduce source-language syntax or lexicon into the output, leading to syntactic confusion. Second, they lack fine-grained semantic alignment due to an over-reliance on function-level parallel datasets, resulting in semantic misalignment between the translated code and the original source. To overcome these limitations, we propose TIT, a Tree-structured Instruction Tuning paradigm for LLM-based code translation. Specifically, TIT consists of three modules. First, to mitigate syntactic confusion, the syntactic information representation module integrates language-agnostic syntactic features via structured parsing. Then, to generate high-quality fine-grained parallel data, the fine-grained parallel dataset augmentation module aligns nodes with code segments through statement-level segmentation and contrastive matching. Finally, we leverage the dual-stage tree instruction tuning module to alleviate the contextual processing burden on the LLM caused by the introduction of syntactic information. The first stage employs syntax-aware fine-tuning to enable the LLM to autonomously comprehend structured syntactic information, while the second stage utilizes code generation fine-tuning to guide the model in generating accurate target code based on function-level syntactic dependencies. The experimental results demonstrate that the proposed method significantly outperforms existing approaches in multiple LLMs, achieving a success rate 1.22x-1.75x higher in code translation while markedly reducing syntactic confusion.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑