Flatness-Aware Prompt Selection Improves Accuracy and Sample Efficiency (2023)

Abstract: With growing capabilities of large language models, prompting them has become the dominant way to access them. This has motivated the development of strategies for automatically selecting effective language prompts. In this paper, we introduce **pFlat** (prompt flatness), a new metric to quantify the expected utility of a language prompt. This metric is inspired by *flatness* regularization in statistical learning that quantifies the robustness of the model towards its parameter perturbations. We provide theoretical foundations for this metric and its relationship with other prompt selection metrics, providing a comprehensive understanding of existing methods. Empirically, we show that combining **pFlat** with existing metrics improves both performance and sample efficiency. Our metric outperforms the previous prompt selection metrics with an average increase of 10% in Pearson correlation across 6 classification benchmarks, and the prompt selected by our metric gains 5% higher accuracy than previous metrics across the benchmarks.

## introduction manually "engineering" prompts for large language models (llms) have been shown to lead to tremendous performance gains and have been a subject of intense study in recent years @xcite @xcite . however, the task of prompt engineering can be challenging due to the difficulty in determining the effectiveness of a prompt solely based on its raw text form. consequently, this process is typically carried out manually, which can be laborious and time-intensive. in particular, llms may produce vastly different predictive distributions for two seemingly comparable prompts, despite their semantic similarity @xcite . in response to such difficulties, recent works propose metrics for automatic prompt selection. notably, @xcite introduces mutual information (mi) to quantify the shared information between prediction and inputs. further, @xcite introduces sensitivity (sen) to quantify model receptiveness to textual perturbations of the input prompts. despite such metrics' empirical effectiveness, the underlying principles that enable them are not well understood. this motivates the following questions: (rq 1 ) what makes the existing methods for prompt selection effective? (rq 2 ) how are these existing methods connected? (rq 3 ) are there any new metrics complementary to the existing ones? to address the questions above, we study existing methods from an optimization perspective. the objective l(p, d, θ 0 ) quantifies the performance of an llm (parameterized by θ 0 ) on labeled data d and a prompt p appended to the dataset inputs. prompt selection is in effect an optimization on l(p, d, θ 0 ) as a function of different choices of p. the challenge is that, in practice, there are few labeled data d @xcite , which would make l(.) an unreliable measure for selecting effective prompts. we show that the existing prompt selection metrics (mi and sen) @xcite approximate the objective function l, and therefore, act as its surrogates. this addresses (rq 1 ) and (rq 2 ) above. additionally, to address (rq 3 ) we borrow ideas from statistical learning on flatness-aware optimization @xcite . we introduce prompt flatness (pflat), a metric that quantifies l's sensitivity to small perturbations in llms parameters, when conditioned on a prompt (see figure 1 for intuitions). our results indicate that prompts with higher flatness generally lead to better accuracy. our formal derivations also show that pflat is distinct from and complementary to prior metrics such as mi and sen. our empirical results ( §3) on six classification benchmarks and four different model sizes also confirm our theoretical intuition. for example, combining pflat and mi improves the downstream performance by 6% accuracy over the prompts selected by mi only. similarly, combining pflat and sen improves the downstream performance by 9% accuracy over prompt selected by sen only. additionally, using pflat substantially improves sample efficiency, an important feature of low-resource scenarios. in summary, our contributions are: (a) we propose a formal optimization framework that unifies several existing prompt selection metrics such as mi and sen. (b) enabled by our formalism, we introduce pflat, a metric for selecting prompts that is more robust to llms' parametric perturbations. (c) we conduct comprehensive experiments and the results demonstrate the effectiveness of our method for prompt selection. ## prompt selection via flatness we start by introducing the necessary background and the notational convention ( §2.1), then introduce our proposed metric, pflat ( §2.2), followed by a discussion of its relation to other existing prompt selection metrics ( §2.3). ## experiments we conduct extensive experiments to assess the effectiveness of prompt selection metrics. experimental setup. we experiment with a variety of classification benchmarks: agnews @xcite , cb @xcite , dbpedia @xcite , sst-2 @xcite , rte @xcite , and trec @xcite . we choose four different gpt-2: base, medium, large, and xl sizes. 2 held-out set for α hyperparameter. for each dataset, we create a small dev-set by randomly selecting 8 labeled sentences per class to tune the value of α. implementation. we prepare 20 human-written instructions by the authors (included in appendix f) appended by random demonstrations for each task. the number of demonstrations is set as 5, which matches the settings in @xcite for a fair comparison. we use mi, sen, pflat, and their combinations for comparison. the results are averaged on three random seeds. we estimate pflat (equation 6 ) via 5 random gaussian perturbations of llm parameters with variance σ 2 set to 1e-4. later, we offer an assessment of the influence of this estimation ( §4.4). evaluation metrics. we use two metric families: correlation with accuracy: the first category measures the alignment between prompt selection metrics (including our proposed metric) and the downstream accuracy of each prompt. this evaluation contrasts the relative quality of prompts based on their accuracy with their prompt-selection accuracy. specifically, for each prompt, we compute the prompt selection metric score (mi, mi + pflat, which uses only task inputs) and the prompt's accuracy on the test set. given a collection of such paired numbers, we compute their correlation. a high correlation indicates that this prompt-selection metric can serve as a "surrogate" (proxy) for selecting the most accurate prompt, bypassing the direct maximization of accuracy which often demands extra held-out labeled data. ranking evaluation: since correlations are sensitive and brittle to outliers (anscombe, 1973), we further use different metrics for best-performance prompt retrieval. specifically, we use ndcg@1 @xcite , ndcg@3, and rate. ndcg is a common metric for ranking quality in information retrieval. here, we take prompts' performance as their quality score for ndcg. we denote the prompt selected by metric (e.g., highest mi or lowest sen) as p, and rate is defined as follows: flatness is complementary to mi and sen. the correlation results are in figure 2 (detailed numbers in appendix c). figure 2 (first row) shows that correlations are higher for mi+pflat and sen+pflat than for metrics without pflat. in other words, combining existing (mi or sen) with flatness results in a more effective prompt selection metric that correlates better with test accuracy. we find similar results in the ranking evaluation illustrated in figure 3 (full results in appendix d). in all benchmarks, metrics incorporating flatness generally surpass those without it, highlighting the importance of utilizing prompt flatness in the prompt selection process. ## related work prompt selection and engineering. performance of llms is highly sensitive to their prompt prefix, including the ordering of demonstrations @xcite or framing of the instructions @xcite . this has motivated work prompt selection, such as the ones discussed in this work @xcite . beyond quantifying prompts' effectiveness, the literature has explored alternative ways to address llms' brittleness, such as chainof-thoughts prompting @xcite , llm self-consistency @xcite and complexity @xcite . our optimization-based framework does not cover these classes of prompt engineering, which we hope future work will address. ## conclusion we developed a theoretical framework for prompt selection techniques that merges prompt loss and flatness, enabling the integration of previous studies to elucidate their distinctions and efficacy. through extensive experimentation, we demonstrated the effectiveness of our proposed flatnessbased metric when used in conjunction with existing ones. our research offers valuable insights and directions for future investigations in effective prompt engineering.