Strategic-guided prompt optimization

The strategic-guided prompt optimization method addresses the issue of suboptimal LLM prompt optimization by developing detailed strategies from positive and negative experiences, enhancing LLMs' ability to produce accurate and tailored prompts for complex tasks.

WO2026055907A1PCT designated stage Publication Date: 2026-03-19MICROSOFT TECHNOLOGY LICENSING LLC +5
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2026-03-19

AI Technical Summary

Technical Problem

Existing LLM-based prompt optimization methods focus solely on correcting failed cases, which can adversely impact previously successful cases, and lack detailed instructions for complex tasks, leading to suboptimal prompts.

Method used

A strategic-guided prompt optimization method that identifies positive and negative experience sets to develop detailed strategies for improving initial prompts, integrating these strategies through crossover operations and paraphrasing to achieve better-performing prompts.

Benefits of technology

This approach enhances LLMs' ability to optimize prompts effectively for complex tasks by preserving successful cases and correcting failed ones, resulting in more accurate and tailored prompts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024118704_19032026_PF_FP_ABST
    Figure CN2024118704_19032026_PF_FP_ABST
Patent Text Reader

Abstract

The present disclosure proposes a method, apparatus and computer program product for prompt optimization. An initial prompt may be received. The initial prompt may be executed, to obtain a successful case set and a failed case set associated with the initial prompt. A positive experience set of the initial prompt may be identified through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set. A negative experience set of the initial prompt may be identified through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set. The initial prompt may be optimized with the positive experience set and the negative experience set.
Need to check novelty before this filing date? Find Prior Art

Description

STRATEGIC-GUIDED PROMPT OPTIMIZATIONBACKGROUND

[0001] In recent years, Large Language Models (LLMs) have been widely adopted in Artificial Intelligence (AI) fields because of their powerful natural language processing capabilities. Herein, an LLM refers to a deep learning model that can understand the meaning of natural language, generate natural language texts, or perform other natural language tasks. It should be appreciated that the LLMs include multi-modal models that can perform processing tasks for natural language as well as other modalities. Humans interact with an LLM through prompts. The prompts are used to instruct the LLM to perform specified tasks. People have realized that the prompts play a crucial role in guiding the LLM’ responses and ensuring the outputs are relevant, accurate, and useful. Thus, the prompt engineering technique that involves generating suitable prompts for enhancing the performance of the LLMs becomes an important technique in the AI fields.SUMMARY

[0002] This Summary is provided to introduce a selection of concepts that are further described below in the Detailed Description. It is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.

[0003] Embodiments of the present disclosure propose a method, apparatus and computer program product for prompt optimization. An initial prompt may be received. The initial prompt may be executed, to obtain a successful case set and a failed case set associated with the initial prompt. A positive experience set of the initial prompt may be identified through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set. A negative experience set of the initial prompt may be identified through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set. The initial prompt may be optimized with the positive experience set and the negative experience set to generate one or multiple revised prompts. After execution, one or more generated prompts may be selected as a new initial prompt for the next round of prompt optimization. This iterative process can  be repeated until a predetermined iteration stopping condition is met.

[0004] It should be noted that the above one or more aspects comprise the features hereinafter fully described and particularly pointed out in the claims. The following description and the drawings set forth in detail certain illustrative features of the one or more aspects. These features are only indicative of the various ways in which the principles of various aspects may be employed, and this disclosure is intended to include all such aspects and their equivalents.BRIEF DESCRIPTION OF THE DRAWINGS

[0005] The disclosed aspects will hereinafter be described in connection with the appended drawings that are provided to illustrate and not to limit the disclosed aspects.

[0006] FIG. 1 illustrates an exemplary process for strategic-guided prompt optimization according to an embodiment of the present disclosure.

[0007] FIG. 2 illustrates an exemplary process for identifying a positive experience set and a negative experience set of an initial prompt according to an embodiment of the present disclosure.

[0008] FIG. 3 illustrates an exemplary process for determining a first strategy set based on a positive experience set according to an embodiment of the present disclosure.

[0009] FIG. 4 illustrates an exemplary process for generating a first strategy based on a positive experience according to an embodiment of the present disclosure.

[0010] FIG. 5 illustrates an exemplary process for evaluating a first strategy according to an embodiment of the present disclosure.

[0011] FIG. 6 illustrates an exemplary process for optimizing an initial prompt according to an embodiment of the present disclosure.

[0012] FIG. 7 illustrates an exemplary process for generating a first revised prompt based on a positive experience according to an embodiment of the present disclosure.

[0013] FIG. 8A illustrates an example of generating a revised prompt based on a positive experience according to an embodiment of the present disclosure.

[0014] FIG. 8B illustrates an example of generating a revised prompt based on a negative experience according to an embodiment of the present disclosure.

[0015] FIG. 9 is a flowchart of an exemplary method for prompt optimization according to an embodiment of the present disclosure.

[0016] FIG. 10 illustrates an exemplary apparatus for prompt optimization  according to an embodiment of the present disclosure.

[0017] FIG. 11 illustrates another exemplary apparatus for prompt optimization according to an embodiment of the present disclosure.DETAILED DESCRIPTION

[0018] The present disclosure will now be discussed with reference to several example implementations. It is to be understood that these implementations are discussed only for enabling those skilled in the art to better understand and thus implement the embodiments of the present disclosure, rather than suggesting any limitations on the scope of the present disclosure.

[0019] Some prompt optimization methods have been developed, to optimize a prompt to be provided to an LLM, thereby facilitating the LLM to generate more accurate model outputs. Recently, many studies have leveraged the power of LLMs themselves as prompt generators or optimizers. That is, LLMs may be used to generate or optimize prompts. These LLM-based prompt optimization methods have proven effective across multiple tasks and represented a promising approach for optimizing prompts. However, these prompt optimization methods may focus on analyzing and correcting failed cases, which may adversely impact previously successful cases while fixing the failed ones. Moreover, these methods typically provide task descriptions and context for LLMs to perform prompt optimization without offering detailed instructions on how to accomplish them, relying entirely on the LLMs’ intrinsic capabilities. This reliance solely on the LLMs’ intrinsic capabilities can be problematic for complex tasks, as the LLMs may not have the necessary skills to execute them effectively, leading to suboptimal prompts.

[0020] Embodiments of the present disclosure propose strategic-guided prompt optimization. A prompt to be optimized may be referred to as an initial prompt. After receiving the initial prompt, the initial prompt may be executed to obtain a successful case set and a failed case set associated with the initial prompt. A successful case refers to a case with an actual execution result matching its desired execution result, while a failed case refers to a case with an actual execution result not matching its desired execution result. Both the successful case set and the failed case set are equally analyzed and used for optimizing the initial prompt. The technical effects of the above approach lie in correcting the failed cases but avoiding bias towards the failed cases, thereby  mitigating the detrimental impacts on the previously successful cases and achieving overall accuracy improvement.

[0021] When optimizing the initial prompt, a positive experience set of the initial prompt may be identified through analyzing the successful case set. The positive experience set may include one or more positive experiences and indicate one or more factors of the initial prompt achieving the successful case set. A negative experience set of the initial prompt may be identified through analyzing the failed case set. The negative experience set may include one or more negative experiences and indicate one or more reasons of the initial prompt causing the failed case set. The technical effects of identifying the positive experience set and the negative experience set lie in informing LLMs of actions to be taken and errors to be avoided when optimizing the initial prompt, which facilitates obtaining a better-performing prompt.

[0022] Subsequently, a first revised prompt set may be generated based on the initial prompt and the positive experience set. Preferably, a first strategy set for improving the initial prompt may be firstly developed through in-context learning based on the positive experience set, the initial prompt, and optionally one or multiple successful cases, and then the first revised prompt set may be generated based on the initial prompt, the positive experience set and the first strategy set. Similarly, a second revised prompt set may be generated based on the initial prompt and the negative experience set. Preferably, a second strategy set for improving the initial prompt may be firstly developed through in-context learning based on the negative experience set, the initial prompt, and optionally one or multiple failed cases, and then the second revised prompt set may be generated based on the initial prompt, the negative experience set and the second strategy set. The first strategy set and the second strategy set can include detailed and explicit execution strategies that outline the necessary actions for improving the initial prompt. The technical effects of developing the strategies lie in offering step-by-step guidance for prompt optimization, unlocking LLMs’ potential to optimize prompts effectively for tasks where they lack sufficient skills, and achieving more stable and effective prompt optimization. Moreover, the strategies can induce effective domain knowledge. By integrating these strategies, the LLMs’ ability to engage in deeper analysis can be enhanced, thereby producing prompts that are more specifically tailored to the relevant area of expertise, which is particularly beneficial for tasks that necessitate domain knowledge.

