Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

Function-to-Style Guidance of LLMs for Code Translation

About

Large language models (LLMs) have made significant strides in code translation tasks. However, ensuring both the correctness and readability of translated code remains a challenge, limiting their effective adoption in real-world software development. In this work, we propose F2STrans, a function-to-style guiding paradigm designed to progressively improve the performance of LLMs in code translation. Our approach comprises two key stages: (1) Functional learning, which optimizes translation correctness using high-quality source-target code pairs mined from online programming platforms, and (2) Style learning, which improves translation readability by incorporating both positive and negative style examples. Additionally, we introduce a novel code translation benchmark that includes up-to-date source code, extensive test cases, and manually annotated ground-truth translations, enabling comprehensive functional and stylistic evaluations. Experiments on both our new benchmark and existing datasets demonstrate that our approach significantly improves code translation performance. Notably, our approach enables Qwen-1.5B to outperform prompt-enhanced Qwen-32B and GPT-4 on average across 20 diverse code translation scenarios.

Longhui Zhang, Bin Wang, Jiahao Wang, Xiaofeng Zhao, Min Zhang, Hao Yang, Meishan Zhang, Yu Li, Jing Li, Jun Yu, Min Zhang• 2025

Related benchmarks

TaskDatasetResultRank
Code TranslationCodeNet
Computational Accuracy (C)91
11
Code TranslationF2SBench
Computational Accuracy (C)85.6
11
Code TranslationSWIFTBENCH
Accuracy (C)87.8
11
Code TranslationSWIFTBENCH C-to-Python
Functional Correctness (%)84.6
6
Class-level Code TranslationClassEval-T
Functional Correctness21.6
4
Code TranslationSWIFTBENCH
Memory Usage (MB)29.1
4
Repository-level Code TranslationAlphaTrans
Functional Correctness16.6
4
Repository-level Code TranslationRepoTrans
Functional Correctness0.00e+0
4
Showing 8 of 8 rows

Other info

Follow for update