Prompt word optimization method and related equipment

By predicting and grouping the labeled data sets, the strategy library is optimized, and the prompt optimization problem in the existing technology is solved, and the content understanding performance of the large model is improved.

CN119166771APending Publication Date: 2024-12-20BEIJING ZITIAO NETWORK TECH CO LTD

Patent Information

Application Number
CN202411186628.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-27
Publication Date
2024-12-20

AI Technical Summary

Technical Problem

The prior art is difficult to effectively optimize prompts, resulting in poor performance of large models in content understanding applications.

Method used

Optimize prompts by predicting the sample data in the tagged dataset, extracting error sample data, grouping candidate policies, evaluating and optimizing the policy library.

Benefits of technology

It significantly improves the performance of large models in content understanding applications, and generates more effective prompts through a more accurate policy library.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166771A_ABST
    Figure CN119166771A_ABST
Patent Text Reader

Abstract

The invention provides a cue word optimization method. The cue word optimization method comprises the following steps: predicting sample data in a marked data set based on strategies in a strategy library by utilizing a first large model; extracting error sample data of which the prediction result is inconsistent with the corresponding marking result from the marking data set; grouping the error sample data to obtain a plurality of error sample data groups; for each error sample data group, generating a candidate strategy corresponding to the error sample data group based on the error sample data in the error sample data group; evaluating candidate strategies corresponding to the error sample data groups, and determining at least one target strategy from the candidate strategies; optimizing the strategy library based on the at least one target strategy; and generating the cue based on the optimized strategy library. The invention further provides a prompt word optimization device, a storage medium and a program product.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a prompt optimization method and related equipment. Background Art

[0002] As the demand for content understanding continues to increase, the demand for recognition based on general knowledge is becoming increasingly common, and large models perform well in this regard. Therefore, how to quickly generate content understanding models based on large models has become an important research topic. Prompts are the communication bridge between humans and large models, and different prompts have a huge impact on the final results. Therefore, how to optimize prompts has become a hot issue in the application of large models. Summary of the invention

[0003] In view of this, the embodiments of the present disclosure provide a prompt optimization method and related devices, which can optimize the strategies in the prompts, so as to achieve the purpose of optimizing the prompts, thereby greatly improving the performance of large models in various content understanding applications.

[0004] The prompt optimization method described in the embodiment of the present disclosure may include: using the first large model to predict the sample data in the marked data set based on the strategies in the strategy library; extracting the error sample data whose prediction results are inconsistent with the corresponding marked results from the marked data set; grouping the error sample data to obtain multiple error sample data groups; for each error sample data group, generating a candidate strategy corresponding to the error sample data group based on the error sample data in the error sample data group; evaluating the candidate strategies corresponding to each error sample data group, and determining at least one target strategy from the candidate strategies; optimizing the strategy library based on the at least one target strategy; and generating the prompt based on the optimized strategy library.

[0005] In an embodiment of the present disclosure, grouping the error sample data to obtain a plurality of error sample data groups includes: clustering the error sample data to obtain the plurality of error sample data groups.

[0006] In an embodiment of the present disclosure, grouping the error sample data to obtain a plurality of error sample data groups includes: grouping the error sample data based on a cumulative error rate of the error sample data to obtain the plurality of error sample data groups.

[0007] In an embodiment of the present disclosure, generating a new candidate strategy based on the error sample data in the error sample data group includes: inputting the error sample data in the error sample data group into a second large model, and generating the candidate strategy by the second large model.

[0008] In an embodiment of the present disclosure, generating a new candidate strategy based on the error sample data in the error sample data group includes: inputting the error sample data in the error sample data group into a third largest model, and having the third largest model output at least one predicted error cause corresponding to the error sample data group; and inputting the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group into a fourth largest model, and having the fourth largest model generate the candidate strategy.

[0009] In an embodiment of the present disclosure, generating new candidate strategies based on the error sample data in the error sample data group includes: inputting the error sample data in the error sample data group into a second large model, and generating a first part of candidate strategies from the second large model; inputting the error sample data in the error sample data group into a third large model, and outputting at least one predicted error cause corresponding to the error sample data group from the third large model; and inputting the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group into a fourth large model, and generating a second part of candidate strategies from the fourth large model.

[0010] In an embodiment of the present disclosure, the prompt optimization method may further include: evolving the candidate strategies corresponding to the respective error sample data groups based on a preset evolutionary algorithm to obtain the evolved candidate strategies corresponding to the respective error sample data groups.

[0011] In an embodiment of the present disclosure, evaluating the candidate strategies includes: generating a test data set based on the cumulative error rate of sample data in the labeled data set; testing the candidate strategies and strategies in the strategy library based on the test data set to obtain the test accuracy corresponding to each strategy; and determining the target strategy from the candidate strategies based on the test accuracy corresponding to each strategy.

