Skip to main content
QUICK REVIEW

[论文解读] LLM-Assisted Code Cleaning For Training Accurate Code Generators

Naman Jain, Tianjun Zhang|arXiv (Cornell University)|Nov 25, 2023
Software Engineering Research被引用 4
一句话总结

本文提出了一种新颖的 LLM 辅助数据清洗流水线,通过使训练数据更具可读性和模块化,提升了代码生成性能。通过重命名变量、将复杂代码分解为辅助函数,并插入自然语言计划,该方法使 CodeLLaMa-7B 的准确率相比原始数据集最高提升 30%,即使仅使用 15% 的清洗后数据进行训练,也优于更大的闭源模型(如 AlphaCode)。

ABSTRACT

Natural language to code generation is an important application area of LLMs and has received wide attention from the community. The majority of relevant studies have exclusively concentrated on increasing the quantity and functional correctness of training sets while disregarding other stylistic elements of programs. More recently, data quality has garnered a lot of interest and multiple works have showcased its importance for improving performance. In this work, we investigate data quality for code and find that making the code more structured and readable leads to improved code generation performance of the system. We build a novel data-cleaning pipeline that uses these principles to transform existing programs by 1.) renaming variables, 2.) modularizing and decomposing complex code into smaller helper sub-functions, and 3.) inserting natural-language based plans via LLM based transformations. We evaluate our approach on two challenging algorithmic code generation benchmarks and find that fine-tuning CodeLLaMa-7B on our transformed modularized programs improves the performance by up to 30% compared to fine-tuning on the original dataset. Additionally, we demonstrate improved performance from using a smaller amount of higher-quality data, finding that a model fine-tuned on the entire original dataset is outperformed by a model trained on 15% of our cleaned dataset. Even in comparison to closed-source models, our models outperform the much larger AlphaCoder models.

研究动机与目标

  • 通过超越功能正确性的数据质量提升,改善代码生成性能。
  • 探究训练数据中可读性、模块化和结构清晰度对模型性能的影响。
  • 开发一种自动化、基于 LLM 的流水线,将现有代码数据集转换为更高品质、更结构化的版本,同时保持功能正确性。
  • 证明高质量数据可提升数据效率,减少对大规模训练集的依赖。
  • 建立一种数据清洗框架,识别并应用关键编程最佳实践作为数据质量改进手段。

提出的方法

  • 使用指令微调的 LLM 执行三次迭代式转换:变量重命名以增强上下文相关性,代码模块化为更小的辅助函数,以及作为注释插入自顶向下的自然语言计划。
  • 通过自然语言提示和输入输出示例应用每项转换,确保原始程序与转换后程序的功能等价。
  • 利用修改现有代码比从零开始生成代码更容易的优势,使用 LLM 对现有程序进行优化而非从头生成。
  • 通过将基准数据集(APPS 和 Code-Contests)中的程序转换为清洗后、模块化和带计划的版本,构建并行数据集。
  • 在原始数据集和转换后数据集上对 CodeLLaMa-7B 进行微调,以评估性能提升。
  • 使用输入输出示例作为验证手段,确保转换后的程序与原始程序产生相同输出。
Figure 1: The overview of our code cleaning approach . We apply instruction-tuned LLMs to transform existing datasets by providing natural language prompts and use input-output examples to maintain function equivalence between original and transformed programs. Our cleaning approach works in three s
Figure 1: The overview of our code cleaning approach . We apply instruction-tuned LLMs to transform existing datasets by providing natural language prompts and use input-output examples to maintain function equivalence between original and transformed programs. Our cleaning approach works in three s

实验结果

研究问题

  • RQ1通过数据清洗提升代码可读性和模块化,对代码生成模型性能有何影响?
  • RQ2更小但质量更高的数据集是否能在微调代码生成模型时超越更大但质量较低的数据集?
  • RQ3基于 LLM 的转换(如变量重命名、模块化和规划注释)在多大程度上提升了模型的泛化能力和功能正确性?
  • RQ4与仅使用原始代码相比,代码中包含自然语言计划是否能提升模型性能?
  • RQ5强调编程最佳实践的数据清洗技术是否能提升代码生成任务中的数据效率?

主要发现

  • 在清洗后、模块化的数据集上微调 CodeLLaMa-7B,性能相比在原始数据集上微调最高提升 30%。
  • 仅使用 15% 清洗后数据微调的模型,其性能优于在完整原始数据集上微调的模型,证明了显著的数据效率提升。
  • 清洗后的数据集(包含命名更清晰的变量、模块化函数和自顶向下的规划注释)使模型输出的代码更具结构性和可读性。
  • 即使与更大的闭源模型(如 AlphaCode)相比,使用清洗数据微调的 CodeLLaMa-7B 模型在算法类代码生成基准测试中也表现出更优性能。
  • 基于 LLM 的清洗流水线成功将现有程序转换为更高品质的版本,同时保持了功能正确性,经由输入输出测试验证。
  • 该方法表明,数据质量(尤其是结构和可读性)对代码生成性能具有可测量且显著的影响,且与数据集大小无关。
Figure 3: Effect of quality on data-efficiency of the model . Finetuning on 15% of clean $\mathcal{D}_{modular}$ dataset results in similar performance as finetuning on the entire $\mathcal{D}_{original}$ dataset.
Figure 3: Effect of quality on data-efficiency of the model . Finetuning on 15% of clean $\mathcal{D}_{modular}$ dataset results in similar performance as finetuning on the entire $\mathcal{D}_{original}$ dataset.

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。