Table of Contents
Fetching ...

Automated Snippet-Alignment Data Augmentation for Code Translation

Zhiming Zhang, Qingfu Zhu, Xianzhen Luo, Yixuan Wang, Bohan Li, Wanxiang Che

TL;DR

This paper tackles the scarcity of effective data for code translation by introducing an automated pipeline to generate snippet-alignment (SA) data from program-alignment (PA) data using large language models. It couples SA augmentation with a simple two-stage training strategy that first leverages PA data and then SA data, achieving consistent improvements over PA-only baselines on standard benchmarks, with up to 3.78% gains in pass@1. The work demonstrates that SA data provides finer-grained training signals that complement PA data, and that a curriculum-like PA→SA training regime yields stronger alignment knowledge, particularly for X2J and X2C directions. Practically, the approach expands usable parallel data with high quality SA examples, enabling more robust code translation across languages and real-world scenarios.

Abstract

Code translation aims to translate the code from its source language to the target language and is used in various software development scenarios. Recent developments in Large Language Models (LLMs) have showcased their capabilities in code translation, and parallel corpora play a crucial role in training models for code translation. Parallel corpora can be categorized into program-alignment (PA) and snippet-alignment (SA) data. Although PA data has complete context and is suitable for semantic alignment learning, it may not provide adequate fine-grained training signals due to its extended length, while the brevity of SA data enables more fine-grained alignment learning. Due to limited parallel corpora, researchers explore several augmentation methods for code translation. Previous studies mainly focus on augmenting PA data. In this paper, we propose a data augmentation method that leverages LLMs to generate SA data automatically. To fully leverage both PA data and SA data, we explore a simple yet effective two-stage training strategy, which consistently enhances model performance compared to fine-tuning solely on PA data. Experiments on TransCoder-test demonstrate that our augmented SA data combined with the two-stage training approach yields consistent improvements over the baseline, achieving a maximum gain of 3.78% on pass@k.

Automated Snippet-Alignment Data Augmentation for Code Translation

TL;DR

This paper tackles the scarcity of effective data for code translation by introducing an automated pipeline to generate snippet-alignment (SA) data from program-alignment (PA) data using large language models. It couples SA augmentation with a simple two-stage training strategy that first leverages PA data and then SA data, achieving consistent improvements over PA-only baselines on standard benchmarks, with up to 3.78% gains in pass@1. The work demonstrates that SA data provides finer-grained training signals that complement PA data, and that a curriculum-like PA→SA training regime yields stronger alignment knowledge, particularly for X2J and X2C directions. Practically, the approach expands usable parallel data with high quality SA examples, enabling more robust code translation across languages and real-world scenarios.

Abstract

Code translation aims to translate the code from its source language to the target language and is used in various software development scenarios. Recent developments in Large Language Models (LLMs) have showcased their capabilities in code translation, and parallel corpora play a crucial role in training models for code translation. Parallel corpora can be categorized into program-alignment (PA) and snippet-alignment (SA) data. Although PA data has complete context and is suitable for semantic alignment learning, it may not provide adequate fine-grained training signals due to its extended length, while the brevity of SA data enables more fine-grained alignment learning. Due to limited parallel corpora, researchers explore several augmentation methods for code translation. Previous studies mainly focus on augmenting PA data. In this paper, we propose a data augmentation method that leverages LLMs to generate SA data automatically. To fully leverage both PA data and SA data, we explore a simple yet effective two-stage training strategy, which consistently enhances model performance compared to fine-tuning solely on PA data. Experiments on TransCoder-test demonstrate that our augmented SA data combined with the two-stage training approach yields consistent improvements over the baseline, achieving a maximum gain of 3.78% on pass@k.
Paper Structure (21 sections, 1 equation, 2 figures, 6 tables)

This paper contains 21 sections, 1 equation, 2 figures, 6 tables.

Figures (2)

  • Figure 1: An example of PA data and SA data. Although PA data is essential for learning semantic alignment due to its complete contextual information, it is usually lengthy. SA data, on the other hand, is brief and can provide more fine-grained training signals.
  • Figure 2: Overview of our data augmentation pipeline. It consists of two LLM-involved stages and a post-processing stage. In Stage 1 (the left part), the LLM takes the source program as input and outputs it with comments inserted. In Stage 2 (the middle part), the LLM takes the output of Stage 1 and the original target program as input, then rewrites the target program to preserve the same content and order of comments in the source program. In Stage 3 (the right part), we can split and match the code snippets according to the comments.