Large language models (LLMs) have made significant progress in code generation tasks, but their performance in tackling programming problems with complex data structures and algorithms remains suboptimal. To address this issue, we propose an in-context learning approach that guides LLMs to debug by using a "print debugging" method, which involves inserting print statements to trace and analysing logs for fixing the bug. We collect a Leetcode problem dataset and evaluate our method using the Leetcode online judging system. Experiments with GPT-4 demonstrate the effectiveness of our approach, outperforming rubber duck debugging in easy and medium-level Leetcode problems by 1.5% and 17.9%.
翻译:大型语言模型(LLMs)在代码生成任务中取得了显著进展,但在处理涉及复杂数据结构和算法的编程问题时,其性能仍不理想。为解决这一问题,我们提出了一种上下文学习方法,引导LLMs通过“打印调试”方法进行调试,该方法涉及插入打印语句以追踪并分析日志来修复错误。我们收集了一个Leetcode问题数据集,并使用Leetcode在线评测系统评估我们的方法。基于GPT-4的实验表明,我们的方法有效性显著,在简单和中等难度的Leetcode问题上,性能分别比橡皮鸭调试方法提升了1.5%和17.9%。