[0012] In an embodiment of the present disclosure, before generating a prompt based on the optimized policy library, the method further includes: in response to determining that the optimized policy library does not satisfy a preset optimization end condition, returning to the step of using the large model to predict the labeled data set based on the strategies in the policy library; and in response to determining that the optimized policy library satisfies the preset optimization end condition, executing the step of generating a prompt based on the optimized policy library.

[0013] In an embodiment of the present disclosure, the prompt optimization method may further include: selecting at least one relevant strategy with the highest similarity to the input sample from the strategy library; and generating a prompt module in the prompt based on the at least one relevant strategy.

[0014] In an embodiment of the present disclosure, generating the prompt based on the optimized policy library includes: generating the prompt based on the optimized policy library, the prompt module and the input sample.

[0015] Based on the above prompt optimization method, an embodiment of the present disclosure further provides a prompt optimization device, including:

[0016] A prediction module, used to predict the sample data in the labeled data set respectively based on the strategies in the strategy library using the first large model, and extract erroneous sample data whose prediction results are inconsistent with the labeled results from the labeled data set;

[0017] A selection module, used for grouping the error sample data to obtain a plurality of error sample data groups;

[0018] A candidate strategy generating module, configured to generate, for each erroneous sample data group, a candidate strategy corresponding to the erroneous sample data group based on the erroneous sample data in the erroneous sample data group;

[0019] An evaluation module, used to evaluate candidate strategies corresponding to each error sample data group, and determine at least one target strategy from the candidate strategies;

[0020] an optimization module, configured to optimize the strategy library based on the at least one target strategy;

[0021] The prompt generation module is used to generate the prompt based on the optimized policy library.

[0022] In an embodiment of the present disclosure, the candidate strategy generation module includes: a first candidate strategy generation unit, which is used to input the error sample data in the error sample data group into a second large model, and generate the candidate strategy by the large model.

[0023] In an embodiment of the present disclosure, the candidate strategy generation module includes:

[0024] an error cause analysis unit, configured to input the error sample data in the error sample data group into a third large model, and the third large model outputs at least one predicted error cause corresponding to the error sample data group;

[0025] The second candidate strategy generating unit is used to input the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group into a fourth large model, and generate the candidate strategy by the fourth large model.

[0026] In addition, an embodiment of the present disclosure further provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned prompt optimization method when executing the program.

[0027] An embodiment of the present disclosure further provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the above-mentioned prompt optimization method.

[0028] An embodiment of the present disclosure further provides a computer program product, including computer program instructions, which, when executed on a computer, enable the computer to execute the above-mentioned prompt optimization method.

[0029] In the above-mentioned prompt optimization method and related devices, after using the large model to predict the labeled data set based on the strategies in the strategy library and extracting the error sample data, the error sample data is first grouped to obtain multiple error sample data groups. Then, candidate strategies are generated for each error sample data group. Finally, after evaluating the candidate strategies, the strategy library is optimized to achieve the purpose of optimizing the prompts. It can be seen that by grouping the error sample data based on the preset grouping strategy, the error samples with basically the same characteristics are grouped together, and the candidate strategies are generated for each error sample data group, more accurate candidate strategies can be generated, so that the strategies in the strategy library can be optimized to achieve the purpose of optimizing the prompts, thereby greatly improving the performance of the large model in various content understanding applications. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are only embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0031] Figure 1 The implementation process of the prompt optimization method described in some embodiments of the present disclosure is shown.

[0032] Figure 2 The implementation flow of the method for generating candidate strategies corresponding to the above-mentioned erroneous sample data group based on the erroneous sample data in the above-mentioned erroneous sample data group by using the second largest model as described in some embodiments of the present disclosure is shown.

[0033] Figure 3 The implementation process of the method for evaluating candidate strategies corresponding to each error sample data group described in some embodiments of the present disclosure is shown.

[0034] Figure 4 The internal structure of the prompt optimization device described in some embodiments of the present disclosure is shown.

[0035] Figure 5 The internal structure of the candidate strategy generation module 430 described in the embodiment of the present disclosure is shown.

[0036] Figure 6 A more specific schematic diagram of the hardware structure of an electronic device described in some embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0037] In order to make the objectives, technical solutions and advantages of the present disclosure more clearly understood, the present disclosure is further described in detail below in combination with specific embodiments and with reference to the accompanying drawings.

