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

Fuente: arXiv
Saved in:
Bibliographic Details
Main Authors: Wu, Yuhan, Zhang, Huan, Cheng, Wei, Shen, Chen, Yang, Jingyue, Hu, Wei
Format: Preprint
Published: 2026
Subjects:
Online Access:
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866910215725645824
author Wu, Yuhan
Zhang, Huan
Cheng, Wei
Shen, Chen
Yang, Jingyue
Hu, Wei
author_facet Wu, Yuhan
Zhang, Huan
Cheng, Wei
Shen, Chen
Yang, Jingyue
Hu, Wei
contents 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.
format Preprint
id arxiv_https___arxiv_org_abs_2605_13229
institution arXiv
publishDate 2026
record_format arxiv
spellingShingle Improving Code Translation with Syntax-Guided and Semantic-aware Preference Optimization
Wu, Yuhan
Zhang, Huan
Cheng, Wei
Shen, Chen
Yang, Jingyue
Hu, Wei
Artificial Intelligence
Software Engineering
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.
title Improving Code Translation with Syntax-Guided and Semantic-aware Preference Optimization
topic Artificial Intelligence
Software Engineering
url https://arxiv.org/abs/2605.13229