Improving Code Translation with Syntax-Guided and Semantic-aware Preference Optimization
Summary
A new method called CTO (Code Translation Optimization) has been developed to enhance large language models' (LLMs) ability to translate code while maintaining both syntactic correctness and semantic consistency. Existing preference-based learning approaches for code translation are often limited by unreliable semantic rewards, which typically come from sparse test cases or overly restrictive reference translations. CTO addresses this by deriving a robust semantic reward directly from the source code. It employs contrastive learning to train a cross-lingual semantic model that directly evaluates the functional equivalence between the original source code and its translated version. This semantic signal is then integrated with compiler-based syntactic feedback within a direct preference optimization framework, treating code translation as a multi-objective optimization problem. Experiments across C++, Java, and Python translations show that CTO significantly surpasses current baselines and other preference optimization strategies.
Key takeaway
For research scientists developing code translation LLMs, CTO's approach of integrating source-derived semantic rewards with compiler feedback offers a robust path to improve both syntactic correctness and functional equivalence. You should consider adopting a multi-objective optimization framework that unifies these signals to achieve superior translation performance across diverse programming languages.
Key insights
CTO improves code translation by unifying syntax-guided and semantic-aware preference optimization.
Principles
- Semantic rewards must derive from source code.
- Functional equivalence is key for code translation.
Method
CTO trains a cross-lingual semantic model via contrastive learning to assess functional equivalence, then unifies this semantic signal with compiler-based syntactic feedback within a direct preference optimization framework.
In practice
- Use contrastive learning for cross-lingual semantic models.
- Integrate compiler feedback for syntactic correctness.
Topics
- Code Translation
- Large Language Models
- Preference Optimization
- Cross-lingual Semantic Model
- Contrastive Learning
Best for: Research Scientist, AI Scientist, Machine Learning Engineer, NLP Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Artificial Intelligence.