[0038] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the embodiments of the present disclosure should be understood by people with ordinary skills in the field to which the present disclosure belongs. The "first", "second" and similar words used in the embodiments of the present disclosure do not indicate any order, quantity or importance, but are only used to distinguish different components. "Including" or "comprising" and similar words mean that the elements or objects appearing before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connect" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0039] It is understandable that before using the technical solutions of each embodiment of the present disclosure, the type, scope of use, usage scenarios, etc. of the personal information involved will be informed to the user in an appropriate manner, and the user's authorization will be obtained.

[0040] For example, in response to receiving an active request from a user, a prompt message is sent to the user to clearly remind the user that the operation requested to be performed will require obtaining and using the user's personal information. Thus, the user can independently choose whether to provide personal information to software or hardware such as an electronic device, application, server, or storage medium that performs the operation of the technical solution of the present disclosure according to the prompt message.

[0041] As an optional but non-limiting implementation, in response to receiving the user's active request, the prompt information may be sent to the user in the form of a pop-up window, in which the prompt information may be presented in text form. In addition, the pop-up window may also carry a selection control for the user to choose "agree" or "disagree" to provide personal information to the electronic device.

[0042] It is understandable that the above notification and the process of obtaining user authorization are merely illustrative and do not constitute a limitation on the implementation of the present disclosure. Other methods that meet relevant laws and regulations may also be applied to the implementation of the present disclosure.

[0043] As mentioned above, since different prompts have a huge impact on the final result, how to optimize the prompts has become a hot issue in large model applications.

[0044] In order to solve the above problems, the embodiments of the present disclosure provide a prompt optimization method, which can optimize the strategies in the prompts, so as to achieve the purpose of optimizing the prompts, thereby greatly improving the performance of large models in various content understanding applications.

[0045] Figure 1 The implementation process of the prompt optimization method described in some embodiments of the present disclosure is shown. Figure 1 As shown, the prompt optimization method described in the embodiment of the present disclosure may include the following steps.

[0046] In step 110, the first large model is used to predict the sample data in the labeled data set based on the strategies in the strategy library.

[0047] In step 120, erroneous sample data whose predicted results are inconsistent with the labeled results are extracted from the labeled data set.

[0048] In step 130, the erroneous sample data are grouped to obtain a plurality of erroneous sample data groups.

[0049] In step 140, for each erroneous sample data group, a candidate strategy corresponding to the erroneous sample data group is generated based on the erroneous sample data in the erroneous sample data group.

[0050] In step 150, candidate strategies corresponding to each error sample data group are evaluated, and at least one target strategy is determined from the candidate strategies.

[0051] In step 160, the policy library is optimized based on the at least one target policy.

[0052] In step 170, prompts are generated based on the optimized policy library.

[0053] The following describes in detail the various steps in the above prompt optimization method with reference to specific examples.

[0054] With respect to the above step 110, in an embodiment of the present disclosure, the above labeled data set is a pre-set training data set. The above labeled data set may include a plurality of data pairs. Each data pair includes: sample data and a labeling result corresponding to the sample data.

[0055] In addition, in the embodiments of the present disclosure, the above-mentioned strategy library may include multiple strategies. The above-mentioned strategies are the content added in the prompts for reference by the big model when performing specific tasks. It can be understood that the accurate strategies added in the prompts for the big model to refer to will greatly improve the effect of the big model in understanding the content, thereby greatly improving the performance of the big model in various content understanding applications.

[0056] In an embodiment of the present disclosure, before executing the above step 110, the policy library needs to be initialized. In a specific example, the above initialization may include: adding an initial policy to an empty policy library. The above initial policy may be any preset policy. For example, it may be a policy of "determining whether the published content is a specific topic". After initialization, the above policy library may only include the above initial policy.

[0057] The above-mentioned large model, also called the basic model, refers to a machine learning model with a large number of parameters and complex structure. It can process massive data and complete various complex tasks, such as natural language processing, computer vision, and speech recognition.

[0058] In the embodiments of the present disclosure, a certain large model can be selected to perform the above step 110, that is, the selected first large model is used to predict the labeled data set based on the strategies in the above strategy library to obtain the prediction results of each sample data in the corresponding labeled data set. Specifically, prompts can be first generated based on the sample data in the labeled data set and the strategies in the above strategy library; then, the generated prompts are input into the above first large model, and the output of the large model is used as the above prediction results. It should be noted that the specific type of the large model selected in the embodiments of the present disclosure is not limited.

[0059] Next, in the above step 120, based on the prediction results of each sample data in the above corresponding labeled data set, sample data whose prediction results are inconsistent with the labeled results corresponding to the sample data can be extracted from the labeled data set as the above erroneous sample data. It can be understood that in the embodiment of the present disclosure, the above erroneous sample data is sample data whose prediction results are inconsistent with the labeled results corresponding to the sample data after the large model predicts the sample data based on the current strategy library.

