ArXiv TLDR

Improving Code Translation with Syntax-Guided and Semantic-aware Preference Optimization

🐦 Tweet
2605.13229

Yuhan Wu, Huan Zhang, Wei Cheng, Chen Shen, Jingyue Yang + 1 more

cs.AIcs.SE

TLDR

CTO enhances LLM code translation using syntax-guided and semantic-aware preference optimization, outperforming baselines.

Key contributions

  • Proposes CTO, a novel framework for syntax-guided and semantic-aware preference optimization in code translation.
  • Develops a cross-lingual semantic model via contrastive learning to assess functional equivalence directly from source code.
  • Integrates robust semantic rewards with compiler-based syntactic feedback in a multi-objective direct preference optimization.
  • Achieves significant performance gains over existing baselines in C++, Java, and Python code translation.

Why it matters

This paper tackles the challenge of ensuring syntactic correctness and semantic consistency in LLM-based code translation. CTO introduces a novel preference optimization framework that provides more reliable evaluation and improvement of translated code. This is crucial for developing robust and trustworthy automated code translation tools.

Original Abstract

LLMs have shown immense potential for code translation, yet they often struggle to ensure both syntactic correctness and semantic consistency. While preference-based learning offers a promising alignment strategy, it is hindered by unreliable semantic rewards derived from sparse test cases or restrictive reference translations. We argue that a robust semantic reward for code translation must be derived directly from the source code. In this paper, we propose CTO to improve code translation with syntax-guided and semantic-aware preference optimization. Through contrastive learning, we train a cross-lingual semantic model to directly assess functional equivalence between source and translated code. By formulating code translation as a multi-objective optimization problem, this robust semantic signal is seamlessly unified with compiler-based syntactic feedback within the direct preference optimization framework. Extensive experiments on C++, Java, and Python translations demonstrate that CTO significantly outperforms existing baselines and alternative preference optimization strategies.

📬 Weekly AI Paper Digest

Get the top 10 AI/ML arXiv papers from the week — summarized, scored, and delivered to your inbox every Monday.