Skip to main content
QUICK REVIEW

[Paper Review] Better patching using LLM prompting, via Self-Consistency

Toufique Ahmed, Prémkumar Dévanbu|arXiv (Cornell University)|May 31, 2023
Software Engineering ResearchComputer Science3 citations
TL;DR

This paper proposes using self-consistency (SC) with commit log messages as reasoning paths in few-shot prompting for large language model (LLM)-based program repair. By sampling multiple explanation-solution pairs from the LLM and selecting the most frequent fix, the method achieves state-of-the-art performance on the MODIT dataset, with statistically significant improvements over greedy decoding and baseline prompting, especially when using correct commit messages in few-shots.

ABSTRACT

Large Language models (LLMs) can be induced to solve non-trivial problems with "few-shot" prompts including illustrative problem-solution examples. Now if the few-shots also include "chain of thought" (CoT) explanations, which are of the form problem-explanation-solution, LLMs will generate a "explained" solution, and perform even better. Recently an exciting, substantially better technique, self-consistency [1] (S-C) has emerged, based on the intuition that there are many plausible explanations for the right solution; when the LLM is sampled repeatedly to generate a pool of explanation-solution pairs, for a given problem, the most frequently occurring solutions in the pool (ignoring the explanations) tend to be even more likely to be correct! Unfortunately, the use of this highly-performant S-C (or even CoT) approach in software engineering settings is hampered by the lack of explanations; most software datasets lack explanations. In this paper, we describe an application of the S-C approach to program repair, using the commit log on the fix as the explanation, only in the illustrative few-shots. We achieve state-of-the art results, beating previous approaches to prompting-based program repair, on the MODIT dataset; we also find evidence suggesting that the correct commit messages are helping the LLM learn to produce better patches.

Motivation & Objective

  • To improve LLM-based program repair by applying self-consistency (SC) to reduce hallucination and increase solution reliability.
  • To investigate whether commit log messages—commonly used in software engineering—can serve as effective reasoning paths in few-shot prompting for code repair.
  • To evaluate the impact of using real versus random commit messages in few-shot examples on repair accuracy.
  • To determine the optimal number of samples for SC to balance performance and computational cost.
  • To demonstrate that SC with real commit messages leads to statistically significant improvements over baseline prompting methods.

Proposed method

  • Apply self-consistency (SC) to program repair by prompting the LLM with few-shot examples that include input code, a commit log message (as reasoning path), and the correct fix.
  • Sample multiple explanation-solution pairs from the LLM using a high temperature to encourage diverse reasoning paths.
  • Select the most frequently occurring fix across all sampled pairs as the final output, marginalizing over reasoning paths.
  • Use BM25 to retrieve the most relevant few-shot examples based on semantic similarity to the test input.
  • Compare performance using real commit messages versus randomly shuffled commit messages in few-shot examples.
  • Use greedy decoding as baseline and apply McNemar’s test to assess statistical significance of improvements.

Experimental results

Research questions

  • RQ1RQ1: Does applying self-consistency with commit log messages as reasoning paths improve program repair accuracy compared to greedy decoding?
  • RQ2RQ2: How many sampled explanation-solution pairs are needed to achieve optimal performance in self-consistency for program repair?
  • RQ3RQ3: Does using real commit messages in few-shot examples improve performance more than using random commit messages?
  • RQ4RQ4: How does BM25-based few-shot retrieval compare to fixed-shot baselines in terms of repair accuracy?

Key findings

  • Self-consistency improved performance over greedy decoding by 42.10% on B2F_s and 38.39% on B2F_m, with p < 0.01, indicating statistical significance.
  • Using BM25 to retrieve few-shot examples further improved accuracy, with gains of 9.65% and 13.08% over greedy decoding, respectively.
  • Using real commit messages in few-shot examples led to a 3.44% and 4.18% improvement over the baseline on B2F_s and B2F_m, respectively, with statistical significance not achieved (p = 0.30).
  • Using random commit messages in few-shot examples did not yield significant improvement over the baseline, suggesting that the model does not benefit from arbitrary reasoning paths.
  • The model achieved 31.80% accuracy on B2F_s and 21.60% on B2F_m using SC with real commit messages, outperforming prior methods like NatGen.
  • Performance plateaued after 10 samples for B2F_m, but continued to improve (with diminishing returns) for B2F_s, justifying 30 samples as a practical default.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.