Task Facet Learning: A Structured Approach To Prompt Optimization (2025)

Abstract: Given a task in the form of a basic description and its training examples, prompt optimization is the problem of synthesizing the given information into a text prompt for a large language model. Humans solve this problem by also considering the different facets that define a task (e.g., counter-examples, explanations, analogies) and including them in the prompt. However, it is unclear whether existing algorithmic approaches, based on iteratively editing a given prompt or automatically selecting a few in-context examples, can cover the multiple facets required to solve a complex task. In this work, we view prompt optimization as that of learning multiple facets of a task from a set of training examples. We exploit structure in the prompt optimization problem and break down a prompt into loosely coupled semantic sections. The proposed algorithm, UniPrompt, (1) clusters the input space and uses clustered batches so that each batch likely corresponds to a different facet of the task, and (2) utilizes a feedback mechanism to propose adding, editing or deleting a section, which in turn is aggregated over a batch to capture generalizable facets. Empirical evaluation on multiple datasets and a real-world task shows that prompts generated using UniPrompt obtain higher accuracy than human-tuned prompts and those from state-of-the-art methods. In particular, our algorithm can generate long, complex prompts that existing methods are unable to generate.

## introduction given a task, choosing an input prompt is a key part of optimizing large language model's (llm) performance @xcite . minor changes in prompt can lead to performance gains or losses, necessitating prompt engineering @xcite . typically, manuallydeveloped prompts combine task description with a few in-context examples, along with modifiers like chain-of-thought @xcite . for greater accuracy, human prompt engineers spend considerable time to identify errors with a current prompt, consider the different facets of a task (e.g., counterexamples, explanations, analogies) that may fix those errors, and include them in the prompt. for instance, for a hate speech classification task, in addition to the definition, it may be helpful to specify the facets that lead to hate speech: the context of conversation, identifying intent, and differentiating hate speech from opinions or closely-related concepts such as vulgarity and profanity. to avoid the above cumbersome manual process, recent work aims to automate the process of generating natural language prompts that are also interpretable. since language tokens are discrete, this leads to a challenging discrete optimization problem with a combinatorial space of possible outputs. techniques for prompt optimization can be divided in two categories: non-directional, e.g., random search @xcite and genetic algorithms @xcite , where the sampling of new input is "random" and does not explicitly aim to reduce error on a train set; and directional, where the sampling of new input depends on some error measure on a representative train sample. recently, more complex methods have been proposed in the second category including rl @xcite , updating prompts using feedback from auxiliary llms @xcite , and optimizing the input to a small lm that generates the prompt @xcite . while these techniques focus on editing parts of a given prompt, they are developed with the goal of obtaining a concise description of the task. none of these focus on ensuring multiple facets of a task are added to the prompt. in this paper, we propose uniprompt, a prompt optimization method to cover diverse, multiple facets of a task and improve overall accuracy. to simulate the manual prompt engineering process, we propose that prompts be constructed from individual sections, where each section may correspond to a different facet that humans may consider for the task. prompt editing proceeds at a sectionlevel: we can add, edit or delete a section from the prompt. similar to @xcite , prompt edits are based on an auxiliary llm's feedback about example predictions with the current prompt. we contribute two key insights in this feedback-based optimization process. first, we find that the feedback on a single example or a randomly selected batch of examples does not yield generalizable facet descriptions. instead, we propose clustering the inputs and creating mini-batches such that each mini-batch is sourced from a single cluster. second, even with clustered batches, the feedback tends to overfit to specific examples or their properties. to generate a prompt edit that conveys a generalizable concept relevant to the task, we propose generating edits at a minibatch level and then aggregating them at the batch level to yield the final edit (figure 1 ). while the two insights may appear simple, we show that they significantly improve extracting diverse task facets. we evaluate uniprompt on several benchmarks where it consistently achieves higher accuracy than existing prompt optimization methods. on ethos, a hate speech dataset, uniprompt obtains 94% accuracy whereas the next best method obtains 82%. even though uniprompt focuses only on the instruction and does not include any in-context examples, we find that its instructiononly accuracy is often higher than methods such as dspy @xcite ) that optimize both. in the few-shot setting, we also compare uniprompt to @xcite , a state-of-theart prompt composition method. we find that uniprompt, requiring only one llm call at inference time, obtains the same accuracy as med-prompt that requires five calls. if we allow multiple calls to uniprompt, we obtain over 4% accuracy gains. finally, we also evaluate uniprompt on a real-world semantic matching task in a web search engine. compared to the best manual prompt, the prompt generated from uniprompt leads to over 5% increase in accuracy on the rare class and nearly 2% accuracy increase overall. ## related work here, we highlight relevant work that are not addressed in the manuscript otherwise. @xcite present a discrete prompt optimization method, rlprompt, using reinforcement learning, where a policy network learns to generate effective prompts through reward-based training, with an emphasis on enhancing training efficiency through effective reward stabilization techniques. a drawback of such automatic prompt optimization approaches @xcite @xcite is that the prompts generated tend to be short, often comprising only one or two sentences, which may not fully encapsulate the complexity of the task at hand. another recent line of work leverages human feedback. automated prompt optimization with human feedback @xcite optimizes prompts for black-box llms using human preference feedback. besides the obvious overhead, it might also introduce potential biases. prior research @xcite has highlighted the significance of specific sections within prompts. however, existing methods do not specifically target the optimization of individual sections and their respective contents within the prompts. @xcite investigate the use of greedy and genetic algorithms to edit lengthy prompts. their method focuses on paraphrasing one line at a time starting from an existing prompt, compared to our goal of learning facets of a task from scratch. another orthogonal line of work explores algorithmic selection of in-context examples @xcite @xcite @xcite . ## uniprompt: capturing task facets state-of-the-art prompt optimization methods such as protegi @xcite and textgrad @xcite iteratively optimize the prompt for a given task. at a high-level, they proceed as follows: (1) start with an initial prompt and a training dataset of ⟨question, answer⟩ pairs for the task, (2) randomly sample from the questions wrongly answered by the current prompt to form a batch, (3) use an expert llm to obtain feedback on the random batch, (4) apply the feedback to the prompt. this procedure is illustrated in figure 1 [left]. our work is motivated by three key observations. 1. larger models are more amenable to prompt optimization. we observe that the change in the tell if the following is hate speech(1) or not(0) ... the intent behind the words, and the potential harm it may cause... non-hate speech includes respectful and inclusive language that does not seek to demean or harm others... carefully analyze ... discriminatory, derogatory, or violent language ... a particular group, such as based on religion or gender... potential impact on the targeted individual or group ... justify your decision with a well-reasoned explanation. include a clear definition of hate speech, … ... emphasize the impact of language, and encourage critical analysis ... determine if they qualify as hate speech. ## results and analysis we present detailed quantitative and qualitative results, along with key ablations. ## conclusions we presented a method inspired by the human prompt engineering process to generate complex prompts from scratch that include different facets of a task. our algorithm provides significant improvements over baseline prompt generation methods on multiple standard datasets. just like incontext learning @xcite , task facet learning could also benefit from connections to submodular optimization @xcite . we leave this as future work. note the focus on small changes in input through the parameter r. intuitively, the lipschitz property bounds the maximum change in f given a small change in input prompt. typically, the lower bound of error for any sequential optimization algorithm over f is directly proportional to the lipschitz constant l (malherbe and vayatis, 2017). therefore, for faster convergence, it is desirable to have a low l, especially near the optimal solution. empirically, we estimate l by sampling taskrelevant prompts so that they are close to the optimal solution. then we make small changes to the prompt such that the semantic meaning stays the same and measure the change in f (see appendix a.2 for experimental details). we show the change in f per change in input for gpt4 and gpt3.5 models in figure 2 for the ethos, gsm8k and medqa datasets. assuming ϵ = 0.05, probabilistic lipschitz constant l for gpt4 @xmath0, whereas it is higher for gpt3.5. thus, as the model sizes increases, the probabilistic lipschitz constant decreases. so, larger models are more amenable to prompt optimization.