[0023] Next, crossover operations may be performed on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set. For example, two prompts, one from the first revised prompt set and the other from the second revised prompt set, are selected and fused using an LLM with evolutionary algorithms to generate a new prompt as the hybrid prompt.

[0024] Once the hybrid prompt set is obtained, preferably, the hybrid prompts in the hybrid prompt set are paraphrased based on a history prompt set and their scores evaluated on a validation set, referred to as the history prompt set, to obtain a paraphrased prompt set. Preferably, the history prompt set contains historical prompts with good scores. Each hybrid prompt in the hybrid prompt set is paraphrased by an LLM according to one or multiple historic prompts and their scores from the history prompt set. The resulting paraphrased prompts form the paraphrased prompt set.

[0025] Finally, each prompt from the hybrid prompt set and / or the paraphrased prompt set is evaluated to obtain its score. A prompt with the highest score in the hybrid prompt set and / or the paraphrased prompt set may be retained as a current optimized prompt. The above process may be iteratively performed, taking the current optimized prompt as the initial prompt for the next iteration, until a predetermined iteration stopping condition is met. The final optimized prompt obtained after the iterations end can achieve effective overall accuracy improvements.

[0026] The above description illustrates the process for optimizing the initial prompt with the positive experience set and the negative experience set. However, the embodiments of the present disclosure are not limited to this. After identifying the positive experience set and the negative experience set, the initial prompt may be optimized through other alternative implementations.

[0027] In an alternative implementation, a first strategy set may be generated from the positive experience set to provide detailed guidance to revise the initial prompt for preserving successful cases, and a second strategy set may be generated from the negative experience set to provide detailed guidance to revise the initial prompt for correcting failed cases. These two strategy sets may be merged into a joint strategy set to provide detailed guidance to revise the initial prompt for correcting failed cases while preserving successful cases. The joint strategy set may be used together with its corresponding experience set (s) , and optionally one or multiple successful and / or failed cases to revise the initial prompt to obtain a revised prompt set. Preferably, a history  prompt set and their scores evaluated on a validation set is collected. A paraphrased prompt set may be obtained by using an LLM to paraphrase each prompt of the revised prompt set based on one or multiple prompts and their scores from the history prompt set. Each prompt from the revised prompt set and / or the paraphrased prompt set is evaluated to obtain its score. A prompt with the highest score in the revised prompt set and / or the paraphrased prompt set may be retained as a current optimized prompt. The above process may be iteratively performed, taking the current optimized prompt as the initial prompt for the next iteration, until a predetermined iteration stopping condition is met. The final optimized prompt obtained after the iterations end can achieve effective overall accuracy improvements.

[0028] In another alternative implementation, the positive experience set and the negative experience set may be combined as a joint experience set, and a strategy set for improving the initial prompt may be developed through in-context learning based on the joint experience set, the initial prompt, and optionally one or multiple successful and / or failed cases, and then a revised prompt set may be generated based on the initial prompt, the joint experience set, and the strategy set. Preferably, a history prompt set and their scores evaluated on a validation set is collected. A paraphrased prompt set may be obtained by using an LLM to paraphrase each prompt of the revised prompt set based on one or multiple prompts and their scores from the history prompt set. Each prompt from the revised prompt set and / or the paraphrased prompt set is evaluated to obtain its score. A prompt with the highest score in the revised prompt set and / or the paraphrased prompt set may be retained as a current optimized prompt. The above process may be iteratively performed, taking the current optimized prompt as the initial prompt for the next iteration, until a predetermined iteration stopping condition is met. The final optimized prompt obtained after the iterations end can achieve effective overall accuracy improvements.

[0029] Various embodiments of the present disclosure will hereinafter be described in detail in connection with the appended drawings.

[0030] A task dataset D= { (x1, y1) , (x2, y2) , … (xn, yn) } may be obtained. The task dataset includes a plurality of data pairs, and each data pair (xi, yi) may include an input xi and its desired output yi. The goal of prompt optimization is to identify the optimal prompt p* that enables an LLM to generate responses closely matching the desired outputs. This problem can be formalized using the following mathematical  model:

[0031] FIG. 1 illustrates an exemplary process 100 for strategic-guided prompt optimization according to an embodiment of the present disclosure.

[0032] An initial prompt 102 may be received. The initial prompt 102 is a prompt to be optimized.

[0033] A positive experience set 112 and a negative experience set 114 of the initial prompt 102 may be identified through an analyzer 110. The positive experience set 112 may include one or more positive experiences and indicate one or more factors of the initial prompt 102 achieving successful cases. The negative experience set 114 may include one or more negative experiences and indicate one or more reasons of the initial prompt 102 causing failed cases. The successful cases and the failed cases are obtained through executing the initial prompt 102. An exemplary process for identifying the positive experience set 112 and the negative experience set 114 will be illustrated later in conjunction with FIG. 2.

[0034] Subsequently, a first strategy set 122 and a second strategy set 124 for improving the initial prompt 102 may be determined through a refiner 120. The first strategy set 122 may include one or more strategies, and each strategy may be generated based on a positive experience in the positive experience set 112. The second strategy set 124 may include one or more strategies, and each strategy may be generated based on a negative experience in the negative experience set 114. An exemplary process for determining the first strategy set 122 will be illustrated later in conjunction with FIG. 3 to FIG. 5. The process for determining the second strategy set 124 may be similar to the process for determining the first strategy set 122.

[0035] Next, the initial prompt 102 may be optimized through an optimizer 130, to obtain a current optimized prompt 132. For example, a first revised prompt set may be generated based on the initial prompt 102, the positive experience set 112 and the first strategy set 122. A second revised prompt set may be generated based on the initial prompt 102, the negative experience set 114 and the second strategy set 124. Crossover operations may be performed on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set. Preferably, each hybrid prompt in the hybrid prompt set may be generated by fusing two prompts, one from the first revised prompt  set and the other from the second revised prompt set, using an LLM with evolutionary algorithms. The hybrid prompt set is then paraphrased to obtain a paraphrased prompt set using an LLM according to a history prompt set that contains historical prompts and their scores. Preferably, the history set contains historical prompts with good scores. Each hybrid prompt from the hybrid prompt set is paraphrased according to one or multiple prompts and their scores from the history prompt set. The hybrid prompt set and / or the paraphrased prompt set may be evaluated, to obtain their scores. A prompt with the highest score in the hybrid prompt set and / or the paraphrased prompt set may be retained as the current optimized prompt 132. An exemplary process for optimizing the initial prompt 102 will be illustrated later in conjunction with FIG. 6 to FIG. 7.

[0036] The above process may be iteratively performed, until a predetermined iteration stopping condition is met. The iteration stopping condition depends on actual application requirements. In an example, the iteration stopping condition is associated with an iteration count threshold. If a current iteration count is larger than the iteration count threshold, the iteration stopping condition is met. Otherwise, if the current iteration count is not larger than the iteration count threshold, the iteration stopping condition is not met. In another example, the iteration stopping condition is associated with a cross-validation result obtained for the current optimized prompt. If the cross-validation result shows that the performance of the current optimized prompt from one or multiple current iterations is not significantly improved, the iteration stopping condition is met. Otherwise, if the cross-validation result shows that the performance of the current optimized prompt is significantly improved after the current iteration, the iteration stopping condition is not met.

[0037] If the iteration stopping condition is not met, the current optimized prompt may be provided to the analyzer 110 as an initial prompt 102, and the next iteration may be performed. If the iteration stopping condition is met, the iterations can end, and the better prompt of the current optimized prompt and the initial prompt 102 can be considered as the final optimized prompt. The final optimized prompt can achieve effective overall accuracy improvements.