[0060] In an embodiment of the present disclosure, in the above step 130, the error sample data may be grouped based on a preset grouping strategy, so that the error samples having substantially the same characteristic are grouped into one group. Specifically, the above step 130 may include multiple implementations.

[0061] In some embodiments, the error sample data may be grouped by clustering, that is, by clustering the error sample data, a plurality of error sample data groups are obtained. The error sample data contained in each error sample data group has a relatively high similarity. It can be understood that the error sample data in the error sample data group obtained by clustering are relatively similar, and it is easy to summarize the error causes, and in subsequent steps, new strategies can be generated based on the summarized error causes, so that the strategy library can be quickly optimized.

[0062] Specifically, in practical applications, a variety of clustering algorithms can be used to implement the above clustering, for example, they can include: K-Means clustering; DBSCAN clustering; or other similarity-based clustering algorithms, etc. For example, you can first randomly select a sample data from the erroneous sample data, and classify the sample data with a similarity greater than a preset threshold into a cluster; then, return to perform the above operation of randomly selecting a sample data from the remaining unclustered samples until all sample data are assigned to a cluster. Corresponding to each of the above clustering algorithms, there can also be multiple distance metrics selected, for example, text edit distance can be used, or BGE-M3 feature (Embedding) similarity can be used, etc. It should be noted that the specific clustering algorithm and distance metric used in the embodiments of the present disclosure when grouping erroneous sample data are not limited.

[0063] In some other embodiments, the error sample data may be grouped based on the cumulative error rate of the error sample data to obtain the plurality of error sample data groups. The error sample data in each error sample data group has a similar cumulative error rate. In subsequent steps, a new strategy is generated based on the similarity of the cumulative error rate of the error sample data in each error sample data group, thereby realizing rapid optimization of the strategy library.

[0064] In the embodiment of the present disclosure, each data pair in the above-mentioned labeled data set, in addition to including the sample data and the labeling result corresponding to the sample data, will further record the cumulative error rate of the sample data. The cumulative error rate of the above-mentioned sample data refers to the ratio of the number of times the above-mentioned sample data is cumulatively determined as the wrong sample data to the cumulative number of times it is predicted in the execution of the prompt optimization method described in the embodiment of the present disclosure, that is, the probability of being determined as the wrong sample data in history. It should be noted that after each execution of the above-mentioned step 110, the cumulative error rate corresponding to the sample data in the above-mentioned labeled data set that has been predicted in this round will be updated. Based on the above-mentioned cumulative error rate, it can be determined which sample data in the above-mentioned labeled data set is more likely to be predicted wrong. Specifically, in the above-mentioned step 130, the above-mentioned wrong sample data can be sorted based on the above-mentioned cumulative error rate, and then the sorted wrong sample data can be grouped according to the preset cumulative error rate interval or the number of sample data in the preset wrong sample data group. In this way, the wrong sample data with roughly similar probabilities of being determined as wrong sample data in history can be grouped.

[0065] With respect to the above step 140, the embodiments of the present disclosure also provide a variety of methods for generating candidate strategies.

[0066] In some embodiments, the above step 140 may include: for each error sample data group, inputting the error sample data in the above error sample data group into the second largest model, and generating the candidate strategy corresponding to the above error sample data group by the second largest model. In the above embodiment, the task assigned to the above second largest model is to generate an optimized strategy based on the error sample data in each error sample data group. It should be noted that in the embodiment of the present disclosure, the second largest model used in the above step 140 may be the same as or different from the first largest model used in the above step 110.

[0067] In other embodiments, the above step 140 may include: for each error sample data group, inputting the error sample data in the above error sample data group into the third largest model, and the third largest model outputs at least one prediction error reason corresponding to the above error sample data group; then, inputting the error sample data in the above error sample data group and at least one prediction error reason corresponding to the above error sample data group into the fourth largest model, and the fourth largest model generates the candidate strategy corresponding to the above error sample data group. In the above embodiment, the task assigned to the above third largest model is to summarize at least one prediction error reason based on the error sample data in each error sample data group; the task assigned to the above fourth largest model is to generate an optimized strategy based on the error sample data in each error sample data group and at least one prediction error reason output by the above third largest model. It should be noted that in the embodiment of the present disclosure, the two large models used in the above step 140 may be the same or different. In addition, the above two large models may be the same or different from the first large model used in the above step 110.

[0068] In some other embodiments, the above step 140 may combine the above two methods. In this case, the implementation of the above step 140 may refer to Figure 2 , for each error sample data group, the following steps may be specifically included.

