SpecTra: Enhancing the Code Translation Ability of Language Models by Generating Multi-Modal Specifications
<|reference_start|>SpecTra: Enhancing the Code Translation Ability of Language Models by Generating Multi-Modal Specifications: Large language models (LLMs) are increasingly being used for the task of automated code translation, which has important real-world applications. However, most existing approaches use only the source code of a program as an input to an LLM, and do not consider the different kinds of specifications that can be extracted from a program. In this paper, we propose SpecTra, a multi-stage approach that uses a novel self-consistency filter to first generate high-quality static specifications, test cases, and natural language descriptions from a given program, and then uses these along with the source code to improve the quality of LLM-generated translations. We evaluate SpecTra on three code translation tasks - C to Rust, C to Go, and JavaScript to TypeScript - and show that it can enhance the performance of six popular LLMs on these tasks by up to 10 percentage points and a relative improvement of 26\%. Our research suggests that generating high-quality specifications could be a promising and efficient way to improve the performance of LLMs for code translation. We make our code and data available, anonymized for review.<|reference_end|>
@article{nitin2024spectra:,
    title={SpecTra: Enhancing the Code Translation Ability of Language Models by
  Generating Multi-Modal Specifications},
    author={Vikram Nitin, Rahul Krishna, Baishakhi Ray},
    journal={arXiv preprint arXiv:2405.18574},
    year={2024},
    archivePrefix={arXiv},
    eprint={2405.18574},
    primaryClass={cs.SE}
}