[0038] It should be appreciated that the process 100 in FIG. 1 is merely an example of the process for strategic-guided prompt optimization. Depending on actual application requirements, the steps in the process for prompt optimization may be replaced or modified in any manner, and the process may comprise more or fewer steps.

[0039] FIG. 2 illustrates an exemplary process 200 for identifying a positive experience set and a negative experience set of an initial prompt according to an embodiment of the present disclosure. The process 200 may be performed by the analyzer 110 in FIG. 1.

[0040] An initial prompt 202 may correspond to the initial prompt 102 in FIG. 1. A positive experience set 252 and a negative experience set 262 of the initial prompt 202 may be identified through performing the process 200. The positive experience set 252 and the negative experience set 262 may correspond to the positive experience set 112 and the negative experience set 114 in FIG. 1, respectively.

[0041] At 210, the initial prompt 202 may be executed, to obtain an initial successful case set 212 and an initial failed case set 214 associated with the initial prompt 202. The initial successful case set 212 includes one or more successful cases. The initial failed case set 214 includes one or more failed cases. The initial successful case set 212 and the initial failed case set 214 may be obtained through the following operations.

[0042] A task dataset D= { (x1, y1) , (x2, y2) , … (xn, yn) } may be obtained. The task dataset includes a plurality of data pairs, and each data pair (xi, yi) may include an input xi and its desired output yi. For example, the data pair may include a question and a reference answer for the question.

[0043] For each data pair in the task dataset, an input of the data pair and the initial prompt 202 may be provided to an LLM. By way of example only but not limitation, the LLM may be Generative Pre-trained Transformer-4 (GPT-4) or GPT-3.5-turbo. The LLM may generate an output corresponding to the input according to the initial prompt 202. If the generated output matches the desired output, this data pair may be considered as a successful case; while if the generated output does not match the desired output, this data pair may be considered as a failed case. Accordingly, the task dataset D may be partitioned into the initial successful case set 212 Dcorrect and the initial failed case set 214 Dincorrect.

[0044] Then, a predetermined number of successful cases may be selected from the initial successful case set 212 to form a successful case set 222, and a predetermined number of failed cases may be selected from the initial failed case set 214 to form a failed case set 224.

[0045] Subsequently, a positive experience set 252 of the initial prompt 202 may  be identified through analyzing the successful case set 222. The positive experience set 252 may indicate one or more factors of the initial prompt 202 achieving the successful case set 222. A negative experience set 262 of the initial prompt 202 may be identified through analyzing the failed case set 224. The negative experience set 262 may indicate one or more reasons of the initial prompt 202 causing the failed case set 224.

[0046] For example, at 230, a meta prompt 232 for identifying the positive experience set 252 may be constructed based on the initial prompt 202, the successful case set 222 and a meta prompt template 226. Herein, any prompt used for instructing an LLM to perform operations associated with the prompt optimization process may be referred to as a meta prompt, to be distinguished with any one of an initial prompt, an optimized prompt, etc. The meta prompt template 226 may include placeholders and / or statements for the initial prompt 202 and the successful case set 222, and an instruction for instructing an LLM to identify positive experiences from the initial prompt 202 and the successful case set 222. By way of example only but not limitation, the instruction in the meta prompt template 226 may be “As a logician, you are good at breaking down the internal logic of the problem step by step. I have provided you with a prompt and several examples that include triples of questions, actual answers, and reference answers. Your task is to summarize the { {num} } most valuable key points to improve your accuracy in solving this type of task” , where { {num} } is a hyperparameter defining the number of positive experiences that should be output.

[0047] After the meta prompt construction at 230, a resulting meta prompt 232 is input to an LLM 250 to identify positive experiences, leading to a positive experience set 252.

[0048] The process for identifying the negative experience set 262 may be similar to the process for identifying the positive experience set 252. For example, at 240, a meta prompt 242 for identifying the negative experience set 262 may be constructed based on the initial prompt 202, the failed case set 224 and a meta prompt template 228. The meta prompt template 228 may include placeholders and / or statements for the initial prompt 202 and the failed case set 224. The resulting meta prompt 242 is then sent to an LLM 260 to identify negative experiences, leading to a negative experience set 262. By way of example only but not limitation, the instruction in the meta prompt template 228 may be “As a logician, you are good at breaking down the internal logic of the problem step by step. I have provided you with a prompt and several examples  that include triples of questions, wrong answers, and reference answers. Your task is to identify { {num} } primary reasons why the prompt causes these wrong answers” , where { {num} } is a hyperparameter defining the number of negative experiences that should be output.

[0049] In the process 200, both the successful case set 222 and the failed case set 224 are equally analyzed and used for optimizing the initial prompt 202. The technical effects of the above approach lie in correcting the failed cases but avoiding bias towards the failed cases, thereby mitigating the detrimental impacts on the previously successful cases and achieving overall accuracy improvement. The positive experience set 252 identified through analyzing the successful case set 222 can indicate factors of the initial prompt 202 achieving the successful case set 222. The negative experience set 262 identified through analyzing the failed case set 224 can indicate reasons of the initial prompt 202 causing the failed case set 224. The technical effects of identifying the positive experience set and the negative experience set lie in informing LLMs of actions to be taken and errors to be avoided when optimizing the initial prompt, which facilitates obtaining a better-performing prompt.

[0050] It should be appreciated that the process 200 in FIG. 2 is merely an example of the process for identifying the positive experience set and the negative experience set of the initial prompt. Depending on actual application requirements, the steps in the process for identifying the positive experience set and the negative experience set may be replaced or modified in any manner, and the process may comprise more or fewer steps. For example, in a case where the initial successful case set 212 contains a small number of cases, the positive experience set 252 may be identified through analyzing the initial successful case set 212. Similarly, in a case where the initial failed case set 214 contains a small number of cases, the negative experience set 262 may be identified through analyzing the initial failed case set 214. In addition, the specific order or hierarchy of the steps in the process 200 is merely exemplary, and the process for identifying the positive experience set and the negative experience set may be performed in an order different from the described order.

[0051] Referring back to FIG. 1, after identifying the positive experience set 112 and the negative experience set 114, the first strategy set 122 and the second strategy set 124 for improving the initial prompt 102 may be determined through the refiner 120. The embodiments of the present disclosure propose to determine the first strategy set  122 and the second strategy set 124 through a two-step approach. FIG. 3 illustrates an exemplary process 300 for determining a first strategy set based on a positive experience set according to an embodiment of the present disclosure. The process for determining the second strategy set may be similar to the process for determining the first strategy set.

[0052] A positive experience set 302 in FIG. 3 may correspond to the positive experience set 112 in FIG. 1.

[0053] At 310, a first preliminary strategy set 312 may be generated based on the positive experience set 302. The first preliminary strategy set 312 may include one or more first strategies, and each strategy may be generated based on a positive experience in the positive experience set 302. An exemplary process for generating a first strategy will be illustrated later in conjunction with FIG. 4.

[0054] At 320, a first strategy set 322 may be selected from the first preliminary strategy set 312. For example, the first preliminary strategy set 312 may be evaluated, to obtain a score set corresponding to the first preliminary strategy set 312. For each first strategy in the first preliminary strategy set, the first strategy may be evaluated by an LLM based on some strategy quality criteria such as at least one of the match degree between the first strategy and a positive experience corresponding to the first strategy, the clarity of the first strategy, and the effectiveness of the first strategy. An exemplary process for evaluating the first strategy will be illustrated later in conjunction with FIG. 5. A predetermined number of first strategies with the highest scores may be extracted from the first preliminary strategy set 312, to form the first strategy set 322.

[0055] FIG. 4 illustrates an exemplary process 400 for generating a first strategy based on a positive experience according to an embodiment of the present disclosure. In the process 400, the in-context learning is employed to create a detailed and explicit execution strategy that outlines the necessary actions for improving the initial prompt.

[0056] An initial prompt 402 may correspond to the initial prompt 202 in FIG. 2. A successful case set 404 may correspond to the successful case set 222 in FIG. 2. A positive experience 406 may be one of the positive experience set 252 in FIG. 2.