[0069] In step 210, the erroneous sample data in the erroneous sample data group is input into the second largest model, and the second largest model generates a first part of candidate strategies corresponding to the erroneous sample data group.

[0070] In step 220, the error sample data in the error sample data group is input into the third largest model, and the third largest model outputs at least one predicted error cause corresponding to the error sample data group.

[0071] In step 230, the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group are input into the fourth largest model, and the fourth largest model generates a second part of candidate strategies corresponding to the error sample data group.

[0072] In step 240, the first part of candidate strategies and the second part of candidate strategies are combined to obtain candidate strategies corresponding to the error sample data group.

[0073] In order to further increase the diversity of candidate strategies, the embodiment of the present disclosure may further include, after the above step 140: evolving the candidate strategies corresponding to the above-mentioned respective error sample data groups based on a preset evolutionary algorithm to obtain evolved candidate strategies.

[0074] In an embodiment of the present disclosure, the above-mentioned evolutionary algorithm may include: one of a mutation algorithm, a genetic algorithm, and a differential evolution algorithm. Among them, the above-mentioned mutation algorithm is used to generate a statement that is semantically unchanged from the candidate strategy. The above-mentioned genetic algorithm includes mutation and crossover, which is used to generate a new candidate strategy from two different candidate strategies. It should be noted that the embodiments of the present disclosure do not limit the evolutionary algorithm adopted and its specific implementation.

[0075] With respect to the above step 150, in the embodiment of the present disclosure, the specific method for evaluating the above candidate strategies can be as follows: Figure 3 As shown, the following steps are included.

[0076] In step 310, a test data set is generated based on the cumulative error rate of sample data in the labeled data set.

[0077] In the embodiment of the present disclosure, the sample data in the test data set may include: sample data with a cumulative error rate higher than a preset error rate threshold; or N sample data with the highest cumulative error rates. Since error-prone samples contribute more to the distinction of prompts, in the embodiment of the present disclosure, sample data with a higher cumulative error rate is preferentially selected, so that candidate strategies can be evaluated more effectively.

[0078] It should be noted that, as a simplified alternative to the above step 310, sample data may also be directly randomly selected from the labeled data set to obtain the above test data set.

[0079] In step 320, the candidate strategies corresponding to the above-mentioned respective error sample data groups and the strategies in the strategy library are tested respectively based on the above-mentioned test data set to obtain the test accuracy rate corresponding to each strategy.

[0080] In an embodiment of the present disclosure, the test process may include: for each of the above strategies, generating multiple prompts based on the strategy and each sample data in the test data set; inputting the generated multiple prompts into the first large model to obtain prediction results corresponding to each prompt; and determining the test accuracy corresponding to the strategy according to the prediction results. The test accuracy is the ratio of the number of sample data whose prediction results are consistent with the labeled results to the number of sample data in the test data set.

[0081] In step 330, the at least one target strategy is determined from the candidate strategies based on the test accuracy corresponding to the various strategies.

[0082] In an embodiment of the present disclosure, in the above step 330, at least one candidate strategy with the highest test accuracy is selected from the above candidate strategies as the above target strategy based on the test accuracy corresponding to the above strategies. The number of the above target strategies may be a preset number.

[0083] Next, in the above step 160, the above at least one target policy is added to the policy library, so as to optimize the above policy library.

[0084] After the above operations, one round of optimization of the policy library can be completed. Through multiple rounds of optimization, the optimization of the above policy library can be completed. In the embodiment of the present disclosure, the optimization end condition can be set in advance, and after each execution of the above step 160, it is determined whether the optimized policy library meets the preset optimization end condition. In response to determining that the optimized policy library does not meet the preset optimization end condition, return to the above step of using the large model to predict the labeled data set based on the strategies in the policy library; and in response to determining that the optimized policy library meets the preset optimization end condition, the optimization of the policy library is completed, and then the step of generating prompts based on the optimized policy library described in the above step 170 is executed.

[0085] In an embodiment of the present disclosure, the above-mentioned optimization termination conditions may include: the number of optimizations reaches a predetermined optimization number threshold; or, after verifying the current policy library using a pre-set verification data set, it is determined that the difference between the optimal index obtained by the policy library through verification after this round of optimization and the historical optimal index is within a pre-set optimization threshold, etc. In some embodiments of the present disclosure, the above-mentioned optimal index may refer to the highest verification accuracy obtained through verification. The above-mentioned historical optimal index may refer to the highest verification accuracy obtained in each historical verification process. The above-mentioned verification accuracy is the ratio of the number of sample data whose verification results are consistent with the marking results to the number of sample data in the above-mentioned verification data set.

