Abstract
Traditional metrics for evaluating program translation, such as BLEU and Computational Accuracy (CA), often fail to provide granular insights into why transcompiler models fail. This paper introduces Syntactic Unit Tests (SUT), a diagnostic framework designed to probe the syntactic competence of Large Language Models (LLMs) in code translation. By utilizing a disentangled testing approach and a novel scoring metric (SETS), we identify specific syntactic elements that trigger model failures. Furthermore, we propose S-Tuning, a diagnostic-driven fine-tuning method that leverages logically equivalent code modifications to bridge syntactic gaps. Our results demonstrate that SUT provides a more precise evaluation of model defects, and S-Tuning significantly improves translation performance across both syntactic and general benchmarks.
Introduction
Program translation, or transcompilation, is the process of converting source code from one programming language to another while preserving functional equivalence. While modern Large Language Models (LLMs) have demonstrated impressive capabilities in this domain, they frequently struggle with "elementary" syntax—basic language-specific constructs that are fundamental to correct execution.
The primary challenge in improving these models lies in evaluation. Current metrics like BLEU or CodeBLEU focus on textual similarity, which does not necessarily correlate with code correctness. Conversely, Computational Accuracy (CA) measures whether code executes correctly but fails to pinpoint the specific cause of failure within a complex function. To address this, we propose Syntactic Unit Tests (SUT), a framework that treats transcompilers as systems requiring diagnostic probing at the microscopic level.
The SUT Framework
The SUT framework consists of three integrated components designed to diagnose and rectify syntactic defects in transcompilers.
1. Syntactic Unit Tests (SUT)
Unlike competitive programming benchmarks that involve complex algorithmic logic, SUT utilizes "disentangled" test samples. Each sample is designed to isolate a specific basic syntax element, such as a switch statement, a do-while loop, or specific pointer operations. This isolation ensures that a failure in the test can be directly attributed to a misunderstanding of that specific syntactic unit.
2. Syntax Element Test Score (SETS)
Because real-world code often contains overlapping syntax elements, the authors employ Lasso regression to statistically disentangle the results. This method allows for the calculation of the Syntax Element Test Score (SETS), which represents the failure rate for individual syntax elements even when they appear concurrently in test cases. This provides a high-resolution map of a model's syntactic "blind spots."
3. S-Tuning (Syntax Fine-Tuning)
To move from diagnosis to repair, we introduce S-Tuning. This method identifies source code snippets containing syntax elements where the model is known to struggle. These snippets are then rewritten into "logically equivalent" versions using simpler syntax more common in the target language. By fine-tuning the model on these pairs, we teach the model to bridge the gap between complex source-language constructs and their functional equivalents in the target language.
Experimental Setup and Datasets
The research utilizes a diverse set of resources to validate the framework:
- SUT Dataset: A manually curated dataset covering C++, Java, Python, and C#, focusing on the core instruction sets of each language.
- TransCoder GeeksforGeeks: Used as a standard benchmark for cross-model comparison.
- IBM Project CodeNet: A large-scale repository of diverse code implementations used as the primary source for S-Tuning data augmentation.
- Baseline Benchmarks: Comparisons were also drawn against CodeXGLUE and XLCoST to contextualize SUT's diagnostic power.
Key Insights and Results
Our analysis reveals that even state-of-the-art models like gpt-3.5-turbo act as "macroscopic" learners. They are adept at capturing the general structure of a function but frequently fail at the microscopic level—specifically regarding language-specific conventions and reserved keywords.
Performance Benchmarks
On the SUT benchmark, gpt-3.5-turbo achieved a pass rate of 66.41%. While this outperformed other models, it indicates that even leading LLMs fail approximately one-third of the time on basic syntactic units.
Impact of S-Tuning
Applying S-Tuning to the TransCoder-ST model yielded significant improvements:
- SUT Accuracy: Increased by 18.4%.
- General Computational Accuracy: Improved by 2.1%.
These results suggest that targeting specific syntactic defects not only fixes those individual errors but also enhances the model's overall ability to generate executable code. Furthermore, SUT scores were found to align more closely with human expert judgments of translation quality than traditional metrics like BLEU.
Limitations and Future Work
While SUT provides a powerful diagnostic tool, several challenges remain. The current framework covers four major languages, but expanding this to a wider array of languages requires significant manual effort. Additionally, certain complex features, such as C++ templates, remain difficult to address through the current S-Tuning approach due to their inherent flexibility and complexity. Future research will focus on automating the generation of unit tests and extending the framework to handle more advanced language-specific features.
Summary updated