Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code

Fuente: arXiv
Salvato in:
Dettagli Bibliografici
Autori principali: Pan, Rangeet, Ibrahimzada, Ali Reza, Krishna, Rahul, Sankar, Divya, Wassi, Lambert Pouguem, Merler, Michele, Sobolev, Boris, Pavuluri, Raju, Sinha, Saurabh, Jabbarvand, Reyhaneh
Natura: Preprint
Pubblicazione: 2023
Soggetti:
Accesso online:
Tags: Aggiungi Tag
Nessun Tag, puoi essere il primo ad aggiungerne!!
_version_ 1866910298641793024
author Pan, Rangeet
Ibrahimzada, Ali Reza
Krishna, Rahul
Sankar, Divya
Wassi, Lambert Pouguem
Merler, Michele
Sobolev, Boris
Pavuluri, Raju
Sinha, Saurabh
Jabbarvand, Reyhaneh
author_facet Pan, Rangeet
Ibrahimzada, Ali Reza
Krishna, Rahul
Sankar, Divya
Wassi, Lambert Pouguem
Merler, Michele
Sobolev, Boris
Pavuluri, Raju
Sinha, Saurabh
Jabbarvand, Reyhaneh
contents Code translation aims to convert source code from one programming language (PL) to another. Given the promising abilities of large language models (LLMs) in code synthesis, researchers are exploring their potential to automate code translation. The prerequisite for advancing the state of LLM-based code translation is to understand their promises and limitations over existing techniques. To that end, we present a large-scale empirical study to investigate the ability of general LLMs and code LLMs for code translation across pairs of different languages, including C, C++, Go, Java, and Python. Our study, which involves the translation of 1,700 code samples from three benchmarks and two real-world projects, reveals that LLMs are yet to be reliably used to automate code translation -- with correct translations ranging from 2.1% to 47.3% for the studied LLMs. Further manual investigation of unsuccessful translations identifies 15 categories of translation bugs. We also compare LLM-based code translation with traditional non-LLM-based approaches. Our analysis shows that these two classes of techniques have their own strengths and weaknesses. Finally, insights from our study suggest that providing more context to LLMs during translation can help them produce better results. To that end, we propose a prompt-crafting approach based on the symptoms of erroneous translations; this improves the performance of LLM-based code translation by 5.5% on average. Our study is the first of its kind, in terms of scale and breadth, that provides insights into the current limitations of LLMs in code translation and opportunities for improving them. Our dataset -- consisting of 1,700 code samples in five PLs with 10K+ tests, 43K+ translated code, 1,748 manually labeled bugs, and 1,365 bug-fix pairs -- can help drive research in this area.
format Preprint
id arxiv_https___arxiv_org_abs_2308_03109
institution arXiv
publishDate 2023
record_format arxiv
spellingShingle Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code
Pan, Rangeet
Ibrahimzada, Ali Reza
Krishna, Rahul
Sankar, Divya
Wassi, Lambert Pouguem
Merler, Michele
Sobolev, Boris
Pavuluri, Raju
Sinha, Saurabh
Jabbarvand, Reyhaneh
Software Engineering
Code translation aims to convert source code from one programming language (PL) to another. Given the promising abilities of large language models (LLMs) in code synthesis, researchers are exploring their potential to automate code translation. The prerequisite for advancing the state of LLM-based code translation is to understand their promises and limitations over existing techniques. To that end, we present a large-scale empirical study to investigate the ability of general LLMs and code LLMs for code translation across pairs of different languages, including C, C++, Go, Java, and Python. Our study, which involves the translation of 1,700 code samples from three benchmarks and two real-world projects, reveals that LLMs are yet to be reliably used to automate code translation -- with correct translations ranging from 2.1% to 47.3% for the studied LLMs. Further manual investigation of unsuccessful translations identifies 15 categories of translation bugs. We also compare LLM-based code translation with traditional non-LLM-based approaches. Our analysis shows that these two classes of techniques have their own strengths and weaknesses. Finally, insights from our study suggest that providing more context to LLMs during translation can help them produce better results. To that end, we propose a prompt-crafting approach based on the symptoms of erroneous translations; this improves the performance of LLM-based code translation by 5.5% on average. Our study is the first of its kind, in terms of scale and breadth, that provides insights into the current limitations of LLMs in code translation and opportunities for improving them. Our dataset -- consisting of 1,700 code samples in five PLs with 10K+ tests, 43K+ translated code, 1,748 manually labeled bugs, and 1,365 bug-fix pairs -- can help drive research in this area.
title Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code
topic Software Engineering
url https://arxiv.org/abs/2308.03109