[0057] A strategy example set 408 includes one or more strategy examples. The purpose of these strategy examples is to be used for in-context learning. Each strategy example may include a prompt, one or more cases associated with the prompt, one or more experiences corresponding to the prompt and the cases, and a tailored strategy.  The cases may be successful cases or failed cases. The tailored strategy may be devised for prevalent error types through an LLM with manual adjustments. For instance, in a mathematical computation task, the prevalent error types may include miscalculation, while in a language understanding task, the prevalent error types may include a lack of contextual comprehension or misunderstandings.

[0058] At 420, a meta prompt 422 for generating the first strategy 432 may be constructed based on the initial prompt 402, the successful case set 404, the positive experience 406, the strategy example set 408, and a meta prompt template 410. The meta prompt template 410 may include placeholders and / or statements for the initial prompt 402, the successful case set 404, the positive experience 406 and the strategy example set 408, and an instruction for instructing an LLM to generate a strategy. By way of example only but not limitation, the instruction in the meta prompt template 410 may be “As an expert in prompt engineer, your task is to create a step-by-step strategy guide on how to use specific experience based on provided prompt” .

[0059] At 430, the first strategy 432 may be generated with the meta prompt 422. The strategy generation at 430 may be performed by an LLM. The LLM can generate the first strategy 432 through in-context learning the strategy example set 408 in the meta prompt 422 and leveraging its intrinsic capabilities such as learning from examples, semantic understanding capability, logical inference capability, etc.

[0060] FIG. 5 illustrates an exemplary process 500 for evaluating a first strategy according to an embodiment of the present disclosure. Through the process 500, a first strategy 502 may be evaluated to obtain a score 522 of the first strategy 502. A positive experience 504 may be the experience corresponding to the first strategy 502. For example, if the first strategy 502 corresponds to the first strategy 432 in FIG. 5, the positive experience 504 may correspond to the positive experience 406 used to generate the first strategy 432. In the process 500, the first strategy 502 may be evaluated based on some strategy quality criteria such as at least one of the match degree between the first strategy 502 and the positive experience 504, the clarity of the first strategy 502, and the effectiveness of the first strategy 502.

[0061] At 510, a meta prompt 512 for evaluating the first strategy 502 may be constructed based on the first strategy 502, the positive experience 504 and a meta prompt template 506. The meta prompt template 506 may include placeholders and / or statements for the first strategy 502 and the positive experience 504, and an instruction  for instructing a LLM to evaluate a strategy. Preferably, the instruction may include one or more strategy quality criteria. The strategy quality criteria may involve, e.g., the match degree between a strategy and an experience corresponding to the strategy, the clarity of the strategy, the effectiveness of the strategy, etc. The technical effects of these strategy quality criteria lie in evaluating the strategy from different aspects, and providing a comprehensive evaluation of the strategy’s quality. By way of example only but not limitation, the instruction in the meta prompt template 506 may be: “As an experienced prompt engineering expert, your task is to evaluate a proposed strategy based on a specific experience. Rate the strategy for its appropriateness, clarity, and effectiveness in addressing the experience.

[0062] #Strategy Quality Criteria

[0063] 1. Match with Experience (M) : The strategy should be directly aimed at mitigating the issue described in the experience. A perfect alignment where the strategy completely addresses the experience issue scores 100 points, whereas a poor match scores lower, depending on how well it addresses the problem.

[0064] 2. Clarity of Strategy (C) : The strategy must be explained clearly and in detail. A strategy that is easy to understand and can be practically implemented by any teacher scores 100 points, while a strategy that is poorly described scores less or 0.

[0065] 3. Effectiveness in Addressing the Issue (E) : Consider how comprehensively the strategy deals with preventing errors and promoting understanding in steps. A strategy that effectively addresses both what should do and what should avoid to minimize errors scores 100 points. A strategy that partially addresses these aspects scores less.

[0066] We asked 5 experts to rate the strategy. Each expert evaluates the strategy independently.

[0067] #Output Format: [ {’ M’ : 78, ’ C’ : 85, ’ E’ : 90} , {’ M’ : 45 ... ] ” .

[0068] At 520, the first strategy 502 may be evaluated with the meta prompt 512, to output the score 522 of the first strategy 502. The strategy evaluation at 520 may be performed by an LLM. The LLM can calculate the score 522 according to the meta prompt 512. Recognizing that LLMs may exhibit significant self-enhancement bias during evaluation, a different LLM than that generates the first strategy 502 is preferably used as the scorer to counteract this bias.

[0069] It should be appreciated that the process 300 to the process 500 in FIG. 3 to FIG. 5 as described above is merely an example of the process for determining the first strategy set based on a positive experience set. Depending on actual application requirements, the steps in the process for determining the first strategy set may be replaced or modified in any manner, and the process may comprise more or fewer steps. For example, in the process 400 in FIG. 4, the first strategy 432 is generated based on the initial prompt 402, the successful case set 404, the positive experience 406 and the strategy example set 408. However, in some embodiments, when generating the first strategy 432, the successful case set 404 may be not taken into account. That is, the first strategy 432 may be generated based on the initial prompt 402, the positive experience 406 and the strategy example set 408. In this case, the strategy example in the strategy example set 408 may not include the cases associated with the prompt.

[0070] The process for determining a second strategy set for improving the initial prompt may be similar to the process for determining the first strategy set. For example, a second preliminary strategy set may be generated based on a negative experience set of the initial prompt. The second preliminary strategy set may include one or more second strategies. Each second strategy may be based on the initial prompt, a failed case set associated with the initial prompt, a negative experience corresponding to the second strategy, and the strategy example set. Subsequently, a second strategy set may be selected from the second preliminary strategy set. For example, the second preliminary strategy set may be evaluated, to obtain a score set corresponding to the second preliminary strategy set. For each second strategy in the second preliminary strategy set, the second strategy may be evaluated based on some strategy quality criteria such as at least one of the match degree between the second strategy and a negative experience corresponding to the second strategy, the clarity of the second strategy, and the effectiveness of the second strategy. A predetermined number of second strategies with the highest scores may be extracted from the second preliminary strategy set, to form the second strategy set.

[0071] Through the above process, detailed and explicit execution strategies that outline the necessary actions for improving the initial prompt can be developed. The technical effects of developing the strategies lie in offering step-by-step guidance for prompt optimization, unlocking LLMs’ potential to optimize prompts effectively for tasks where they lack sufficient skills, and achieving more stable and effective prompt  optimization. Moreover, the strategies can induce effective domain knowledge. By integrating these strategies, the LLMs’ ability to engage in deeper analysis can be enhanced, thereby producing prompts that are more specifically tailored to the relevant area of expertise, which is particularly beneficial for tasks that necessitate domain knowledge.

[0072] Referring back to FIG. 1, after determining the first strategy set 122 and the second strategy set 124, the initial prompt 102 may be optimized through an optimizer 130, to obtain the current optimized prompt 132. FIG. 6 illustrates an exemplary process 600 for optimizing an initial prompt according to an embodiment of the present disclosure. Although LLMs are capable of processing long text inputs, they may struggle to comprehensively and meticulously consider the details of each part when provided with positive and negative experiences, along with their respective strategies. Consequently, the process 600 adopts a method that optimizes the initial prompt with these experiences and strategies separately and then integrates them through a crossover procedure.

[0073] At 620, a first revised prompt set 622 may be generated based on an initial prompt 602, a successful case set 604, a positive experience set 606 and a first strategy set 608. In addition, a second revised prompt set 624 may be generated based on the initial prompt 602, a failed case set 614, a negative experience set 616 and a second strategy set 618. The first revised prompt set 622 includes one or more first revised prompts, and each first revised prompt may be generated based on the initial prompt 602, the successful case set 604, a positive experience in the positive experience set 606 and a first strategy in the first strategy set 608 corresponding to the positive experience. An exemplary process for generating the first revised prompt will be illustrated later in conjunction with FIG. 7. The second revised prompt set 624 includes one or more second revised prompts. The process for generating the second revised prompt may be similar to the process for generating the first revised prompt.

[0074] It should be appreciated that the step 620 in FIG. 6 is merely an example of the step for prompt generation. In some embodiments, when generating the first revised prompt set 622, the successful case set 604 may be not taken into account. That is, the first revised prompt set 622 may be generated based on the initial prompt 602, the positive experience set 606 and the first strategy set 608. Similarly, when generating the second revised prompt set 624, the failed case set 614 may be not taken into account.  That is, the second revised prompt set 624 may be generated based on the initial prompt 602, the negative experience set 616 and the second strategy set 618.