[0086] In the above step 170, a prompt is generated based on the above optimized strategy library and the input sample. Specifically, based on a preset prompt template, the entire content of the optimized strategy library can be added to the reference part of the prompt to assist the prompt model in understanding the content of other parts of the prompt, so that the model can perform specific tasks more accurately and efficiently.

[0087] In the above prompt optimization method, after using the large model to predict the labeled data set based on the strategies in the strategy library and extracting the error sample data, the error sample data is first grouped to obtain multiple error sample data groups. Then, candidate strategies are generated for each error sample data group. Finally, after evaluating the candidate strategies, the strategy library is optimized to achieve the purpose of optimizing the prompt. It can be seen that by grouping the error sample data based on the preset strategy and generating candidate strategies for each error sample data group, more accurate candidate strategies can be generated, so that the strategies in the strategy library can be optimized to achieve the purpose of optimizing the prompt, thereby greatly improving the performance of the large model in various content understanding applications.

[0088] In order to further optimize the prompt, the prompt optimization method may further include: selecting at least one relevant strategy with the highest similarity to the input sample from the strategy library; and generating a prompt module in the prompt based on the at least one relevant strategy.

[0089] Based on the above scheme, in the above embodiment of the present disclosure, generating the prompt based on the optimized policy library may include: generating the prompt based on the optimized policy library, the above prompt module and the input sample. Specifically, based on a pre-set prompt template, the optimized policy library may be added to the reference part of the prompt, and the above prompt module may be added to the prompt.

[0090] The optimized policy library often contains a lot of content. When applying the above policy library, the content with a higher degree of similarity to the current input sample is more conducive to the judgment of the model. Therefore, in the embodiment of the present disclosure, the highest K content that is most similar to the current input sample is further retrieved from the optimized policy library, and the K content is used to add an "important prompt" module to the generated prompt to assist the prompt model in understanding the content. In the embodiment of the present disclosure, the specific method of selecting at least one relevant policy with the highest similarity to the input sample from the above policy library can be implemented by a pre-set similarity algorithm or a trained similarity prediction model. The embodiment of the present disclosure does not limit the specific method for implementing the above steps.

[0091] Based on the above prompt optimization method, an embodiment of the present disclosure also provides a prompt optimization device. Figure 4 The internal structure of the prompt optimization device described in the embodiment of the present disclosure is shown. Figure 4 As shown, the above prompt optimization device includes the following modules.

[0092] The prediction module 410 is used to use the first large model to predict the sample data in the marked data set based on the strategies in the strategy library, and extract erroneous sample data whose prediction results are inconsistent with the marked results from the marked data set.

[0093] The selection module 420 is used to group the above-mentioned error sample data to obtain multiple error sample data groups.

[0094] The candidate strategy generating module 430 is configured to generate, for each erroneous sample data group, a candidate strategy corresponding to the erroneous sample data group based on the erroneous sample data in the erroneous sample data group.

[0095] The evaluation module 440 is used to evaluate the candidate strategies corresponding to each error sample data group and determine at least one target strategy.

[0096] The optimization module 450 is used to optimize the policy library based on at least one target policy.

[0097] The prompt generating module 460 is used to generate prompts based on the optimized policy library.

[0098] In some embodiments of the present disclosure, the candidate strategy generation module 430 may include: a first candidate strategy generation unit, configured to input the error sample data in the error sample data group into the second large model, and generate the candidate strategy by the second large model.

[0099] In some other embodiments of the present disclosure, the candidate strategy generation module 430 may include:

[0100] an error cause analysis unit, configured to input the error sample data in the error sample data group into a third large model, and the third large model outputs at least one predicted error cause corresponding to the error sample data group;

[0101] The second candidate strategy generating unit is used to input the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group into the fourth largest model, and generate the candidate strategy by the fourth largest model.

[0102] In some other embodiments of the present disclosure, the candidate strategy generation module 430 may include: the first candidate strategy generation unit, the error cause analysis unit, and the second candidate strategy generation unit.

[0103] Furthermore, the candidate strategy generation module 430 may further include: an evolution unit, configured to evolve the candidate strategies corresponding to the respective error sample data groups based on a preset evolution algorithm to obtain evolved candidate strategies.

[0104] Figure 5 A specific example of the candidate strategy generation module 430 described in the embodiment of the present disclosure is shown. Figure 5 In the example, the candidate strategy generation module 430 includes: a first candidate strategy generation unit 4301 , an error cause analysis unit 4302 , a second candidate strategy generation unit 4303 and an evolution unit 4304 .

[0105] It should be noted that the specific implementation methods of the various modules included in the prompt optimization device described in the embodiments of the present disclosure can refer to the aforementioned embodiments, and will not be repeated here. Furthermore, the prompt optimization device described in the aforementioned embodiments has the same beneficial effects as the corresponding method embodiments, and will not be repeated here.

