Don't Transform the Code, Code the Transforms: Towards Precise Code Rewriting using LLMs

Fuente: arXiv
Enregistré dans:
Détails bibliographiques
Auteurs principaux: Cummins, Chris, Seeker, Volker, Armengol-Estapé, Jordi, Markosyan, Aram H., Synnaeve, Gabriel, Leather, Hugh
Format: Preprint
Publié: 2024
Sujets:
Accès en ligne:
Tags: Ajouter un tag
Pas de tags, Soyez le premier à ajouter un tag!
_version_ 1866913541957615616
author Cummins, Chris
Seeker, Volker
Armengol-Estapé, Jordi
Markosyan, Aram H.
Synnaeve, Gabriel
Leather, Hugh
author_facet Cummins, Chris
Seeker, Volker
Armengol-Estapé, Jordi
Markosyan, Aram H.
Synnaeve, Gabriel
Leather, Hugh
contents Tools for rewriting, refactoring and optimizing code should be fast and correct. Large language models (LLMs), by their nature, possess neither of these qualities. Yet, there remains tremendous opportunity in using LLMs to improve code. We explore the use of LLMs not to transform code, but to code transforms. We propose a chain-of-thought approach to synthesizing code transformations from a small number of input/output code examples that incorporates execution and feedback. Unlike the direct rewrite approach, LLM-generated transformations are easy to inspect, debug, and validate. The logic of the rewrite is explicitly coded and easy to adapt. The compute required to run code transformations is minute compared to that of LLM rewriting. We test our approach on 16 Python code transformations and find that LLM- generated transforms are perfectly precise for 7 of them and less imprecise than direct LLM rewriting on the others. We hope to encourage further research to improving the precision of LLM code rewriting.
format Preprint
id arxiv_https___arxiv_org_abs_2410_08806
institution arXiv
publishDate 2024
record_format arxiv
spellingShingle Don't Transform the Code, Code the Transforms: Towards Precise Code Rewriting using LLMs
Cummins, Chris
Seeker, Volker
Armengol-Estapé, Jordi
Markosyan, Aram H.
Synnaeve, Gabriel
Leather, Hugh
Machine Learning
Tools for rewriting, refactoring and optimizing code should be fast and correct. Large language models (LLMs), by their nature, possess neither of these qualities. Yet, there remains tremendous opportunity in using LLMs to improve code. We explore the use of LLMs not to transform code, but to code transforms. We propose a chain-of-thought approach to synthesizing code transformations from a small number of input/output code examples that incorporates execution and feedback. Unlike the direct rewrite approach, LLM-generated transformations are easy to inspect, debug, and validate. The logic of the rewrite is explicitly coded and easy to adapt. The compute required to run code transformations is minute compared to that of LLM rewriting. We test our approach on 16 Python code transformations and find that LLM- generated transforms are perfectly precise for 7 of them and less imprecise than direct LLM rewriting on the others. We hope to encourage further research to improving the precision of LLM code rewriting.
title Don't Transform the Code, Code the Transforms: Towards Precise Code Rewriting using LLMs
topic Machine Learning
url https://arxiv.org/abs/2410.08806