[0075] At 630, crossover operations may be performed on the first revised prompt set 622 and the second revised prompt set 624, to produce a hybrid prompt set 632. For example, a first revised prompt may be selected from the first revised prompt set 622. A second revised prompt may be selected from the second revised prompt set 624. A crossover operation may be performed on the first revised prompt and the second revised prompt, to produce a hybrid prompt. The crossover operation may be performed by an LLM in combination with evolutionary algorithms.

[0076] Preferably, at 640, for each hybrid prompt in the hybrid prompt set 632, the hybrid prompt may be paraphrased based on a history prompt set and a history score set corresponding to the history prompt set, to obtain a paraphrased prompt set 642. The history prompt set and the history score set may be stored in a memory such as a cache. The history prompt set stored in the memory may be the highest quality prompts from history. Preferably, only the instruction part in the hybrid prompt may be paraphrased. The paraphrase may be performed by an LLM. By way of example only but not limitation, a meta prompt provided to the LLM for paraphrasing the hybrid prompt may be constructed by replacing placeholders with actual texts in a meta prompt template that contain the following instruction: “Mutate the following instruction reference [#Instruction-Score] and generate a better instruction” . The technical effect of paraphrasing the hybrid prompt lies in generating a prompt with higher quality than the hybrid prompt.

[0077] At 650, the hybrid prompt set 632 and / or the paraphrased prompt set 642 may be evaluated, to obtain a current optimized prompt 652. A score set corresponding to the hybrid prompt set 632 and / or a score set corresponding to the paraphrased prompt set 642 may be obtained through evaluation on a validation dataset. A prompt with the highest score in the hybrid prompt set 632 and / or the paraphrased prompt set 642 may be retained as the current optimized prompt 652, while other prompts in the hybrid prompt set 632 and / or the paraphrased prompt set 642 may be placed into a history prompt set along with their scores or discarded.

[0078] The evaluation at 650 may be performed according to metrics specific to the task of the initial prompt 602, such as accuracy, etc. Additionally, during iterative prompt optimization, it is crucial to assess the impact of new prompts on both  previously successful and failed cases. For this purpose, the embodiments of the present disclosure introduce two metrics: Adverse Correction Rate (ACR) and Beneficial Correction Rate (BCR) . The ACR quantifies the negative impact of prompt optimization by calculating the rate at which previously successful cases become failed cases after applying the new prompt, such as the current optimized prompt. Conversely, the BCR assesses the positive impact of prompt optimization by calculating the rate at which previously failed cases become successful cases after applying the new prompt, such as the hybrid prompt or the paraphrased prompt. The ACR and BCR may be formulated, in case of classification task, as:

[0079] where ppre (xi) and ppost (xi) represent the model’s actual output before and after optimization, respectively, for each input xi and its desired output yi. The technical effects of evaluating the new prompt according to the ACR and / or the BCR lie in clarifying the drawbacks and improvements of the new prompt, and providing an additional evaluation of the new prompt’s effectiveness, in addition to the commonly used metrics specific to the task of the initial prompt 602, especially when comparing different prompt optimization methods.

[0080] After obtaining the score set corresponding to the hybrid prompt set 632 and / or the score set corresponding to the paraphrased prompt set 642, prompts stored in the memory may be updated based on the hybrid prompt set 632, the paraphrased prompt set 642 and scores corresponding to the hybrid prompt set 632 and the paraphrased prompt set 642, such that the memory stores a predetermined number of prompts with the highest scores.

[0081] In the case where the paraphrase in 640 is not performed, the evaluation in 650 may be performed only on the hybrid prompt set 632. The current optimized prompt 652 may be a prompt with the highest score in the hybrid prompt set 632. Also, prompts stored in the memory may be updated based merely on the hybrid prompt set 632 and scores corresponding to the hybrid prompt set 632.

[0082] In the process 600, the current optimized prompt 652 is obtained through generating the first revised prompt set 622 based on the positive experience set 606 and  the first strategy set 608, generating the second revised prompt set 624 based on the negative experience set 616 and the second strategy set 618, and performing crossover operations on the first revised prompt set 622 and the second revised prompt set 624. The technical effects of the above approach lie in obtaining a prompt that integrates both the positive experiences and the negative experiences as well as corresponding strategies, thereby achieving more stable and effective prompt optimization result.

[0083] FIG. 7 illustrates an exemplary process 700 for generating a first revised prompt based on a positive experience according to an embodiment of the present disclosure.

[0084] An initial prompt 702 may correspond to the initial prompt 602 in FIG. 6. A successful case set 704 may correspond to the successful case set 604 in FIG. 6. A positive experience 706 may be one of the positive experience set 606 in FIG. 6. A first strategy 708 may be a first strategy in the first strategy set 608 in FIG. 6 which is generated based on the positive experience 706.

[0085] At 720, a meta prompt 722 for revising the initial prompt 702 may be constructed based on the initial prompt 702, the successful case set 704, the positive experience 706, the first strategy 708 and a meta prompt template 710. The meta prompt template 710 may include placeholders and / or statements for the initial prompt 702, the successful case set 704, the positive experience 706 and the first strategy 708, and an instruction for instructing a LLM to revise a prompt. By way of example only but not limitation, the instruction in the meta prompt template 710 may be “Based on my current prompt, refer to the experience and the strategy, write 1 different improved prompt” .

[0086] At 730, the initial prompt 702 may be revised into a first revised prompt 732 with the meta prompt 722. The prompt revision at 730 may be performed by an LLM.

[0087] The process for generating the second revised prompt in the second revised prompt set 624 may be similar to the process for generating the first revised prompt. For example, a meta prompt may be constructed based on the initial prompt, the failed case set, a negative experience, a second strategy corresponding to the negative experience and a meta prompt template. The meta prompt template may include placeholders and / or statements for the initial prompt, the failed case set, the negative experience and the second strategy corresponding to the negative experience, and an instruction for instructing a LLM to revise a prompt. The instruction may be the same  as the instruction in the meta prompt template 710. Subsequently, the initial prompt may be revised into the second revised prompt with the meta prompt.

[0088] It should be appreciated that the process 600 to the process 700 in FIG. 6 to FIG. 7 is merely an example of the process for optimizing the initial prompt. Depending on actual application requirements, the steps in the process for optimizing the initial prompt may be replaced or modified in any manner, and the process may comprise more or fewer steps. For example, an embodiment may not use a successful case set 704 in generating the first revised prompt 732 from an initial prompt 702. Similarly, an embodiment may not use a failed case set in generating the second revised prompt from an initial prompt.

[0089] FIG. 8A illustrates an example 800a of generating a revised prompt based on a positive experience according to an embodiment of the present disclosure.

[0090] The example 800a pertains to a sarcastic statement identification task. An initial prompt for this task is “Please identify the sarcastic statement from the given options. The context of the statement can also help you understand its sarcastic nature” .

[0091] A positive experience of this initial prompt identified through, e.g., the process 200 may be “Contextual Clues: Notice words or phrases that may indicate sarcasm. This can be a circumstance or expectation that sounds out of ordinary, such as losing money for winning in example” . This positive experience indicates a factor of the initial prompt achieving successful cases, that is, focusing on contextual clues, such as specific words or phrases.

[0092] Subsequently, a strategy that not only incorporates the basic experiential insights but also emphasizes the analysis of sentence tone, specifically to discern exaggeration or overstatement is developed. These additional insights are pivotal in determining the ironic intent of a sentence. The developed strategy may be “... 2. Look for any words or phrases that contradict usual or expected situations ... 3. Pay special attention to the tone of the statement ... 4. Locate any exaggeration or hyperbole in the statement ... ” This strategy may be generated based on the initial prompt, the positive experience, etc.

[0093] A revised prompt corresponding to the initial prompt may be “Please identify the sarcastic statement from the given options. Remember, sarcasm often involves statements that contradict usual situations or expectations and has a mocking or scornful tone. Look for statements that are implausible or absurd under  normal circumstances and note any exaggerations or hyperbole. The context of the statement can also help you understand its sarcastic nature. ” The revised part is highlighted in bold, which is generated based on the initial prompt, the positive experience, the strategy, etc.

[0094] FIG. 8B illustrates an example 800b of generating a revised prompt based on a negative experience according to an embodiment of the present disclosure.

[0095] The example 800b pertains to a movie recommendation task. An initial prompt for this task is “Let’s carefully analyze each step. Remember, in the absence of clear instructions or when there are multiple potential correct answers, it might be necessary to make an educated guess. Let’s begin” .

[0096] A negative experience of this prompt identified through, e.g., the process 200 may be “Ambiguity in the similarity criterion: The prompt asks to find a movie similar to a given set of movies without specifying the basis of similarity” . This negative experience indicates a reason of the initial prompt causing failed cases, that is, the absence of a clear similarity criterion.

[0097] To rectify this, a strategy focusing on identifying such a criterion by scrutinizing outlier data is developed. The developed strategy may be “... 3. Recognize Outliers: Also pay attention to the odd ones out, or the movies that don’ t share the above listed common factors. This could potentially give hints on what the ’similarity’ criterion could be ... ” This strategy may be generated based on the initial prompt, the negative experience, etc.

[0098] Subsequently, the initial prompt may be revised through addressing this diagnosed error and integrating the strategic insights. The revised prompt may be “Let’s carefully analyze each step. Given a set of movies, determine which option is most similar based on common factors such as genre, era, theme, actors, or director. Be aware of any outliers in the set, as this might give hints on what the ’similarity’ criterion could be. Remember, in the absence of clear instructions or when there are multiple potential correct answers, it might be necessary to make an educated guess. Let’s begin. ” The revised part is highlighted in bold, which may be generated based on the initial prompt, the negative experience, the strategy, etc.

[0099] It should be appreciated that the example 800a and the example 800b in FIG. 8A and FIG. 8B are merely examples of generating the revised prompts. Depending on actual application requirements, the revised prompts may contain other content. In  addition, the revised prompts illustrated in the example 800a and the example 800b do not represent the best or final optimization result.

[0100] The above description illustrates the process for optimizing the initial prompt with the positive experience set and the negative experience set in conjunction with FIG. 1 to FIG. 8B. However, the embodiments of the present disclosure are not limited to this. After identifying the positive experience set and the negative experience set, the initial prompt may be optimized through other alternative implementations.

[0101] In an alternative implementation, a first strategy set may be generated from the positive experience set to provide detailed guidance to revise the initial prompt for preserving successful cases, and a second strategy set may be generated from the negative experience set to provide detailed guidance to revise the initial prompt for correcting failed cases. The process for determining the first strategy set or the second strategy set may be similar to the process for determining the first strategy set 322 as described in connection with FIG. 3 and FIG. 4.

[0102] These two strategy sets may be merged into a joint strategy set to provide detailed guidance to revise the initial prompt for correcting failed cases while preserving successful cases. The joint strategy set may be used together with its corresponding experience set (s) , and optionally one or multiple successful and / or failed cases to revise the initial prompt to obtain a revised prompt set. The process for obtaining the revised prompt set may be similar to the process for obtaining the first revised prompt set 622 as described in connection with FIG. 6 and FIG. 7.

[0103] Preferably, a history prompt set and their scores evaluated on a validation set is collected. The history prompt set may be the highest quality prompts from history. A paraphrased prompt set may be obtained by using an LLM with evolutionary algorithms to paraphrase each prompt of the revised prompt set based on one or multiple prompts and their scores from the history prompt set. The process for paraphrasing the prompt in the revised prompt set may be similar to the process for paraphrasing the prompt in the hybrid prompt set 632 as described in connection with FIG. 6.

[0104] Each prompt from the revised prompt set and / or the paraphrased prompt set is evaluated to obtain its score. A prompt with the highest score in the revised prompt set and / or the paraphrased prompt set may be retained as a current optimized prompt. The process for evaluating the revised prompt set and / or the paraphrased prompt set may be similar to the process for evaluating the hybrid prompt set 632 and / or the  paraphrased prompt set 642 as described in connection with FIG. 6.

[0105] The above process may be iteratively performed, taking the current optimized prompt as the initial prompt for the next iteration, until a predetermined iteration stopping condition is met. The final optimized prompt obtained after the iterations end can achieve effective overall accuracy improvements.

[0106] In another alternative implementation, the positive experience set and the negative experience set may be combined as a joint experience set. A strategy set for improving the initial prompt may be developed through in-context learning based on the joint experience set, the initial prompt, and optionally one or multiple successful and / or failed cases. The process for determining the strategy set may be similar to the process for determining the first strategy set 322 as described in connection with FIG. 3 and FIG. 4.

[0107] A revised prompt set may be then generated based on the initial prompt, the joint experience set, and the strategy set. The process for obtaining the revised prompt set may be similar to the process for obtaining the first revised prompt set 622 as described in connection with FIG. 6 and FIG. 7.

[0108] Preferably, a history prompt set and their scores evaluated on a validation set is collected. The history prompt set may be the highest quality prompts from history. A paraphrased prompt set may be obtained by using an LLM with evolutionary algorithms to paraphrase each prompt of the revised prompt set based on one or multiple prompts and their scores from the history prompt set. The process for paraphrasing the prompt in the revised prompt set may be similar to the process for paraphrasing the prompt in the hybrid prompt set 632 as described in connection with FIG. 6.

[0109] Each prompt from the revised prompt set and / or the paraphrased prompt set is evaluated to obtain its score. A prompt with the highest score in the revised prompt set and / or the paraphrased prompt set may be retained as a current optimized prompt. The process for evaluating the revised prompt set and / or the paraphrased prompt set may be similar to the process for evaluating the hybrid prompt set 632 and / or the paraphrased prompt set 642 as described in connection with FIG. 6.

[0110] The above process may be iteratively performed, taking the current optimized prompt as the initial prompt for the next iteration, until a predetermined iteration stopping condition is met. The final optimized prompt obtained after the iterations end can achieve effective overall accuracy improvements.

[0111] FIG. 9 is a flowchart of an exemplary method 900 for prompt optimization according to an embodiment of the present disclosure.

[0112] At 910, an initial prompt may be received.

[0113] At 920, the initial prompt may be executed, to obtain a successful case set and a failed case set associated with the initial prompt.

[0114] At 930, a positive experience set of the initial prompt may be identified through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set.

[0115] At 940, a negative experience set of the initial prompt may be identified through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set.

[0116] At 950, the initial prompt may be optimized with the positive experience set and the negative experience set.

[0117] In an implementation, the optimizing the initial prompt may comprise: generating a first revised prompt set based on the initial prompt and the positive experience set; generating a second revised prompt set based on the initial prompt and the negative experience set; performing crossover operations on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set; evaluating the hybrid prompt set, to obtain a score set corresponding to the hybrid prompt set; and retaining a prompt with the highest score in the hybrid prompt set as a current optimized prompt.

[0118] The generating a first revised prompt set may comprise: determining a first strategy set for improving the initial prompt based on the positive experience set; and generating the first revised prompt set based on the initial prompt, the positive experience set and the first strategy set.

[0119] The determining a first strategy set for improving the initial prompt may comprise: generating a first preliminary strategy set based on the positive experience set; evaluating the quality of each strategy in the first preliminary strategy set, to obtain a score set corresponding to the first preliminary strategy set; and extracting, from the first preliminary strategy set, a predetermined number of first strategies with the highest scores, to form the first strategy set.

[0120] The generating a first preliminary strategy set may comprise, for each positive experience in the positive experience set: generating a first strategy based on  the initial prompt, the positive experience and a strategy example set.

[0121] The evaluating the quality of each strategy in the first preliminary strategy set may comprise, for each first strategy in the first preliminary strategy set: evaluating the first strategy based on one or more strategy quality criteria, the strategy quality criteria including at least one of the match degree between the first strategy and a positive experience corresponding to the first strategy, the clarity of the first strategy, and the effectiveness of the first strategy.

[0122] The evaluating the hybrid prompt set may comprise, for each hybrid prompt in the hybrid prompt set, calculating: the rate at which previously successful cases become failed cases after applying the hybrid prompt, and / or the rate at which previously failed cases become successful cases after applying the hybrid prompt.

[0123] The method 900 may further comprise: for each hybrid prompt in the hybrid prompt set, paraphrasing the hybrid prompt based on a history prompt set and a history score set corresponding to the history prompt set, to obtain a paraphrased prompt set; and evaluating the paraphrased prompt set, to obtain a score set corresponding to the paraphrased prompt set. The retaining a prompt with the highest score may comprise: retaining a prompt with the highest score in the hybrid prompt set and the paraphrased prompt set as a current optimized prompt.

[0124] The history prompt set and the history score set may be stored in a memory. The method 900 may further comprise: updating prompts stored in the memory based on the hybrid prompt set, the paraphrased prompt set and scores corresponding to the hybrid prompt set and the paraphrased prompt set, such that the memory stores a predetermined number of prompts with the highest scores.

[0125] In an implementation, the optimizing the initial prompt may comprise: determining a first strategy set for improving the initial prompt based on the positive experience set; determining a second strategy set for improving the initial prompt based on the negative experience set; merging the first strategy set and the second strategy set into a joint strategy set; generating a revised prompt set based on the initial prompt, the positive experience set, the negative experience set and the joint strategy set; evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; and retaining a prompt with the highest score in the revised prompt set as a current optimized prompt.

[0126] In an implementation, the optimizing the initial prompt may comprise:  combining the positive experience set and the negative experience set into a joint experience set; determining a strategy set for improving the initial prompt based on the joint experience set; generating a revised prompt set based on the initial prompt, the joint experience set and the strategy set; evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; and retaining a prompt with the highest score in the revised prompt set as a current optimized prompt.

[0127] It should be appreciated that the method 900 may further comprise any other steps / processes for prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0128] FIG. 10 illustrates an exemplary apparatus 1000 for prompt optimization according to an embodiment of the present disclosure.

