Large Language Models (LLMs) perform well on basic programming problems. However, they encounter challenges when dealing with complex tasks involving the use of diverse algorithmic and data structure skills, particularly programming competition-level problems. Notably, ChatGPT exhibits proficient performance on problems it has encountered during its pre-training phase, but this performance deteriorates when faced with novel problems. Consequently, enhancing the ability of LLMs to address unfamiliar problems has emerged as a pivotal research focus. The problem-solving process of LLMs mirrors human programmers' approach to a certain extent. When confronted with new programming tasks, human programmers engage in task planning and code writing with the previously acquired knowledge about algorithms and data structures. Despite having learned such knowledge, LLMs struggle to effectively apply it when faced with specific new problems. To address this issue, we constructed a novel dataset, CodeF, which contains a portion of programming problems that ChatGPT has not previously encountered. Furthermore, we developed a Knowledge Library tailored for Python programming contest problems and introduced the concept of Knowledge-Aware Code Generation (KareCoder). KareCoder bolsters the models' understanding and problem-solving capabilities by integrating prompt and knowledge from the library into the LLMs' code generation reasoning process, especially on Pass@1 metrics. Upon testing on the CodeF and APPS datasets, KareCoder demonstrated outstanding performance in handling novel problems previously unencountered by LLMs. In contrast with the code directly generated by ChatGPT, KareCoder achieved a relative improvement of 23.3% on the Pass@1 metric on the CodeF post2021-9 dataset. Additionally, it performs well compared to other methods when dealing with problems that LLMs have previously encountered.
翻译:大型语言模型(LLMs)在解决基础编程问题上表现良好。然而,在涉及多种算法与数据结构技能的复杂任务(尤其是编程竞赛级问题)中,它们面临挑战。值得注意的是,ChatGPT 对预训练阶段已遇到的问题表现出熟练性能,但在面对新问题时性能下降。因此,提升 LLMs 解决陌生问题的能力已成为关键研究方向。LLMs 的问题求解过程在一定程度上模仿了人类程序员的方法。面对新编程任务时,人类程序员会运用先前习得的算法与数据结构知识进行任务规划与代码编写。尽管 LLMs 已学习此类知识,但在应对特定新问题时难以有效应用。为解决此问题,我们构建了一个新型数据集 CodeF,其中包含部分 ChatGPT 未接触过的编程问题。此外,我们为 Python 编程竞赛问题开发了一个知识库,并提出了知识增强的代码生成概念(KareCoder)。KareCoder 通过将提示与知识库中的知识整合到 LLMs 的代码生成推理过程中(尤其在 Pass@1 指标上),增强了模型的理解与求解能力。在 CodeF 和 APPS 数据集上的测试表明,KareCoder 在处理 LLMs 此前未遇到的新问题方面表现卓越。与 ChatGPT 直接生成的代码相比,KareCoder 在 CodeF post2021-9 数据集上的 Pass@1 指标实现了 23.3% 的相对提升。此外,在处理 LLMs 此前已遇到的问题时,该方法相较其他方法也表现优异。