SpecTra: Enhancing the Code Translation Ability of Language Models by Generating Multi-Modal Specifications (2405.18574v2)
Abstract: 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.
- Summarize and generate to back-translate: Unsupervised translation of programming languages. arXiv preprint arXiv:2205.11116, 2022.
- Codet: Code generation with generated tests. arXiv preprint arXiv:2207.10397, 2022.
- Formalizing natural language intent into program specifications via large language models. arXiv preprint arXiv:2310.01831, 2023.
- Stuart I Feldman. A fortran to c converter. In ACM SIGPLAN Fortran Forum, volume 9, pages 21–22. ACM New York, NY, USA, 1990.
- Galois. C2Rust, 08 2018. URL https://galois.com/blog/2018/08/c2rust/.
- Code structure–guided transformer for source code summarization. ACM Transactions on Software Engineering and Methodology, 32(1):1–32, 2023.
- M2ts: Multi-scale multi-modal approach based on transformer for source code summarization. In Proceedings of the 30th IEEE/ACM International Conference on Program Comprehension, pages 24–35, 2022.
- Source code summarization with structural relative position guided transformer. In 2022 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER), pages 13–24. IEEE, 2022.
- Google. Rust in the Android platform, 4 2021a. URL https://security.googleblog.com/2021/04/rust-in-android-platform.html.
- Google. Rust in the Linux kernel, 4 2021b. URL https://security.googleblog.com/2021/04/rust-in-linux-kernel.html.
- Competition-level code generation with alphacode. Science, 378(6624):1092–1097, 2022.
- Is your code generated by chatgpt really correct? rigorous evaluation of large language models for code generation. In A. Oh, T. Neumann, A. Globerson, K. Saenko, M. Hardt, and S. Levine, editors, Advances in Neural Information Processing Systems, volume 36, pages 21558–21572. Curran Associates, Inc., 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/file/43e9d647ccd3e4b7b5baab53f0368686-Paper-Conference.pdf.
- Christopher Mims. The invisible $1.52 trillion problem: Clunky old software. The Wall Street Journal, March 2024. URL https://www.wsj.com/tech/personal-tech/the-invisible-1-52-trillion-problem-clunky-old-software-f5cbba27.
- Beyond accuracy: Evaluating self-consistency of code large language models with identitychain. arXiv preprint arXiv:2310.14053, 2023.
- Lost in translation: A study of bugs introduced by large language models while translating code. In Proceedings of the IEEE/ACM 46th International Conference on Software Engineering, pages 1–13, 2024.
- Codenet: A large-scale ai for code dataset for learning a diversity of coding tasks. arXiv preprint arXiv:2105.12655, 2021.
- Unsupervised translation of programming languages. Advances in neural information processing systems, 33:20601–20611, 2020.
- Leveraging automated unit tests for unsupervised code translation. arXiv preprint arXiv:2110.06773, 2021.
- Ast-transformer: Encoding abstract syntax trees efficiently for code summarization. In 2021 36th IEEE/ACM International Conference on Automated Software Engineering (ASE), pages 1193–1195. IEEE, 2021.
- Code summarization with structure-induced transformer. In Chengqing Zong, Fei Xia, Wenjie Li, and Roberto Navigli, editors, Findings of the Association for Computational Linguistics: ACL-IJCNLP 2021, pages 1078–1090, Online, August 2021. Association for Computational Linguistics. doi: 10.18653/v1/2021.findings-acl.93. URL https://aclanthology.org/2021.findings-acl.93.
- Exploring and unleashing the power of large language models in automated code translation. arXiv preprint arXiv:2404.14646, 2024.
- Parsel: Algorithmic reasoning with language models by composing decompositions. Advances in Neural Information Processing Systems, 36:31466–31523, 2023.