| 摘要: |
| 大语言模型在自动代码生成领域已展现出巨大的潜力, 但在实际应用中, 生成的代码常存在语法、语义、安全性、运行效率和可维护性等多方面的问题. 为解决这些挑战, 受约束代码生成技术应运而生. 此技术借鉴了受约束文本生成的方法, 通过在代码生成的各个阶段引入严格的约束, 确保生成代码能够满足预期的要求. 首先回顾大语言模型在代码生成过程中所暴露的主要问题, 详细分析代码正确性与代码质量方面的缺陷. 接着, 总结当前受约束代码生成技术的研究进展, 深入探讨不同方法的优势与局限. 之后, 讨论评估方法, 包括基准数据集的构建和评价指标的设计, 为后续研究的实验方案提供有价值的参考. 最后, 展望受约束代码生成技术面临的研究挑战和未来发展趋势. |
| 关键词: 大语言模型 代码生成 代码质量 受约束生成 评估方法 |
| DOI:10.13328/j.cnki.jos.007613 |
| 分类号:TP311 |
| 基金项目:国家重点研发计划(2023YFB4503803) |
|
| Research Progress on Constrained Code Generation in Large Language Models |
|
LI Yu-Xuan1,2, ZOU Yan-Zhen1,2, WANG Yue1,2, XIE Bing1,2
|
|
1.Key Laboratory of High Confidence Software Technologies (Peking University), Ministry of Education, Beijing 100871, China;2.School of Computer Science, Peking University, Beijing 100871, China
|
| Abstract: |
| Large language models (LLMs) demonstrate significant potential in automatic code generation. However, in practical applications, the generated code often suffers from multiple issues, including syntax errors, semantics inconsistencies, security inconsistencies, inefficient runtime performance, and poor maintainability. To address these challenges, constrained code generation techniques are introduced. Drawing inspiration from constrained text generation, these techniques impose explicit constraints at various stages of the code generation process to ensure that the generated code satisfies predefined requirements. This study first reviews the major issues exposed by LLMs in code generation, with a detailed analysis of deficiencies related to code correctness and quality. Subsequently, recent research progress in constrained code generation is summarized, and the strengths and limitations of existing approaches are systematically examined. Furthermore, evaluation methods are discussed, including the construction of benchmark datasets and the design of evaluation metrics, providing valuable references for experimental settings in future research. Finally, the research challenges faced by constrained code generation and its future development trends are outlined. |
| Key words: large language model (LLM) code generation code quality constrained generation evaluation method |