Data processing method, device and equipment and readable storage medium
By iteratively optimizing algorithms and expanding thought chains, we automatically generate target prompt words for large language models, solving the problem of low efficiency in manual design, improving the accuracy and recall rate of prompt words, and shortening development time.
Patent Information
- Application Number
- CN202510680474.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-09-05
AI Technical Summary
The prompt word design of existing large language models relies on manual writing, which is inefficient, costly, and difficult to adapt to complex business needs, resulting in poor model judgment and classification effects. In addition, prompt words are usually designed for a single task and need to be redesigned when switching tasks, which increases development time.
Test prompt words are generated through T iterative optimization algorithms. Based on the prediction results and sample label set evaluation scores, M thought chains are generated for content expansion. Multiple rounds of optimization are performed using the target iterative optimization algorithm to obtain S target prompt words, and accurate prompt words are automatically generated.
The accuracy and recall rate of prompt words are improved, the cost of manual design and adjustment is reduced, the development cycle is shortened, and an automated prompt word optimization process is realized.
Smart Images

Figure CN120597877A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method, apparatus, device, and readable storage medium. Background Art
[0002] Although large language models have powerful language understanding and generation capabilities, their performance in practical applications is often affected by the quality of their prompts. Existing prompt design methods typically rely on manual writing and debugging. When faced with complex business needs, designing efficient prompts is very time-consuming and labor-intensive. Due to the complexity of the model and the diversity of tasks, for example, in tasks such as content review and sentiment analysis, manually designed prompts may have problems such as unclear expression and task ambiguity, which affects the model's judgment and classification performance. At the same time, the input prompts of large language models are usually designed for a single task. When faced with different tasks, the prompts may need to be designed or adjusted from scratch, which means that they often need to be redesigned when switching tasks, which increases development time and cost. Therefore, manually designed prompts suffer from high labor costs, low efficiency, and poor quality. Summary of the Invention
[0003] The embodiments of the present application provide a data processing method, apparatus, device, and readable storage medium, which can optimize prompt words efficiently and at low cost, and improve the accuracy and recall rate of prompt words.
[0004] On the one hand, an embodiment of the present application provides a data processing method, including:
[0005] Obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word through T iterative optimization algorithms, input the T test prompt words and the test dataset into the large language model, and use the large language model to generate a set of prediction results corresponding to the test dataset under the T test prompt words; T is a positive integer;
[0006] Based on the T prediction result sets and the sample label sets corresponding to the test data set, generate algorithm evaluation scores corresponding to the T iterative optimization algorithms respectively, and based on the T algorithm evaluation scores, determine the target iterative optimization algorithm among the T iterative optimization algorithms;
[0007] Generate M thought chains corresponding to the initial prompt word, and based on the M thought chains and the test data set, expand the content of the initial prompt word to obtain M content-expanded prompt words; M is a positive integer;
[0008] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words; S is a positive integer.
[0009] Among them, T iterative optimization algorithms include iterative optimization algorithm Ai , i is a positive integer less than or equal to T, T test prompt words include iterative optimization algorithm A i Corresponding test prompt word B i , the test data set includes positive data and negative data; based on the T prediction result sets and the sample label sets corresponding to the test data set, the algorithm evaluation scores corresponding to the T iterative optimization algorithms are generated, including:
[0010] Based on the test prompt word B i For the corresponding prediction result set and the sample label set corresponding to the test data set, the number of first positive examples of correctly predicted positive data, the number of second positive examples of incorrectly predicted positive data, the number of first negative examples of correctly predicted negative data, and the number of second negative examples of incorrectly predicted negative data are counted; the sum of the number of first positive examples and the number of second positive examples is the number of positive data, and the sum of the number of first negative examples and the number of second negative examples is the number of negative data;
[0011] Generate an iterative optimization algorithm A based on the first number of positive examples, the second number of positive examples, the first number of negative examples, and the second number of negative examples i The corresponding prediction accuracy;
[0012] Based on the first number of positive examples and the second number of positive examples, an iterative optimization algorithm A is generated. i The corresponding prediction recall rate;
[0013] Based on iterative optimization algorithm A i Corresponding prediction accuracy and iterative optimization algorithm A i The corresponding prediction recall rate generates an iterative optimization algorithm A i The corresponding algorithm evaluation score.
[0014] Among them, the M thought chains corresponding to the initial prompt word are generated, including:
[0015] Semantically decompose the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word; each semantic decomposition sequence includes at least two task keywords and a semantic mapping relationship between at least two task keywords;
[0016] Based on the at least two task keywords in each semantic decomposition sequence and the semantic mapping relationship between the at least two task keywords, generating a unit reasoning task corresponding to each semantic decomposition sequence;
[0017] The unit reasoning tasks corresponding to the M semantic decomposition sequences are determined as the M thinking chains corresponding to the initial prompt words.
[0018] Among them, the M thought chains corresponding to the initial prompt word are generated, including:
[0019] Generate a root node task based on the initial prompt word, generate Q candidate tasks based on the initial prompt word and the root node task, and generate growth scores corresponding to the Q candidate tasks based on the semantic correctness scores corresponding to the Q candidate tasks and the vector similarity between the Q candidate tasks and the root node task; Q is a positive integer;
[0020] Based on the Q growth scores, H tasks to be grown are determined from the Q candidate tasks. Based on the initial prompt word, the root node task and the H tasks to be grown, candidate tasks corresponding to the H tasks to be grown are generated. New tasks to be grown are continued to be determined through the candidate tasks corresponding to the H tasks to be grown. When the new tasks to be grown meet the growth termination conditions, the M task paths between the root node task and the new tasks to be grown are determined as the M thinking chains corresponding to the initial prompt word; H is a positive integer less than or equal to Q.
[0021] Based on M thought chains and test data sets, the initial prompt words are expanded to obtain M content-expanded prompt words, including:
[0022] Based on M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words;
[0023] N test data are obtained from a test data set, and the N test data are respectively inserted into M instruction rewriting prompt words to obtain M content expansion prompt words; each content expansion prompt word includes N test data.
[0024] Based on M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words, including:
[0025] Obtain task keywords corresponding to M thought chains, perform statistics on the task keywords corresponding to the M thought chains, obtain L keyword statistics results, and determine at least two target keywords from the task keywords corresponding to the M thought chains based on the L keyword statistics results; L is a positive integer less than or equal to M;
[0026] Generate a task framework text corresponding to the initial prompt word based on at least two target keywords; the task framework text includes a role prompt word, a task prompt word, and an output format prompt word, the role prompt word is used to indicate the task domain to be processed by the large language model, the task prompt word indicates the task content to be processed by the large language model, and the output format prompt word is used to instruct the large language model to generate an output in a predetermined format;
[0027] Perform semantic expansion on the task keywords corresponding to each of the M thought chains to obtain at least two expanded keywords;
[0028] Based on the task framework text, M thought chains and at least two extended keywords, M instruction rewriting prompts are generated.
[0029] Among them, N test data are obtained in the test data set, including:
[0030] Generate vector similarity between each test data in the test data set and the initial prompt word, and determine the test data in the test data set whose vector similarity is greater than or equal to the nearest neighbor threshold as N test data.
[0031] Among them, N test data are obtained in the test data set, including:
[0032] Cluster the test data in the test data set to obtain N clusters; each cluster includes a cluster center data, and a cluster center data is used to represent the average characteristics of the test data in a cluster;
[0033] In the N clusters, the mixed similarity between each test data and the associated cluster center data is obtained, and the test data with the maximum mixed similarity in each cluster is sampled to obtain N test data.
[0034] Among them, N clusters include cluster R i , i is a positive integer less than or equal to N; in N clusters, obtain the mixed similarity corresponding to each test data and its cluster center data, including:
[0035] The cluster R i The test data in the cluster is determined as the in-cluster data, and the semantic vector of each in-cluster data and the cluster R i The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to the data in each cluster;
[0036] Cluster R based on text length and data within each cluster i The text length of the cluster center data is used to generate the text length similarity corresponding to the data in each cluster;
[0037] Get cluster R i The information entropy corresponding to the data in each cluster;
[0038] Based on the cosine similarity, text length similarity and information entropy corresponding to each cluster data, the data within each cluster and the cluster R are generated. i The mixed similarity corresponding to the cluster center data.
[0039] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including:
[0040] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words; K is a positive integer less than or equal to M;
[0041] Combine the K iteratively optimized prompt words to obtain S content expansion prompt phrases, and perform semantic induction on the content expansion prompt words in each content expansion prompt phrase to obtain S merged optimized prompt words;
[0042] The validation data set is used to generate validation evaluation scores corresponding to S merged optimization prompt words. Based on the validation evaluation scores corresponding to the S merged optimization prompt words, new K iterative optimization prompt words are continuously determined from the S merged optimization prompt words until the new S merged optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S merged optimization prompt words are determined as the S target prompt words.
[0043] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including:
[0044] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores, and determine the prompt words from the M content expansion prompt words, excluding the K iteratively optimized prompt words, as C example prompt words, where K is a positive integer less than or equal to M, and C is the difference between M and K.
[0045] Based on C example prompt words, generate F example gradient values. Based on the F example gradient values, semantic adjustment is performed on each iteratively optimized prompt word to obtain S example optimized prompt words. F is a positive integer, and S is the product of C and F.
[0046] The validation data set is used to generate validation evaluation scores corresponding to S example optimization prompt words. Based on the validation evaluation scores corresponding to the S example optimization prompt words, new K iterative optimization prompt words are continuously determined from the S example optimization prompt words until the new S example optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S example optimization prompt words are determined as the S target prompt words.
[0047] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including:
[0048] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, and generate feedback optimization prompt words corresponding to the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words and M first historical score information; each first historical score information is used to indicate the validation evaluation score corresponding to a content expansion prompt word in this round of prompt word optimization;
[0049] Generate verification evaluation scores corresponding to M feedback optimization prompt words using the verification data set. Generate new M feedback optimization prompt words using the verification evaluation scores corresponding to the M feedback optimization prompt words and M second historical score information until the obtained new M feedback optimization prompt words meet the iteration termination condition. The new M feedback optimization prompt words are determined as S target prompt words; S and M are equal, and one second historical score information is used to indicate the verification evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the verification evaluation score corresponding to the previous round of prompt word optimization.
[0050] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including:
[0051] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words, where K is a positive integer less than or equal to M.
[0052] Perform keyword replacement on the K iteratively optimized prompt words to obtain K replacement prompt words, and combine any two replacement prompt words among the K replacement prompt words to obtain S replacement prompt phrase groups;
[0053] Perform semantic induction on the replacement prompt words in each replacement prompt phrase to obtain S cross-optimized prompt words;
[0054] The validation data set is used to generate validation evaluation scores corresponding to S cross-optimization prompt words. Based on the validation evaluation scores corresponding to the S cross-optimization prompt words, new K iterative optimization prompt words are continuously determined from the S cross-optimization prompt words until the new S cross-optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S cross-optimization prompt words are determined as the S target prompt words.
[0055] Among them, obtaining the initial prompt words and test data set includes:
[0056] In response to a triggering operation of an upload control in a prompt word optimization page, the uploaded test data set is displayed;
[0057] In response to a triggering operation of a prompt word input control in a prompt word optimization page, the inputted initial prompt word is displayed;
[0058] The method also includes:
[0059] In response to a triggering operation of an initial optimization control in a prompt word optimization page, M content-expanded prompt words obtained by expanding the content of the initial prompt word are displayed;
[0060] In response to a triggering operation of an iterative optimization control in the prompt word optimization page, S target prompt words obtained by performing multiple rounds of prompt word optimization on the M content expansion prompt words are displayed.
[0061] In one aspect, an embodiment of the present application provides a data processing device, including:
[0062] The algorithm testing module is used to obtain an initial prompt word and a test data set, generate test prompt words corresponding to the initial prompt word through T iterative optimization algorithms, input the T test prompt words and the test data set into the large language model, and generate a set of prediction results corresponding to the test data set under the T test prompt words through the large language model; T is a positive integer;
[0063] An algorithm determination module is used to generate algorithm evaluation scores corresponding to T iterative optimization algorithms based on the T prediction result sets and the sample label sets corresponding to the test data set, and to determine a target iterative optimization algorithm among the T iterative optimization algorithms based on the T algorithm evaluation scores;
[0064] The content expansion module is used to generate M thought chains corresponding to the initial prompt word, and based on the M thought chains and the test data set, expand the content of the initial prompt word to obtain M content expansion prompt words; M is a positive integer;
[0065] The iterative optimization module is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words; S is a positive integer.
[0066] In one possible implementation, the T iterative optimization algorithms include iterative optimization algorithm A i , i is a positive integer less than or equal to T, T test prompt words include iterative optimization algorithm A i Corresponding test prompt word B i The test data set includes positive and negative data. The algorithm testing module is used to generate algorithm evaluation scores corresponding to T iterative optimization algorithms based on T prediction result sets and the sample label sets corresponding to the test data set. Specifically, it is used to perform the following operations:
[0067] Based on the test prompt word B iFor the corresponding prediction result set and the sample label set corresponding to the test data set, the number of first positive examples of correctly predicted positive data, the number of second positive examples of incorrectly predicted positive data, the number of first negative examples of correctly predicted negative data, and the number of second negative examples of incorrectly predicted negative data are counted; the sum of the number of first positive examples and the number of second positive examples is the number of positive data, and the sum of the number of first negative examples and the number of second negative examples is the number of negative data;
[0068] Generate an iterative optimization algorithm A based on the first number of positive examples, the second number of positive examples, the first number of negative examples, and the second number of negative examples i The corresponding prediction accuracy;
[0069] Based on the first number of positive examples and the second number of positive examples, an iterative optimization algorithm A is generated. i The corresponding prediction recall rate;
[0070] Based on iterative optimization algorithm A i Corresponding prediction accuracy and iterative optimization algorithm A i The corresponding prediction recall rate generates an iterative optimization algorithm A i The corresponding algorithm evaluation score.
[0071] In a possible implementation, when the content expansion module is used to generate M thought chains corresponding to the initial prompt word, it is specifically used to perform the following operations:
[0072] Semantically decompose the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word; each semantic decomposition sequence includes at least two task keywords and a semantic mapping relationship between at least two task keywords;
[0073] Based on the at least two task keywords in each semantic decomposition sequence and the semantic mapping relationship between the at least two task keywords, generating a unit reasoning task corresponding to each semantic decomposition sequence;
[0074] The unit reasoning tasks corresponding to the M semantic decomposition sequences are determined as the M thinking chains corresponding to the initial prompt words.
[0075] In a possible implementation, when the content expansion module is used to generate M thought chains corresponding to the initial prompt word, it is specifically used to perform the following operations:
[0076] Generate a root node task based on the initial prompt word, generate Q candidate tasks based on the initial prompt word and the root node task, and generate growth scores corresponding to the Q candidate tasks based on the semantic correctness scores corresponding to the Q candidate tasks and the vector similarity between the Q candidate tasks and the root node task; Q is a positive integer;
[0077] Based on the Q growth scores, H tasks to be grown are determined from the Q candidate tasks. Based on the initial prompt word, the root node task and the H tasks to be grown, candidate tasks corresponding to the H tasks to be grown are generated. New tasks to be grown are continued to be determined through the candidate tasks corresponding to the H tasks to be grown. When the new tasks to be grown meet the growth termination conditions, the M task paths between the root node task and the new tasks to be grown are determined as the M thinking chains corresponding to the initial prompt word; H is a positive integer less than or equal to Q.
[0078] In one possible implementation, the content expansion module is configured to expand the content of the initial prompt words based on the M thought chains and the test data set to obtain M content expansion prompt words, and specifically to perform the following operations:
[0079] Based on M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words;
[0080] N test data are obtained from a test data set, and the N test data are respectively inserted into M instruction rewriting prompt words to obtain M content expansion prompt words; each content expansion prompt word includes N test data.
[0081] In one possible implementation, the content expansion module is configured to rewrite the initial prompt words based on M thought chains. When M rewriting prompt words are obtained, the content expansion module is configured to perform the following operations:
[0082] Obtain task keywords corresponding to M thought chains, perform statistics on the task keywords corresponding to the M thought chains, obtain L keyword statistics results, and determine at least two target keywords from the task keywords corresponding to the M thought chains based on the L keyword statistics results; L is a positive integer less than or equal to M;
[0083] Generate a task framework text corresponding to the initial prompt word based on at least two target keywords; the task framework text includes a role prompt word, a task prompt word, and an output format prompt word, the role prompt word is used to indicate the task domain to be processed by the large language model, the task prompt word indicates the task content to be processed by the large language model, and the output format prompt word is used to instruct the large language model to generate an output in a predetermined format;
[0084] Perform semantic expansion on the task keywords corresponding to each of the M thought chains to obtain at least two expanded keywords;
[0085] Based on the task framework text, M thought chains and at least two extended keywords, M instruction rewriting prompts are generated.
[0086] In a possible implementation, when the content expansion module is used to obtain N test data from the test data set, it is specifically used to perform the following operations:
[0087] Generate vector similarity between each test data in the test data set and the initial prompt word, and determine the test data in the test data set whose vector similarity is greater than or equal to the nearest neighbor threshold as N test data.
[0088] In a possible implementation, the content expansion module is used to cluster the test data in the test data set to obtain N clusters; each cluster includes a cluster center data, and the cluster center data is used to represent the average characteristics of the test data in the cluster;
[0089] In N clusters, the mixed similarity between each test data and the associated cluster center data is obtained, and the test data with the maximum mixed similarity in each cluster is sampled to obtain N test data. When , it is specifically used to perform the following operations:
[0090] In one possible implementation, the N clusters include cluster R i , i is a positive integer less than or equal to N; the content expansion module is used to obtain the mixed similarity corresponding to each test data and its cluster center data in N clusters, specifically for performing the following operations:
[0091] The cluster R i The test data in the cluster is determined as the in-cluster data, and the semantic vector of each in-cluster data and the cluster R i The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to the data in each cluster;
[0092] Cluster R based on text length and data within each cluster i The text length of the cluster center data is used to generate the text length similarity corresponding to the data in each cluster;
[0093] Get cluster R i The information entropy corresponding to the data in each cluster;
[0094] Based on the cosine similarity, text length similarity and information entropy corresponding to each cluster data, the data within each cluster and the cluster R are generated. i The mixed similarity corresponding to the cluster center data.
[0095] In one possible implementation, the iterative optimization module is configured to perform multiple rounds of prompt word optimization on M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module is configured to perform the following operations:
[0096] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words; K is a positive integer less than or equal to M;
[0097] Combine the K iteratively optimized prompt words to obtain S content expansion prompt phrases, and perform semantic induction on the content expansion prompt words in each content expansion prompt phrase to obtain S merged optimized prompt words;
[0098] The validation data set is used to generate validation evaluation scores corresponding to S merged optimization prompt words. Based on the validation evaluation scores corresponding to the S merged optimization prompt words, new K iterative optimization prompt words are continuously determined from the S merged optimization prompt words until the new S merged optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S merged optimization prompt words are determined as the S target prompt words.
[0099] In one possible implementation, the iterative optimization module is configured to perform multiple rounds of prompt word optimization on M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module is configured to perform the following operations:
[0100] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores, and determine the prompt words from the M content expansion prompt words, excluding the K iteratively optimized prompt words, as C example prompt words, where K is a positive integer less than or equal to M, and C is the difference between M and K.
[0101] Based on C example prompt words, generate F example gradient values. Based on the F example gradient values, semantic adjustment is performed on each iteratively optimized prompt word to obtain S example optimized prompt words. F is a positive integer, and S is the product of C and F.
[0102] The validation data set is used to generate validation evaluation scores corresponding to S example optimization prompt words. Based on the validation evaluation scores corresponding to the S example optimization prompt words, new K iterative optimization prompt words are continuously determined from the S example optimization prompt words until the new S example optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S example optimization prompt words are determined as the S target prompt words.
[0103] In one possible implementation, the iterative optimization module is configured to perform multiple rounds of prompt word optimization on M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module is configured to perform the following operations:
[0104] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, and generate feedback optimization prompt words corresponding to the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words and M first historical score information; each first historical score information is used to indicate the validation evaluation score corresponding to a content expansion prompt word in this round of prompt word optimization;
[0105] Generate verification evaluation scores corresponding to M feedback optimization prompt words using the verification data set. Generate new M feedback optimization prompt words using the verification evaluation scores corresponding to the M feedback optimization prompt words and M second historical score information until the obtained new M feedback optimization prompt words meet the iteration termination condition. The new M feedback optimization prompt words are determined as S target prompt words; S and M are equal, and one second historical score information is used to indicate the verification evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the verification evaluation score corresponding to the previous round of prompt word optimization.
[0106] In one possible implementation, the iterative optimization module is configured to perform multiple rounds of prompt word optimization on M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module is configured to perform the following operations:
[0107] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words, where K is a positive integer less than or equal to M.
[0108] Perform keyword replacement on the K iteratively optimized prompt words to obtain K replacement prompt words, and combine any two replacement prompt words among the K replacement prompt words to obtain S replacement prompt phrase groups;
[0109] Perform semantic induction on the replacement prompt words in each replacement prompt phrase to obtain S cross-optimized prompt words;
[0110] The validation data set is used to generate validation evaluation scores corresponding to S cross-optimization prompt words. Based on the validation evaluation scores corresponding to the S cross-optimization prompt words, new K iterative optimization prompt words are continuously determined from the S cross-optimization prompt words until the new S cross-optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S cross-optimization prompt words are determined as the S target prompt words.
[0111] An embodiment of the present application provides a computer device, including: a processor, a memory, and a network interface;
[0112] The processor is connected to the memory and the network interface, wherein the network interface is used to provide data communication functions, and the memory is used to store computer programs. When the computer program is executed by the processor, the computer device executes the method provided in the embodiment of the present application.
[0113] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program is suitable for being loaded and executed by a processor so that a computer device having the processor executes the method provided by the embodiment of the present application.
[0114] In one aspect, an embodiment of the present application provides a computer program product, comprising a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the method provided in the embodiment of the present application.
[0115] The embodiment of the present application introduces T iterative optimization algorithms. Different iterative optimization algorithms can perform different iterative optimization processes for prompt words in different task scenarios, obtain initial prompt words and test data sets, iteratively optimize the initial prompt words through T iterative optimization algorithms, and obtain test prompt words corresponding to the initial prompt words by T iterative optimization algorithms. The T test prompt words and the test data set are input into a large language model. The large language model generates prediction result sets corresponding to the test data sets under the T test prompt words. Based on the T prediction result sets and the sample label sets corresponding to the test data sets, algorithm evaluation scores corresponding to the T iterative optimization algorithms are generated. Based on the T algorithm evaluation scores, a target iterative optimization algorithm is determined among the T iterative optimization algorithms. That is, the optimal iterative optimization algorithm suitable for the initial prompt words can be selected based on the test data set. In addition, M thought chains corresponding to the initial prompt word can be generated. Based on the M thought chains and the test data set, the initial prompt word is expanded to obtain M content-expanded prompt words. The semantic depth and the number (width) of the prompt word can be increased through the thought chain and the test data set. Since the thought chain can decompose complex problems into steps of gradual thrust, the thought chain in the content-expanded prompt word can be used to instruct the large language model to generate an intermediate thinking process, rather than directly outputting a conclusion, which can improve the accuracy under complex reasoning tasks. The test data set can allow the content-expanded prompt word to contain more reference information, helping the model to understand and complete the task more accurately, further improving the accuracy. By performing multiple rounds of prompt word optimization on the M content-expanded prompt words that have been optimized and enriched through the target iterative optimization algorithm, S target prompt words with guaranteed accuracy and recall can be obtained. It can be seen that the present application can automatically generate S accurate target prompt words. Compared with the traditional manual prompt design, the embodiment of the present application can significantly shorten the development cycle, reduce the cost of manual design and adjustment, and improve the optimization efficiency of the prompt word. The optimization process no longer relies on manual repeated trial and error, and the prompt word can be automatically optimized in a cycle without manual intervention. BRIEF DESCRIPTION OF THE DRAWINGS
[0116] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0117] Figure 1 This is a schematic diagram of a network architecture provided by an embodiment of the present application;
[0118] Figure 2 This is a data processing scenario provided by the embodiment of the present application. Figure 1 ;
[0119] Figure 3 This is a flow diagram of a data processing method provided in an embodiment of the present application. Figure 1 ;
[0120] Figure 4 This is a flow diagram of a data processing method provided in an embodiment of the present application. Figure 2 ;
[0121] Figure 5 This is a data processing scenario provided by the embodiment of the present application. Figure 2 ;
[0122] Figure 6 This is a data processing scenario provided by the embodiment of the present application. Figure 3 ;
[0123] Figure 7 This is a data processing scenario provided by the embodiment of the present application. Figure 4 ;
[0124] Figure 8 This is a data processing scenario provided by the embodiment of the present application. Figure 5 ;
[0125] Figure 9 This is a data processing scenario provided by the embodiment of the present application. Figure 6 ;
[0126] Figure 10 This is a data processing scenario provided by the embodiment of the present application. Figure 7 ;
[0127] Figure 11 This is a data processing scenario provided by the embodiment of the present application. Figure 8 ;
[0128] Figure 12 is a structural diagram of a data processing device provided in an embodiment of the present application;
[0129] Figure 13 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0130] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0131] See Figure 1 , Figure 1 This is a network architecture diagram provided by an embodiment of the present application. Figure 1 As shown, the network architecture may include a business server 100 and a terminal device cluster, and the terminal device cluster may include terminal device 10a, terminal device 10b, ..., terminal device 10n, wherein any terminal device in the terminal device cluster may have a communication connection with the business server 100, for example, there is a communication connection between terminal device 10a and the business server 100, and there is a communication connection between terminal device 10b and the business server 100, wherein the above-mentioned communication connection does not limit the connection method, and may be directly or indirectly connected through wired communication, or directly or indirectly connected through wireless communication, or through other methods, and this application does not impose any restrictions here.
[0132] Each terminal device in the terminal device cluster may include: smart phones, tablet computers, laptop computers, desktop computers, intelligent voice interaction devices, smart home appliances (e.g., smart TVs), wearable devices, vehicle terminals, aircraft, and other smart terminals with data processing capabilities. Among them, the vehicle terminal can be a terminal device in the smart transportation scenario and the assisted driving scenario. It should be understood that, if Figure 1 Each terminal device in the terminal device cluster shown can be installed with an application client with data processing function. When the application client runs in each terminal device, it can be respectively connected to the above Figure 1 The business servers 100 shown here interact with each other.
[0133] like Figure 1 As shown, for ease of understanding, the terminal device 10a in the terminal device cluster is taken as an example for explanation. The object (user) can enter the initial prompt word and the test data set in the application client in the terminal device 10a. The number of initial prompt words can be one or more, and the test data set can be a data set sampled in various task fields. Each test data in the test data set includes a corresponding sample label. The initial prompt word can be a manually designed prompt word, or it can be a task keyword selected by the object in the application client. The embodiment of the present application does not limit this. The test data can be, for example, text data, and the sample label of the test data can be the classification label corresponding to the text data.
[0134] The terminal device can send the initial prompt word and the test data set to the service server 100. The service server 100 can be deployed with a large language model (LLM). The service server 100 can obtain the initial prompt word and the test data set, and iteratively optimize the initial prompt word using T iterative optimization algorithms to obtain test prompt words corresponding to the T iterative optimization algorithms. The service server 100 can input the test prompt word and the test data set into the large language model. The service server 100 can use the large language model to generate a set of test results corresponding to each of the T test prompt words. Optionally, the test data set can also be a data set collected by the service server 100.
[0135] Based on the T prediction result sets and the sample label sets corresponding to the test dataset, the service server 100 can generate algorithm evaluation scores corresponding to each of the T iterative optimization algorithms, and determine the iterative optimization algorithm with the highest algorithm evaluation score as the target iterative optimization algorithm. The algorithm evaluation score can be used to indicate the precision or recall of the test prompt word obtained by the iterative optimization algorithm. Therefore, the target iterative optimization algorithm can be the most suitable algorithm for optimizing the initial prompt word.
[0136] The business server 100 can generate M thought chains corresponding to the initial prompt words, and based on the M thought chains and the test data set, perform content expansion on the initial prompt words to obtain M content-expanded prompt words. Content expansion can refer to instruction rewriting (Instruction Optimization, IO) of the initial prompt words through M thought chains and example optimization (Exemplar Optimization, EO) of the initial prompt words through the test data set. The embodiment of the present application does not limit this. The business server 100 can perform multiple rounds of prompt word optimization on the M content-expanded prompt words through the target iterative optimization algorithm to obtain S target prompt words. The business server 100 can send the S target prompt words to the terminal device 10a. The terminal device 10a can input the target prompt words into the large language model to improve the performance of the large language model in tasks such as content understanding, reasoning and classification.
[0137] The embodiment of the present application uses T differentiated iterative optimization algorithms, each of which can provide an independent prompt word optimization process. The algorithm evaluation scores of each iterative optimization algorithm are generated through a large language model and a test data set, and the optimal target iterative optimization algorithm is screened accordingly. Furthermore, the initial prompt word can be expanded through M thinking chains and a test data set, by injecting the step-by-step reasoning steps of the thinking chain disassembly and inserting the sample standard output style in the test data set. The thinking chain can force the model to think about the intermediate reasoning process and improve the accuracy of complex tasks, while the sample can provide an output paradigm reference. Under dual optimization, the semantic depth and quantity are expanded simultaneously. The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words. It can be seen that not only the number of prompt words can be expanded, but also the target prompt words obtained through automated expansion and iterative optimization can ensure their recall rate and accuracy.
[0138] See Figure 2 , Figure 2 This is a data processing scenario provided by the embodiment of the present application. Figure 1 .like Figure 2 As shown, the object (user) can start the application client through the terminal device, and the application client can display the prompt word optimization page. Figure 2 Page 101, page 102 and page 103 in the above table can all be referred to as prompt word optimization pages. Figure 1 Any terminal device of the corresponding embodiment may be, for example, the terminal device 10a.
[0139] The terminal device can display page 101. On page 101, the terminal device can respond to the trigger operation of the upload control W on page 101 to display the uploaded test data set. The terminal device can respond to the trigger operation of the prompt word input control Z on page 101 to display the initial prompt word entered by the object. After the terminal device obtains the above-mentioned test data set and the input initial prompt word, the terminal device can display page 102. On page 102, the terminal device can divide the initial prompt word into a task description part and a task rule part. For example, the task description part can be "You are a senior news editor. Now you need to classify the news according to the content of the news." The task rule part can be "Natural disasters: News about natural disasters refers to reports on serious natural disaster events and ecological environmental deterioration, including but not limited to earthquakes, floods, typhoons, droughts, wildfires, mudslides, etc. If the content of the news is reconstruction and ecological protection news after natural disasters, such as urban reconstruction, environmental protection, etc., it is not considered natural disaster news. Other: Other categories of news refer to news other than natural disaster categories." Optionally, the initial prompt word may only include the task description part, and the terminal device may generate the task rule part corresponding to the initial prompt word based on the large language model and the task description part. This embodiment of the present application does not limit this.
[0140] The terminal device can respond to the trigger operation of the initial optimization control E in page 102, and display M content expansion prompt words obtained by expanding the content of the initial prompt word. The content expansion can be the instruction rewriting and sample optimization of the initial prompt word, which is not limited in this embodiment of the present application. The terminal device can respond to the trigger operation of the iterative optimization control Y in page 102, and display page 103. S iterative optimization results (including the first optimization result, the second optimization result and then the third optimization result) obtained by multiple rounds of prompt word optimization for the M content expansion prompt words are displayed in page 103. Each iterative optimization result can include a target prompt word. The S target prompt words can include target prompt word 1, target prompt word 2, ..., target prompt word S. Multi-round prompt word optimization can be achieved through a target iterative optimization algorithm. The target iterative optimization algorithm can be based on the selection of the initial prompt word in T iterative optimization algorithms. The selection process of the target iterative optimization algorithm can refer to the above Figure 1 The content in the corresponding embodiment.
[0141] Each iterative optimization result may include associated test controls and optimization controls. The test controls are used to generate the accuracy and recall rates corresponding to the target prompt words in the iterative optimization result. The optimization controls are used to continue to perform multiple rounds of iterative optimization on the target prompt words in the iterative optimization result.
[0142] The embodiment of the present application realizes the automated optimization of prompt words. The user only needs to provide basic preliminary prompts, and the system can expand the content of the prompt words through initial optimization. Through iterative optimization, the best prompt word optimization solution is automatically generated. This process not only saves a lot of manual design time, but also significantly improves the efficiency and quality of prompt optimization. By optimizing the prompt words, the performance of large language models in tasks such as content understanding, reasoning and classification can be improved. Whether it is content understanding, text classification, sentiment analysis, or more complex reasoning tasks, the embodiment of the present application can intelligently adjust and optimize the prompt words based on the initial prompt words, and quickly adapt to different business scenarios. It can be widely applied to multiple fields such as content review, text classification, and intelligent question and answer, greatly improving the efficiency of business development, reducing development costs, and has significant market application prospects. It can significantly improve the adaptability of the model using the prompt words to different tasks, and can maintain efficient performance in a wider range of tasks.
[0143] See Figure 3 , Figure 3 This is a flow diagram of a data processing method provided in an embodiment of the present application. Figure 1 The data processing method can be executed by a computer device, which can be Figure 1 The service server 100 shown or any terminal device in the terminal device cluster, such as the terminal device 10a, is described below using the data processing method executed by a computer device as an example. The data processing method may include at least the following steps S101 to S104:
[0144] Step S101: Obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word through T iterative optimization algorithms, input the T test prompt words and the test dataset into a large language model, and generate a set of prediction results corresponding to the test dataset under the T test prompt words through the large language model; T is a positive integer;
[0145] Specifically, the computer device can obtain an initial prompt word and a test data set. The initial prompt word can be a manually designed prompt word or a task keyword selected by the subject (user). The number of initial prompt words can be one or more. The initial prompt word can also be called a question-and-answer prompt word (text used to instruct the model to generate an answer to the input data), a classification prompt word (text used to instruct the model to classify the input data), a generation prompt word (used to instruct the model to generate an image or video that meets the description), etc.
[0146] Among them, the initial prompt word and the various prompt words mentioned below can all be a kind of prompt text. The prompt word can also be called a prompt or instruction. The prompt word can be a text used to instruct the large language model to generate an output that conforms to the prompt word. In the classification scenario, the prompt word can be "classify the input picture". After the prompt word and the picture are input into the large language model, the large language model can generate the classification result of the picture. In the question-and-answer scenario, the prompt word can be "Why is the sky blue?" After the prompt word is input into the large language model, the large language model can generate the answer result of the above prompt word.
[0147] The test dataset can be a dataset sampled from various task domains, and each test data item in the test dataset includes a corresponding sample label. For example, the initial prompt word can refer to the text of "classified input news." The test data can be text data, and the sample label of the test data can be the classification label corresponding to the text data.
[0148] The computer device can generate test prompt words corresponding to the initial prompt words using T iterative optimization algorithms. Each of the T iterative optimization algorithms can be an automated script including a preset iterative optimization process. The test prompt words can be prompt words obtained after a certain number of rounds of iterative optimization of the initial prompt words. The computer device can input the test prompt words and the test dataset into a large language model. The large language model uses the test prompt words and the test dataset to generate a set of prediction results corresponding to each of the test datasets under the T test prompt words. Taking the classification of natural disaster news as an example, the prediction results can include "news related to natural disasters" and "news not related to natural disasters."
[0149] Among them, the T iterative optimization algorithms may include an automatic iterative optimization algorithm (Auto Prompt Engineering, APE), a prompt word optimization algorithm based on textual gradients (ProTeGi), a prompt word optimization algorithm based on natural language (Optimization by Prompting, OPRO), an evolutionary prompting algorithm based on an evolutionary mechanism (EvoPrompt), etc., and the embodiments of the present application are not limited thereto.
[0150] Step S102: Based on the T prediction result sets and the sample label sets corresponding to the test data set, generate algorithm evaluation scores corresponding to the T iterative optimization algorithms respectively, and determine a target iterative optimization algorithm from the T iterative optimization algorithms based on the T algorithm evaluation scores;
[0151] Specifically, the computer device may generate algorithm evaluation scores corresponding to each of the T iterative optimization algorithms based on the T prediction result sets and the sample label sets corresponding to the test dataset. The algorithm evaluation score may be the accuracy or recall rate generated based on the prediction result sets and the sample label sets, or the algorithm evaluation score may be the sum of the accuracy and recall rate. The computer device may determine the iterative optimization algorithm corresponding to the maximum algorithm evaluation score as the target iterative optimization algorithm. The target iterative optimization algorithm may be the algorithm most suitable for optimizing the initial prompt word.
[0152] Step S103: Generate M thought chains corresponding to the initial prompt word, and expand the content of the initial prompt word based on the M thought chains and the test data set to obtain M content-expanded prompt words; M is a positive integer;
[0153] Specifically, the computer device can generate M thought chains corresponding to the initial prompt word. The methods for generating thought chains can include few-shot generation methods and zero-shot generation methods. The few-shot generation method refers to guiding the model to generate step-by-step reasoning thought chains through a small number of examples containing questions, reasoning steps, and answers. The zero-shot generation method refers to triggering the model to generate step-by-step reasoning thought chains through prompt words such as "Please answer step by step."
[0154] The computer device can perform content expansion on the initial prompt word based on M thought chains and a test data set to obtain M content-expanded prompt words. The content expansion can be instruction rewriting and sample optimization of the initial prompt word. The execution order of instruction rewriting and sample optimization can be irrelevant. The example of first rewriting the instruction on the initial prompt word and then optimizing the sample is used for illustration. The computer device can perform instruction rewriting on the initial prompt word based on M thought chains to obtain M instruction rewriting prompt words. Instruction rewriting can include adding task framework text (Role Task and Footer, RTF), adding step-by-step reasoning steps of the thought chain, and adjusting vague or important language expressions in the initial prompt word. The task framework text may include role prompts, task prompts, and output format prompts. Role prompts are used to clarify the role played by the large language model (such as news classification expert, weather forecast expert, etc.) and to indicate the task area that the large language model needs to handle. Task prompts are used to describe the specific work goals that need to be completed (such as "analyzing the market share of a certain industry" or "classifying input news") and to indicate the task content that the large language model needs to handle. Output format prompts are used to instruct the large language model to generate output in a predetermined format, for example, it can be a structured requirement for specifying the output, such as a Markdown list (a lightweight markup language), a PPT outline (Power Point, a presentation), or a step-by-step explanation.
[0155] The computer device can perform sample optimization on M instruction rewriting prompts using a test data set. The sample optimization process can, for example, include selecting N test data from the test data set, inserting the N test data into each of the M instruction rewriting prompts, and obtaining M content expansion prompts. Each content expansion prompt can include N test data. For example, the content expansion prompt can be "Compose a poem about autumn in the style of the following verse: [test data]."
[0156] Among them, sample optimization can include zero samples (i.e., not using any samples), random samples (using randomly sampled samples), nearest neighbor samples (using samples that are most similar to the input), diversity samples (using multiple representative samples), all samples (using all samples) and other methods, and the embodiments of this application are not limited here.
[0157] It is understood that when the initial prompt word is a question-and-answer prompt word, the content expansion prompt word can also be called a question-and-answer content expansion prompt word. When the initial prompt word is a classification prompt word, the content expansion prompt word can also be called a classification content expansion prompt word. When the initial prompt word is a generation prompt word, the content expansion prompt word can also be called a generation content expansion prompt word.
[0158] Step S104 , performing multiple rounds of prompt word optimization on the M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words; S is a positive integer.
[0159] Specifically, the computer device can perform multiple rounds of prompt word optimization on M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words. Each round of prompt word optimization in the multiple rounds of prompt word optimization can mainly include an evaluation phase (Score), a screening and induction phase (Reduce), and an optimization phase (Refine). Among them, the evaluation phase is used to evaluate the effectiveness of the prompt words, using a verification data set to score different prompt words and find out the advantages and disadvantages of the prompt words. The screening and induction phase is used to filter out prompt words with poor performance based on the results of the evaluation phase, and generate prompt words for the next round of iterative optimization through optimization methods such as induction, merging, and adjustment. The optimization phase is used to further optimize the prompt words through instruction rewriting and sample optimization to improve their performance in specific tasks.
[0160] It is understood that when the initial prompt word is a question-answer prompt word, the target prompt word can also be called a target question-answer prompt word. When the initial prompt word is a classification prompt word, the target prompt word can also be called a target classification prompt word. When the initial prompt word is a generation prompt word, the target prompt word can also be called a target generation prompt word.
[0161] The embodiment of the present application introduces T iterative optimization algorithms. Different iterative optimization algorithms can perform different iterative optimization processes for prompt words in different task scenarios, obtain initial prompt words and test data sets, iteratively optimize the initial prompt words through T iterative optimization algorithms, and obtain test prompt words corresponding to the initial prompt words by T iterative optimization algorithms. The T test prompt words and the test data set are input into a large language model. The large language model generates prediction result sets corresponding to the test data sets under the T test prompt words. Based on the T prediction result sets and the sample label sets corresponding to the test data sets, algorithm evaluation scores corresponding to the T iterative optimization algorithms are generated. Based on the T algorithm evaluation scores, a target iterative optimization algorithm is determined among the T iterative optimization algorithms. That is, the optimal iterative optimization algorithm suitable for the initial prompt words can be selected based on the test data set. In addition, M thought chains corresponding to the initial prompt word can be generated. Based on the M thought chains and the test data set, the initial prompt word is expanded to obtain M content-expanded prompt words. The semantic depth and the number (width) of the prompt word can be increased through the thought chain and the test data set. Since the thought chain can decompose complex problems into steps of gradual thrust, the thought chain in the content-expanded prompt word can be used to instruct the large language model to generate an intermediate thinking process, rather than directly outputting a conclusion, which can improve the accuracy under complex reasoning tasks. The test data set can allow the content-expanded prompt word to contain more reference information, helping the model to understand and complete the task more accurately, further improving the accuracy. By performing multiple rounds of prompt word optimization on the M content-expanded prompt words that have been optimized and enriched through the target iterative optimization algorithm, S target prompt words with guaranteed accuracy and recall can be obtained. It can be seen that the present application can automatically generate S accurate target prompt words. Compared with the traditional manual prompt design, the embodiment of the present application can significantly shorten the development cycle, reduce the cost of manual design and adjustment, and improve the optimization efficiency of the prompt word. The optimization process no longer relies on manual repeated trial and error, and the prompt word can be automatically optimized in a cycle without manual intervention.
[0162] See Figure 4 , Figure 4 This is a flow diagram of a data processing method provided in an embodiment of the present application. Figure 2 The data processing method can be executed by a computer device, which can be Figure 1 The service server 100 shown or any terminal device in the terminal device cluster, such as the terminal device 10a, is described below using the data processing method executed by a computer device as an example. The data processing method may include at least the following steps S201 to S208:
[0163] Step S201: Obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word through T iterative optimization algorithms, input the T test prompt words and the test dataset into a large language model, and generate a set of prediction results corresponding to the test dataset under the T test prompt words through the large language model; T is a positive integer;
[0164] For details, please refer to the above Figure 3 The corresponding step S101 in the embodiment will not be described again here.
[0165] Step S202: Generate algorithm evaluation scores corresponding to T iterative optimization algorithms based on the T prediction result sets and the sample label sets corresponding to the test data set;
[0166] Specifically, the T iterative optimization algorithms include iterative optimization algorithm A i , T test prompt words include iterative optimization algorithm A i Corresponding test prompt word B i , test prompt word B i It can be the initial prompt word through the iterative optimization algorithm A i The prompt words are obtained after a certain number of rounds of iterative optimization. The test dataset includes positive samples and negative samples. Positive samples refer to samples with the target category (positive class) that need to be recognized or predicted by the model, and negative samples refer to samples with non-target categories (negative class). For example, in the task of classifying natural disaster news, samples with the sample label of "natural disaster" are positive samples, and samples without the sample label of "natural disaster" are negative samples.
[0167] The computer device can input the initial prompt word and the test data set into the large language model. In the large language model, the initial prompt word and the test data set generate a set of prediction results corresponding to the test data set under T test prompt words. Taking the classification of natural disaster news as an example, the prediction results may include "news related to natural disasters" and "news not related to natural disasters". The computer device can be based on the test prompt word B iFor the corresponding prediction result set and the sample label set corresponding to the test dataset, count the number of first positive examples (True Positive, TP) that are correctly predicted as positive data, the number of second positive examples (False Negative, FN) that are incorrectly predicted as positive data, the number of first negative examples (True Negative, TN) that are correctly predicted as negative data, and the number of second negative examples (False Positive, FP) that are incorrectly predicted as negative data. The sum of the first positive examples and the second positive examples is the number of positive data, and the sum of the first negative examples and the second negative examples is the number of negative data. The first positive example refers to the number of samples with a positive label predicted as positive by the large language model, the second positive example refers to the number of samples with a positive label predicted as negative by the large language model, the first negative example refers to the number of samples with a negative label predicted as negative by the large language model, and the second negative example refers to the number of samples with a negative label predicted as positive by the large language model.
[0168] The computer device may generate an iterative optimization algorithm A based on the first number of positive examples, the second number of positive examples, the first number of negative examples, and the second number of negative examples. i The corresponding prediction accuracy is shown in formula (1):
[0169]
[0170] Among them, Accuracy i Iterative optimization algorithm A i The corresponding prediction accuracy is TP, which is the number of first positive examples, TN, which is the number of first negative examples, FP, which is the number of second positive examples, and FN, which is the number of second negative examples.
[0171] The computer device can generate an iterative optimization algorithm A based on the first number of positive examples and the second number of positive examples. i The corresponding prediction recall rate is shown in formula (2):
[0172]
[0173] Among them, Recall i Iterative optimization algorithm A i The corresponding prediction recall rate.
[0174] Computer equipment can be based on iterative optimization algorithm A i Corresponding prediction accuracy and iterative optimization algorithm A i The corresponding prediction recall rate generates an iterative optimization algorithm A i The corresponding algorithm evaluation score. For example, the algorithm evaluation score can be the prediction accuracy or the prediction recall rate, or the sum of the prediction accuracy and the prediction recall rate.
[0175] Step S203, determining a target iterative optimization algorithm from the T iterative optimization algorithms based on the T algorithm evaluation scores;
[0176] For details, please refer to the above Figure 3 The corresponding step S102 in the embodiment will not be described again here.
[0177] Step S204, generating M thought chains corresponding to the initial prompt word;
[0178] Specifically, the computer device can generate M thought chains corresponding to the initial prompt word. The method of generating the thought chain can include a few-sample generation method, a zero-sample generation method, an automatic thought chain method (Automatic Chain of Thought), a thought tree method (Tree of Thoughts, ToT), and the like.
[0179] Taking the automatic thought chain method as an example, the process of a computer device generating M thought chains corresponding to the initial prompt word can be: semantically decomposing the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word; each semantic decomposition sequence includes at least two task keywords and a semantic mapping relationship between at least two task keywords; based on the semantic mapping relationship between at least two task keywords in each semantic decomposition sequence and at least two task keywords, a unit reasoning task corresponding to each semantic decomposition sequence is generated; the unit reasoning tasks corresponding to the M semantic decomposition sequences are determined as the M thought chains corresponding to the initial prompt word.
[0180] Specifically, the computer device may perform semantic decomposition on the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word, each semantic decomposition sequence including a plurality of task keywords and semantic mapping relationships between the task keywords. The semantic decomposition may be performed by segmenting the initial prompt word, and the M semantic decomposition sequences may correspond to M different segmentation schemes.
[0181] Based on the mapping relationship between task keywords and semantics in each semantic decomposition sequence, the computer device can generate a corresponding unit reasoning task for each semantic decomposition sequence. For example, in a text review task, the semantic decomposition sequence can correspond to unit reasoning tasks such as "classifying speech, classifying given speech as expressing opinions, venting emotions, etc.", "identifying keywords, identifying keywords with derogatory connotations," and "determining the text type, determining the degree of derogatory connotations in the text." The computer device can determine the unit reasoning tasks corresponding to M semantic decomposition sequences as M thought chains corresponding to the initial prompt word. Multiple unit reasoning tasks corresponding to a semantic decomposition sequence can be used to form a thought chain.
[0182] Please also refer to Figure 5 , Figure 5 This is a scenario diagram proposed in the embodiment of this application Figure 2 ,like Figure 5 As shown, the automatic thought chain method can be to input the initial prompt word into the large language model, parse and disassemble the initial prompt word according to preset rules, and obtain the task keywords such as the object, target, and rule of the initial prompt word. Different parsing and disassembly can obtain different semantic disassembly sequences. The large language model can also reconstruct the task keywords in the semantic disassembly sequence according to preset rules to obtain the unit reasoning task corresponding to each semantic disassembly sequence, and then obtain M thought chains corresponding to the initial prompt word. Among them, the preset rules can refer to pre-set structured strategies or logical templates used to guide the model to complete the task disassembly and reconstruction process.
[0183] Taking the thinking tree as an example, the process of a computer device generating M thinking chains corresponding to the initial prompt word can be: generating a root node task based on the initial prompt word, generating Q candidate tasks based on the initial prompt word and the root node task, generating growth scores corresponding to the Q candidate tasks based on the semantic correctness scores corresponding to the Q candidate tasks, and the vector similarity between the Q candidate tasks and the root node task; Q is a positive integer; based on the Q growth scores, determining H tasks to be grown from the Q candidate tasks, based on the initial prompt word, the root node task and the H tasks to be grown, generating candidate tasks corresponding to the H tasks to be grown, and continuing to determine new tasks to be grown through the candidate tasks corresponding to the H tasks to be grown, until the new tasks to be grown meet the growth termination condition, and then determining the M task paths between the root node task and the new tasks to be grown as the M thinking chains corresponding to the initial prompt word; H is a positive integer less than or equal to Q.
[0184] For details, please refer to Figure 6 , Figure 6 This is a scenario diagram proposed in the embodiment of this application Figure 3 ,like Figure 6 As shown, the computer device can generate a root node task based on the initial prompt word. For example, if the initial prompt word is "How to improve personal learning efficiency," the computer device can generate the root node task based on the zero-shot generation method. The root node task can be the reasoning step text of "Please list preliminary methods to improve personal learning efficiency." Optionally, the root node task can also be the same text as the initial prompt word.
[0185] The computer device can generate Q candidate tasks based on the initial prompt word and the root node task. The Q candidate tasks can include candidate task 11, candidate task 12 and candidate task 13. Candidate task 11 can be the reasoning step text of "improving personal learning efficiency by extending learning time", candidate task 12 can be the reasoning step text of "improving personal learning efficiency by improving the learning environment", and candidate task 13 can be the reasoning step text of "improving personal learning efficiency by optimizing learning methods".
[0186] The computer device can generate growth scores corresponding to the Q candidate tasks based on the semantic correctness scores corresponding to the Q candidate tasks and the vector similarities between the Q candidate tasks and the root node task. Among them, the semantic correctness score can be a score obtained by evaluating the logical consistency of the candidate task through a large language model, and the vector similarity can be a measure such as cosine similarity, Pearson Correlation Coefficient, and Euclidean Distance. The growth score can be a weighted sum of the semantic correctness score and the vector similarity, which is not limited in the embodiment of the present application.
[0187] The computer device can determine H tasks to be grown from Q candidate tasks based on the Q growth scores. For example, the candidate tasks with growth scores greater than or equal to the preset growth scores can be determined as tasks to be grown. For example, if extending the learning time for candidate task 11 does not improve learning efficiency, the semantic correctness score corresponding to candidate task 11 is low, and the growth score corresponding to candidate task 11 is less than the preset growth score. The computer device can delete candidate task 11 and determine candidate task 12 and candidate task 13 as tasks to be grown.
[0188] The computer device can generate candidate tasks corresponding to H tasks to be grown based on the initial prompt word, the root node task and the H tasks to be grown. The candidate tasks corresponding to the H tasks to be grown can also be generated based on the zero-sample generation method. For example, candidate tasks 21 and candidate tasks 22 corresponding to candidate task 12, and candidate tasks 23 and candidate tasks 24 corresponding to candidate task 13 can be generated. For example, candidate task 23 can be "Improve personal learning efficiency through mind mapping."
[0189] The computer device can continue to determine new tasks to be grown using the candidate tasks corresponding to the H tasks to be grown. For example, it can delete candidate tasks 22 and 24, determine candidate tasks 21 and 23 as new tasks to be grown, and continue to generate candidate tasks 31 and 32 corresponding to candidate task 21, and candidate tasks 33 and 34 corresponding to candidate task 23. The computer device can determine that candidate tasks 31, 32, and 33 are new tasks to be grown and delete candidate task 34. At this point, the computer device can determine that the growth termination condition is met. The growth termination condition can be that the depth of the task path reaches a preset depth value or that the obtained tasks to be grown cannot generate further candidate tasks. For example, if the task path at this time is 4, which is equal to the preset depth value, the computer device can determine the three task paths between the root node task and candidate tasks 31, 32, and 33 as the three thought chains corresponding to the initial prompt word. For example, one of the task paths can include the root node task, candidate task 12, candidate task 21, and candidate task 31.
[0190] Step S205: Based on the M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words;
[0191] Specifically, the computer device may obtain task keywords corresponding to M thought chains, perform statistics on the task keywords corresponding to the M thought chains, and obtain L keyword statistics. Based on the L keyword statistics, the computer device may determine a target keyword from the task keywords corresponding to the M thought chains. The target keyword may be a task keyword whose number in the L keyword statistics exceeds a preset threshold. In the task of classifying natural disaster news, the target keywords may include "classification," "natural disaster," and "news."
[0192] The computer device can generate task framework text corresponding to the initial prompt word based on the target keyword. The task framework text may include role prompt words, task prompt words, and output format prompt words. The role prompt words are used to clarify the role played by the large language model (such as news classification expert, weather forecast expert, etc.) and are used to indicate the task area that the large language model needs to process. The task prompt words are used to describe the specific work objectives to be completed (such as "analyzing the market share of a certain industry" or "classifying input news") and are used to indicate the task content that the large language model needs to process. The output format prompt words are used to instruct the large language model to generate output in a predetermined format. For example, it can be a structured requirement for specifying the output, such as a Markdown list, a PPT outline, or a step-by-step explanation. In the task of classifying natural disaster news, the task framework text corresponding to the initial prompt word can be "You are a news classification expert. Classify the following news and determine whether the news is natural disaster news. Output the result of the Markdown list."
[0193] The computer device can perform semantic expansion on the task keywords corresponding to the M thinking chains to obtain extended keywords. For example, the task keyword of "natural disasters" can be semantically expanded, and the obtained extended keywords may include "earthquakes, vibrations caused by crustal movement", "floods, rivers, lakes, reservoirs and other water bodies overflowing", "typhoons, tropical cyclones, usually accompanied by strong winds and heavy rains", etc.
[0194] Please also refer to Figure 7 , Figure 7 This is a scenario diagram proposed in the embodiment of this application Figure 4 ,like Figure 7 As shown, the computer device can generate M instruction rewriting prompts based on the task framework text, M thought chains, and extended keywords. For example, the task framework text, thought chains, and extended keywords can be concatenated to generate instruction rewriting prompts. In the natural disaster news classification task, one thought chain can be "1. Keyword recognition: identifying whether the news contains the following keywords: earthquake, flood, typhoon, etc.; 2. Event description: determining whether the news content describes serious events caused by the above keywords; 3. Excluding reconstruction and ecological protection: If the news content is about reconstruction and ecological protection after a natural disaster, such as urban reconstruction and environmental protection, it is not considered natural disaster news."
[0195] Therefore, the spliced instruction rewrite prompt can be "You are a news classification expert. Classify the following news and determine whether the news is natural disaster news. Output the result of the Markdown list. Rules and guidelines: 1. Keyword recognition, identify whether the news contains the following keywords: earthquake, flood, typhoon, etc.; 2. Event description, determine whether the news content describes serious events caused by the above keywords; 3. Exclude reconstruction and ecological protection. If the content of the news is reconstruction and ecological protection news after natural disasters, such as urban reconstruction, environmental protection, etc., it is not considered natural disaster news. Specific explanation: earthquakes, vibrations caused by crustal movement, floods, flooding of rivers, lakes, reservoirs and other water bodies, typhoons, tropical cyclones, usually accompanied by strong winds and heavy rains."
[0196] Step S206, obtaining N test data from the test data set;
[0197] Specifically, the computer device can obtain N test data in the test data set. The method of determining N test data can be zero samples (that is, not using any samples), random samples (using randomly sampled samples), nearest neighbor samples (using samples most similar to the input), diversity samples (using multiple representative samples), all samples (using all samples), etc. The embodiments of the present application are not limited here.
[0198] Taking the nearest neighbor examples as an example, the computer device can use the KATE method (K-nearest neighbor Augmented Training Examples, a sampling method designed based on the nearest neighbor principle) to generate vector similarities between each test data in the test data set and the initial prompt word. The vector similarity between the test data and the initial text prompt can also be measured by cosine similarity, Pearson correlation coefficient, Euclidean distance, etc. The computer device can determine the test data in the test data set whose vector similarity is greater than or equal to the nearest neighbor threshold as N test data.
[0199] As you can understand, the nearest neighbor examples can be selected as those most similar to the initial prompt. This example optimization generates content-expanded prompts. The large language model can then refer to the input-output pairs in these content-expanded prompts to help it generate better answers. Providing high-quality examples in content-expanded prompts to guide the model's learning tasks can improve the model's understanding and ability to handle complex tasks. This not only provides guiding demonstrations but also broadens the model's application scope through diverse examples, preventing poor performance due to a lack of sufficient learning references.
[0200] Taking diversity samples as an example, the process of a computer device determining N test data in a test data set can be: clustering the test data in the test data set to obtain N clusters; each cluster includes a cluster center data, and a cluster center data is used to represent the average characteristics of the test data in a cluster; in the N clusters, obtaining the mixed similarity corresponding to each test data and the associated cluster center data, sampling the test data with the maximum mixed similarity in each cluster to obtain N test data.
[0201] Specifically, the computer device can obtain the vector similarity between each test data in the test data set and the initial prompt word, and cluster the test data in the test data set based on the vector similarity between the test data and the initial prompt word to obtain N clusters. Each cluster includes a cluster center data, and the cluster center data is used to represent the average characteristics of the test data in the cluster. The clustering method can be K-means clustering or C-means clustering, which is not limited in this embodiment of the present application.
[0202] In N clusters, the computer device obtains the mixed similarity corresponding to each test data and the associated cluster center data, and the N clusters include cluster R i For example, get the cluster R i The process of the mixed similarity corresponding to each test data in can be: cluster cluster R i The test data in the cluster is determined as the in-cluster data, and the semantic vector of each in-cluster data and the cluster Ri The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to each cluster data; based on the text length of each cluster data and the cluster R i The text length of the cluster center data is used to generate the text length similarity corresponding to each cluster data; the cluster R is obtained. i The information entropy corresponding to each data in the cluster is generated based on the cosine similarity, text length similarity and information entropy corresponding to each data in the cluster. i The mixed similarity corresponding to the cluster center data.
[0203] Specifically, the computer device can cluster the cluster R i The test data in the cluster is determined as the in-cluster data, and the semantic vector of each in-cluster data and the cluster R i The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to each cluster data. The process is shown in formula (3):
[0204] Simlarity i =cosine_sim(emb(x i ),emb(x test )) Formula (3)
[0205] Among them, Simlarity i is the cluster R i Data x in the cluster i The corresponding cosine similarity, emb(x i ) is the data x in the cluster i The semantic vector of emb(x test ) is the semantic vector of cluster center data.
[0206] The computer device can cluster the clusters based on the text length of the data in each cluster and the R i The text length of the cluster center data is used to generate the text length similarity (Smooth Length Similarity) corresponding to each cluster data. The process is shown in formula (4):
[0207]
[0208] Among them, SLS i is the cluster R i Data x in the cluster i The corresponding text length similarity, len(x i ) is the data x in the cluster i The length of the text, len(x test ) is the text length of the cluster center data, and T is the average length of the data within the cluster.
[0209] Computer equipment can cluster R i The cluster data in the word segmentation is performed to obtain V word units. The occurrence probability of each word unit is generated through X word units, and the cluster R is generated based on the occurrence probability of each word unit. i The information entropy corresponding to each data in the cluster is shown in formula (5):
[0210]
[0211] Among them, H i is the cluster R i Data x in the cluster i The corresponding information entropy, the data x in the cluster i It can include X words, X words include Cluster R i The cluster data in can be segmented to obtain a total of V tokens. Represents the data x in the cluster i Corresponding word The probability of appearing in V words.
[0212] The computer device can generate the relationship between each cluster data and the cluster R based on the cosine similarity, text length similarity and information entropy corresponding to each cluster data. i The mixed similarity corresponding to the cluster center data is respectively calculated. The mixed similarity can be a weighted sum of cosine similarity, text length similarity, and information entropy. The present embodiment of the application does not limit the coefficients of the weighted calculation. The computer device can sample the test data with the maximum mixed similarity in each cluster to obtain N test data.
[0213] It can be understood that in the diversity sample method proposed in the embodiment of the present application, by considering the cosine similarity, text length similarity and information entropy corresponding to each cluster data, it is possible to avoid the problem of incomplete features caused by only using the cluster data that is the nearest neighbor of the cosine similarity with the cluster center data. It is possible to further consider comprehensive indicators such as information entropy and text length in more dimensions of the data to improve the diversity of adoption. By selecting high-quality examples, the model can be guided to complete the task with fewer data samples, reducing the dependence on large-scale annotated data. Through carefully selected examples, the model can achieve higher performance on smaller data sets, effectively reducing the cost and time of data preparation.
[0214] Step S207: insert N test data into each of the M instruction rewriting prompt words to obtain M content expansion prompt words; each content expansion prompt word includes N test data;
[0215] For details, please refer to Figure 7 ,like Figure 7 As shown, the computer device can perform sample optimization on M instruction rewriting prompt words through N test data. For example, N test data can be respectively inserted into the M instruction rewriting prompt words to obtain M content expansion prompt words.
[0216] Step S208 : performing multiple rounds of prompt word optimization on the M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words.
[0217] Specifically, the computer device can perform multiple rounds of prompt word optimization on M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words. Each round of prompt word optimization in the multiple rounds of prompt word optimization can mainly include an evaluation phase (Score), a screening and induction phase (Reduce), and an optimization phase (Refine). Among them, the evaluation phase is used to evaluate the effectiveness of the prompt words, using a verification data set to score different prompt words and find out the advantages and disadvantages of the prompt words. The screening and induction phase is used to filter out prompt words with poor performance based on the results of the evaluation phase, and generate prompt words for the next round of iterative optimization through optimization methods such as induction, merging, and adjustment. The optimization phase is used to further optimize the prompt words through instruction rewriting and sample optimization to improve their performance in specific tasks.
[0218] When the target iterative optimization algorithm is an automatic iterative optimization algorithm (APE), the multi-round prompt word optimization process may include: obtaining a validation dataset, generating validation evaluation scores corresponding to M content expansion prompt words using the validation dataset, determining K iterative optimization prompt words from the M content expansion prompt words using the validation evaluation scores corresponding to the M content expansion prompt words, where K is a positive integer less than or equal to M; combining the K iterative optimization prompt words to obtain S content expansion prompt word groups, performing semantic induction on the content expansion prompt words in each content expansion prompt word group to obtain S merged optimization prompt words; generating validation evaluation scores corresponding to the S merged optimization prompt words using the validation dataset, and continuously determining new K iterative optimization prompt words from the S merged optimization prompt words using the validation evaluation scores corresponding to the S merged optimization prompt words, until the new S merged optimization prompt words obtained from the new K iterative optimization prompt words meet the iteration termination condition, and determining the new S merged optimization prompt words as the S target prompt words.
[0219] For details, please refer to Figure 8 , Figure 8 This is a scenario diagram proposed in the embodiment of this application Figure 5 ,like Figure 8As shown, the computer device can obtain a verification data set, which can be a data set sampled in various task fields, and each verification data in the verification data set includes a corresponding sample label. The amount of data in the verification data set can be larger than the test data set. The computer device can generate verification evaluation scores corresponding to M content expansion prompt words through the verification data set. Optionally, the computer device can sample in the verification data set, and generate verification evaluation scores corresponding to M content expansion prompt words through the verification subset obtained by sampling. The sampling method can include random sampling, diversity sampling, etc., which is not limited in the embodiment of the present application.
[0220] The computer device may input M content expansion prompt words and a verification dataset into a large language model. In the large language model, a first set of prediction results corresponding to the verification dataset is generated using the M content expansion prompt words. The precision and recall rates corresponding to each of the M content expansion prompt words are determined using the first set of prediction results and the set of sample labels corresponding to the verification dataset. The computer device may then generate verification evaluation scores corresponding to each of the M content expansion prompt words based on the precision and recall rates corresponding to the M content expansion prompt words.
[0221] The computer device can determine K iteratively optimized prompt words from the M content expansion prompt words based on the verification evaluation scores corresponding to each of the M content expansion prompt words. The K iteratively optimized prompt words can be those with higher verification evaluation scores among the M content expansion prompt words. Any number of combinations of the K iteratively optimized prompt words can be performed to obtain S content expansion prompt phrase groups. Each content expansion prompt phrase group can include any number of iteratively optimized prompt words. The computer device can perform semantic induction on the content expansion prompt words in each content expansion prompt phrase group using a large language model to obtain S merged optimized prompt words. A merged optimized prompt word can have the global semantics of the content expansion prompt words in its corresponding content expansion prompt phrase group.
[0222] The computer device can generate verification evaluation scores corresponding to S merged optimization prompt words from the verification data set. Based on the verification evaluation scores corresponding to the S merged optimization prompt words, K new iterative optimization prompt words are continuously determined from the S merged optimization prompt words until the new S merged optimization prompt words obtained from the new K iterative optimization prompt words meet an iteration termination condition, and the new S merged optimization prompt words are determined as the S target prompt words. The iteration termination condition can be that the number of iteration rounds of iterative optimization reaches a certain round threshold, or that the verification evaluation scores of the new S merged optimization prompt words reach a certain evaluation threshold, which is not limited in this embodiment of the present application.
[0223] It can be understood that the APE algorithm incorporates screening and induction stages during the iterative optimization process. After the optimization stage, it generates a batch of new prompt words through merging and induction. Through multiple stages of evaluation and screening, the prompt words can be scored, and the tail (poorly performing) prompt words can be screened out. While maintaining the credibility of the evaluation as much as possible, the evaluation of prompt words is accelerated, cross-task generalization is supported, and a diverse prompt word design space can be covered.
[0224] When the target iterative optimization algorithm is a text gradient-based prompt word optimization algorithm (ProTeGi), the process of multi-round prompt word optimization can be: obtaining a verification data set, generating verification evaluation scores corresponding to M content expansion prompt words through the verification data set, determining K iterative optimization prompt words from the M content expansion prompt words through the verification evaluation scores corresponding to the M content expansion prompt words, determining the prompt words other than the K iterative optimization prompt words from the M content expansion prompt words as C example prompt words; K is a positive integer less than or equal to M, and C is the difference between M and K; based on the C example prompt words, generating F example gradient values are generated, and semantic adjustment is performed on each iterative optimization prompt word based on the F example gradient values to obtain S example optimization prompt words; F is a positive integer, and S is the product of C and F; verification evaluation scores corresponding to the S example optimization prompt words are generated through the verification data set, and new K iterative optimization prompt words are continuously determined from the S example optimization prompt words based on the verification evaluation scores corresponding to the S example optimization prompt words, until the new S example optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S example optimization prompt words are determined as the S target prompt words.
[0225] For details, please refer to Figure 9 , Figure 9 This is a scenario diagram proposed in the embodiment of this application Figure 6 ,like Figure 9 As shown, the computer device can obtain a verification data set, which can be a data set sampled in various task fields, and each verification data in the verification data set includes a corresponding sample label. The amount of data in the verification data set can be larger than the test data set. The computer device can generate verification evaluation scores corresponding to M content expansion prompt words through the verification data set. Optionally, the computer device can sample in the verification data set, and generate verification evaluation scores corresponding to M content expansion prompt words through the verification subset obtained by sampling. The sampling method can include random sampling, diversity sampling, etc., which is not limited in the embodiment of the present application.
[0226] The computer device may input the M content expansion prompt words and the verification dataset into a large language model. In the large language model, a second set of prediction results corresponding to the verification dataset is generated using the M content expansion prompt words. The precision and recall rates corresponding to the M content expansion prompt words are determined based on the second set of prediction results and the set of sample labels corresponding to the verification dataset. The computer device may then generate verification evaluation scores corresponding to the M content expansion prompt words based on the precision and recall rates corresponding to the M content expansion prompt words.
[0227] The computer device can determine K iterative optimization prompt words from the M content expansion prompt words based on the verification evaluation scores corresponding to each of the M content expansion prompt words. The content expansion prompt words other than the K iterative optimization prompt words from the M content expansion prompt words are determined as C example prompt words. Example prompt words can also be called bad case prompt words (Bad Cases). Optionally, the computer device can also determine content expansion prompt words that are predicted incorrectly (the prediction result is inconsistent with the sample label) in the second prediction result set as example prompt words. The computer device can input the C example prompt words into a large language model, use the large language model to mine their "error causes", and generate F example gradient values for instruction optimization. An example gradient value can be generated based on any number of example prompt words, and different example gradient values use different example prompt words.
[0228] The computer device may perform semantic adjustments on each iterative optimization prompt word based on the F example gradient values to obtain S example optimization prompt words, generate verification evaluation scores corresponding to each of the S example optimization prompt words using a verification dataset, and continue to determine K new iterative optimization prompt words from the S example optimization prompt words based on the verification evaluation scores corresponding to each of the S example optimization prompt words until the S new example optimization prompt words obtained from the new K iterative optimization prompt words meet an iteration termination condition, and then determine the new S example optimization prompt words as the S target prompt words. The iteration termination condition may be that the number of iteration rounds of the iterative optimization reaches a certain round threshold, or that the verification evaluation scores of the S new example optimization prompt words reach a certain evaluation threshold, which is not limited in this embodiment of the present application.
[0229] Optionally, during each round of iterative optimization, the computer device can use the UCBBandits (Upper Confidence Bound Bandits) algorithm or the Successive Halving algorithm to calculate the verification evaluation score for each prompt word during the screening and summarization phases. The UCB Bandits algorithm is a confidence interval quantization algorithm used to generate a comprehensive evaluation for screening based on the precision or recall rate of the prompt word in each round, the number of times the prompt word is retained, and the total number of iterative optimization rounds. This avoids falling into local optimality during the screening and summarization phases and accelerates the iterative efficiency of prompt word optimization. The Successive Halving algorithm is a phased elimination algorithm used to allocate different numbers of verification subsets in different iterative rounds, thereby eliminating low-potential prompt words early and concentrating resources on verifying high-potential prompt words, thereby accelerating the iterative efficiency of prompt word optimization. During the screening and summarization phases, the UCB Bandits algorithm and the Successive Halving algorithm can also be used in combination, which is not limited in this embodiment of the present application.
[0230] It can be understood that the ProTeGi algorithm takes into account example prompt words that were predicted incorrectly in the previous round of prompt words during the optimization stage. By instructing the large language model to explore the "cause of the error" as the "gradient" for prompt word optimization, it is used to update the screened prompt words. The prompt word optimization is modeled as a gradient descent problem, and the semantic gradient of the discrete text is adjusted through backpropagation. The optimization efficiency is high, the optimization goal is clear, and it can converge quickly.
[0231] When the target iterative optimization algorithm is a natural language-based prompt word optimization algorithm (OPRO), the process of multiple rounds of prompt word optimization may include: obtaining a validation dataset, generating validation evaluation scores corresponding to M content expansion prompt words using the validation dataset, generating feedback optimization prompt words corresponding to M content expansion prompt words using the validation evaluation scores corresponding to the M content expansion prompt words and M first historical score information; a first historical score information is used to indicate the validation evaluation score corresponding to a content expansion prompt word in the current round of prompt word optimization; generating validation evaluation scores corresponding to M feedback optimization prompt words using the validation dataset, generating new M feedback optimization prompt words using the validation evaluation scores corresponding to the M feedback optimization prompt words and M second historical score information, until the obtained new M feedback optimization prompt words meet the iteration termination condition, and determining the new M feedback optimization prompt words as S target prompt words; S and M are equal, and a second historical score information is used to indicate the validation evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the validation evaluation score corresponding to the previous round of prompt word optimization.
[0232] For details, please refer to Figure 10 , Figure 10 This is a scenario diagram proposed in the embodiment of this application Figure 7 ,like Figure 10 As shown, the computer device can obtain a verification data set, which can be a data set sampled in various task fields, and each verification data in the verification data set includes a corresponding sample label. The amount of data in the verification data set can be larger than the test data set. The computer device can generate verification evaluation scores corresponding to M content expansion prompt words through the verification data set. Optionally, the computer device can sample in the verification data set, and generate verification evaluation scores corresponding to M content expansion prompt words through the verification subset obtained by sampling. The sampling method can include random sampling, diversity sampling, etc., which is not limited in the embodiment of the present application.
[0233] The computer device may input the M content expansion prompt words and the verification dataset into a large language model. In the large language model, a third set of prediction results corresponding to the verification dataset is generated using the M content expansion prompt words. The precision and recall rates corresponding to the M content expansion prompt words are determined based on the third set of prediction results and the set of sample labels corresponding to the verification dataset. The computer device may then generate verification evaluation scores corresponding to the M content expansion prompt words based on the precision and recall rates corresponding to the M content expansion prompt words.
[0234] The computer device can obtain the first historical score information corresponding to M content expansion prompt words respectively. The first historical score information is used to indicate the verification evaluation score corresponding to a content expansion prompt word in this round of prompt word optimization. The first historical score information can also include text such as "The verification evaluation score of the content expansion prompt word in this round of prompt word optimization is 67. Please continue to optimize the prompt word to improve its verification evaluation score." The computer device can generate feedback optimization prompt words corresponding to the M content expansion prompt words through the verification evaluation scores corresponding to the M content expansion prompt words and the M first historical score information. The computer device can generate the verification evaluation scores corresponding to the M feedback optimization prompt words through the verification data set, and obtain the second historical score information corresponding to the M feedback optimization prompt words. The second historical score information is used to indicate the verification evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the verification evaluation score corresponding to the previous round of prompt word optimization. The first historical score information can also include text such as "The verification evaluation score of the content expansion prompt word in the previous round of prompt word optimization is 67, and the verification evaluation score in the current round of prompt word optimization is 73. Please continue to optimize the prompt word to improve its verification evaluation score."
[0235] The computer device may generate M new feedback optimization prompt words using the verification evaluation scores corresponding to the M feedback optimization prompt words and the M second historical score information, until the M new feedback optimization prompt words satisfy an iteration termination condition, and then determine the M new feedback optimization prompt words as the S target prompt words. The iteration termination condition may be when the number of iterations of the iterative optimization reaches a certain round threshold, or when the verification evaluation scores of the S new feedback optimization prompt words reach a certain evaluation threshold, which is not limited in this embodiment of the present application.
[0236] It can be understood that the OPRO algorithm considers another type of prior knowledge for prompt word optimization during its optimization phase (which can also be considered the screening and induction phase here). This is the previous round of prompt words and their performance scores. This provides the large language model with historical score information for the previous round of prompt words, helping the large language model to better summarize favorable information and iteratively improve the prompt words through natural language feedback. Without the need for mathematical modeling, the algorithm leverages the large language model's inherent reasoning capabilities to optimize the prompt words.
[0237] When the target iterative optimization algorithm is an evolutionary-based prompt word optimization algorithm (EvoPrompt), the multi-round prompt word optimization process may include: obtaining a validation dataset, generating validation evaluation scores corresponding to M content expansion prompt words using the validation dataset, determining K iterative optimization prompt words from the M content expansion prompt words based on the validation evaluation scores, wherein K is a positive integer less than or equal to M; performing keyword replacement on the K iterative optimization prompt words to obtain K replacement prompt words, combining any two replacement prompt words from the K replacement prompt words to obtain S replacement prompt phrase groups; performing semantic induction on the replacement prompt words in each replacement prompt phrase group to obtain S cross-optimization prompt words; generating validation evaluation scores corresponding to the S cross-optimization prompt words using the validation dataset, and continuously determining K new iterative optimization prompt words from the S cross-optimization prompt words based on the validation evaluation scores, until the new S cross-optimization prompt words obtained from the new K iterative optimization prompt words meet the iteration termination condition, and determining the new S cross-optimization prompt words as the S target prompt words.
[0238] For details, please refer to Figure 11 , Figure 11 This is a scenario diagram proposed in the embodiment of this application Figure 8 ,like Figure 11As shown, the computer device can obtain a verification data set, which can be a data set sampled in various task fields, and each verification data in the verification data set includes a corresponding sample label. The amount of data in the verification data set can be larger than the test data set. The computer device can generate verification evaluation scores corresponding to M content expansion prompt words through the verification data set. Optionally, the computer device can sample in the verification data set, and generate verification evaluation scores corresponding to M content expansion prompt words through the verification subset obtained by sampling. The sampling method can include random sampling, diversity sampling, etc., which is not limited in the embodiment of the present application.
[0239] The computer device may input the M content expansion prompt words and the verification dataset into a large language model. In the large language model, a fourth set of prediction results corresponding to the verification dataset is generated using the M content expansion prompt words. The precision and recall rates corresponding to the M content expansion prompt words are determined based on the fourth set of prediction results and the set of sample labels corresponding to the verification dataset. The computer device may then generate verification evaluation scores corresponding to the M content expansion prompt words based on the precision and recall rates corresponding to the M content expansion prompt words.
[0240] The computer device may determine K iterative optimization prompt words from the M content expansion prompt words. The K iterative optimization prompt words may be content expansion prompt words with higher verification evaluation scores among the M content expansion prompt words. The computer device may perform keyword substitution (also known as rewriting) on the K iterative optimization prompt words to obtain K replacement prompt words. Any two replacement prompt words from the K replacement prompt words may be combined (crossover) to obtain S replacement prompt phrase groups. Each replacement prompt phrase group includes two replacement prompt words, and the replacement prompt words in different replacement prompt phrase groups are different.
[0241] The computer device may perform semantic induction on the replacement prompt words in each replacement prompt word group to obtain S cross-optimization prompt words, generate verification evaluation scores corresponding to each of the S cross-optimization prompt words using a verification data set, and continue to determine K new iterative optimization prompt words from the S cross-optimization prompt words based on the verification evaluation scores corresponding to each of the S cross-optimization prompt words until the new S cross-optimization prompt words obtained from the new K iterative optimization prompt words meet an iteration termination condition, and then determine the new S cross-optimization prompt words as the S target prompt words. The iteration termination condition may be that the number of iteration rounds of iterative optimization reaches a certain round threshold, or that the verification evaluation scores of the new S cross-optimization prompt words reach a certain evaluation threshold, which is not limited in this embodiment of the present application.
[0242] It can be understood that the EvoPrompt algorithm proposes replacement and combination operations in the screening and induction stages as well as the optimization stage, which to a certain extent expands the search space of the prompt word optimization process. Its replacement and combination operations imitate biological evolution and generate high-quality prompt words through mutation, crossover and natural selection.
[0243] This embodiment of the present application introduces T iterative optimization algorithms and generates algorithm evaluation scores corresponding to each of the T iterative optimization algorithms. The optimal iterative optimization algorithm for the initial prompt word can be selected from a test dataset. By rewriting the instructions, thought chains, task framework text, and extended keywords are added to the prompt word, enabling the large language model to more accurately understand the task requirements. The thought chains in the content-expanded prompt word can instruct the large language model to generate intermediate thought processes rather than directly output conclusions, thereby improving accuracy in complex reasoning tasks. The examples in the content-expanded prompt word provide high-quality reference information to guide the model in learning task patterns, improving the model's understanding and ability to cope with complex tasks. This not only provides guiding demonstrations but also broadens the model's application scope through different types of examples, avoiding poor performance due to a lack of sufficient learning references. Using a target iterative optimization algorithm, multiple rounds of prompt word optimization are performed on M content-expanded prompt words to obtain S target prompt words. The optimization process no longer relies on manual trial and error, but instead rapidly generates high-quality prompts through intelligent evaluation, screening, and rewriting steps. This improves the efficiency of prompt word optimization, as well as the accuracy and recall of prompt words.
[0244] By using the prompt word optimization method of the embodiment of the present application, the target prompt word obtained can more accurately guide the large language model to perform tasks, thereby reducing the instability of the output. Through the optimized prompt word, the model can better understand the task requirements and provide more accurate and expected output results. For example, in complex content review tasks, the optimized prompt word can clarify the model's judgment rules and avoid misjudgments caused by vague tasks or unclear prompts. Through automated prompt word optimization and efficient task adaptability, the embodiment of the present application can significantly improve the efficiency of developers in the model application process. Compared with traditional manual prompt design, the embodiment of the present application can significantly shorten the development cycle and reduce the cost of manual design and adjustment. At the same time, since the optimization process no longer relies on a large amount of data annotation, enterprises and developers can complete more tasks in a shorter time, reducing development and training costs. In summary, the embodiment of the present application solves the problems of inefficiency, instability, and poor task adaptability of prompt word design by introducing an automated and intelligent prompt word optimization method, significantly improves the performance of large language models in practical applications, and provides developers with a more efficient and scalable solution.
[0245] See Figure 12 , Figure 12This is a structural diagram of a data processing device provided in an embodiment of the present application. Figure 12 As shown, the data processing device 1 includes an algorithm testing module 610 , an algorithm determination module 620 , a content expansion module 630 and an iterative optimization module 640 .
[0246] Algorithm testing module 610 is configured to obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word using T iterative optimization algorithms, input the T test prompt words and the test dataset into a large language model, and generate a set of prediction results corresponding to the test dataset under the T test prompt words using the large language model, where T is a positive integer.
[0247] An algorithm determination module 620 is configured to generate algorithm evaluation scores corresponding to the T iterative optimization algorithms based on the T prediction result sets and the sample label sets corresponding to the test dataset, and to determine a target iterative optimization algorithm from the T iterative optimization algorithms based on the T algorithm evaluation scores;
[0248] The content expansion module 630 is used to generate M thought chains corresponding to the initial prompt word, and based on the M thought chains and the test data set, expand the content of the initial prompt word to obtain M content-expanded prompt words; M is a positive integer;
[0249] The iterative optimization module 640 is configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words through a target iterative optimization algorithm to obtain S target prompt words, where S is a positive integer.
[0250] In one possible implementation, the T iterative optimization algorithms include iterative optimization algorithm A i , i is a positive integer less than or equal to T, T test prompt words include iterative optimization algorithm A i Corresponding test prompt word B i The test data set includes positive data and negative data; the algorithm testing module 610 is used to generate algorithm evaluation scores corresponding to T iterative optimization algorithms based on the T prediction result sets and the sample label sets corresponding to the test data set, and specifically performs the following operations:
[0251] Based on the test prompt word B i For the corresponding prediction result set and the sample label set corresponding to the test data set, the number of first positive examples of correctly predicted positive data, the number of second positive examples of incorrectly predicted positive data, the number of first negative examples of correctly predicted negative data, and the number of second negative examples of incorrectly predicted negative data are counted; the sum of the number of first positive examples and the number of second positive examples is the number of positive data, and the sum of the number of first negative examples and the number of second negative examples is the number of negative data;
[0252] Generate an iterative optimization algorithm A based on the first number of positive examples, the second number of positive examples, the first number of negative examples, and the second number of negative examples i The corresponding prediction accuracy;
[0253] Based on the first number of positive examples and the second number of positive examples, an iterative optimization algorithm A is generated. i The corresponding prediction recall rate;
[0254] Based on iterative optimization algorithm A i Corresponding prediction accuracy and iterative optimization algorithm A i The corresponding prediction recall rate generates an iterative optimization algorithm A i The corresponding algorithm evaluation score.
[0255] In a possible implementation, when the content expansion module 630 is used to generate M thought chains corresponding to the initial prompt word, it is specifically used to perform the following operations:
[0256] Semantically decompose the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word; each semantic decomposition sequence includes at least two task keywords and a semantic mapping relationship between at least two task keywords;
[0257] Based on the at least two task keywords in each semantic decomposition sequence and the semantic mapping relationship between the at least two task keywords, generating a unit reasoning task corresponding to each semantic decomposition sequence;
[0258] The unit reasoning tasks corresponding to the M semantic decomposition sequences are determined as the M thinking chains corresponding to the initial prompt words.
[0259] In a possible implementation, when the content expansion module 630 is used to generate M thought chains corresponding to the initial prompt word, it is specifically used to perform the following operations:
[0260] Generate a root node task based on the initial prompt word, generate Q candidate tasks based on the initial prompt word and the root node task, and generate growth scores corresponding to the Q candidate tasks based on the semantic correctness scores corresponding to the Q candidate tasks and the vector similarity between the Q candidate tasks and the root node task; Q is a positive integer;
[0261] Based on the Q growth scores, H tasks to be grown are determined from the Q candidate tasks. Based on the initial prompt word, the root node task and the H tasks to be grown, candidate tasks corresponding to the H tasks to be grown are generated. New tasks to be grown are continued to be determined through the candidate tasks corresponding to the H tasks to be grown. When the new tasks to be grown meet the growth termination conditions, the M task paths between the root node task and the new tasks to be grown are determined as the M thinking chains corresponding to the initial prompt word; H is a positive integer less than or equal to Q.
[0262] In one possible implementation, the content expansion module 630 is configured to expand the content of the initial prompt words based on the M thought chains and the test data set to obtain M content expansion prompt words, and specifically to perform the following operations:
[0263] Based on M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words;
[0264] N test data are obtained from a test data set, and the N test data are respectively inserted into M instruction rewriting prompt words to obtain M content expansion prompt words; each content expansion prompt word includes N test data.
[0265] In a possible implementation, the content expansion module 630 is configured to rewrite the initial prompt word based on M thought chains, and when M instruction rewriting prompt words are obtained, specifically to perform the following operations:
[0266] Obtain task keywords corresponding to M thought chains, perform statistics on the task keywords corresponding to the M thought chains, obtain L keyword statistics results, and determine at least two target keywords from the task keywords corresponding to the M thought chains based on the L keyword statistics results; L is a positive integer less than or equal to M;
[0267] Generate a task framework text corresponding to the initial prompt word based on at least two target keywords; the task framework text includes a role prompt word, a task prompt word, and an output format prompt word, the role prompt word is used to indicate the task domain to be processed by the large language model, the task prompt word indicates the task content to be processed by the large language model, and the output format prompt word is used to instruct the large language model to generate an output in a predetermined format;
[0268] Perform semantic expansion on the task keywords corresponding to each of the M thought chains to obtain at least two expanded keywords;
[0269] Based on the task framework text, M thought chains and at least two extended keywords, M instruction rewriting prompts are generated.
[0270] In a possible implementation, when the content expansion module 630 is configured to obtain N test data from the test data set, it is specifically configured to perform the following operations:
[0271] Generate vector similarity between each test data in the test data set and the initial prompt word, and determine the test data in the test data set whose vector similarity is greater than or equal to the nearest neighbor threshold as N test data.
[0272] In a possible implementation, the content expansion module 630 is used to cluster the test data in the test data set to obtain N clusters; each cluster includes a cluster center data, and the cluster center data is used to represent the average characteristics of the test data in the cluster;
[0273] In N clusters, the mixed similarity between each test data and the associated cluster center data is obtained, and the test data with the maximum mixed similarity in each cluster is sampled to obtain N test data. When , it is specifically used to perform the following operations:
[0274] In one possible implementation, the N clusters include cluster R i , i is a positive integer less than or equal to N; the content expansion module 630 is used to obtain the mixed similarity corresponding to each test data and its cluster center data in N clusters, specifically for performing the following operations:
[0275] The cluster R i The test data in the cluster is determined as the in-cluster data, and the semantic vector of each in-cluster data and the cluster R i The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to the data in each cluster;
[0276] Cluster R based on text length and data within each cluster i The text length of the cluster center data is used to generate the text length similarity corresponding to the data in each cluster;
[0277] Get cluster R i The information entropy corresponding to the data in each cluster;
[0278] Based on the cosine similarity, text length similarity and information entropy corresponding to each cluster data, the data within each cluster and the cluster R are generated. i The mixed similarity corresponding to the cluster center data.
[0279] In one possible implementation, the iterative optimization module 640 is configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module 640 is configured to perform the following operations:
[0280] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words; K is a positive integer less than or equal to M;
[0281] Combine the K iteratively optimized prompt words to obtain S content expansion prompt phrases, and perform semantic induction on the content expansion prompt words in each content expansion prompt phrase to obtain S merged optimized prompt words;
[0282] The validation data set is used to generate validation evaluation scores corresponding to S merged optimization prompt words. Based on the validation evaluation scores corresponding to the S merged optimization prompt words, new K iterative optimization prompt words are continuously determined from the S merged optimization prompt words until the new S merged optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S merged optimization prompt words are determined as the S target prompt words.
[0283] In one possible implementation, the iterative optimization module 640 is configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module 640 is configured to perform the following operations:
[0284] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, determine K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores, and determine the prompt words from the M content expansion prompt words, excluding the K iteratively optimized prompt words, as C example prompt words, where K is a positive integer less than or equal to M, and C is the difference between M and K.
[0285] Based on C example prompt words, generate F example gradient values. Based on the F example gradient values, semantic adjustment is performed on each iteratively optimized prompt word to obtain S example optimized prompt words. F is a positive integer, and S is the product of C and F.
[0286] The validation data set is used to generate validation evaluation scores corresponding to S example optimization prompt words. Based on the validation evaluation scores corresponding to the S example optimization prompt words, new K iterative optimization prompt words are continuously determined from the S example optimization prompt words until the new S example optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S example optimization prompt words are determined as the S target prompt words.
[0287] In one possible implementation, the iterative optimization module 640 is configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module 640 is configured to perform the following operations:
[0288] Obtain a validation dataset, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation dataset, and generate feedback optimization prompt words corresponding to the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words and M first historical score information; each first historical score information is used to indicate the validation evaluation score corresponding to a content expansion prompt word in this round of prompt word optimization;
[0289] Generate verification evaluation scores corresponding to M feedback optimization prompt words using the verification data set. Generate new M feedback optimization prompt words using the verification evaluation scores corresponding to the M feedback optimization prompt words and M second historical score information until the obtained new M feedback optimization prompt words meet the iteration termination condition. The new M feedback optimization prompt words are determined as S target prompt words; S and M are equal, and one second historical score information is used to indicate the verification evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the verification evaluation score corresponding to the previous round of prompt word optimization.
[0290] In one possible implementation, the iterative optimization module 640 is configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words using a target iterative optimization algorithm. When S target prompt words are obtained, the iterative optimization module 640 is configured to perform the following operations:
[0291] Obtain a validation data set, generate validation evaluation scores corresponding to M content expansion prompt words based on the validation data set, and determine K iteratively optimized prompt words from the M content expansion prompt words, where K is a positive integer less than or equal to M.
[0292] Perform keyword replacement on the K iteratively optimized prompt words to obtain K replacement prompt words, and combine any two replacement prompt words among the K replacement prompt words to obtain S replacement prompt phrase groups;
[0293] Perform semantic induction on the replacement prompt words in each replacement prompt phrase to obtain S cross-optimized prompt words;
[0294] The validation data set is used to generate validation evaluation scores corresponding to S cross-optimization prompt words. Based on the validation evaluation scores corresponding to the S cross-optimization prompt words, new K iterative optimization prompt words are continuously determined from the S cross-optimization prompt words until the new S cross-optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S cross-optimization prompt words are determined as the S target prompt words.
[0295] This embodiment of the present application introduces T iterative optimization algorithms and generates algorithm evaluation scores corresponding to each of the T iterative optimization algorithms. The optimal iterative optimization algorithm for the initial prompt word can be selected from a test dataset. By rewriting the instructions, thought chains, task framework text, and extended keywords are added to the prompt word, enabling the large language model to more accurately understand the task requirements. The thought chains in the content-expanded prompt word can instruct the large language model to generate intermediate thought processes rather than directly output conclusions, thereby improving accuracy in complex reasoning tasks. The examples in the content-expanded prompt word provide high-quality reference information to guide the model in learning task patterns, improving the model's understanding and ability to cope with complex tasks. This not only provides guiding demonstrations but also broadens the model's application scope through different types of examples, avoiding poor performance due to a lack of sufficient learning references. Using a target iterative optimization algorithm, multiple rounds of prompt word optimization are performed on M content-expanded prompt words to obtain S target prompt words. The optimization process no longer relies on manual trial and error, but instead rapidly generates high-quality prompts through intelligent evaluation, screening, and rewriting steps. This improves the efficiency of prompt word optimization, as well as the accuracy and recall of prompt words.
[0296] By using the prompt word optimization method of the embodiment of the present application, the target prompt word obtained can more accurately guide the large language model to perform tasks, thereby reducing the instability of the output. Through the optimized prompt word, the model can better understand the task requirements and provide more accurate and expected output results. For example, in complex content review tasks, the optimized prompt word can clarify the model's judgment rules and avoid misjudgments caused by vague tasks or unclear prompts. Through automated prompt word optimization and efficient task adaptability, the embodiment of the present application can significantly improve the efficiency of developers in the model application process. Compared with traditional manual prompt design, the embodiment of the present application can significantly shorten the development cycle and reduce the cost of manual design and adjustment. At the same time, since the optimization process no longer relies on a large amount of data annotation, enterprises and developers can complete more tasks in a shorter time, reducing development and training costs. In summary, the embodiment of the present application solves the problems of inefficiency, instability, and poor task adaptability of prompt word design by introducing an automated and intelligent prompt word optimization method, significantly improves the performance of large language models in practical applications, and provides developers with a more efficient and scalable solution.
[0297] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0298] See Figure 13 , Figure 13 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 13 As shown, the computer device 1000 may include: a processor 1001, a network interface 1004 and a memory 1005. In addition, the above-mentioned computer device 1000 may also include: a user interface 1003, and at least one communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), a keyboard (Keyboard), and the user interface 1003 may optionally include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk memory. The memory 1005 may optionally also be at least one storage device located away from the aforementioned processor 1001. As Figure 13 As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application.
[0299] In such Figure 13 In the computer device 1000 shown, the network interface 1004 can provide a network communication element; the user interface 1003 is mainly used to provide an interface for user input; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve:
[0300] Obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word through T iterative optimization algorithms, input the T test prompt words and the test dataset into the large language model, and use the large language model to generate a set of prediction results corresponding to the test dataset under the T test prompt words; T is a positive integer;
[0301] Based on the T prediction result sets and the sample label sets corresponding to the test data set, generate algorithm evaluation scores corresponding to the T iterative optimization algorithms respectively, and based on the T algorithm evaluation scores, determine the target iterative optimization algorithm among the T iterative optimization algorithms;
[0302] Generate M thought chains corresponding to the initial prompt word, and based on the M thought chains and the test data set, expand the content of the initial prompt word to obtain M content-expanded prompt words; M is a positive integer;
[0303] The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words; S is a positive integer.
[0304] It should be understood that the computer device 1000 described in the embodiment of the present application can execute the above Figure 3 and Figure 4 The description of the data processing method in any corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated here either.
[0305] In addition, it should be noted that: the embodiment of the present application also provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program, and when the processor executes the computer program, it can execute the above Figure 3 and Figure 4 The description of the above-mentioned data processing method in any corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated here. For technical details not disclosed in the computer-readable storage medium embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0306] The computer-readable storage medium may be the data processing device provided in any of the aforementioned embodiments or the internal storage unit of the computer device, such as the hard disk or memory of the computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device. Furthermore, the computer-readable storage medium may also include both the internal storage unit of the computer device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer-readable storage medium may also be used to temporarily store data that has been displayed or is about to be displayed.
[0307] In addition, it should be noted that the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor executes the computer program, so that the computer device performs the above-mentioned Figure 3 and Figure 4 The method provided by any corresponding embodiment.
[0308] The terms "first", "second", etc. in the description, claims, and drawings of the embodiments of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, apparatus, product, or device comprising a series of steps or units is not limited to the listed steps or modules, but may optionally include steps or modules not listed, or may optionally include other step units inherent to these processes, methods, apparatuses, products, or devices.
[0309] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example in terms of network elements. Whether these network elements are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel may use different methods to implement the described network elements for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0310] The methods and related devices provided in the embodiments of the present application are described with reference to the method flow charts and / or structural diagrams provided in the embodiments of the present application. Specifically, each process and / or block in the method flow charts and / or structural diagrams, as well as the combination of processes and / or blocks in the flow charts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable device to generate a machine, so that the instructions executed by the processor of the computer or other programmable device generate instructions for implementing the steps in the process. Figure 1 Schematic diagram of one or more processes and / or structures Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including the instruction device, which implements the function specified in the process. Figure 1 Schematic diagram of one or more processes and / or structures Figure 1 These computer program instructions can also be loaded onto a computer or other programmable device so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable device. Figure 1 The flow or flows and / or structures illustrate the steps of the functions specified in one block or multiple blocks.
[0311] The steps in the method of the embodiment of the present application can be adjusted in order, combined and deleted according to actual needs.
[0312] The modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.
[0313] The above disclosure is only a preferred embodiment of the present application, and certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A data processing method, characterized in that: include: Obtaining an initial prompt word and a test dataset, generating test prompt words corresponding to the initial prompt word using T iterative optimization algorithms, inputting the T test prompt words and the test dataset into a large language model, and generating a set of prediction results corresponding to the test dataset under the T test prompt words using the large language model; T is a positive integer; Based on the T prediction result sets and the sample label sets corresponding to the test data set, generating algorithm evaluation scores corresponding to the T iterative optimization algorithms respectively, and based on the T algorithm evaluation scores, determining a target iterative optimization algorithm among the T iterative optimization algorithms; Generate M thought chains corresponding to the initial prompt word, and expand the content of the initial prompt word based on the M thought chains and the test data set to obtain M content-expanded prompt words; M is a positive integer; Perform multiple rounds of prompt word optimization on the M content expansion prompt words using the target iterative optimization algorithm to obtain S target prompt words; S is a positive integer.
2. The method according to claim 1, characterized in that The T iterative optimization algorithms include iterative optimization algorithm A i , i is a positive integer less than or equal to T, and the T test prompt words include the iterative optimization algorithm A i Corresponding test prompt word B i , the test data set includes positive data and negative data; the algorithm evaluation scores corresponding to the T iterative optimization algorithms are generated based on the T prediction result sets and the sample label sets corresponding to the test data set, including: Based on the test prompt word B i The corresponding prediction result set and the sample label set corresponding to the test data set are used to count the number of first positive examples that correctly predict the positive data, the number of second positive examples that incorrectly predict the positive data, the number of first negative examples that correctly predict the negative data, and the number of second negative examples that incorrectly predict the negative data; the sum of the first number of positive examples and the second number of positive examples is the number of positive data, and the sum of the first number of negative examples and the second number of negative examples is the number of negative data; Generate the iterative optimization algorithm A based on the first number of positive examples, the second number of positive examples, the first number of negative examples, and the second number of negative examples i The corresponding prediction accuracy; Based on the first number of positive examples and the second number of positive examples, the iterative optimization algorithm A is generated. i The corresponding prediction recall rate; Based on the iterative optimization algorithm A i The corresponding prediction accuracy and the iterative optimization algorithm A i The corresponding prediction recall rate generates the iterative optimization algorithm A i The corresponding algorithm evaluation score.
3. The method according to claim 1, characterized in that Generating M thought chains corresponding to the initial prompt word includes: Performing semantic decomposition on the initial prompt word to obtain M semantic decomposition sequences corresponding to the initial prompt word; each semantic decomposition sequence includes at least two task keywords and a semantic mapping relationship between the at least two task keywords; Based on the at least two task keywords in each semantic decomposition sequence and the semantic mapping relationship between the at least two task keywords, generating a unit reasoning task corresponding to each semantic decomposition sequence; The unit reasoning tasks corresponding to the M semantic decomposition sequences are determined as the M thinking chains corresponding to the initial prompt word.
4. The method according to claim 1, wherein Generating M thought chains corresponding to the initial prompt word includes: A root node task is generated based on the initial prompt word, Q candidate tasks are generated based on the initial prompt word and the root node task, and growth scores are generated for each of the Q candidate tasks based on the semantic correctness scores corresponding to each of the Q candidate tasks and the vector similarities between the Q candidate tasks and the root node task; Q is a positive integer; Based on Q growth scores, H tasks to be grown are determined from the Q candidate tasks. Based on the initial prompt word, the root node task and the H tasks to be grown, candidate tasks corresponding to the H tasks to be grown are generated respectively. New tasks to be grown are continuously determined through the candidate tasks corresponding to the H tasks to be grown. When the obtained new tasks to be grown meet the growth termination conditions, the M task paths between the root node task and the new tasks to be grown are determined as the M thinking chains corresponding to the initial prompt word; H is a positive integer less than or equal to Q.
5. The method according to claim 1, wherein The initial prompt words are expanded based on the M thought chains and the test data set to obtain M content-expanded prompt words, including: Based on the M thought chains, the initial prompt words are rewritten to obtain M rewritten prompt words; N test data are obtained from the test data set, and the N test data are respectively inserted into the M instruction rewriting prompt words to obtain M content expansion prompt words; each content expansion prompt word includes the N test data.
6. The method according to claim 5, characterized in that The initial prompt word is rewritten based on the M thought chains to obtain M instruction rewriting prompt words, including: Obtaining task keywords corresponding to the M thought chains, respectively, performing statistics on the task keywords corresponding to the M thought chains, obtaining L keyword statistical results, and determining at least two target keywords from the task keywords corresponding to the M thought chains, respectively, based on the L keyword statistical results; L is a positive integer less than or equal to M; generating a task framework text corresponding to the initial prompt word based on the at least two target keywords; the task framework text includes a role prompt word, a task prompt word, and an output format prompt word, wherein the role prompt word is used to indicate the task domain to be processed by the large language model, the task prompt word indicates the task content to be processed by the large language model, and the output format prompt word is used to instruct the large language model to generate an output in a predetermined format; Performing semantic expansion on the task keywords corresponding to the M thought chains to obtain at least two expanded keywords; Based on the task framework text, the M thought chains and the at least two extended keywords, M instruction rewriting prompt words are generated.
7. The method according to claim 5, characterized in that The obtaining N test data from the test data set includes: Generate vector similarities between each test data in the test data set and the initial prompt word, and determine the test data in the test data set whose vector similarities are greater than or equal to a nearest neighbor threshold as N test data.
8. The method according to claim 5, characterized in that The obtaining N test data from the test data set includes: Clustering the test data in the test data set to obtain N clusters; each cluster includes a cluster center data, and the cluster center data is used to represent the average characteristics of the test data in the cluster; In the N clusters, the mixed similarity corresponding to each test data and the associated cluster center data is obtained, and the test data with the maximum mixed similarity in each cluster is sampled to obtain N test data.
9. The method according to claim 8, characterized in that The N clusters include cluster R i , i is a positive integer less than or equal to N; The step of obtaining the mixed similarity between each test data and its cluster center data in the N clusters includes: The cluster R i The test data in the cluster is determined as the in-cluster data, based on the semantic vector of each in-cluster data and the cluster R i The semantic vector of the cluster center data is used to generate the cosine similarity corresponding to the data in each cluster; Based on the text length of each cluster data and the cluster R i The text length of the cluster center data is used to generate the text length similarity corresponding to the data in each cluster; Get the cluster R i The information entropy corresponding to the data in each cluster; Based on the cosine similarity, text length similarity and information entropy corresponding to each cluster data, generate the cluster R of each cluster data. i The mixed similarity corresponding to the cluster center data.
10. The method according to claim 1, characterized in that The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including: Obtaining a validation data set, generating validation evaluation scores corresponding to the M content expansion prompt words based on the validation data set, and determining K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores corresponding to the M content expansion prompt words, where K is a positive integer less than or equal to M; Combining the K iteratively optimized prompt words to obtain S content expansion prompt phrases, and semantically summarizing the content expansion prompt words in each content expansion prompt phrase to obtain S merged optimized prompt words; Verification evaluation scores corresponding to the S merged optimization prompt words are generated using the verification data set. K new iterative optimization prompt words are continuously determined from the S merged optimization prompt words based on the verification evaluation scores corresponding to the S merged optimization prompt words until S new merged optimization prompt words obtained from the new K iterative optimization prompt words meet an iteration termination condition, and the new S merged optimization prompt words are determined as the S target prompt words.
11. The method according to claim 1, wherein The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including: Obtaining a validation data set, generating validation evaluation scores corresponding to the M content expansion prompt words based on the validation data set, determining K iteratively optimized prompt words from the M content expansion prompt words based on the validation evaluation scores, and determining prompt words from the M content expansion prompt words other than the K iteratively optimized prompt words as C example prompt words, where K is a positive integer less than or equal to M, and C is the difference between M and K; Based on the C example prompt words, generate F example gradient values, and perform semantic adjustment on each iteratively optimized prompt word based on the F example gradient values to obtain S example optimized prompt words; F is a positive integer, and S is the product of C and F; The validation data set is used to generate validation evaluation scores corresponding to the S example optimization prompt words. Based on the validation evaluation scores corresponding to the S example optimization prompt words, K new iterative optimization prompt words are continuously determined from the S example optimization prompt words until S new example optimization prompt words obtained through the new K iterative optimization prompt words meet the iteration termination condition, and the new S example optimization prompt words are determined as S target prompt words.
12. The method according to claim 1, characterized in that The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including: Obtaining a verification data set, generating verification evaluation scores corresponding to the M content expansion prompt words based on the verification data set, and generating feedback optimization prompt words corresponding to the M content expansion prompt words based on the verification evaluation scores corresponding to the M content expansion prompt words and M pieces of first historical score information; each piece of first historical score information is used to indicate the verification evaluation score corresponding to a content expansion prompt word in the current round of prompt word optimization; Generate verification evaluation scores corresponding to M feedback optimization prompt words using the verification data set, and generate M new feedback optimization prompt words using the verification evaluation scores corresponding to the M feedback optimization prompt words and M second historical score information until the obtained new M feedback optimization prompt words meet the iteration termination condition, and determine the new M feedback optimization prompt words as S target prompt words; S and M are equal, and one second historical score information is used to indicate the verification evaluation score corresponding to a feedback optimization prompt word in the current round of prompt word optimization and the verification evaluation score corresponding to the previous round of prompt word optimization.
13. The method according to claim 1, wherein The target iterative optimization algorithm is used to perform multiple rounds of prompt word optimization on the M content expansion prompt words to obtain S target prompt words, including: Obtaining a validation data set, generating validation evaluation scores corresponding to the M content expansion prompt words based on the validation data set, and determining K iteratively optimized prompt words from the M content expansion prompt words, where K is a positive integer less than or equal to M; Perform keyword replacement on the K iteratively optimized prompt words to obtain K replacement prompt words, and combine any two replacement prompt words among the K replacement prompt words to obtain S replacement prompt phrase groups; Perform semantic induction on the replacement prompt words in each replacement prompt phrase to obtain S cross-optimized prompt words; Validation evaluation scores corresponding to the S cross-optimization prompt words are generated using the validation data set. K new iterative optimization prompt words are continuously determined from the S cross-optimization prompt words based on the validation evaluation scores corresponding to the S cross-optimization prompt words until S new cross-optimization prompt words obtained from the new K iterative optimization prompt words meet an iteration termination condition, and the new S cross-optimization prompt words are determined as S target prompt words.
14. The method according to claim 1, wherein The obtaining of the initial prompt words and the test data set includes: In response to a triggering operation of an upload control in a prompt word optimization page, the uploaded test data set is displayed; In response to a triggering operation on a prompt word input control in the prompt word optimization page, displaying the input initial prompt word; The method further comprises: In response to a triggering operation of an initial optimization control in the prompt word optimization page, M content-expanded prompt words obtained by expanding the content of the initial prompt word are displayed; In response to a triggering operation of an iterative optimization control in the prompt word optimization page, S target prompt words obtained by performing multiple rounds of prompt word optimization on the M content expansion prompt words are displayed.
15. A data processing device, characterized in that: include: An algorithm testing module is configured to obtain an initial prompt word and a test dataset, generate test prompt words corresponding to the initial prompt word using T iterative optimization algorithms, input the T test prompt words and the test dataset into a large language model, and generate a set of prediction results corresponding to the test dataset under the T test prompt words using the large language model; T is a positive integer; an algorithm determination module, configured to generate algorithm evaluation scores corresponding to T iterative optimization algorithms based on the T prediction result sets and the sample label set corresponding to the test data set, and determine a target iterative optimization algorithm from the T iterative optimization algorithms based on the T algorithm evaluation scores; a content expansion module, configured to generate M thought chains corresponding to the initial prompt word, and expand the content of the initial prompt word based on the M thought chains and the test data set to obtain M content-expanded prompt words; M is a positive integer; an iterative optimization module, configured to perform multiple rounds of prompt word optimization on the M content expansion prompt words using the target iterative optimization algorithm to obtain S target prompt words; S is a positive integer.
16. A computer device, characterized in that: include: processor, memory, and network interface; The processor is connected to the memory and the network interface, wherein the network interface is used to provide a data communication function, the memory is used to store a computer program, and the processor is used to call the computer program so that the computer device executes the method according to any one of claims 1 to 14.
17. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, which is suitable for being loaded and executed by a processor, so that a computer device having the processor executes the method according to any one of claims 1 to 14.
18. A computer program product, characterized in that The computer program product includes a computer program, which is stored in a computer-readable storage medium and is suitable for being read and executed by a processor, so as to enable a computer device having the processor to perform the method according to any one of claims 1 to 14.
Citation Information
Cited By
Prompt information optimization method and device, computer readable medium and electronic equipment
CN121052384A
Data generation method and device, electronic equipment and storage medium
CN121935261A