Improving Code Translation with Syntax-Guided and Semantic-aware Preference Optimization
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.
Code (0)
등록된 구현이 없습니다.
Tasks
Contrastive LearningCode TranslationSimilar Papers 제목 키워드 기반
SASST: Leveraging Syntax-Aware Chunking and LLMs for Simultaneous Speech Translation
This work proposes a grammar-based chunking strategy that segments input streams into semantically complete units by parsing dependency relations (e.g., noun phrase boundaries, verb-object structures) and punctuation fea…
NL2LOGIC: AST-Guided Translation of Natural Language into First-Order Logic with Large Language Models
Automated reasoning is critical in domains such as law and governance, where verifying claims against facts in documents requires both accuracy and interpretability. Recent work adopts structured reasoning pipelines that…
Code GenerationSemantics-aware Attention Improves Neural Machine Translation
The integration of syntactic structure into Transformer machine translation has shown positive results, but to our knowledge, no work has attempted to do so with semantic structures. In this work we propose two novel par…
DecoderMachine TranslationTranslationSemantics-aware Attention Improves Neural Machine Translation
The integration of syntactic structures into Transformer machine translation has shown positive results, but to our knowledge, no work has attempted to do so with semantic structures. In this work we propose two novel pa…
DecoderMachine TranslationTranslationExploiting Semantics in Neural Machine Translation with Graph Convolutional Networks
Semantic representations have long been argued as potentially useful for enforcing meaning preservation and improving generalization performance of machine translation methods. In this work, we are the first to incorpora…
Machine TranslationSentenceTranslation