AMPO : Automatic Multi-Branched Prompt Optimization (2024)

Abstract: Prompt engineering is very important to enhance the performance of large language models (LLMs). When dealing with complex issues, prompt engineers tend to distill multiple patterns from examples and inject relevant solutions to optimize the prompts, achieving satisfying results. However, existing automatic prompt optimization techniques are only limited to producing single flow instructions, struggling with handling diverse patterns. In this paper, we present AMPO, an automatic prompt optimization method that can iteratively develop a multi-branched prompt using failure cases as feedback. Our goal is to explore a novel way of structuring prompts with multi-branches to better handle multiple patterns in complex tasks, for which we introduce three modules: Pattern Recognition, Branch Adjustment, and Branch Pruning. In experiments across five tasks, AMPO consistently achieves the best results. Additionally, our approach demonstrates significant optimization efficiency due to our adoption of a minimal search strategy.

## introduction prompt engineering involves creating the best possible prompts to enhance the performance of large language models (llms). it has become increasingly significant in the development of llm applications @xcite . creating suitable prompts frequently demands considerable human effort, specialized knowledge, and numerous trial-and-error attempts @xcite . therefore, investigating efficient automatic prompt engineering techniques is crucial @xcite . in recent times, automatic prompt optimization methods based on llms have seen extensive explo-figure 1 : our prompt optimization approach aims to iteratively optimize a single flow of instructions into a multi-branched format to handle multiple patterns. despite the success of feedback-based optimization methods, we find that the optimized prompts are primarily achieved by meticulously rewriting certain steps, attempting to provide more details. essentially, they are mainly a form of single flow instructions. as shown in figure 1 , when dealing with complex issues, categorizing problems in advance can help llm analyze issues more systematically and easier to find appropriate solutions @xcite @xcite . it is evident that an llm optimizer generating a single flow instructions struggles with handling various patterns. for example, current feedback-based methods either fail to provide effective fixes or cause numerous regressions when failed cases are not addressed by the single flow instructions @xcite . given the complexity of real-world scenarios, we contend that a single flow of instructions is inadequate. the llm optimizer should identify multiple patterns from failure cases, which in turn allows for the exploration and development of more adaptable prompt structures. motivated by this, we propose ampo, a prompt optimization method that moderately transforms a prompt into a multibranched format and then optimizes the prompt using failure cases as a guide. the key aspect of this process is to create an adaptive prompt structure that aligns with the complexity of the task. to achieve this, we introduce three modules: (1) pattern recognition is responsible for analyzing the pattern of the failure cases. (2) branch adjustment can adaptively choose between adding the branches to address the new pattern and providing more details to enhance the existing branches. (3) branch pruning takes both pre-pruning and postpruning techniques to prevent the prompt from overfitting. the advantage of our multi-branched prompt structure is that it allows the target llm to autonomously determine the most appropriate path for each sample during inference, thereby enhancing its ability to handle diverse patterns and complexities. we conduct experiments across five tasks, encompassing various levels of complexity. our experimental results show that ampo consistently achieves the best results across five tasks from general nlu and domain knowledge. additionally, compared with other feedback-based optimization approaches, our approach exhibits impressive optimization efficiency due to our adoption of a minimal search strategy. our contributions are as follows: ## motivating example to illustrate the importance of recognizing and handling different patterns when dealing with complex issues, we take search query understanding task as an example, in this task, we employ llm to predict a personalized query intent using the current query and user's search history as input. as the saying goes "there are a thousand hamlets in a thousand people's eyes", predicting personalized intents is quite difficult. according to expert experience, the best approach is to first categorize users' search behaviors into distinct classes and then develop a strategy for predicting personalized intent for each category. for example, if the current query is a refinding query-identical to a previous query-the most likely intent is to revisit the same webpage from the user's recent clicks. if the current query is a reformulation query derived from any previous queries, the intent should be personalized based on the nature of the reformulation, such as an expansion or filtering of the original query. when the query is a domain preference query, where the user's history indicates a preference for specific domains related to the current query, we should refine the query intent using this domain preference. inspired by this, ampo introduces multiple branches to handle various categories, adaptively expanding or pruning them to achieve the most appropriate coverage. ## methodology given a task τ specified by a provided training set as d @xmath0, a 1 ), (q 2 , a 2 )..., (q n , a n )}, where q i /a i are input/output pairs from each entry, we start with an initial prompt p 0 . the model input consists of p and q i , and the base llm β makes the prediction based on p β (a i |q i , p ). the goal of prompt optimization is to find the optimal prompt p * that maximizes the performance towards a measure function r (e.g., accuracy) over d train . ## conclusion in this paper, we proposed automatic multi-branched prompt optimization (ampo), which explicitly converts a prompt into a multi-branched format and then iteratively refines it using fail-ure cases as feedback. specifically, we employ three llm agents working in tandem and propose guiding principles to balancing the adaptability of the multi-branched structure. experimental results demonstrate that ampo outperforms existing state-of-the-art feedback-based optimization approaches while significantly improving optimization efficiency.