[0129] The apparatus 1000 may comprise: a prompt receiving module 1010, for receiving an initial prompt; a prompt executing module 1020, for executing the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt; a positive experience identifying module 1030, for identifying a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set; a negative experience identifying module 1040, for identifying a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; and a prompt optimizing module 1050, for optimizing the initial prompt with the positive experience set and the negative experience set. Furthermore, the apparatus 1000 may further comprise any other modules configured for prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0130] FIG. 11 illustrates another exemplary apparatus 1100 for prompt optimization according to an embodiment of the present disclosure.

[0131] The apparatus 1100 may comprise: a processor 1110; and a memory 1120 storing computer-executable instructions. The computer-executable instructions, when executed, may cause the processor 1110 to: receive an initial prompt; execute the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt; identify a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the  initial prompt achieving the successful case set; identify a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; and optimize the initial prompt with the positive experience set and the negative experience set.

[0132] In an implementation, the optimizing the initial prompt may comprise: generating a first revised prompt set based on the initial prompt and the positive experience set; generating a second revised prompt set based on the initial prompt and the negative experience set; performing crossover operations on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set; evaluating the hybrid prompt set, to obtain a score set corresponding to the hybrid prompt set; and retaining a prompt with the highest score in the hybrid prompt set as a current optimized prompt.