[0106] Based on the same inventive concept, corresponding to any of the above-mentioned embodiments, the present disclosure also provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the prompt optimization method described in any of the above embodiments is implemented.

[0107] Figure 6 A more specific hardware structure diagram of an electronic device provided in this embodiment is shown, and the device may include: a processor 2010, a memory 2020, an input / output interface 2030, a communication interface 2040, and a bus 2050. The processor 2010, the memory 2020, the input / output interface 2030, and the communication interface 2040 are connected to each other in communication within the device through the bus 2050.

[0108] The processor 2010 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this specification.

[0109] The memory 2020 can be implemented in the form of ROM (Read Only Memory), RAM (Random Access Memory), static storage device, dynamic storage device, etc. The memory 2020 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented by software or firmware, the relevant program codes are stored in the memory 2020 and are called and executed by the processor 2010.

[0110] The input / output interface 2030 is used to connect input / output devices to realize information input and output. The input / output devices can be configured in the device as components, or can be externally connected to the device to provide corresponding functions. The input devices can include microphones, various sensors, etc., and the output devices can include displays, speakers, vibrators, indicator lights, etc.

[0111] The communication interface 2040 is used to connect a communication module (not shown) to realize communication interaction between the device and other devices. The communication module can realize communication through a wired mode (such as USB, network cable, etc.) or a wireless mode (such as mobile network, WIFI, Bluetooth, etc.).

[0112] The bus 2050 includes a path that transmits information between the various components of the device (eg, the processor 2010, the memory 2020, the input / output interface 2030, and the communication interface 2040).

[0113] It should be noted that, although the above device only shows the processor 2010, the memory 2020, the input / output interface 2030, the communication interface 2040, and the bus 2050, in the specific implementation process, the device may also include other components necessary for normal operation. In addition, it can be understood by those skilled in the art that the above device may also only include the components necessary for implementing the embodiments of the present specification, and does not necessarily include all the components shown in the figure.

[0114] The electronic device of the above embodiment is used to implement the corresponding prompt optimization method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiment, which will not be described in detail here.

[0115] Based on the same inventive concept, corresponding to any of the above-mentioned embodiment methods, the present disclosure also provides a non-transitory computer-readable storage medium, wherein the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions are used to enable the computer to execute the prompt optimization method described in any of the above embodiments.

[0116] The computer-readable medium of this embodiment includes permanent and non-permanent, removable and non-removable media, and information storage can be implemented by any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device.

[0117] The computer instructions stored in the storage medium of the above embodiment are used to enable the computer to execute the prompt optimization method described in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which will not be repeated here.

[0118] Those skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of the present disclosure (including the claims) is limited to these examples. Based on the concept of the present disclosure, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present disclosure as described above, which are not provided in detail for the sake of simplicity.

[0119] In addition, to simplify the description and discussion, and in order not to make the embodiments of the present disclosure difficult to understand, the known power / ground connections to the integrated circuit (IC) chips and other components may or may not be shown in the provided figures. In addition, the device can be shown in the form of a block diagram to avoid making the embodiments of the present disclosure difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform on which the embodiments of the present disclosure will be implemented (that is, these details should be fully within the scope of understanding of those skilled in the art). Where specific details (e.g., circuits) are set forth to describe exemplary embodiments of the present disclosure, it is apparent to those skilled in the art that the embodiments of the present disclosure can be implemented without these specific details or with changes in these specific details. Therefore, these descriptions should be considered illustrative rather than restrictive.

[0120] Although the present disclosure has been described in conjunction with specific embodiments of the present disclosure, many replacements, modifications and variations of these embodiments will be apparent to those skilled in the art from the foregoing description. For example, other memory architectures (e.g., dynamic RAM (DRAM)) may use the embodiments discussed.

[0121] The embodiments of the present disclosure are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present disclosure should be included in the scope of protection of the present disclosure.

Claims

1. A prompt optimization method, comprising: Using the first model to predict the sample data in the labeled data set based on the strategies in the strategy library; Extracting erroneous sample data whose prediction results are inconsistent with corresponding labeled results from the labeled data set; Grouping the error sample data to obtain a plurality of error sample data groups; For each error sample data group, generating a candidate strategy corresponding to the error sample data group based on the error sample data in the error sample data group; Evaluate candidate strategies corresponding to each error sample data group to determine at least one target strategy; Optimizing the policy library based on the at least one target policy; as well as The prompt is generated based on the optimized strategy library.

2. The prompt optimization method according to claim 1, wherein: Grouping the error sample data to obtain a plurality of error sample data groups includes: clustering the error sample data to obtain the plurality of error sample data groups.

