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

· Source: Artificial Intelligence · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Software Development & Engineering · Depth: Expert, quick

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

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

Topics

Best for: Research Scientist, AI Scientist, Machine Learning Engineer, NLP Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Artificial Intelligence.