[0133] The generating a first revised prompt set may comprise: determining a first strategy set for improving the initial prompt based on the positive experience set; and generating the first revised prompt set based on the initial prompt, the positive experience set and the first strategy set.

[0134] The determining a first strategy set for improving the initial prompt may comprise: generating a first preliminary strategy set based on the positive experience set; evaluating the quality of each strategy in the first preliminary strategy set, to obtain a score set corresponding to the first preliminary strategy set; and extracting, from the first preliminary strategy set, a predetermined number of first strategies with the highest scores, to form the first strategy set.

[0135] The generating a first preliminary strategy set may comprise, for each positive experience in the positive experience set: generating a first strategy based on the initial prompt, the positive experience and a strategy example set.

[0136] The evaluating the quality of each strategy in the first preliminary strategy set may comprise, for each first strategy in the first preliminary strategy set: evaluating the first strategy based on one or more strategy quality criteria, the strategy quality criteria including at least one of the match degree between the first strategy and a positive experience corresponding to the first strategy, the clarity of the first strategy, and the effectiveness of the first strategy.

[0137] The evaluating the hybrid prompt set may comprise, for each hybrid prompt  in the hybrid prompt set, calculating: the rate at which previously successful cases become failed cases after applying the hybrid prompt, and / or the rate at which previously failed cases become successful cases after applying the hybrid prompt.

[0138] The computer-executable instructions, when executed, may further cause the processor 1110 to: for each hybrid prompt in the hybrid prompt set, paraphrase the hybrid prompt based on a history prompt set and a history score set corresponding to the history prompt set, to obtain a paraphrased prompt set; and evaluate the paraphrased prompt set, to obtain a score set corresponding to the paraphrased prompt set. The retaining a prompt with the highest score may comprise: retaining a prompt with the highest score in the hybrid prompt set and the paraphrased prompt set as a current optimized prompt.

[0139] The history prompt set and the history score set may be stored in a memory. The computer-executable instructions, when executed, may further cause the processor 1110 to: update prompts stored in the memory based on the hybrid prompt set, the paraphrased prompt set and scores corresponding to the hybrid prompt set and the paraphrased prompt set, such that the memory stores a predetermined number of prompts with the highest scores.

[0140] In an implementation, the optimizing the initial prompt may comprise: determining a first strategy set for improving the initial prompt based on the positive experience set; determining a second strategy set for improving the initial prompt based on the negative experience set; merging the first strategy set and the second strategy set into a joint strategy set; generating a revised prompt set based on the initial prompt, the positive experience set, the negative experience set and the joint strategy set; evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; and retaining a prompt with the highest score in the revised prompt set as a current optimized prompt.

[0141] In an implementation, the optimizing the initial prompt may comprise: combining the positive experience set and the negative experience set into a joint experience set; determining a strategy set for improving the initial prompt based on the joint experience set; generating a revised prompt set based on the initial prompt, the joint experience set and the strategy set; evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; and retaining a prompt with the highest score in the revised prompt set as a current optimized prompt.

[0142] It should be appreciated that the processor 1110 may further perform any other steps / processes of the method for prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0143] The embodiments of the present disclosure propose a computer program product for prompt optimization, comprising a computer program that is executed by a processor for: receiving an initial prompt; executing the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt; identifying a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set; identifying a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; and optimizing the initial prompt with the positive experience set and the negative experience set. Furthermore, the computer program may be further executed for implementing any other steps / processes of the method for prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0144] The embodiments of the present disclosure may be embodied in a computer-readable medium for prompt optimization. The computer-readable medium may comprise instructions that, when executed, cause a processor to: receive an initial prompt; execute the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt; identify a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set; identify a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; and optimize the initial prompt with the positive experience set and the negative experience set. Furthermore, the instructions, when executed, may further cause the processor to perform any other steps / processes of the method for prompt optimization according to the embodiments of the present disclosure as mentioned above.

[0145] It should be appreciated that all the operations in the methods described above are merely exemplary, and the present disclosure is not limited to any operations in the methods or sequence orders of these operations, and should cover all other  equivalents under the same or similar concepts. In addition, the articles “a” and “an” as used in this specification and the appended claims should generally be construed to mean “one” or “one or more” unless specified otherwise or clear from the context to be directed to a singular form.

[0146] It should also be appreciated that all the modules in the apparatuses described above may be implemented in various approaches. These modules may be implemented as hardware, software, or a combination thereof. Moreover, any of these modules may be further functionally divided into sub-modules or combined together.

[0147] Processors have been described in connection with various apparatuses and methods. These processors may be implemented using electronic hardware, computer software, or any combination thereof. Whether such processors are implemented as hardware or software will depend upon the particular application and overall design constraints imposed on the system. By way of example, a processor, any portion of a processor, or any combination of processors presented in the present disclosure may be implemented with a microprocessor, microcontroller, digital signal processor (DSP) , a field-programmable gate array (FPGA) , a programmable logic device (PLD) , a state machine, gated logic, discrete hardware circuits, and other suitable processing components configured for performing the various functions described throughout the present disclosure. The functionality of a processor, any portion of a processor, or any combination of processors presented in the present disclosure may be implemented with software being executed by a microprocessor, microcontroller, DSP, or other suitable platform.