3. The prompt optimization method according to claim 1, wherein: Grouping the error sample data to obtain a plurality of error sample data groups includes: grouping the error sample data based on a cumulative error rate of the error sample data to obtain the plurality of error sample data groups.

4. The prompt optimization method according to claim 1, wherein: Generating a new candidate strategy based on the error sample data in the error sample data group includes: inputting the error sample data in the error sample data group into a second large model, and generating the candidate strategy by the second large model.

5. The prompt optimization method according to claim 1, wherein: Generating a new candidate strategy based on the error sample data in the error sample data group includes: Inputting the error sample data in the error sample data group into a third large model, and having the third large model output at least one predicted error cause corresponding to the error sample data group; and The error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group are input into a fourth largest model, and the candidate strategy is generated by the fourth largest model.

6. The prompt optimization method according to claim 1, wherein: Generating a new candidate strategy based on the error sample data in the error sample data group includes: Inputting the error sample data in the error sample data group into a second large model, and generating a first part of candidate strategies by the second large model; Inputting the error sample data in the error sample data group into a third large model, and having the third large model output at least one predicted error cause corresponding to the error sample data group; and The error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group are input into a fourth large model, and the fourth large model generates a second part of candidate strategies.

7. The prompt optimization method according to any one of claims 4 to 6, further comprising: The candidate strategies corresponding to the respective error sample data groups are evolved based on a preset evolutionary algorithm to obtain the evolved candidate strategies corresponding to the respective error sample data groups.

8. The prompt optimization method according to claim 1, wherein: The evaluation of candidate strategies corresponding to each error sample data group includes: Generate a test data set based on the cumulative error rate of sample data in the labeled data set; Based on the test data set, the candidate strategies corresponding to each error sample data group and the strategies in the strategy library are tested respectively to obtain the test accuracy corresponding to each strategy; and The target strategy is determined from the candidate strategies based on the test accuracy rates corresponding to the various strategies.

9. The prompt optimization method according to claim 1, wherein: Before generating prompts based on the optimized strategy library, the method further comprises: In response to determining that the optimized policy library does not satisfy the preset optimization end condition, returning to the step of using the large model to predict the labeled data set based on the policies in the policy library; and In response to determining that the optimized policy library meets the preset optimization end condition, the step of generating a prompt based on the optimized policy library is performed.

10. The prompt optimization method according to claim 1, further comprising: Selecting at least one relevant strategy with the highest similarity to the input sample from the strategy library; as well as A prompt module in the prompt is generated based on the at least one relevant strategy.

11. The prompt optimization method according to claim 10, wherein: Generating the prompt based on the optimized policy library includes: generating the prompt based on the optimized policy library, the prompt module and the input sample.

12. A prompt optimization device, comprising: A prediction module, used to predict the labeled data set based on the strategies in the strategy library using the first large model, and extract erroneous sample data whose prediction results are inconsistent with the labeled results from the labeled data set; A selection module, used for grouping the error sample data to obtain a plurality of error sample data groups; A candidate strategy generating module, configured to generate, for each erroneous sample data group, a candidate strategy corresponding to the erroneous sample data group based on the erroneous sample data in the erroneous sample data group; An evaluation module, used to evaluate candidate strategies corresponding to each error sample data group, and determine at least one target strategy from the candidate strategies; an optimization module, configured to optimize the strategy library based on the at least one target strategy; The prompt generation module is used to generate the prompt based on the optimized policy library.

13. The prompt optimization device according to claim 12, wherein: The candidate strategy generation module comprises: a first candidate strategy generation unit, which is used to input the error sample data in the error sample data group into a second large model, and generate the candidate strategy by the second large model; and / or, The candidate strategy generation module includes: an error cause analysis unit, configured to input the error sample data in the error sample data group into a third large model, and the third large model outputs at least one predicted error cause corresponding to the error sample data group; The second candidate strategy generating unit is used to input the error sample data in the error sample data group and at least one predicted error cause corresponding to the error sample data group into a fourth large model, and generate the candidate strategy by the fourth large model.

14. An electronic device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the prompt optimization method according to any one of claims 1 to 11 is implemented.

15. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable a computer to execute the prompt optimization method according to any one of claims 1 to 11.

16. A computer program product, comprising computer program instructions, which, when executed on a computer, enable the computer to execute the prompt optimization method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Question and answer model optimization method and device and question and answer robot system

    CN110046234A

  • Language model and active learning-based data annotation method, medium and equipment

    CN117669764A

  • Method and device for extracting prompt context prompt

    CN118428351A

Cited By

  • Large model-based research and judgment strategy optimization method, apparatus and device, and storage medium

    CN121256419A