Self-reflective prompt word optimization method and system based on large language model
Through the self-reflective prompt word optimization method of large language model, the prompt word template is automatically updated, which solves the high cost and untimely update problems caused by the dependence of manual intervention in the existing technology, and improves the model response speed and accuracy.
Patent Information
- Application Number
- CN202411441108.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-10-16
AI Technical Summary
Existing prompt word optimization methods rely on manual intervention, which leads to high costs and is difficult to ensure the timeliness of prompt word updates, and cannot be automatically modified online to ensure the accuracy and relevance of model output.
Using a self-reflective prompt word optimization method based on a large language model, by obtaining the initial prompt word template, dividing the correct and error sample sets according to the model evaluation results, constructing a revised prompt word template, generating new prompt words, and filtering through the quality evaluator New prompt words that meet stability and consistency requirements to realize automatic update of prompt words.
Asynchronous and timely update of prompt words is realized, which significantly reduces the cost of manual intervention optimization, improves the response speed and accuracy of large language models, and improves user experience.
Smart Images

Figure CN118966208B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a self-reflective prompt word optimization method and system based on a large language model. Background Art
[0002] Nowadays, more and more tasks can be solved by large language models (LLMs), which have demonstrated excellent performance in many fields such as natural language processing, text generation, and machine translation. The writing of prompts is the core of realizing the specific functions of large models. Through accurate and effective prompts, large language models can be guided to generate the desired results. However, in practical applications, the cost of calling large language models is very high, mainly reflected in the consumption of computing resources and calling time. In addition, in the continuous development of applications, prompts need to be updated as needs and environments change to maintain the accuracy and relevance of model output.
[0003] The problem of prompt word optimization mainly refers to the fact that prompt words need to be repeatedly modified during the task, but there is no guarantee that the effect after modification is better than before modification, and that they can be modified automatically online; current prompt word optimization methods mostly rely on manual intervention, which is not only time-consuming and labor-intensive, but also difficult to ensure the timeliness of prompt word updates. Summary of the invention
[0004] The present invention aims to provide a self-reflective prompt word optimization method and system based on a large language model, which automatically updates the prompt words by using the feedback mechanism of the large model itself, thereby realizing asynchronous and timely updating of the prompt words.
[0005] To achieve the above object, the present invention proposes the following technical solutions:
[0006] First, a self-reflective prompt word optimization method based on a large language model is proposed, including:
[0007] Based on the application task of the large language model, an initialized prompt word template is obtained, so that the application task obtains a number of prompt word use cases after executing a set period according to a preset data set;
[0008] Using a large language model to review the prompt word use cases according to the evaluation index, classifying the prompt word use cases into correct sample sets and incorrect sample sets in turn according to the model evaluation results, and then establishing an optimized sample set after uniformly sampling from the correct sample set and the incorrect sample set;
[0009] Constructing a revised prompt word template, wherein the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a plurality of new prompt words;
[0010] Evaluating a number of the new prompt words, and selecting new prompt words that meet the prompt word stability and consistency requirements;
[0011] The new prompt word is verified by using a large language model according to the evaluation index. When the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the new prompt word obtained meets the optimization target.
[0012] Furthermore, the process of evaluating the new prompt words and selecting the new prompt words that meet the prompt word stability and consistency requirements includes:
[0013] Grouping the new prompt words, wherein any group of the new prompt words includes at least 5 words;
[0014] For each group of new prompt words, a prompt word revision summarizer is introduced to perform a first summary on the new prompt words, and the new prompt words with the highest quality evaluation after the first screening of each group are determined;
[0015] The prompt word revision summarizer is used to perform a second summary on the plurality of new prompt words screened out in the first screening, and the new prompt word with the highest quality evaluation after the second screening is determined;
[0016] The new prompt word summarizing process is repeatedly performed until only one new prompt word is retained after screening.
[0017] Furthermore, the process of constructing and revising the prompt word template to modify the prompt word use case according to the optimized sample set to generate a number of new prompt words is as follows:
[0018] Construct a revision prompt word template, denoted as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct and incorrect samples obtained;
[0019] For any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ;
[0020] According to the optimization sample concentration Group sample, using the revised prompt word template generate New prompt words ;in, .
[0021] Furthermore, the process of evaluating the new prompt words and selecting the new prompt words that meet the prompt word stability and consistency requirements includes:
[0022] Constructing a prompt word quality evaluator, and using the prompt word quality evaluator to evaluate the new prompt words to obtain a quality score of each of the new prompt words;
[0023] Comparing the quality scores of the new prompt words, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements;
[0024] The prompt word quality assessor is a neural network, and the corresponding expression is: ;
[0025] in, represents the quality score, To revise the prompt word template according to the number of new prompt words obtained by optimizing the sample set, LLM ( ) is the i New prompt words The actual output of the corresponding large language model, For the i Tip word examples The expected output of the corresponding large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
[0026] Furthermore, the example of the prompt word is recorded as , ;in, is the initialization prompt word template, The preset data set is preset data; For preset data Prompt words generated based on the initialized prompt word template;
[0027] The process of using a large language model to review the prompt word use cases according to the evaluation index to classify the prompt word use cases is as follows:
[0028] According to the evaluation index, input the prompt words in the prompt word use case into the large language model, and output the model evaluation result;
[0029] Determine whether the model evaluation result meets the preset task expectations. When the model evaluation result exceeds the preset task expectations, the prompt word use case is recorded as a correct sample and classified into the correct sample set; otherwise, the prompt word use case is recorded as an incorrect sample and classified into the incorrect sample set.
[0030] Secondly, a self-reflective prompt word optimization system based on a large language model is proposed, including:
[0031] An acquisition module, used for acquiring an initialized prompt word template for an application task based on a large language model, so that the application task can obtain a number of prompt word use cases after executing a set period according to a preset data set;
[0032] An audit establishment module is used to audit the prompt word use cases according to the evaluation index using a large language model, and to classify the prompt word use cases into a correct sample set and an incorrect sample set according to the model evaluation result, and then to establish an optimized sample set after uniform sampling from the correct sample set and the incorrect sample set;
[0033] A construction generation module is used to construct a revised prompt word template, wherein the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a plurality of new prompt words;
[0034] An evaluation and screening module, used to evaluate the new prompt words and screen the new prompt words that meet the prompt word stability and consistency requirements;
[0035] The verification and updating module is used to verify the new prompt word according to the evaluation index using a large language model. When the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the new prompt word obtained meets the optimization target.
[0036] Furthermore, the evaluation and screening module evaluates the new prompt words and screens the execution units of the new prompt words that meet the prompt word stability and consistency requirements, including:
[0037] A grouping unit, used for grouping a plurality of the new prompt words, wherein any group of the new prompt words includes at least 5;
[0038] A first summarizing unit is used to introduce a prompt word revision summarizer to perform a first summary on the new prompt words in each group, and determine the new prompt words with the highest quality evaluation after a first screening of each group;
[0039] A second summarizing unit is used to use the prompt word revision summarizer to perform a second summary on the plurality of new prompt words screened out once, and determine the new prompt word with the highest quality evaluation after the second screening;
[0040] The execution screening unit is used to repeatedly perform the new prompt word summarizing process until only one new prompt word is retained after screening.
[0041] Furthermore, the construction generation module constructs a revised prompt word template to modify the prompt word use case according to the optimized sample set to generate several execution units of new prompt words, including:
[0042] The construction unit is used to construct a revision prompt word template, denoted as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct and incorrect samples obtained;
[0043] Get unit, used for any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ;
[0044] A generating unit is used to optimize the sample set according to the Group sample, using the revised prompt word template generate New prompt words ;in, .
[0045] Furthermore, the evaluation and screening module evaluates the new prompt words and screens the execution units of the new prompt words that meet the prompt word stability and consistency requirements, including:
[0046] Constructing an evaluation unit, which is used to construct a prompt word quality evaluator, and using the prompt word quality evaluator to evaluate the new prompt words to obtain a quality score of each of the new prompt words;
[0047] A comparison and selection unit, used for comparing the quality scores of the new prompt words, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements;
[0048] The prompt word quality assessor is a neural network, and the corresponding expression is: ;
[0049] in, represents the quality score, The number of new prompt words generated by the optimized sample set to revise the prompt word template, LLM( ) is the i New prompt words Based on the actual output of the large language model, For the i Prompt words Based on the expected output of the large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
[0050] In a third aspect, an electronic device is proposed, comprising a computer program, wherein the computer program is stored in a computer-readable storage medium; when a processor of the electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device performs the steps of the above-mentioned self-reflective prompt word optimization method based on a large language model.
[0051] It can be seen from the above technical solutions that the technical solutions of the present invention have the following beneficial effects:
[0052] The invention discloses a self-reflective prompt word optimization method and system based on a large language model. The method comprises: obtaining an initialized prompt word template based on an application task of the large language model, so that the application task obtains a plurality of prompt word use cases after executing a set period according to a preset data set; using the large language model to review the prompt word use cases according to evaluation indicators, and classifying each of the prompt word use cases into a correct sample set and an incorrect sample set in turn according to the model evaluation result, and then establishing an optimized sample set after uniform sampling from the correct sample set and the incorrect sample set; constructing a revised prompt word template, the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a plurality of new prompt words; evaluating the plurality of new prompt words, and selecting new prompt words that meet the prompt word stability and consistency requirements; using the large language model to verify the new prompt word according to the evaluation indicators, and when the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before revision, updating the prompt word template; otherwise, repeating the above prompt word optimization process until the obtained new prompt word meets the optimization target.
[0053] Compared with the current technical status that the prompt word optimization process mostly relies on manual intervention, which is costly and difficult to ensure the timeliness of prompt word updates, the present invention uses the feedback mechanism of the large language model itself to automatically update the prompt word template, thereby realizing asynchronous and timely updating of the prompt words; the present invention can not only significantly reduce the cost of manual intervention to optimize the prompt words, but also improve the response speed and accuracy of the large language model after application, and enhance the user experience of the large language model in the application scenario.
[0054] It should be appreciated that all combinations of the foregoing concepts, as well as additional concepts described in greater detail below, may be considered to be part of the inventive subject matter of the present disclosure, provided such concepts are not mutually inconsistent.
[0055] The foregoing and other aspects, embodiments and features of the present invention can be more fully understood from the following description in conjunction with the accompanying drawings. Other additional aspects of the present invention, such as the features and / or beneficial effects of the exemplary embodiments, will be apparent from the following description or learned from the practice of the specific embodiments according to the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] The accompanying drawings are not drawn to scale according to actual reference objects. In the accompanying drawings, each identical or nearly identical component shown in various figures may be represented by the same reference numeral. For the sake of clarity, not every component is labeled in each figure. Now, embodiments of various aspects of the present invention will be described by way of example and with reference to the accompanying drawings, in which:
[0057] Figure 1A flow chart of a self-reflective prompt word optimization method based on a large language model disclosed in an embodiment;
[0058] Figure 2 The method flow of screening new prompt words that meet the target requirements disclosed in the embodiment Figure 1 ;
[0059] Figure 3 A flow chart of a method for generating new prompt words by combining a construction revision prompt word with an optimized sample set disclosed in an embodiment;
[0060] Figure 4 The method flow of screening new prompt words that meet the target requirements disclosed in the embodiment Figure 2 ;
[0061] Figure 5 It is a structural block diagram of a self-reflective prompt word optimization system based on a large language model disclosed in an embodiment;
[0062] Figure 6 A structural block diagram of an electronic device disclosed in an embodiment. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention. Unless otherwise defined, the technical terms or scientific terms used herein should be the common meaning understood by people with general skills in the field to which the present invention belongs.
[0064] The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, unless the context clearly indicates otherwise, the singular form of "a", "an" or "the" and similar words do not indicate a quantitative limitation, but indicate the existence of at least one. "Include" or "comprises" and similar words mean that the elements or objects appearing before "include" or "comprises" include the features, wholes, steps, operations, elements and / or components listed after "include" or "comprises", and do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or their collections.
[0065] Based on the fact that calling a large language model currently consumes a lot of time resources, the prompt words also need to be updated as the needs and environment change during application to maintain the accuracy and relevance of the model output; however, the current prompt word optimization method mainly relies on manual intervention, which further leads to the time cost of calling the large language model, and it is difficult to ensure the timeliness of the prompt word update; therefore, the present invention aims to propose a self-reflective prompt word optimization method and system based on a large language model, which uses the feedback mechanism of the large language model itself to automatically update the prompt words, which not only realizes the timely update of the prompt words, but also effectively reduces the time cost consumption when applied in the large language model.
[0066] The following is a further detailed introduction to the self-reflective prompt word optimization method and system based on a large language model disclosed in the present invention in conjunction with the specific embodiments shown in the accompanying drawings.
[0067] Combination Figure 1 As shown, the self-reflective prompt word optimization method based on a large language model disclosed in the embodiment specifically includes the following steps:
[0068] Step S102, based on the application task of the large language model, obtaining an initialized prompt word template, so that the application task obtains a number of prompt word use cases after executing a set period according to a preset data set;
[0069] The initial prompt word template is recorded as After the application task is executed for a period of time, the prompt word template is obtained. prompt word use cases, and record the prompt word use cases as , , The prompt word example is: ,in, The preset data set is preset data; For preset data Prompt words generated based on the initialized prompt word template;
[0070] Step S104, using a large language model to review the prompt word use cases according to the evaluation index, and classifying the prompt word use cases into a correct sample set and an incorrect sample set in turn according to the model evaluation result, and then establishing an optimized sample set after uniformly sampling from the correct sample set and the incorrect sample set; wherein the optimized sample set uses an equal amount of data from the correct sample set and the incorrect sample set;
[0071] In this embodiment, the review process is to evaluate the output results of the prompt word use cases generated by the large language model according to the evaluation indicators, and then divide the prompt word use cases according to the evaluation results; specifically including: the process of using the large language model to review the prompt word use cases according to the evaluation indicators to classify the prompt word use cases is: according to the evaluation indicators, input the prompt words in the prompt word use cases to the large language model, and output the model evaluation results; determine whether the model evaluation results meet the preset task expectations, when the model evaluation results exceed the preset task expectations, record the prompt word use cases as correct samples and classify them into the correct sample set; otherwise, record the prompt word use cases as incorrect samples and classify them into the incorrect sample set.
[0072] Step S106, constructing a revised prompt word template, wherein the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a number of new prompt words;
[0073] like Figure 3 As shown, the specific process of generating a number of new prompt words includes: Step S1061, constructing a revised prompt word template, recorded as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct samples and incorrect samples; Step S1062, for any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ; Step S1063, according to the optimization sample set Group sample, using the revised prompt word template generate New prompt words ;in, The revised prompt word template modifies the generated new prompt words based on the correct samples and the wrong samples, so as to achieve the technical effect of prompt word self-reflection.
[0074] Step S108, evaluating the new prompt words, and selecting new prompt words that meet the prompt word stability and consistency requirements;
[0075] Directly using all correct and incorrect samples to modify and screen prompt words consumes a lot of time and cost. Applying all samples will also make the prompt words too complicated, the model application effect is poor, some problems will be submerged, and the results obtained are not very logical. Therefore, in this case, several new prompt words are screened to ensure the stability and consistency of the generated new prompt words.
[0076] Figure 2 A scheme for screening new prompt words is shown, and the scheme includes the following steps: step S1081, grouping a number of the new prompt words, and any group of the new prompt words includes at least 5; dividing the new prompt words into batches, reducing the amount of data to be processed while increasing the focus of the subsequent prompt word summary screening process; step S1082, for each group of the new prompt words, introducing a prompt word revision summarizer to perform the first summary of the new prompt words, and determining the new prompt word with the highest quality evaluation after each group is screened once. The prompt word revision summarizer itself is a prompt word, denoted as , its input is a prompt word and the test result of the prompt word, usually 5 test results are sampled, including the input and output of the prompt word, and the output is the evaluation of the prompt word, modification opinions and the modified prompt word. The large language model can give an evaluation from the perspective of language analysis through the task description and the results of the relevant prompt words. When the evaluation is not good, it will give certain revision opinions and give the modified prompt word according to the revision opinions. The principle of the prompt word revision summarizer is that the large language model can easily distinguish the matching degree of language and content. It is a thinking chain technology in the prompt word engineering, through which the prompt word can be well improved and iterated. Step S1083, the prompt word revision summarizer is used to summarize the several new prompt words screened out once for the second time, and determine the new prompt word with the highest quality evaluation after the second screening; step S1084, repeat the new prompt word summary process until only one new prompt word is retained after screening.
[0077] Step S110, using a large language model to verify the new prompt word according to the evaluation index, when the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the new prompt word meets the optimization target.
[0078] As an optional implementation, the process of selecting new prompt words that meet the prompt word stability and consistency requirements in step S108 can also be performed by Figure 4 The process shown in the figure is implemented; specifically includes: step S1081', constructing a prompt word quality evaluator, using the prompt word quality evaluator to evaluate the new prompt word, and obtaining the quality score of each new prompt word; step S1082', comparing the quality scores of each new prompt word, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements;
[0079] The prompt word quality assessor is a neural network, and the corresponding expression is: ;
[0080] in, represents the quality score, To revise the prompt word template according to the number of new prompt words obtained by optimizing the sample set, LLM ( ) is the i New prompt words The actual output of the corresponding large language model, For the i Tip word examples The expected output of the corresponding large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
[0081] In order to solve the problem that the current prompt word optimization method mainly relies on manual intervention, consumes a lot of time and is difficult to ensure the timeliness of prompt word updates, the embodiment proposes a self-reflective prompt word optimization method based on a large language model. The prompt word template is automatically updated through the prompt word self-reflection effect combined with the large language model self-feedback mechanism, and then the prompt word is asynchronously and timely updated based on the updated prompt word template; at the same time, it avoids the use of manual intervention in prompt word optimization, and achieves the technical effect of improving the response speed and accuracy of calling the large language model in the task, and significantly reduces the time cost.
[0082] In an embodiment of the present application, an electronic device is also provided, including a computer program, the computer program being stored in a computer-readable storage medium; when a processor of the electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device executes the steps of the self-reflective prompt word optimization method based on a large language model. Taking an electronic device running on a computer as an example, Figure 6 As shown, the electronic device may include one or more (only one is shown in the figure) processors (the processor may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory for storing data, and a transmission device for communication functions. A person skilled in the art can understand that Figure 6 The structure shown is for illustration only and does not limit the structure of the above-mentioned electronic device.
[0083] The above program can be run in the processor, or it can be stored in the memory, that is, in the computer-readable medium, which includes permanent and non-permanent, removable and non-removable media. Information storage can be achieved by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, read-only compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined in this article, computer-readable media does not include temporary computer-readable media, such as modulated data signals and carrier waves. These computer programs can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps of the functions specified in a block or multiple blocks may be implemented by different modules corresponding to different method steps.
[0084] In this embodiment, such a device or system is provided. The system can be called a self-reflective prompt word optimization system based on a large language model. Figure 5As shown, it includes: an acquisition module, which is used for obtaining an initialized prompt word template based on an application task of a large language model, so that the application task can obtain a number of prompt word use cases after executing a set period according to a preset data set; an audit establishment module, which is used to audit the prompt word use cases according to the evaluation index using the large language model, and classify each of the prompt word use cases into a correct sample set and an incorrect sample set according to the model evaluation result, and then establish an optimized sample set after uniform sampling from the correct sample set and the incorrect sample set; a construction generation module, which is used to construct a revised prompt word template, and the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a number of new prompt words; an evaluation and screening module, which is used to evaluate the several new prompt words and screen the new prompt words that meet the prompt word stability and consistency requirements; a verification and update module, which is used to verify the new prompt words according to the evaluation index using the large language model, and when the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before the revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the obtained new prompt word meets the optimization target.
[0085] The steps of the system for implementing the self-reflective prompt word optimization method based on a large language model disclosed in the above embodiment have been described and will not be repeated here.
[0086] For example, the evaluation and screening module evaluates the new prompt words and screens the execution unit of the new prompt words that meet the prompt word stability and consistency requirements, which may include: a grouping unit, which is used to group the new prompt words, and any group of the new prompt words includes at least 5; a first summarizing unit, which is used to introduce a prompt word revision summarizer to perform a first summary on the new prompt words in each group of the new prompt words, and determine the new prompt words with the highest quality evaluation after the first screening of each group; a second summarizing unit, which is used to use the prompt word revision summarizer to perform a second summary on the new prompt words screened out once, and determine the new prompt word with the highest quality evaluation after the second screening; and an execution and screening unit, which is used to repeatedly execute the new prompt word summarizing process until only one new prompt word is retained after screening.
[0087] Optionally, the evaluation and screening module can also evaluate the quality of the prompt words in a neural network manner. When implemented, its execution unit includes: an evaluation unit for constructing a prompt word quality evaluator, using the prompt word quality evaluator to evaluate the new prompt words to obtain the quality score of each new prompt word; a comparison and selection unit for comparing the quality scores of each new prompt word, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements; the prompt word quality evaluator is a neural network, and the corresponding expression is: ;
[0088] in, represents the quality score, The number of new prompt words generated by the optimized sample set to revise the prompt word template, LLM( ) is the i New prompt words Based on the actual output of the large language model, For the i Prompt words Based on the expected output of the large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
[0089] For another example, the construction generation module in the self-reflective prompt word optimization system constructs a revised prompt word template to modify the prompt word use case according to the optimization sample set to generate a number of new prompt words. The execution unit includes: a construction unit for constructing a revised prompt word template, denoted as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct samples and wrong samples; obtain the unit for any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ; A generating unit, used to optimize the sample set according to Group sample, using the revised prompt word template generate New prompt words ;in, .
[0090] The prompt word use case obtained by the acquisition module in the self-reflective prompt word optimization system of the embodiment is recorded as , ;in, is the initialization prompt word template, The preset data set is preset data; For preset data Prompt words generated based on the initialized prompt word template. The review establishment module uses a large language model to review the prompt word use cases according to the evaluation indicators to classify the prompt word use cases. The process is as follows: according to the evaluation indicators, the prompt words in the prompt word use cases are input into the large language model, and the model evaluation results are output; it is determined whether the model evaluation results meet the preset task expectations. When the model evaluation results exceed the preset task expectations, the prompt word use cases are recorded as correct samples and classified into the correct sample set; otherwise, the prompt word use cases are recorded as incorrect samples and classified into the incorrect sample set.
[0091] Although the present invention has been disclosed as above with preferred embodiments, it is not intended to limit the present invention. A person with ordinary knowledge in the technical field to which the present invention belongs may make various changes and modifications without departing from the spirit and scope of the present invention. Therefore, the protection scope of the present invention shall be determined by the definition of the claims.
Claims
1. A self-reflective prompt word optimization method based on a large language model, characterized in that: include: Based on the application task of the large language model, an initialized prompt word template is obtained, so that the application task obtains a number of prompt word use cases after executing a set period according to a preset data set; Using a large language model to review the prompt word use cases according to the evaluation index, classifying the prompt word use cases into correct sample sets and incorrect sample sets in turn according to the model evaluation results, and then establishing an optimized sample set after uniformly sampling from the correct sample set and the incorrect sample set; Constructing a revised prompt word template, wherein the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a plurality of new prompt words; Evaluating a number of the new prompt words, and selecting new prompt words that meet the prompt word stability and consistency requirements; The new prompt word is verified by using a large language model according to the evaluation index. When the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before the revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the new prompt word meets the optimization target; The process of evaluating the new prompt words and selecting the new prompt words that meet the prompt word stability and consistency requirements includes: Constructing a prompt word quality evaluator, and using the prompt word quality evaluator to evaluate the new prompt words to obtain a quality score of each of the new prompt words; Comparing the quality scores of the new prompt words, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements; The prompt word quality assessor is a neural network, and the corresponding expression is: ; in, represents the quality score, To revise the prompt word template according to the number of new prompt words obtained by optimizing the sample set, LLM ( ) is the i New prompt words The actual output of the corresponding large language model, For the i Example of prompt words The expected output of the corresponding large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
2. The self-reflective prompt word optimization method based on a large language model according to claim 1, characterized in that: The process of evaluating the new prompt words and selecting the new prompt words that meet the prompt word stability and consistency requirements includes: Grouping the new prompt words, wherein any group of the new prompt words includes at least 5 words; For each group of new prompt words, a prompt word revision summarizer is introduced to perform a first summary on the new prompt words, and the new prompt words with the highest quality evaluation after the first screening of each group are determined; The prompt word revision summarizer is used to perform a second summary on the plurality of new prompt words screened out in the first screening, and the new prompt word with the highest quality evaluation after the second screening is determined; The new prompt word summarizing process is repeatedly performed until only one new prompt word is retained after screening.
3. The self-reflective prompt word optimization method based on a large language model according to claim 1, characterized in that: The process of constructing and revising the prompt word template to modify the prompt word use case according to the optimized sample set to generate a number of new prompt words is as follows: Construct a revision prompt word template, denoted as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct and incorrect samples obtained; For any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ; According to the optimization sample concentration Group sample, using the revised prompt word template generate New prompt words ;in, .
4. The self-reflective prompt word optimization method based on a large language model according to claim 1, characterized in that: The example of the prompt word is recorded as , ;in, is the initialization prompt word template, The preset data set is preset data; For preset data Prompt words generated based on the initialized prompt word template; The process of using a large language model to review the prompt word use cases according to the evaluation index to classify the prompt word use cases is as follows: According to the evaluation index, input the prompt words in the prompt word use case into the large language model, and output the model evaluation result; Determine whether the model evaluation result meets the preset task expectations. When the model evaluation result exceeds the preset task expectations, the prompt word use case is recorded as a correct sample and classified into the correct sample set; otherwise, the prompt word use case is recorded as an incorrect sample and classified into the incorrect sample set.
5. A self-reflective prompt word optimization system based on a large language model, characterized in that: include: An acquisition module, used for acquiring an initialized prompt word template for an application task based on a large language model, so that the application task can obtain a number of prompt word use cases after executing a set period according to a preset data set; An audit establishment module is used to audit the prompt word use cases according to the evaluation index using a large language model, and to classify the prompt word use cases into a correct sample set and an incorrect sample set according to the model evaluation result, and then to establish an optimized sample set after uniform sampling from the correct sample set and the incorrect sample set; A construction generation module is used to construct a revised prompt word template, wherein the revised prompt word template is used to modify the prompt word use case according to the optimized sample set to generate a plurality of new prompt words; An evaluation and screening module, used to evaluate the new prompt words and screen the new prompt words that meet the prompt word stability and consistency requirements; A verification and updating module, used to verify the new prompt word according to the evaluation index using a large language model, and when the model evaluation result corresponding to the verified new prompt word exceeds the model evaluation result of the prompt word use case before the revision, the prompt word template is updated; otherwise, the above prompt word optimization process is repeated until the new prompt word obtained meets the optimization target; The evaluation and screening module evaluates the new prompt words and screens the execution units of the new prompt words that meet the prompt word stability and consistency requirements, including: Constructing an evaluation unit, which is used to construct a prompt word quality evaluator, and using the prompt word quality evaluator to evaluate the new prompt words to obtain a quality score of each of the new prompt words; A comparison and selection unit, used for comparing the quality scores of the new prompt words, and selecting the new prompt word with the highest score as the new prompt word that meets the prompt word stability and consistency requirements; The prompt word quality assessor is a neural network, and the corresponding expression is: ; in, represents the quality score, The number of new prompt words generated according to the optimized sample set to revise the prompt word template, LLM( ) is the i New prompt words Based on the actual output of the large language model, For the i Prompt words Based on the expected output of the large language model, L (LLM( ), Y i ) is used to measure whether the actual output of the large language model matches the expected output. If so, L (LLM( ), Y i ) has a value of 1, if it does not match L (LLM( ), Y i ) has a value of 0.
6. The self-reflective prompt word optimization system based on a large language model according to claim 5, characterized in that: The evaluation and screening module evaluates the new prompt words and screens the execution units of the new prompt words that meet the prompt word stability and consistency requirements, including: A grouping unit, used for grouping a plurality of the new prompt words, wherein any group of the new prompt words includes at least 5; A first summarizing unit is used to introduce a prompt word revision summarizer to perform a first summary on the new prompt words in each group, and determine the new prompt words with the highest quality evaluation after a first screening of each group; A second summarizing unit is used to use the prompt word revision summarizer to perform a second summary on the plurality of new prompt words screened out once, and determine the new prompt word with the highest quality evaluation after the second screening; The execution screening unit is used to repeatedly perform the new prompt word summarizing process until only one new prompt word is retained after screening.
7. The self-reflective prompt word optimization system based on a large language model according to claim 5, characterized in that: The construction generation module constructs a revised prompt word template to modify the prompt word use case according to the optimized sample set to generate a plurality of execution units of new prompt words, including: The construction unit is used to construct a revision prompt word template, denoted as ;in, Indicates the prompt word template revision function, Respectively represent the prompt word template Generate and review the correct and incorrect samples obtained; Get unit, used for any prompt word template , get the prompt word template The optimized sample set includes Correct sample and error samples ; A generating unit is used to optimize the sample set according to the Group sample, using the revised prompt word template generate New prompt words ;in, .
8. An electronic device, characterized in that: It includes a computer program, which is stored in a computer-readable storage medium; when a processor of an electronic device reads the computer program from the computer-readable storage medium, the processor executes the computer program, so that the electronic device executes the steps of the self-reflective prompt word optimization method based on a large language model as described in any one of claims 1-4.
Citation Information
Patent Citations
Text classification method of regular expression generated based on large language model
CN117556049A
Prompt word evaluation method and device, electronic equipment and storage medium
CN118410141A