[0148] Software shall be construed broadly to mean instructions, instruction sets, code, code segments, program code, programs, subprograms, software modules, applications, software applications, software packages, routines, subroutines, objects, threads of execution, procedures, functions, etc. The software may reside on a computer-readable medium. A computer-readable medium may include, by way of example, memory such as a magnetic storage device (e.g., hard disk, floppy disk, magnetic strip) , an optical disk, a smart card, a flash memory device, random access memory (RAM) , read only memory (ROM) , programmable ROM (PROM) , erasable PROM (EPROM) , electrically erasable PROM (EEPROM) , a register, or a removable disk. Although memory is shown separate from the processors in the various aspects presented throughout the present disclosure, the memory may be internal to the  processors, e.g., cache or register.

[0149] The previous description is provided to enable any person skilled in the art to practice the various aspects described herein. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects. Thus, the claims are not intended to be limited to the aspects shown herein. All structural and functional equivalents to the elements of the various aspects described throughout the present disclosure that are known or later come to be known to those of ordinary skilled in the art are expressly incorporated herein and intended to be encompassed by the claims.

Claims

1.A method for prompt optimization, comprising:receiving an initial prompt;executing the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt;identifying a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set;identifying a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; andoptimizing the initial prompt with the positive experience set and the negative experience set.2.The method of claim 1, wherein the optimizing the initial prompt comprises:generating a first revised prompt set based on the initial prompt and the positive experience set;generating a second revised prompt set based on the initial prompt and the negative experience set;performing crossover operations on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set;evaluating the hybrid prompt set, to obtain a score set corresponding to the hybrid prompt set; andretaining a prompt with the highest score in the hybrid prompt set as a current optimized prompt.3.The method of claim 2, wherein the generating a first revised prompt set comprises:determining a first strategy set for improving the initial prompt based on the positive experience set; andgenerating the first revised prompt set based on the initial prompt, the positive experience set and the first strategy set.4.The method of claim 3, wherein the determining a first strategy set for improving the initial prompt comprises:generating a first preliminary strategy set based on the positive experience set;evaluating the quality of each strategy in the first preliminary strategy set, to obtain a score set corresponding to the first preliminary strategy set; andextracting, from the first preliminary strategy set, a predetermined number of first strategies with the highest scores, to form the first strategy set.5.The method of claim 4, wherein the generating a first preliminary strategy set comprises, for each positive experience in the positive experience set:generating a first strategy based on the initial prompt, the positive experience and a strategy example set.6.The method of claim 4, wherein the evaluating the quality of each strategy in the first preliminary strategy set comprises, for each first strategy in the first preliminary strategy set:evaluating the first strategy based on one or more strategy quality criteria, the strategy quality criteria including at least one of the match degree between the first strategy and a positive experience corresponding to the first strategy, the clarity of the first strategy, and the effectiveness of the first strategy.7.The method of claim 2, further comprising:for each hybrid prompt in the hybrid prompt set, paraphrasing the hybrid prompt based on a history prompt set and a history score set corresponding to the history prompt set, to obtain a paraphrased prompt set; andevaluating the paraphrased prompt set, to obtain a score set corresponding to the paraphrased prompt set, andwherein the retaining a prompt with the highest score comprises:retaining a prompt with the highest score in the hybrid prompt set and the paraphrased prompt set as a current optimized prompt.8.The method of claim 7, wherein the history prompt set and the history score  set are stored in a memory, and the method further comprises:updating prompts stored in the memory based on the hybrid prompt set, the paraphrased prompt set and scores corresponding to the hybrid prompt set and the paraphrased prompt set, such that the memory stores a predetermined number of prompts with the highest scores.9.The method of claim 1, wherein the optimizing the initial prompt comprises:determining a first strategy set for improving the initial prompt based on the positive experience set;determining a second strategy set for improving the initial prompt based on the negative experience set;merging the first strategy set and the second strategy set into a joint strategy set;generating a revised prompt set based on the initial prompt, the positive experience set, the negative experience set and the joint strategy set;evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; andretaining a prompt with the highest score in the revised prompt set as a current optimized prompt.10.The method of claim 1, wherein the optimizing the initial prompt comprises:combining the positive experience set and the negative experience set into a joint experience set;determining a strategy set for improving the initial prompt based on the joint experience set;generating a revised prompt set based on the initial prompt, the joint experience set and the strategy set;evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; andretaining a prompt with the highest score in the revised prompt set as a current optimized prompt.11.An apparatus for prompt optimization, comprising:a processor; anda memory storing computer-executable instructions that, when executed, cause the processor to:receive an initial prompt;execute the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt;identify a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set;identify a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; andoptimize the initial prompt with the positive experience set and the negative experience set.12.The apparatus of claim 11, wherein the optimizing the initial prompt comprises:generating a first revised prompt set based on the initial prompt and the positive experience set;generating a second revised prompt set based on the initial prompt and the negative experience set;performing crossover operations on the first revised prompt set and the second revised prompt set, to produce a hybrid prompt set;evaluating the hybrid prompt set, to obtain a score set corresponding to the hybrid prompt set; andretaining a prompt with the highest score in the hybrid prompt set as a current optimized prompt.13.The apparatus of claim 12, wherein the generating a first revised prompt set comprises:determining a first strategy set for improving the initial prompt based on the positive experience set; andgenerating the first revised prompt set based on the initial prompt, the positive experience set and the first strategy set.14.The apparatus of claim 13, wherein the determining a first strategy set for improving the initial prompt comprises:generating a first preliminary strategy set based on the positive experience set;evaluating the quality of each strategy in the first preliminary strategy set, to obtain a score set corresponding to the first preliminary strategy set; andextracting, from the first preliminary strategy set, a predetermined number of first strategies with the highest scores, to form the first strategy set.15.The apparatus of claim 14, wherein the generating a first preliminary strategy set comprises, for each positive experience in the positive experience set:generating a first strategy based on the initial prompt, the positive experience and a strategy example set.16.The apparatus of claim 14, wherein the evaluating the quality of each strategy in the first preliminary strategy set comprises, for each first strategy in the first preliminary strategy set:evaluating the first strategy based on one or more strategy quality criteria, the strategy quality criteria including at least one of the match degree between the first strategy and a positive experience corresponding to the first strategy, the clarity of the first strategy, and the effectiveness of the first strategy.17.The apparatus of claim 12, wherein the computer-executable instructions, when executed, further cause the processor to:for each hybrid prompt in the hybrid prompt set, paraphrase the hybrid prompt based on a history prompt set and a history score set corresponding to the history prompt set, to obtain a paraphrased prompt set; andevaluate the paraphrased prompt set, to obtain a score set corresponding to the paraphrased prompt set, andwherein the retaining a prompt with the highest score comprises:retaining a prompt with the highest score in the hybrid prompt set and the paraphrased prompt set as a current optimized prompt.18.The apparatus of claim 11, wherein the optimizing the initial prompt comprises:determining a first strategy set for improving the initial prompt based on the positive experience set;determining a second strategy set for improving the initial prompt based on the negative experience set;merging the first strategy set and the second strategy set into a joint strategy set;generating a revised prompt set based on the initial prompt, the positive experience set, the negative experience set and the joint strategy set;evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; andretaining a prompt with the highest score in the revised prompt set as a current optimized prompt.19.The apparatus of claim 11, wherein the optimizing the initial prompt comprises:combining the positive experience set and the negative experience set into a joint experience set;determining a strategy set for improving the initial prompt based on the joint experience set;generating a revised prompt set based on the initial prompt, the joint experience set and the strategy set;evaluating the revised prompt set, to obtain a score set corresponding to the revised prompt set; andretaining a prompt with the highest score in the revised prompt set as a current optimized prompt.20.A computer program product for prompt optimization, comprising a computer program that is executed by a processor for:receiving an initial prompt;executing the initial prompt, to obtain a successful case set and a failed case set associated with the initial prompt;identifying a positive experience set of the initial prompt through analyzing the successful case set, the positive experience set indicating one or more factors of the initial prompt achieving the successful case set;identifying a negative experience set of the initial prompt through analyzing the failed case set, the negative experience set indicating one or more reasons of the initial prompt causing the failed case set; andoptimizing the initial prompt with the positive experience set and the negative experience set.