ReGAL: Refactoring Programs to Discover Generalizable Abstractions

Elias Stengel-Eskin, Archiki Prasad, Mohit Bansal
1/29/2024
cs.SEcs.AIcs.CL

No official code found. Best implementation: esteng/regal_program_learning (27 stars, last commit 2024-09-11).

Abstract

While large language models (LLMs) are increasingly being used for program synthesis, they lack the global view needed to develop useful abstractions; they generally predict programs one at a time, often repeating the same functionality. Generating redundant code from scratch is both inefficient and error-prone. To address this, we propose Refactoring for Generalizable Abstraction Learning (ReGAL), a gradient-free method for learning a library of reusable functions via code refactorization, i.e., restructuring code without changing its execution output. ReGAL learns from a small set of existing programs, iteratively verifying and refining its abstractions via execution. We find that the shared function libraries discovered by ReGAL make programs easier to predict across diverse domains. On five datasets -- LOGO graphics generation, Date reasoning, TextCraft (a Minecraft-based text-game) MATH, and TabMWP -- both open-source and proprietary LLMs improve in accuracy when predicting programs with ReGAL functions. For CodeLlama-13B, ReGAL results in absolute accuracy increases of 11.5% on LOGO, 26.1% on date understanding, and 8.1% on TextCraft, outperforming GPT-3.5 in two of three domains. Our analysis reveals ReGAL's abstractions encapsulate frequently-used subroutines as well as environment dynamics.

View on arXivView PDF

Code Implementations(1)

274Shell, PythonJan 28, 20242 years ago

Similar Papers

Cite this paper

@article{stengeleskin2024regal,
  title  = {ReGAL: Refactoring Programs to Discover Generalizable Abstractions},
  author = {Elias Stengel-Eskin and Archiki Prasad and Mohit Bansal},
  year   = {2024},
  eprint = {2401.16467},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2401.16467v2},
  journal = {ICML 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2401.16467.svg)](https://codeofpaper.com/paper/2401.16467)

Discussion