Socratic Human Feedback ( S o HF ): Expert Steering Strategies for LLM Code Generation (2024)

Abstract: Large Language Models (LLMs) are increasingly used for generating code solutions, empowered by features like self-debugging and self-reflection. However, LLMs often struggle with complex programming problems without human guidance. This paper investigates the strategies employed by expert programmers to steer code-generating LLMs toward successful outcomes. Through a study involving experts using natural language to guide GPT-4, Gemini Ultra, and, Claude 3.5 Sonnet on highly difficult programming challenges, we frame our analysis using the “Socratic Feedback” paradigm for understanding effective steering strategies. By analyzing 30 conversational transcripts across all three models, we map observed feedback strategies to five stages of Socratic Questioning: Definition, Elenhus, Maieutic, Dialectic, and Counter-factual reasoning. We find evidence that by employing a combination of different Socratic feedback strategies across multiple turns, programmers successfully guided the models to solve 74% of the problems that the models initially failed to solve on their own.

## introduction the rapid advancements in large language models (llms) have revolutionized the field of natural language processing (nlp) and automated code generation. analyses of state-of-the-art models, such as gpt-4 (openai, 2023), claude @xcite and gemini ultra @xcite , illustrate remarkable capabilities in generating code snippets based on natural language prompts, introducing new opportunities for enhancing developer productivity and transforming the broader practice of software engineering. however, despite their impressive performance, llms still face challenges when it comes to handling complex coding problems that require a deep understanding of the task * authors contributed equally to this work @xcite , effective problem decomposition, and the nuanced application of algorithms and libraries within specific constraints. recent research has demonstrated how llms can iteratively analyze and refine generated code based on the outcomes of unit tests through self-debugging, mimicking the trial-and-error approach commonly employed by human programmers @xcite . while these capabilities show substantial promise, state-of-the-art llms remain challenged by the task of accurately identify failures in generated code or generate effective feedback to guide subsequent code refinements, resulting in modest performance improvements when tackling complex programming tasks, such as certain leetcode's medium and hard-level problems. however, with certain human feedback during the iterative analysis, we are able to find that we are able to successfully steer models into providing a successful solution. thus, understanding how humans currently interact with these models and the category of steering strategies that lead to successful steering is essential for future human-ai model interaction design. in this paper, we present an empirical study that explores how expert programmers effectively steer sota llms, such as gpt-4, gemini ultra, and claude 3.5 sonnet, to generate functionally correct code for programming problems that the models initially failed to solve independently. we focus on the socratic feedback approach, a technique commonly used in argumentation and tutoring, where targeted questions or prompts are used to stimulate critical thinking and guide learners towards formulating their own solutions. this approach mirrors the dynamics of college programming tutoring sessions, with the instructor providing incremental feedback based on the learner's most recent attempt, while the learner engages in multiple rounds of debugging before seeking further guidance. our study, involving 8 expert programmers solving 30 problems across three modern llms gpt-4, gemini ultra and claude 3.5 sonnet provided a total of 90 conversational data points. our study demonstrates that these modern llms can successfully solve originally failed competition-level programming problems with just a few rounds of human socratic feedback. furthermore, we reveal a set of socratic feedback techniques employed by programmers to guide the llm effectively. we also discuss the failed attempts for successful steering and discuss the challenges faced by programmers in steering llms for coding task. ## related work recent studies suggest that incorporating code into training data enables general-purpose llms to generate programs from natural language prompts or to complete incomplete code snippets @xcite @xcite . alternatively, specialized models like codex @xcite , alphacode @xcite , starcoder @xcite , and code llama @xcite have also been developed or fine-tuned specifically for coding tasks. though they have achieved sota performance on code generation benchmarks @xcite , llms still exhibit limited performance on medium and hard competition-level programming problems. these complex problems typically require a programmer's adept skills in understanding, planning, and implementing sophisticated reasoning tasks. furthermore, approaches such as alphacode @xcite are impractical for real applications due to the dependency on available unit tests and extreme amounts of computational resources. to address this limitation, some works used prompt-based techniques to boost llms' reasoning for correct code. for example, studies have demonstrated the utility of cot prompting @xcite and tree-of-thought prompting @xcite as tools for decomposing challenging tasks into more manageable intermediate sub-problems. additionally, self-debugging or reflection techniques @xcite @xcite encouraged models to analyze their own outputs and divide the debugging process into stages of code explanation and self-feedback generation. then llms refined their planning and execution grounded on the insights obtained from their self-generated feedback. besides stimulating models' self-reflection, some works used human prompts to support the code refinement process. for example, @xcite explored human-model collaborative coding on the mbpp dataset. they found that llms can improve or correct code based on human feedback, benefiting from human clarification of underspecified prompts and correction of small context errors. however, our focus diverges as we concentrate on tackle competition-level problems, which are notably more complex than those found in the mbpp dataset. apart from incorporating human feedback as prompts, chen et al. (2023a) improved codegen using imitation learning from human language feedback, where human feedback is used to learn a refinement model that generates modification from human feedback and previous incorrect code. ## methodology we conducted a study involving three state-of-theart models: gpt-4, gemini ultra, and claude 3.5 sonnet. the study focused on the models' ability to generate python code solutions for algorithmic and data structure problems sourced from leetcode, spanning various difficulty levels and topics. we randomly selected 223 problems from leetcode and filtered them to identify instances where the models were unable to independently generate correct solutions. this filtering process yielded a set of 45 hard problems that the models failed to solve on their first attempt. these problems were chosen as the basis for our study among which 30 were solved due to availability of the programmers. we recruited 8 expert programmers to participate in the study. each programmer was tasked with steering the three llms to solve the selected problems through successive conversational prompting. the experts were first asked to solve or at least have an understanding on how to solve each problem on their own before starting to steer the model. the final code is considered a success if it passes all test cases provided in the initial problem description and the final solution was accepted by leetcode. the code was tested and submitted manually to the leetcode platform. programmers were provided with a prompt template that addressed key aspects of the problem, including the problem description, function signature, test cases, and constraints. they were also given a digital document containing task instructions and sample prompt templates to guide their interactions with the llms. programmers engaged in an iterative prompting process, providing socratic feedback to the llms based on the generated code's performance. they were instructed to continue the prompting process for a maximum of 10 iterations or until a correct solution was generated, whichever occurred first. the collected conversational data was analyzed to identify and categorize the various strategies employed by the programmers. these strategies were then mapped to corresponding socratic feedback themes. ## steering strategies after analyzing all 90 dialogues consisting of 507 conversational turns (3 models across 30 problems), we have identified various strategies employed by users in their interactions with the model. figure 2 presents a snippet of the conversation with the model, and we will elucidate these different strategies using samples from these conversation snippets. ## results & discussion a total of 90 conversations were recorded across the three models: gpt-4, gemini ultra, and claude 3.5 sonnet. the conversations comprised a total of 507 turns, during which programmers employed various steering strategies to guide the llms towards correct solutions. among these conversations, 67 (74%) led to successful code generation after steering, with the model producing a solution that was accepted by leetcode. claude 3.5 sonnet had the highest success rate, with 29 out of 30 conversations resulting in correct solutions, followed by gpt-4, and gemini ultra with 26 and 12 respectively. as shown in figure 5 , the most commonly used strategy was "point out specific error", which was applied in 22% of the turns (112 out of 507). this strategy involved programmers identifying and highlighting specific errors in the code generated by the llms, prompting the models to rectify those issues. the second most frequently employed strategy was "specific approach instruction" used in 18% of the turns (91 out of 507). in this approach, programmers provided the llms with specific guidelines, algorithms, or techniques to solve the problem at hand. by offering targeted guidance, programmers aimed to steer the models towards more efficient and effective solutions. interestingly, "revising unit test" and "requirement re-iteration" were the least preferred strategies among the programmers, applied in only 4% and 5% of the turns respectively. this suggests that programmers found it more effective to directly address the code generated by the llms, rather than modifying the test cases or restating the problem requirements. other strategies employed by the programmers included "new unit test" used in 8% of the turns, and "requirement clarification" used in 13% of the turns. "new unit test" involved providing additional test cases to help the llms understand the problem better and cover edge cases, while "requirement clarification" focused on explaining the problem statement or constraints more clearly to the models. "address code inefficiency" and "test re-iteration" were used in 9% and 13% of the turns, respectively. the former strategy aimed at guiding the llms to generate more efficient and optimized code, while the latter involved rerunning the test cases to validate the correctness of the generated solutions. the results of our study demonstrate the effectiveness of socratic feedback in enabling expert programmers to steer code-generating large language models (llms) towards correct solutions for complex programming problems. by employing a combination of strategies, with a focus on pointing out specific errors and providing targeted guidance, programmers successfully guided the models to overcome initial failures and generate code that met the required specifications. claude 3.5 sonnet exhibits the highest success rate among all the models tested. by testing several different models, we were able to find evidence for the application of a socratic feedback-based steering strategy across models. an essential aspect of successful steering identified is the ability to identify the specific programming stage at which the model is struggling. participants who provided relevant feedback to help the model overcome hurdles at different stages, such as understanding, planning, implementation, and testing, were more likely to achieve successful outcomes. clear communication about misunderstandings or overlooked details proved to be crucial in guiding the llms towards the correct solution. in one example, clarifying a misunderstood problem condition led to successful steering, while in another case, overlooking a crucial detail resulted in a failed discourse. this finding emphasizes the importance of programmers being attentive to the specific challenges faced by the llms at each stage of the problem-solving process and providing targeted feedback to address those issues. it is unclear however, if novice programmers will have the same level of success similar to that of the experts in this study. ## limitation & future work our study presents an initial investigation into the application of socratic feedback in steering codegenerating large language models (llms). to establish an upper bound on the feasibility of llm interaction, we focused our data collection on expert programmers. while the observed strategies demonstrated success across three different models, suggesting their generalizability in improving the models' problem-solving abilities through human steering, some strategies, such as "point out specific error" or "approach re-orientation," may only be feasible for experts. future research could conduct a longitudinal study involving novice users to determine if they can effectively employ the same strategies identified by experts and if their productivity improves with the understanding and application of socratic feedback in their prompting techniques. we acknowledge the limitations in the quantity of data points gathered for making larger generalized claims. however, this preliminary work provides valuable insights that can be expanded upon through more extensive data collection efforts in the future. one potential direction is to create a mapping between the different types of errors in the model feedback and the programmers' chosen strategies for steering the models. such a mapping would be instrumental in designing future human-llm interfaces, enabling the model to recommend follow-up prompts, ask clarifying questions, or provide prompt templates that align with the socratic feedback paradigm. the findings from this study pave the way for future research to explore the dynamics of steering language models in code generation tasks further, enhancing our understanding of user challenges and optimizing human-ai collaboration. while our study participants employed various strategies, there is potential for developing and evaluating more sophisticated steering techniques. future work could investigate the integration of machine learning or reinforcement learning approaches to dynamically adapt steering strategies based on the model's responsiveness and the evolving context of the conversation. ## conclusion in this paper, we conducted an empirical study to investigate the use of socratic feedback by expert programmers in steering code-generating large language models (llms) to solve complex programming problems. by examining the interactions between programmers and three state-of-theart llms -gpt-4, gemini ultra, and claude 3.5 sonnet -we identified common strategies and feedback techniques employed to guide the models towards generating correct and efficient solutions. our findings demonstrate that socratic feedback plays a crucial role in enabling programmers to effectively steer llms when the models are unable to independently generate correct solutions. our findings contribute to the growing body of research on human-ai interaction and provide valuable insights for the development of more effective collaboration techniques. … provide an updated version of the program along with the execution results for all the given unit tests.