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已接触过的问题时,该方法相较于其他方案同样表现优异。