Large model prompt word optimization method and device, equipment and storage medium
By combining semantic reflection and sentence editing, the prompt words of the large model are optimized, which solves the problems of low efficiency and poor effect in the existing technology and realizes efficient and accurate prompt word generation.
Patent Information
- Application Number
- CN202410301185.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-15
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2044-03-15
AI Technical Summary
Existing methods for optimizing prompts in large models are inefficient and have poor optimization results, making it difficult to effectively understand user intent.
By employing a method based on semantic reflection and sentence editing, the optimal prompt word is obtained through generating initial prompt words, iterative optimization, and testing, combined with semantic and sentence optimization.
It significantly improves the optimization efficiency and effect of prompt words in large models, and achieves the optimization of prompt words in both deep semantics and surface sentences.
Smart Images

Figure CN118410778B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large model technology, and in particular to a method, apparatus, device and storage medium for optimizing prompt words in large models. Background Technology
[0002] With the advent of the era of large-scale models, chat-GPT has become a global phenomenon, and various industries are building large-scale models. However, many users currently have a poor experience using these models, often failing to understand user input and frequently providing irrelevant answers. Enabling large-scale models to correctly and efficiently understand user intent is a major challenge. To better address this issue, cue words have been introduced. Cue words in large-scale models refer to the initial words or phrases input when using a pre-trained language model to guide the model in generating specific text content. By providing cue words, users can convey contextual information, topics, or intentions to the model, enabling it to generate relevant responses or text.
[0003] There are few existing technical solutions for optimizing prompts in large models. There are two main approaches: the first is manual prompt writing, which is extremely inefficient. The second is algorithmic automatic prompt generation, but this method typically only optimizes prompts at one level, resulting in poor optimization performance. Summary of the Invention
[0004] The main objective of this invention is to provide a method, apparatus, device, and storage medium for optimizing large model prompt words, aiming to solve the technical problems of low efficiency and poor optimization effect in existing large model prompt word optimization methods.
[0005] The first aspect of this invention provides a method for optimizing large model prompt words, the method comprising:
[0006] Obtain the first prompt word and input it into the large model to generate multiple first prompt words. Test the first prompt words and determine the initial prompt words and whether to perform semantic optimization based on the test results.
[0007] If semantic optimization is determined, then based on the initial prompt words, construct second-order prompt words based on semantic reflection and input them into the large model to generate multiple second-order prompt words. Then, iteratively optimize and test the second-order prompt words, and determine the semantically optimized prompt words and whether to optimize the sentence based on the test results.
[0008] If it is determined that sentence optimization is to be performed, the semantic optimization prompt words are edited to generate multiple third prompt words, and the third prompt words are iteratively optimized and tested. Based on the test results, the sentence optimization prompt words are determined and output as the optimal prompt words.
[0009] Optionally, in a first implementation of the first aspect of the present invention, the step of obtaining a first meta-prompt word and inputting it into a large model, generating multiple first prompt words, testing the first prompt words, and determining the initial prompt word and whether to perform semantic optimization based on the test results includes:
[0010] Based on the pre-defined first task description and task examples, construct the first meta prompt word;
[0011] The first prompt word is input into the large model for processing to generate multiple first prompt words;
[0012] Pre-set test cases were used and a large model was invoked to test each first prompt word, and the accuracy of the test results corresponding to each first prompt word was calculated.
[0013] Determine whether the highest accuracy rate among all test results corresponding to the first prompt word reaches the preset first accuracy rate threshold;
[0014] If the first accuracy threshold is reached, then semantic optimization will not be performed and the corresponding first prompt word will be output as the optimal prompt word.
[0015] If the first accuracy threshold is not reached, semantic optimization is determined, and the first prompt word with the highest accuracy among all test results is output as the initial prompt word.
[0016] Optionally, in a second implementation of the first aspect of the present invention, the step of constructing a second-order prompt word based on semantic reflection and inputting it into a large model based on the initial prompt word to generate multiple second prompt words, and iteratively optimizing and testing the second prompt words, and determining the semantically optimized prompt word and whether to perform sentence optimization based on the test results includes:
[0017] S201: Based on the optimization results of the previous round of prompt word optimization, construct the second-order prompt words based on semantic reflection for this round and input them into the large model to generate multiple second-order prompt words for this round of prompt word optimization, wherein the optimization results of the previous round of prompt word optimization include the initial prompt words;
[0018] S202: Using the test cases and calling the large model, test each of the second prompt words generated in this round, calculate the accuracy of the test results corresponding to each second prompt word, and output the second prompt word with the highest accuracy among all test results in this round as the optimization result of the prompt word optimization in this round;
[0019] S203: Iterate through S201-S202 until the preset first iteration exit condition is met, then stop the iteration and use the second prompt word with the highest accuracy among all test results as the first candidate prompt word;
[0020] S204: Determine whether the accuracy of the test result corresponding to the first candidate prompt word reaches a preset second accuracy threshold;
[0021] S205: If the second accuracy threshold is reached, then it is determined that no statement optimization will be performed and the first candidate prompt word will be output as the optimal prompt word;
[0022] S206: If the second accuracy threshold is not reached, then sentence optimization is determined, and the initial prompt word is used as the second candidate prompt word. The accuracy of the test results corresponding to the first candidate prompt word and the second candidate prompt word is compared, and the prompt word with the highest accuracy is selected as the semantic optimization prompt word for output.
[0023] Optionally, in a third implementation of the first aspect of the present invention, the step of constructing a second-order prompt word based on semantic reflection based on the optimization results of the previous round of prompt word optimization and inputting it into a large model to generate multiple second prompt words for this round of prompt word optimization includes:
[0024] The test cases are used to test the optimization results of the previous round of prompt word optimization by calling the large model, and the test cases with incorrect answers are extracted from the test results as the wrong question set for this round of testing.
[0025] Based on the pre-defined second task description and the set of incorrect questions from this round of testing, a second-order prompt word based on semantic reflection is constructed for this round and input into the large model to generate multiple second prompt words for this round of prompt word optimization.
[0026] Optionally, in a fourth implementation of the first aspect of the present invention, the step of editing the semantically optimized prompt word to generate multiple third prompt words, iteratively optimizing and testing the third prompt words, and determining the sentence-optimized prompt word based on the test results and outputting it as the optimal prompt word includes:
[0027] S301: Extract the third task description from the semantic optimization prompt words as the first key content, and set stop words and a custom dictionary based on the first key content;
[0028] S302: Based on the stop words and the custom dictionary, the first key content is segmented to obtain the second key content composed of multiple segmented words;
[0029] S303: Perform a statement editing operation on the second key content to generate multiple third key content, and replace the third task description in the semantic optimization prompt word with each of the third key content, thereby obtaining multiple third prompt words for this round of prompt word optimization. The statement editing operation includes one or more of the following: add operation, delete operation, modify operation and swap operation.
[0030] S304: Using the test cases and calling the large model, test each of the third prompt words generated in this round, and calculate the accuracy of the test results corresponding to all the third prompt words in this round;
[0031] S305: Iterate through S303-S304 until the preset second iteration exit condition is met, then stop the iteration and use the third prompt word with the highest accuracy among all test results as the third candidate prompt word;
[0032] S306: The semantic optimization prompt word is used as the fourth candidate prompt word, and the accuracy of the test results corresponding to the third candidate prompt word and the fourth candidate prompt word are compared. The prompt word with the highest accuracy is selected as the sentence optimization prompt word and the sentence optimization prompt word is output as the optimal prompt word.
[0033] Optionally, in a fifth implementation of the first aspect of the present invention, the large model prompt word optimization method further includes:
[0034] Obtain the optimal prompt words output by the large model;
[0035] The optimal prompt words are tested using new test cases and a large model, and the test results are output and the test effect is displayed.
[0036] Optionally, in the sixth implementation of the first aspect of the present invention, the step of using new test cases and calling a large model to test the optimal prompt words, outputting test results, and displaying the test effect includes:
[0037] Input the optimal prompt words and the new test cases into the large model for testing, output the test answers of all the new test cases and print them out;
[0038] Based on the standard answers corresponding to the new test cases, the accuracy of the test answers is calculated and visualized.
[0039] A second aspect of the present invention also provides a large model prompt word optimization device, the large model prompt word optimization device comprising:
[0040] The initialization module is used to obtain the first prompt word and input it into the large model, generate multiple first prompt words, test the first prompt words, and determine the initial prompt word and whether to perform semantic optimization based on the test results;
[0041] The semantic optimization module is used to construct a second-order prompt word based on semantic reflection based on the initial prompt word and input it into the large model if semantic optimization is determined. This generates multiple second prompt words, and iteratively optimizes and tests the second prompt words. Based on the test results, the semantic optimization prompt word and whether sentence optimization should be performed are determined.
[0042] The statement optimization module is used to edit the semantic optimization prompt words if it is determined that statement optimization is to be performed, generate multiple third prompt words, iteratively optimize and test the third prompt words, determine the statement optimization prompt words based on the test results, and output them as the optimal prompt words.
[0043] Optionally, in a first implementation of the second aspect of the present invention, the initialization module is specifically used for:
[0044] Based on the pre-defined first task description and task examples, construct the first meta prompt word;
[0045] The first prompt word is input into the large model for processing to generate multiple first prompt words;
[0046] Pre-set test cases were used and a large model was invoked to test each first prompt word, and the accuracy of the test results corresponding to each first prompt word was calculated.
[0047] Determine whether the highest accuracy rate among all test results corresponding to the first prompt word reaches the preset first accuracy rate threshold;
[0048] If the first accuracy threshold is reached, then semantic optimization will not be performed and the corresponding first prompt word will be output as the optimal prompt word.
[0049] If the first accuracy threshold is not reached, semantic optimization is determined, and the first prompt word with the highest accuracy among all test results is output as the initial prompt word.
[0050] Optionally, in a second implementation of the second aspect of the present invention, the semantic optimization module is specifically used for:
[0051] Based on the optimization results of the previous round of prompt word optimization, construct the second-order prompt words based on semantic reflection for this round and input them into the large model to generate multiple second-order prompt words for this round of prompt word optimization. The optimization results of the previous round of prompt word optimization include the initial prompt words.
[0052] Using the test cases and calling the large model, each second prompt word generated in this round is tested. The accuracy of the test results corresponding to each second prompt word is calculated. The second prompt word with the highest accuracy among all test results in this round is output as the optimization result of the prompt word optimization in this round.
[0053] Iteratively perform semantic optimization until the preset first iteration exit condition is met, then stop the iteration and take the second prompt word with the highest accuracy among all test results as the first candidate prompt word;
[0054] Determine whether the accuracy of the test result corresponding to the first candidate prompt word reaches a preset second accuracy threshold;
[0055] If the second accuracy threshold is reached, then no statement optimization is performed and the first candidate prompt word is output as the optimal prompt word.
[0056] If the second accuracy threshold is not reached, then sentence optimization is determined, and the initial prompt word is used as the second candidate prompt word. The accuracy of the test results corresponding to the first candidate prompt word and the second candidate prompt word are compared, and the prompt word with the highest accuracy is selected as the semantic optimization prompt word for output.
[0057] Optionally, in a third implementation of the second aspect of the present invention, the semantic optimization module is further configured to:
[0058] The test cases are used to test the optimization results of the previous round of prompt word optimization by calling the large model, and the test cases with incorrect answers are extracted from the test results as the wrong question set for this round of testing.
[0059] Based on the pre-defined second task description and the set of incorrect questions from this round of testing, a second-order prompt word based on semantic reflection is constructed for this round and input into the large model to generate multiple second prompt words for this round of prompt word optimization.
[0060] Optionally, in a fourth implementation of the second aspect of the present invention, the statement optimization module is specifically used for:
[0061] Extract the third task description from the semantic optimization prompt words as the first key content, and set stop words and a custom dictionary based on the first key content;
[0062] Based on the stop words and the custom dictionary, the first key content is segmented to obtain the second key content composed of multiple segmented words.
[0063] The second key content is edited to generate multiple third key content, and each of the third key content replaces the third task description in the semantic optimization prompt word, thereby obtaining multiple third prompt words for this round of prompt word optimization. The sentence editing operation includes one or more of the following: add operation, delete operation, modify operation and swap operation.
[0064] Using the aforementioned test cases and calling the large model, each of the third prompt words generated in this round is tested, and the accuracy of the test results corresponding to all the third prompt words in this round is calculated.
[0065] Iteratively optimize the statement until the preset second iteration exit condition is met, then stop the iteration and use the third prompt word with the highest accuracy among all test results as the third candidate prompt word;
[0066] The semantic optimization prompt word is selected as the fourth candidate prompt word. The accuracy of the test results corresponding to the third candidate prompt word and the fourth candidate prompt word are compared. The prompt word with the highest accuracy is selected as the sentence optimization prompt word and the sentence optimization prompt word is output as the optimal prompt word.
[0067] Optionally, in a fifth implementation of the second aspect of the present invention, the large model prompt word optimization device further includes:
[0068] The test demonstration module is used to obtain the optimal prompt words output by the large model; use new test cases and call the large model to test the optimal prompt words, output the test results and demonstrate the test effect.
[0069] Optionally, in a sixth implementation of the second aspect of the present invention, the test demonstration module is specifically used for:
[0070] Input the optimal prompt words and the new test cases into the large model for testing, output the test answers of all the new test cases and print them out;
[0071] Based on the standard answers corresponding to the new test cases, the accuracy of the test answers is calculated and visualized.
[0072] A third aspect of the present invention provides a computer device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor invokes the instructions in the memory to cause the computer device to perform the above-described large model prompt word optimization method.
[0073] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the above-described large model prompt word optimization method.
[0074] The technical solution provided by this invention specifically employs a method based on semantic reflection and sentence editing to optimize prompt words for large models. First, prompt words are generated based on the large model; then, prompt word optimization is performed based on semantic reflection; finally, prompt words are further optimized based on sentence editing, ultimately obtaining the optimal prompt words. This invention achieves automatic generation and optimization of prompt words for large models, requiring no manual intervention throughout the process, significantly improving the optimization efficiency of prompt words for large models. Furthermore, this invention innovatively combines semantics and sentence analysis to optimize prompt words from two aspects. Through prompt word optimization based on semantic reflection, the prompt words achieve optimal results at the deep semantic level; subsequently, prompt word optimization based on sentence editing achieves optimal results at the surface sentence level. By combining semantics and sentence analysis, the optimization effect of prompt words is significantly improved in both surface sentence and deep semantic aspects. Attached Figure Description
[0075] Figure 1 This is a schematic flowchart of an embodiment of the large model prompt word optimization method of the present invention;
[0076] Figure 2 This is a schematic diagram of an embodiment of the large model prompt word optimization method of the present invention, which generates initial prompt words based on a large model;
[0077] Figure 3 This is a schematic diagram of an embodiment of the prompt word optimization based on semantic reflection in the large-scale prompt word optimization method of the present invention;
[0078] Figure 4 This is a schematic diagram of an embodiment of the prompt word optimization based on sentence editing in the large model prompt word optimization method of the present invention;
[0079] Figure 5 This is a schematic diagram of the functional modules of an embodiment of the large model prompt word optimization device of the present invention;
[0080] Figure 6 This is a schematic diagram of one embodiment of the computer device in this invention. Detailed Implementation
[0081] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” or “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0082] To facilitate understanding of the present invention, the technical terms involved in the embodiments are explained below.
[0083] Large Language Models (LLMs) are natural language processing models based on deep learning techniques. They possess very high language understanding and generation capabilities, and can generate high-quality natural language text.
[0084] Meta-prompts guide models to generate specific types of output and adjust their internal processing, influencing the quality, style, and diversity of the generated results. Meta-prompts can include various elements such as instructions, context, constraints, and examples, which together form a more complex framework to guide the model's generation process. By adjusting these elements, attention allocation, inference paths, and creativity can be controlled, allowing for finer and more flexible control.
[0085] A prompt is a word or phrase that is input when using a pre-trained language model to guide the model in generating specific text content.
[0086] A user dictionary is used when certain words do not exist in the Chinese dictionary database, such as the Jieba database, but need to be accurately segmented. In this case, a user dictionary needs to be introduced during the segmentation process.
[0087] Stop words refer to certain characters or words that are automatically filtered out in information retrieval and natural language processing.
[0088] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to... Figure 1 , Figure 1This is a schematic flowchart of an embodiment of the large model prompt word optimization method of the present invention. The large model prompt word optimization method provided in this embodiment can be executed by a computer device, which can be implemented by software and / or hardware. Generally, the computer device can be a terminal device, such as a computer, server, etc. The following description uses a computer device as the main body for executing the large model prompt word optimization method. The large model prompt word optimization method in this embodiment of the present invention includes:
[0089] S10. Obtain the first prompt word and input it into the large model to generate multiple first prompt words. Test the first prompt words and determine the initial prompt word and whether to perform semantic optimization based on the test results.
[0090] This embodiment requires first generating initial prompt words based on a large model, and then optimizing these initial prompt words. Specifically, the first-order prompt word is obtained, and then input into the large model for processing. To improve the optimization effect, the large model is generally allowed to output multiple first-order prompt words. Finally, accuracy evaluation tests are performed on each of the multiple first-order prompt words, and the best first-order prompt word is selected from the test results as the initial prompt word for further optimization. It should be noted that the large model itself has the function of generating prompt words, so this embodiment will not elaborate on the prompt word generation process.
[0091] In this embodiment, due to the uncertainty in the generation of the first prompt word by the large model, it is necessary to further determine whether the initial prompt word needs to be optimized based on the test results. For example, assuming the accuracy of the initial prompt word is 100%, no prompt word optimization is required, that is, no further optimization steps are performed.
[0092] Figure 2 This is a schematic diagram of an embodiment of the large model prompt word optimization method of the present invention, which generates initial prompt words based on a large model.
[0093] S101. Construct the first meta prompt word based on the preset first task description and task case;
[0094] In this embodiment, before generating prompt words through the large model, it is necessary to first construct first-order prompt words as input data for the large model to generate prompt words. Specifically, the first-order prompt words are constructed based on the first task description and task cases. The first task description is determined by the task optimized by the prompt words, such as geographical knowledge question answering, while the task cases can be randomly selected from test cases. It should be noted that both the task description and task cases have their own standard formats, and the first-order prompt words can be automatically constructed based on these standard formats.
[0095] In this embodiment, test cases are used to test the prompt words generated by the large model. The accuracy of the tested prompt words can be calculated based on the test results, and the accuracy can be used to measure the quality of the prompt words. Test cases need to be prepared by the user in advance based on business requirements, determining the types of problem sets that need optimization, and then collecting relevant datasets and organizing them into test cases. It should be further noted that if open-source datasets related to prompt word optimization exist, they can be directly searched and downloaded as test cases; otherwise, test cases need to be created manually.
[0096] For example, assuming the business requirement is to perform geographical knowledge question answering, the following are the compiled test cases for the geographical category:
[0097] Question: "Is Beijing the capital of China?" Answer: "Yes".
[0098] Question: "What is the capital city of Guangdong Province?" Answer: "Guangzhou"
[0099] This embodiment does not limit the number of test cases used; the specific number can be set according to actual needs.
[0100] S102. Input the first meta prompt word into the large model for processing to generate multiple first prompt words;
[0101] In this embodiment, after the first-order prompt word is constructed, it is input into the large model for processing. The large model can automatically generate multiple corresponding first-order prompt words based on the first-order prompt word.
[0102] For example, taking geographical knowledge question answering as an example, the constructed first-order prompt words are as follows:
[0103] My task is to answer a geography-related question. Here's an example: Question: "Is Beijing the capital of China?" Answer: "Yes." Please return to the prompt for this task.
[0104] By inputting the aforementioned first-order prompt words into the large model for processing, multiple corresponding first-order prompt words can be generated. For example: My task is to help you answer geographical knowledge questions.
[0105] S103. Using pre-set test cases and calling the large model, test each first prompt word separately, and calculate the accuracy of the test results corresponding to each first prompt word;
[0106] In this embodiment, after generating prompt words for the large model, it is also necessary to use pre-set test cases to test multiple first prompt words generated by the large model based on the first element prompt word, and calculate the accuracy of the test results corresponding to each first prompt word, so as to facilitate the selection of the prompt word with the highest accuracy.
[0107] The testing process is completed by a large model. Specifically, a primary clue word is selected, and this primary clue word, along with all test cases, is input into the large model for processing. The model outputs the test answers for all test cases. Then, the test answers output by the large model are compared with the standard answers for the test cases to calculate the accuracy rate of the primary clue word. For example, if there are 100 test questions, and the test answers using clue word A are correct for 80 questions and incorrect for 20, then the accuracy rate of the test results corresponding to clue word A is 80%.
[0108] S104. Determine whether the highest accuracy rate among all test results corresponding to the first prompt word reaches the preset first accuracy rate threshold.
[0109] In this embodiment, after calculating the accuracy of each first prompt word generated by the large model through test cases, the prompt word with the highest accuracy can be selected. Meanwhile, considering that unoptimized first prompt words may also meet the task requirements, to further improve optimization efficiency, it is necessary to further determine whether the accuracy of the first prompt words generated this time meets the task requirements before optimization. Specifically, a first accuracy threshold is preset; if the highest accuracy of the first prompt words generated this time reaches this first accuracy threshold, then the first prompt word is determined to meet the task requirements.
[0110] S105. If the first accuracy threshold is reached, then it is determined that semantic optimization will not be performed and the corresponding first prompt word will be output as the optimal prompt word.
[0111] S106. If the first accuracy threshold is not reached, semantic optimization is determined, and the first prompt word with the highest accuracy among all test results is output as the initial prompt word.
[0112] This embodiment does not limit the setting of the first accuracy threshold; it can be set according to the actual application requirements. For example, if the first accuracy threshold is 100%, and at least one of the multiple first prompt words generated by the large model has an accuracy of 100%, then it is determined that no further prompt word optimization (i.e., semantic optimization) will be performed, and the corresponding first prompt word will be output as the optimal prompt word. Conversely, if the accuracy of all the first prompt words generated by the large model is lower than 100%, then it is determined that semantic optimization of the first prompt words is required, and the first prompt word with the highest accuracy among all test results will be used as the initial prompt word and enter the semantic optimization process. It should be noted that the first accuracy threshold can also be other values, such as setting the first accuracy threshold to 95%. By setting the first accuracy threshold, it is possible to quickly determine whether the currently output prompt word meets the task requirements, thereby improving optimization efficiency. If there are multiple first prompt words with the highest accuracy among the test results, any one of them can be selected as the initial prompt word.
[0113] S20. If semantic optimization is determined, then based on the initial prompt words, construct second-order prompt words based on semantic reflection and input them into the large model to generate multiple second-order prompt words. Then, iteratively optimize and test the second-order prompt words, and determine the semantic optimization prompt words and whether to optimize the sentences based on the test results.
[0114] In this embodiment, after generating multiple initial prompt words and determining semantic optimization in the previous step, this step performs semantic optimization on the initial prompt words output in the previous step. Specifically, this embodiment optimizes prompt words based on semantic reflection. Its key point is the need to construct meta-prompt words based on semantic reflection. Furthermore, to improve the semantic optimization effect, an iterative optimization method is used to continuously improve the accuracy of the prompt words.
[0115] In this embodiment, firstly, based on the initial prompt words from the previous step, a first round of semantic reflection-based binary prompt words is constructed and input into the large model to generate multiple second prompt words. These are then tested using test cases, and the best second prompt word is selected as the input for the next round of semantic optimization. Then, the next round of semantic reflection-based binary prompt words is constructed based on the best second prompt word selected in the previous round, until the iteration exit condition is met, at which point the final semantically optimized prompt word is output.
[0116] Similarly, due to the uncertainty in the generation of the second prompt word by the large model, it is necessary to further determine whether the semantically optimized prompt word needs to be optimized again based on the test results. For example, assuming that the accuracy of the semantically optimized prompt word is 100%, then there is no need to optimize the prompt word again, that is, no further optimization steps will be performed.
[0117] Figure 3 This is a schematic diagram of an embodiment of the semantic reflection-based prompt word optimization method in the large model prompt word optimization method of the present invention.
[0118] S201: Based on the optimization results of the previous round of prompt word optimization, construct the second-order prompt words based on semantic reflection for this round and input them into the large model to generate multiple second-order prompt words for this round of prompt word optimization, wherein the optimization results of the previous round of prompt word optimization include the initial prompt words;
[0119] In this embodiment, the semantic reflection-based prompt word optimization is performed iteratively, meaning that the output of the previous round of semantic optimization is used as the input for the next round. Specifically, the first round of semantic optimization uses the initial prompt words to construct the first round of semantic reflection-based second-order prompt words.
[0120] In an optional embodiment, step S201 above involves constructing a semantically reflective meta-catch word and generating a second catch word in the following manner:
[0121] The test cases are used to test the optimization results of the previous round of prompt word optimization by calling the large model, and the test cases with incorrect answers are extracted from the test results as the wrong question set for this round of testing.
[0122] Based on the pre-defined second task description and the set of incorrect questions from this round of testing, a second-order prompt word based on semantic reflection is constructed for this round and input into the large model to generate multiple second prompt words for this round of prompt word optimization.
[0123] In this optional embodiment, before constructing the second-order prompt word in each round, a set of incorrect answers for semantic reflection needs to be generated first. Specifically, using the same test cases, the large model is called to test the optimization results of the previous round of prompt word optimization, and the test cases with incorrect answers are extracted from the test results as the set of incorrect answers for this round of testing. The testing method is the same as the testing method in the above steps, so it will not be described in detail. After generating the set of incorrect answers for each round of testing, the set of incorrect answers for this round of testing is used as a task case, and combined with a preset second task description, the second-order prompt word based on semantic reflection for this round is constructed. The second task description can be the same as the first task description, or it can be slightly different.
[0124] For example, continuing with the geographical knowledge question-and-answer example, the second-order prompt words based on semantic reflection are constructed as follows:
[0125] My task is to generate prompts for answering geography-related questions. The current prompt is ***, and the incorrect answer set is ***. Please reflect on your answers to improve your accuracy and generate new prompts.
[0126] By inputting the above second-order prompt words into a large model for processing, multiple corresponding second-order prompt words can be generated. For example: My task is to answer geography-related questions. As a geography expert, please note that your answer should be clear and concise, and you do not need to output any other unnecessary content.
[0127] S202: Using the test cases and calling the large model, test each of the second prompt words generated in this round, calculate the accuracy of the test results corresponding to each second prompt word, and output the second prompt word with the highest accuracy among all test results in this round as the optimization result of the prompt word optimization in this round;
[0128] In this embodiment, since the large model generates multiple second prompt words in each round of semantic optimization, to improve optimization efficiency and effectiveness, a test case approach is used to select the second prompt word with the highest accuracy for constructing the next round of semantic reflection-based second-order prompt words. It should be noted that if there are multiple second prompt words with the highest accuracy, any one of them can be selected. The testing method in this embodiment is the same as the testing method in the above steps, so it will not be elaborated further.
[0129] S203: Iterate through S201-S202 until the preset first iteration exit condition is met, then stop the iteration and use the second prompt word with the highest accuracy among all test results as the first candidate prompt word;
[0130] In this embodiment, since an iterative optimization method is used, it is necessary to pre-set the first iteration exit condition for semantic iterative optimization.
[0131] In an alternative embodiment, the first iteration exit condition is set using any one or more of the following methods in combination:
[0132] Method 1: Set the exit condition for the first iteration based on the answer accuracy. For example, set the answer accuracy to 90%. When the test accuracy is greater than 90%, the iteration will be terminated.
[0133] Method 2: Set the first iteration exit condition based on the number of iterations. For example, set the maximum number of iterations to 10, and exit the iteration after 10 iterations.
[0134] Method 3: Set the exit condition for the first iteration based on the patience value. For example, set the patience value to 3. If the accuracy decreases for three consecutive iterations, then exit the iteration.
[0135] In this embodiment, any of the above methods can be used to set the first iteration exit condition, or multiple methods can be used simultaneously to set the first iteration exit condition. When multiple methods are used to set the first iteration exit condition, the iteration will exit as long as any one of the selected conditions is met.
[0136] In this embodiment, during the semantic optimization process of iteratively executing S201-S202, after each iteration, it is determined whether the current round of prompt word optimization meets the preset first iteration exit condition. If the first iteration exit condition is met, the iteration optimization stops, and the second prompt word with the highest accuracy among all test results is selected as the first candidate prompt word; otherwise, iteration execution of S201-S202 continues. Since the first iteration exit condition is set in various ways—that is, the first iteration exit condition is not necessarily set in the way with the highest accuracy—it cannot be guaranteed that the accuracy of the output prompt word when iteration stops will be the highest. Therefore, when the first iteration exit condition is met, the test results of each round of semantic optimization need to be merged, and then the second prompt word with the highest accuracy is selected from the merged test result set as the first candidate prompt word for semantic optimization. If there are multiple second prompt words with the highest accuracy, any one of them can be selected.
[0137] S204: Determine whether the accuracy of the test result corresponding to the first candidate prompt word reaches a preset second accuracy threshold;
[0138] S205: If the second accuracy threshold is reached, then it is determined that no statement optimization will be performed and the first candidate prompt word will be output as the optimal prompt word;
[0139] In this embodiment, by setting a first accuracy threshold and a second accuracy threshold, it can be quickly determined whether the currently output prompt words meet the task requirements. If they do, no further optimization is needed, thereby improving the optimization efficiency of the prompt words. The first and second accuracy thresholds can be the same or different, depending on the specific application requirements. For example, both can be set to 100%, or the first accuracy threshold can be set to 100%, and the second accuracy threshold can be set to 96%, etc.
[0140] In this embodiment, if the accuracy of the test result corresponding to the first candidate prompt word reaches (that is, is greater than or equal to) the second accuracy threshold, it means that the first candidate prompt word as the semantic optimization result meets the task requirements. Therefore, no further optimization is needed, and it can be directly output as the optimal prompt word.
[0141] S206: If the second accuracy threshold is not reached, then sentence optimization is determined, and the initial prompt word is used as the second candidate prompt word. The accuracy of the test results corresponding to the first candidate prompt word and the second candidate prompt word is compared, and the prompt word with the highest accuracy is selected as the semantic optimization prompt word for output.
[0142] In this embodiment, if the accuracy of the test result corresponding to the first candidate prompt word does not reach the second accuracy threshold, it indicates that the first candidate prompt word, as the semantic optimization result, does not meet the task requirements and therefore requires further optimization. Considering that the effect of semantic optimization may be better (higher accuracy) or worse (lower accuracy) than before optimization, it is necessary to compare the accuracy with the prompt word before semantic optimization (i.e., the initial prompt word) and select the prompt word with the highest accuracy as the semantically optimized prompt word output. For example, assuming the accuracy of the initial prompt word before semantic optimization is 91%, while the accuracy of the prompt word after semantic optimization is 86%, then the initial prompt word is selected as the semantically optimized prompt word output. It should be noted that the accuracy comparison standard for the prompt words before and after semantic optimization is the same; that is, both must use the same test cases for accuracy comparison.
[0143] In this embodiment, prompt words are generated and semantically reflected based on a large model. This method collects sets of incorrect answers corresponding to different prompt words, utilizes the capabilities of the large model itself to generate prompt words and reflect semantics, and then selects the prompt word with the highest answer accuracy as the optimization result through iterative optimization and testing. This improves the optimization effect of prompt words and can be automated, which is more effective and efficient than manually writing prompt words.
[0144] S30. If it is determined that sentence optimization should be performed, the semantic optimization prompt words are edited to generate multiple third prompt words, and the third prompt words are iteratively optimized and tested. Based on the test results, the sentence optimization prompt words are determined and output as the optimal prompt words.
[0145] In this embodiment, if the semantic optimization result still does not meet the task requirements after step S20, further optimization is required. In this embodiment, based on the semantic optimization result of the prompt words, the prompt words are further optimized using the sentence optimization method.
[0146] In this embodiment, the prompt word optimization based on sentence editing adopts an iterative approach, meaning that multiple rounds of sentence editing are performed on the key content of the same prompt word. Each round of sentence editing uses the same semantically optimized prompt word. By performing multiple rounds of sentence editing on the same semantically optimized prompt word, a new prompt word is generated in each round. By testing the new prompt words generated in each round of sentence editing, prompt words that meet the task requirements (i.e., optimized prompt words) can be selected and output as the optimal prompt word.
[0147] Figure 4 This is a schematic diagram of an embodiment of the prompt word optimization based on sentence editing in the large model prompt word optimization method of the present invention.
[0148] S301: Extract the third task description from the semantic optimization prompt words as the first key content, and set stop words and a custom dictionary based on the first key content;
[0149] This embodiment optimizes the semantically optimized prompts output in step S20. The prompts in this embodiment adopt a standard format, including a task description and task examples. The task description is used to describe a large-scale model application scenario, such as: My task is to generate text, or my task is to answer geographical questions. The task examples are only used to illustrate the task and improve the prompt generation effect. Therefore, this embodiment extracts the task description from the prompts as the key content and performs sentence editing operations on this key content.
[0150] In this embodiment, to further improve accuracy, it is necessary to further set stop words and a custom dictionary based on the key content. The purpose of setting a custom dictionary is to ensure higher accuracy by adding new words to specific terms within the key content; the purpose of setting stop words is to automatically filter out certain meaningless characters or words in the key content, extracting only useful information, thereby saving storage space and improving search efficiency.
[0151] S302: Based on the stop words and the custom dictionary, the first key content is segmented to obtain the second key content composed of multiple segmented words;
[0152] After extracting the key content, further word segmentation is required to facilitate sentence editing. This embodiment is not limited to any specific word segmentation method, such as Jieba segmentation, and uses pre-set stop words and a custom dictionary to segment the first key content, resulting in a second key content composed of multiple segmented words.
[0153] Through the above steps S301-S302, the preprocessing such as extraction and optimization of the corpus required for sentence editing is realized, and the key content suitable for direct sentence editing in the semantic optimization prompt words is obtained.
[0154] S303: Perform a statement editing operation on the second key content to generate multiple third key content, and replace the third task description in the semantic optimization prompt word with each of the third key content, thereby obtaining multiple third prompt words for this round of prompt word optimization. The statement editing operation includes one or more of the following: add operation, delete operation, modify operation and swap operation.
[0155] The sentence editing operations in this embodiment include one or more of the following: add, delete, modify, and swap. That is, one or more sentence editing operations can be performed on the second key content in the word segmentation form, thereby generating multiple third key contents.
[0156] This embodiment modifies the key content in the prompt words through editing operations such as "add, delete, modify, and replace". "Add" refers to the operation of adding, that is, randomly adding the words or their synonyms that appear after word segmentation to the second key content; "delete" refers to the operation of deleting, that is, randomly deleting a word in the second key content; "modify" refers to the operation of modifying, that is, randomly selecting a word in the second key content and modifying it to its synonym; "replace" refers to the operation of swapping, that is, randomly selecting two words in the second key content and exchanging their positions.
[0157] In this embodiment, the object of the statement editing operation is actually the third task description (i.e., the second key content) in the semantic optimization prompt. Therefore, the third key content generated by the statement editing operation is not a complete prompt. Therefore, it is necessary to further replace the third task description in the semantic optimization prompt with each third key content to obtain multiple third prompts for this round of prompt optimization.
[0158] For example, continuing with the geography knowledge quiz:
[0159] Key content of semantically optimized prompt words: My task is to answer geography-related questions.
[0160] Word Segmentation: My | task | is | to | answer | geography-related | questions.
[0161] Stop Words and Custom Dictionaries: Among them, the stop words are: of; there are no special words, and the custom dictionary can be not set. If there are special words, the custom dictionary needs to be set. For example: "Large Language Model", this word is concrete and does not need to be segmented again, and it needs to be put into the custom dictionary.
[0162] The sentence editing operation for the key content after word segmentation to obtain a new prompt:
[0163] Add (add "question"): My task is to answer geography-related questions question;
[0164] Delete (delete "related"): My task is to answer geography questions;
[0165] Modify (modify "answer" to "solve"): My task is to solve geography questions;
[0166] Swap (swap "geography" and "related"): My task is to answer related geography questions.
[0167] S304: Adopt the test case and call the large model to test each third prompt generated in this round respectively, and calculate the accuracy rate of the test results corresponding to all third prompts in this round;
[0168] In this embodiment, since the large model generates multiple third prompts for each round of sentence editing, in order to improve the optimization efficiency and effect, therefore, the method of using test cases for testing is adopted, so as to calculate the accuracy rate of each third prompt in each round of test results, and then it is convenient to judge whether to continue iterative optimization. The test method in this embodiment is the same as the test method in the above steps, so it will not be elaborated too much. It should be noted that in order to ensure the unity of the prompt optimization standard, the same test case is used to test the prompts generated by the large model, the prompts generated by semantic optimization, and the prompts generated by sentence optimization.
[0169] S305: Iteratively execute S303 - S304 until the preset second iteration exit condition is met, then stop the iteration and use the third prompt with the highest accuracy rate among all test results as the third candidate prompt;
[0170] In this embodiment, since an iterative optimization method is adopted, therefore, a second iteration exit condition for sentence iterative optimization needs to be set in advance. It should be noted that the first iteration exit condition and the second iteration exit condition can be the same or different, and they are specifically set according to actual application needs.
[0171] In an optional embodiment, the second iteration exit condition is set using any one or more of the following methods in combination:
[0172] Method 1: Set the exit condition for the first iteration based on the answer accuracy. For example, set the answer accuracy to 90%. When the test accuracy is greater than 90%, the iteration will be terminated.
[0173] Method 2: Set the first iteration exit condition based on the number of iterations. For example, set the maximum number of iterations to 10, and exit the iteration after 10 iterations.
[0174] Method 3: Set the exit condition for the first iteration based on the patience value. For example, set the patience value to 3. If the accuracy decreases for three consecutive iterations, then exit the iteration.
[0175] In this embodiment, any of the above methods can be used to set the second iteration exit condition, or multiple methods can be used simultaneously. When multiple methods are used to set the second iteration exit condition, the iteration will exit as long as any one of the selected conditions is met.
[0176] In this embodiment, during the iterative execution of S303-S304 for sentence optimization, after each iteration, it is determined whether the current round of prompt word optimization meets the preset second iteration exit condition. If the second iteration exit condition is met, the iteration optimization stops, and the third prompt word with the highest accuracy among all test results is selected as the third candidate prompt word. Otherwise, iteration execution of S303-S304 continues. Since the second iteration exit condition is set in various ways—that is, the second iteration exit condition is not necessarily set in the way of highest accuracy—it cannot be guaranteed that the accuracy of the output prompt word when iteration stops will be the highest. Therefore, when the second iteration exit condition is met, the test results of each round of sentence optimization need to be merged, and then the third prompt word with the highest accuracy is selected from the merged test result set as the third candidate prompt word for sentence optimization. If there are multiple third prompt words with the highest accuracy, any one of them can be selected as the third candidate prompt word.
[0177] S306: The semantic optimization prompt word is used as the fourth candidate prompt word, and the accuracy of the test results corresponding to the third candidate prompt word and the fourth candidate prompt word are compared. The prompt word with the highest accuracy is selected as the sentence optimization prompt word and the sentence optimization prompt word is output as the optimal prompt word.
[0178] In this embodiment, considering that the effect of sentence optimization may be better (higher accuracy) or worse (lower accuracy) than before optimization, it is necessary to compare the accuracy with the prompt words before sentence optimization (i.e., semantically optimized prompt words), and select the prompt word with the highest accuracy as the output sentence optimization prompt word. For example, assuming that the accuracy of the semantically optimized prompt word before sentence optimization is 95%, while the accuracy of the prompt word after sentence optimization is 88%, then the semantically optimized prompt word is selected as the output sentence optimization prompt word. It should be noted that the accuracy comparison standard for prompt words before and after sentence optimization is the same, that is, the same test cases must be used for accuracy comparison.
[0179] This embodiment optimizes suggestion words based on key phrase editing. By extracting key phrases, it ensures a correct and efficient optimization direction, optimizing only the effective information of the suggestion words without optimizing other content such as task examples. Secondly, it utilizes a custom dictionary and stop words to improve optimization accuracy and search efficiency. Furthermore, this embodiment increases the diversity of the statements through adding, deleting, and modifying phrases, obtaining more possibilities for suggestion words and ultimately achieving the optimal suggestion words.
[0180] In an optional embodiment, the large model prompt word optimization method further includes:
[0181] (1) Obtain the optimal prompt words output by the large model;
[0182] In this optional embodiment, the optimal prompt word output by the large model may be generated without optimization, or it may be generated after semantic optimization only, or it may be generated after semantic optimization and sentence optimization respectively. This optimal prompt word can ensure a high accuracy when completing the corresponding large model application task.
[0183] (2) Use new test cases and call the large model to test the optimal prompt words, output the test results and display the test effect.
[0184] In this optional embodiment, after obtaining the optimal prompt word output by the large model, the optimal prompt word can also be tested and the test effect can be displayed, so that users can understand the accuracy of the optimized prompt word.
[0185] In one optional embodiment, the test results of the optimal prompt word are demonstrated in the following manner:
[0186] Input the optimal prompt words and the new test cases into the large model for testing, output the test answers of all the new test cases and print them out;
[0187] Based on the standard answers corresponding to the new test cases, the accuracy of the test answers is calculated and visualized.
[0188] In this optional embodiment, after obtaining the optimal prompt word output by the large model, the optimal prompt word is tested using test cases different from those used for prompt word optimization. The test answer corresponding to the optimal prompt word is then output and printed for user viewing and analysis. Simultaneously, the accuracy rate of the test answer for the optimal prompt word is further calculated and displayed visually, such as through a pie chart, for easy and intuitive understanding by the user.
[0189] Please refer to Figure 5 , Figure 5 This is a functional module diagram of an embodiment of the large model prompt word optimization device of the present invention. In this embodiment, the large model prompt word optimization device includes:
[0190] The initialization module 501 is used to obtain the first prompt word and input it into the large model, generate multiple first prompt words, test the first prompt words, and determine the initial prompt word and whether to perform semantic optimization based on the test results;
[0191] The semantic optimization module 502 is used to construct a second-order prompt word based on semantic reflection based on the initial prompt word and input it into the large model if semantic optimization is determined to be performed. This generates multiple second prompt words, and iteratively optimizes and tests the second prompt words. Based on the test results, it determines the semantic optimization prompt word and whether to perform sentence optimization.
[0192] The statement optimization module 503 is used to edit the semantic optimization prompt words if it is determined that statement optimization is to be performed, generate multiple third prompt words, iteratively optimize and test the third prompt words, determine the statement optimization prompt words based on the test results, and output them as the optimal prompt words.
[0193] Optionally, in one embodiment, the initialization module 501 is specifically used for:
[0194] Based on the pre-defined first task description and task examples, construct the first meta prompt word;
[0195] The first prompt word is input into the large model for processing to generate multiple first prompt words;
[0196] Pre-set test cases were used and a large model was invoked to test each first prompt word, and the accuracy of the test results corresponding to each first prompt word was calculated.
[0197] Determine whether the highest accuracy rate among all test results corresponding to the first prompt word reaches the preset first accuracy rate threshold;
[0198] If the first accuracy threshold is reached, then semantic optimization will not be performed and the corresponding first prompt word will be output as the optimal prompt word.
[0199] If the first accuracy threshold is not reached, semantic optimization is determined, and the first prompt word with the highest accuracy among all test results is output as the initial prompt word.
[0200] Optionally, in one embodiment, the semantic optimization module 502 is specifically used for:
[0201] Based on the optimization results of the previous round of prompt word optimization, construct the second-order prompt words based on semantic reflection for this round and input them into the large model to generate multiple second-order prompt words for this round of prompt word optimization. The optimization results of the previous round of prompt word optimization include the initial prompt words.
[0202] Using the test cases and calling the large model, each second prompt word generated in this round is tested. The accuracy of the test results corresponding to each second prompt word is calculated. The second prompt word with the highest accuracy among all test results in this round is output as the optimization result of the prompt word optimization in this round.
[0203] Iteratively perform semantic optimization until the preset first iteration exit condition is met, then stop the iteration and take the second prompt word with the highest accuracy among all test results as the first candidate prompt word;
[0204] Determine whether the accuracy of the test result corresponding to the first candidate prompt word reaches a preset second accuracy threshold;
[0205] If the second accuracy threshold is reached, then no statement optimization is performed and the first candidate prompt word is output as the optimal prompt word.
[0206] If the second accuracy threshold is not reached, then sentence optimization is determined, and the initial prompt word is used as the second candidate prompt word. The accuracy of the test results corresponding to the first candidate prompt word and the second candidate prompt word are compared, and the prompt word with the highest accuracy is selected as the semantic optimization prompt word for output.
[0207] In this embodiment, prompt words are generated and semantically reflected based on a large model. This method collects sets of incorrect answers corresponding to different prompt words, utilizes the capabilities of the large model itself to generate prompt words and reflect semantics, and then selects the prompt word with the highest answer accuracy as the optimization result through iterative optimization and testing. This improves the optimization effect of prompt words and can be automated, which is more effective and efficient than manually writing prompt words.
[0208] Optionally, in one embodiment, the semantic optimization module 502 is further configured to:
[0209] The test cases are used to test the optimization results of the previous round of prompt word optimization by calling the large model, and the test cases with incorrect answers are extracted from the test results as the wrong question set for this round of testing.
[0210] Based on the pre-defined second task description and the set of incorrect questions from this round of testing, a second-order prompt word based on semantic reflection is constructed for this round and input into the large model to generate multiple second prompt words for this round of prompt word optimization.
[0211] Optionally, in one embodiment, the statement optimization module 503 is specifically used for:
[0212] Extract the third task description from the semantic optimization prompt words as the first key content, and set stop words and a custom dictionary based on the first key content;
[0213] Based on the stop words and the custom dictionary, the first key content is segmented to obtain the second key content composed of multiple segmented words.
[0214] The second key content is edited to generate multiple third key content, and each of the third key content replaces the third task description in the semantic optimization prompt word, thereby obtaining multiple third prompt words for this round of prompt word optimization. The sentence editing operation includes one or more of the following: add operation, delete operation, modify operation and swap operation.
[0215] Using the aforementioned test cases and calling the large model, each of the third prompt words generated in this round is tested, and the accuracy of the test results corresponding to all the third prompt words in this round is calculated.
[0216] Iteratively optimize the statement until the preset second iteration exit condition is met, then stop the iteration and use the third prompt word with the highest accuracy among all test results as the third candidate prompt word;
[0217] The semantic optimization prompt word is selected as the fourth candidate prompt word. The accuracy of the test results corresponding to the third candidate prompt word and the fourth candidate prompt word are compared. The prompt word with the highest accuracy is selected as the sentence optimization prompt word and the sentence optimization prompt word is output as the optimal prompt word.
[0218] This embodiment optimizes suggestion words based on key phrase editing. By extracting key phrases, it ensures a correct and efficient optimization direction, optimizing only the effective information of the suggestion words without optimizing other content such as task examples. Secondly, it utilizes a custom dictionary and stop words to improve optimization accuracy and search efficiency. Furthermore, this embodiment increases the diversity of the statements through adding, deleting, and modifying phrases, obtaining more possibilities for suggestion words and ultimately achieving the optimal suggestion words.
[0219] Optionally, in one embodiment, the large model prompt word optimization device further includes:
[0220] The test demonstration module 504 is used to obtain the optimal prompt word output by the large model; use new test cases and call the large model to test the optimal prompt word, output the test results and demonstrate the test effect.
[0221] Optionally, in one embodiment, the test demonstration module 504 is specifically used for:
[0222] Input the optimal prompt words and the new test cases into the large model for testing, output the test answers of all the new test cases and print them out;
[0223] Based on the standard answers corresponding to the new test cases, the accuracy of the test answers is calculated and visualized.
[0224] Since the embodiments of the device part correspond to the embodiments of the above method, please refer to the above method embodiments for the introduction of the large model prompt word optimization device provided by the present invention. The present invention will not be described again here, but it has the same beneficial effects as the above large model prompt word optimization method.
[0225] In this embodiment, a method based on semantic reflection and sentence editing is specifically adopted to optimize prompt words for a large model. First, prompt words are generated based on the large model; then, prompt word optimization is performed based on semantic reflection; finally, prompt words are further optimized based on sentence editing to obtain the optimal prompt words. This embodiment achieves automatic generation and optimization of prompt words for a large model, requiring no manual intervention throughout the process, significantly improving the optimization efficiency. Furthermore, this embodiment innovatively combines semantics and sentence analysis to optimize prompt words from two aspects. Through prompt word optimization based on semantic reflection, the prompt words achieve optimal results at the deep semantic level; subsequently, prompt word optimization based on sentence editing achieves optimal results at the surface sentence level. By combining semantics and sentence analysis, the optimization effect of prompt words is significantly improved at both the surface sentence and deep semantic levels.
[0226] above Figure 5 The large model prompt word optimization device in this embodiment of the invention is described in detail from the perspective of modular functional entities. The computer device in this embodiment of the invention is described in detail from the perspective of hardware processing.
[0227] Figure 6This is a schematic diagram of a computer device 500 provided in an embodiment of the present invention. The computer device 500 can vary significantly due to different configurations or performance characteristics. It may include one or more central processing units (CPUs) 510 and memory 520, and one or more storage media 530 (e.g., one or more mass storage devices) for storing application programs 533 or data 532. The memory 520 and storage media 530 may be temporary or persistent storage. The program stored in the storage media 530 may include one or more modules (not shown in the diagram), each module including a series of instruction operations on the computer device 500. Furthermore, the processor 510 may be configured to communicate with the storage media 530 and execute the series of instruction operations in the storage media 530 on the computer device 500.
[0228] Computer device 500 may also include one or more power supplies 540, one or more wired or wireless network interfaces 550, one or more input / output interfaces 560, and / or one or more operating systems 531, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 6 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0229] The present invention also provides a computer device, the computer device including a memory and a processor, the memory storing computer-readable instructions, which, when executed by the processor, cause the processor to perform the steps of the large model prompt word optimization method described in the above embodiments.
[0230] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium, wherein the computer-readable storage medium stores instructions that, when the instructions are executed on a computer, cause the computer to perform the steps of the large model prompt word optimization method.
[0231] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0232] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0233] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for optimizing prompt words in a large model, characterized in that, The large model prompt word optimization method includes: Obtain the first prompt word and input it into the large model to generate multiple first prompt words. Test the first prompt words and determine the initial prompt words and whether to perform semantic optimization based on the test results. If semantic optimization is determined, then based on the initial prompt words, construct second-order prompt words based on semantic reflection and input them into the large model to generate multiple second-order prompt words. Then, iteratively optimize and test the second-order prompt words, and determine the semantically optimized prompt words and whether to optimize the sentence based on the test results. If it is determined that sentence optimization is to be performed, the semantic optimization prompt words are edited to generate multiple third prompt words, and the third prompt words are iteratively optimized and tested. Based on the test results, the sentence optimization prompt words are determined and output as the optimal prompt words. The step of editing the semantically optimized prompt words to generate multiple third prompt words, iteratively optimizing and testing the third prompt words, and determining the optimized prompt words based on the test results and outputting them as the optimal prompt words includes: Extract the task description from the semantically optimized prompt words and perform word segmentation. Then, perform sentence editing operations on the word segmentation to generate multiple third prompt words. The accuracy of each third prompt word is tested and iteratively optimized until the exit condition is met. Then, the third prompt word with the highest accuracy is selected as the candidate prompt word. Compare the accuracy of the candidate prompts with that of the semantically optimized prompts, and output the prompt with the highest accuracy as the optimal prompt.
2. The large model prompt word optimization method according to claim 1, characterized in that, The process of obtaining the first prompt word and inputting it into the large model to generate multiple first prompt words, testing the first prompt words, and determining the initial prompt word and whether to perform semantic optimization based on the test results includes: Based on the pre-defined first task description and task examples, construct the first meta prompt word; The first prompt word is input into the large model for processing to generate multiple first prompt words; Pre-set test cases were used and a large model was invoked to test each first prompt word, and the accuracy of the test results corresponding to each first prompt word was calculated. Determine whether the highest accuracy rate among all test results corresponding to the first prompt word reaches the preset first accuracy rate threshold; If the first accuracy threshold is reached, then semantic optimization will not be performed and the corresponding first prompt word will be output as the optimal prompt word. If the first accuracy threshold is not reached, semantic optimization is determined, and the first prompt word with the highest accuracy among all test results is output as the initial prompt word.
3. The large model prompt word optimization method according to claim 2, characterized in that, The process of constructing a second-order prompt word based on semantic reflection based on the initial prompt word and inputting it into a large model to generate multiple second-order prompt words, and iteratively optimizing and testing the second-order prompt words, and determining the semantically optimized prompt word and whether to perform sentence optimization based on the test results includes: S201: Based on the optimization results of the previous round of prompt word optimization, construct the second-order prompt words based on semantic reflection for this round and input them into the large model to generate multiple second-order prompt words for this round of prompt word optimization, wherein the optimization results of the previous round of prompt word optimization include the initial prompt words; S202: Using the test cases and calling the large model, test each of the second prompt words generated in this round, calculate the accuracy of the test results corresponding to each second prompt word, and output the second prompt word with the highest accuracy among all test results in this round as the optimization result of the prompt word optimization in this round; S203: Iterate through S201-S202 until the preset first iteration exit condition is met, then stop the iteration and use the second prompt word with the highest accuracy among all test results as the first candidate prompt word; S204: Determine whether the accuracy of the test result corresponding to the first candidate prompt word reaches a preset second accuracy threshold; S205: If the second accuracy threshold is reached, then it is determined that no statement optimization will be performed and the first candidate prompt word will be output as the optimal prompt word; S206: If the second accuracy threshold is not reached, then sentence optimization is determined, and the initial prompt word is used as the second candidate prompt word. The accuracy of the test results corresponding to the first candidate prompt word and the second candidate prompt word is compared, and the prompt word with the highest accuracy is selected as the semantic optimization prompt word for output.
4. The large model prompt word optimization method according to claim 3, characterized in that, Based on the optimization results of the previous round of prompt word optimization, the second-order prompt words based on semantic reflection are constructed for this round and input into the large model, generating multiple second-order prompt words for this round of prompt word optimization, including: The test cases are used to test the optimization results of the previous round of prompt word optimization by calling the large model, and the test cases with incorrect answers are extracted from the test results as the wrong question set for this round of testing. Based on the pre-defined second task description and the set of incorrect questions from this round of testing, a second-order prompt word based on semantic reflection is constructed for this round and input into the large model to generate multiple second prompt words for this round of prompt word optimization.
5. The large model prompt word optimization method according to claim 3, characterized in that, The step of editing the semantically optimized prompt words to generate multiple third prompt words, iteratively optimizing and testing the third prompt words, and determining the optimized prompt words based on the test results and outputting them as the optimal prompt words includes: S301: Extract the third task description from the semantic optimization prompt words as the first key content, and set stop words and a custom dictionary based on the first key content; S302: Based on the stop words and the custom dictionary, the first key content is segmented to obtain the second key content composed of multiple segmented words; S303: Perform a statement editing operation on the second key content to generate multiple third key content, and replace the third task description in the semantic optimization prompt word with each of the third key content, thereby obtaining multiple third prompt words for this round of prompt word optimization. The statement editing operation includes one or more of the following: add operation, delete operation, modify operation and swap operation. S304: Using the test cases and calling the large model, test each of the third prompt words generated in this round, and calculate the accuracy of the test results corresponding to all the third prompt words in this round; S305: Iterate through S303-S304 until the preset second iteration exit condition is met, then stop the iteration and use the third prompt word with the highest accuracy among all test results as the third candidate prompt word; S306: The semantic optimization prompt word is used as the fourth candidate prompt word, and the accuracy of the test results corresponding to the third candidate prompt word and the fourth candidate prompt word are compared. The prompt word with the highest accuracy is selected as the sentence optimization prompt word and the sentence optimization prompt word is output as the optimal prompt word.
6. The method for optimizing large model prompt words according to any one of claims 1-5, characterized in that, The large model prompt word optimization method also includes: Obtain the optimal prompt words output by the large model; The optimal prompt words are tested using new test cases and a large model, and the test results are output and the test effect is displayed.
7. The large model prompt word optimization method according to claim 6, characterized in that, The process of using new test cases and calling a large model to test the optimal prompt words, outputting test results, and displaying the test effects includes: Input the optimal prompt words and the new test cases into the large model for testing, output the test answers of all the new test cases and print them out; Based on the standard answers corresponding to the new test cases, the accuracy of the test answers is calculated and visualized.
8. A large-scale model prompt word optimization device, characterized in that, The large model prompt word optimization device includes: The initialization module is used to obtain the first prompt word and input it into the large model, generate multiple first prompt words, test the first prompt words, and determine the initial prompt word and whether to perform semantic optimization based on the test results; The semantic optimization module is used to construct a second-order prompt word based on semantic reflection based on the initial prompt word and input it into the large model if semantic optimization is determined. This generates multiple second prompt words, and iteratively optimizes and tests the second prompt words. Based on the test results, the semantic optimization prompt word and whether sentence optimization should be performed are determined. The statement optimization module is used to edit the semantic optimization prompt words if it is determined that statement optimization is to be performed, generate multiple third prompt words, iteratively optimize and test the third prompt words, determine the statement optimization prompt words based on the test results and output them as the optimal prompt words. Specifically, the statement optimization module is used to: extract the task description from the semantic optimization prompt words and perform word segmentation; perform statement editing operations on the word segmentation to generate multiple third prompt words; test the accuracy of each third prompt word and perform iterative optimization until the exit condition is met, then select the third prompt word with the highest accuracy as a candidate prompt word; compare the accuracy of the candidate prompt word with that of the semantic optimization prompt words, and output the prompt word with the highest accuracy as the optimal prompt word.
9. A computer device, characterized in that, The computer device includes: a memory and at least one processor, wherein the memory stores instructions; The at least one processor invokes the instructions in the memory to cause the computer device to execute the large model prompt word optimization method as described in any one of claims 1-7.
10. A computer-readable storage medium storing instructions thereon, characterized in that, When the instruction is executed by the processor, it implements the large model prompt word optimization method as described in any one of claims 1-7.
Citation Information
Patent Citations
Prompt word full life cycle management method and system, electronic equipment and storage medium
CN117494814A
Generation method and device of cue word information of large language model, equipment and medium
CN117539975A