The widespread use of Large Language Models (LLMs) in software engineering has intensified the need for improved model and resource efficiency. In particular, for neural code generation, LLMs are used to translate function/method signature and DocString to executable code. DocStrings which capture user re quirements for the code and used as the prompt for LLMs, often contains redundant information. Recent advancements in prompt compression have shown promising results in Natural Language Processing (NLP), but their applicability to code generation remains uncertain. Our empirical study show that the state-of-the-art prompt compression methods achieve only about 10% reduction, as further reductions would cause significant performance degradation. In our study, we propose a novel compression method, ShortenDoc, dedicated to DocString compression for code generation. Our extensive experiments on six code generation datasets, five open-source LLMs (1B to 10B parameters), and one closed-source LLM GPT-4o confirm that ShortenDoc achieves 25-40% compression while preserving the quality of generated code, outperforming other baseline methods at similar compression levels. The benefit of this research is to improve efficiency and reduce the cost while maintaining the quality of the generated code, especially when calling third-party APIs, and is able to reduce the token processing cost by 25-40%.
翻译:大型语言模型(LLM)在软件工程中的广泛应用,增强了对提升模型与资源效率的需求。特别是在神经代码生成领域,LLM被用于将函数/方法签名及文档字符串转换为可执行代码。文档字符串作为捕获用户代码需求并用作LLM提示的文本,通常包含冗余信息。尽管提示压缩领域的最新进展在自然语言处理(NLP)中已展现出有希望的结果,但其在代码生成中的适用性仍不确定。我们的实证研究表明,当前最先进的提示压缩方法仅能实现约10%的压缩率,因为进一步的压缩将导致性能显著下降。在本研究中,我们提出了一种专为代码生成设计的文档字符串压缩新方法——ShortenDoc。我们在六个代码生成数据集、五个开源LLM(参数规模从1B到10B)以及一个闭源LLM GPT-4o上进行的广泛实验证实,ShortenDoc在保持生成代码质量的同时实现了25-40%的压缩率,在相似压缩水平下优于其他基线方法。本研究的意义在于,能够在保持生成代码质量的同时提升效率并降低成本,特别是在调用第三方API时,能够减少25-40%的令牌处理开销。