Leveraging Print Debugging to Improve Code Generation in Large Language Models
Xueyu Hu, Kun Kuang, Jiankai Sun, Hongxia Yang, Fei Wu

TL;DR
This paper introduces a print debugging technique for large language models to enhance their code generation capabilities, especially for complex problems, showing significant improvements over traditional debugging methods.
Contribution
It presents a novel in-context learning approach using print debugging for LLMs, with empirical validation on Leetcode problems demonstrating improved performance.
Findings
Outperforms rubber duck debugging on Leetcode problems
Achieves 1.5% improvement on easy problems
Achieves 17.9% improvement on medium problems
Abstract
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%.
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsTopic Modeling · Software Engineering Research · Natural Language Processing Techniques
MethodsMulti-Head Attention · Attention Is All You Need · Linear Layer · Softmax · Adam · Absolute Position Encodings · Layer Normalization · Residual Connection · Byte Pair Encoding · Dropout
