Large language model prompt word automatic optimization method

By combining gradient generation and editing of prompt word templates with a cluster search algorithm, and optimizing prompt words using 70B and 7B large language models, the problems of high resource consumption, poor generalization ability and insufficient task adaptability in existing technologies are solved, and efficient and stable prompt word optimization and model performance are achieved.

CN120542583BActive Publication Date: 2025-11-21云筑信息科技(成都)有限公司

Patent Information

Application Number
CN202511042994.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-28
Publication Date
2025-11-21
Estimated Expiration
2045-07-28

AI Technical Summary

Technical Problem

Existing methods for optimizing prompt words in large language models suffer from problems such as high resource consumption, poor generalization ability, insufficient task adaptability, low efficiency and unstable results of manual writing, difficulty in adapting to complex tasks, and lack of targeted model selection.

Method used

Gradient generation of prompt word templates and optimizer models are used to generate natural language gradients. Combined with editing prompt word templates and beam search algorithms, prompt words are optimized through a 70B large language model and a 7B task model to generate high-quality candidate prompt words. The effectiveness of these prompt words is then evaluated through a task model.

Benefits of technology

It improves the efficiency and quality of prompt word optimization, reduces computational resource consumption, enhances the generalization ability and adaptability of prompt words to complex tasks, and ensures stable model performance on different data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120542583B_ABST
    Figure CN120542583B_ABST
Patent Text Reader

Abstract

The application discloses a large language model prompt word automatic optimization method, and relates to the technical field of prompt word optimization. The method comprises the following steps: setting an initial prompt word; constructing training data, a gradient generation prompt word template, a prompt word editing template, an optimizer and a task model; randomly sampling small batch data from the training data as a training set, and predicting an answer of the training set by the task model according to the initial prompt word; comparing the answer with sample labels of the training set to obtain an error example set; inputting the error example set and the initial prompt word into the gradient generation prompt word template to generate a gradient analysis request; receiving and analyzing the gradient analysis request by the optimizer model to generate a second natural language gradient; and inputting the second natural language gradient and the initial prompt word into the prompt word editing template, and modifying the initial prompt word by the optimizer model according to the editing prompt word template to generate a second candidate prompt word. The application solves the technical problem of low efficiency of manually writing prompt words.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of prompt optimization, and particularly relates to a large language model prompt automatic optimization method. BACKGROUND

[0002] With the wide application of large language models (LLMs) in natural language processing, the performance of LLMs largely depends on the input prompts. Traditional prompt design mainly relies on manual trial and error, which is time-consuming and labor-intensive and difficult to ensure optimality. In recent years, automatic prompt optimization techniques have emerged, aiming to generate and optimize prompts through automated methods to improve model performance on specific tasks. In existing technologies, prompt optimization is mainly carried out through reinforcement learning or gradient-based methods. However, these methods have the following problems: high resource consumption: the full process of large language models is involved in optimization and reasoning, resulting in high computational cost; poor generalization ability: the diversity and semantic consistency of prompts are not effectively controlled during the prompt optimization process, and the optimization process is prone to local optimum, resulting in overfitting or insignificant optimization effect; insufficient task adaptation: simple tasks and complex tasks have different requirements for model capabilities, and a single model cannot balance efficiency and accuracy; low efficiency and unstable effect of manual writing: manual writing of prompts relies on human experience, which is inefficient and difficult to adapt to complex and variable task requirements, and different tasks have different requirements for prompts, making it difficult to quickly find the optimal prompt, resulting in the inability of the model to fully exert its performance.

[0003] The existing optimization methods have the following defects: optimization techniques that rely on the internal state of LLMs cannot be used in scenarios that request LLM services based on API; reinforcement learning methods are complex to train and lack interpretability; methods based on Monte Carlo search lack semantic guidance and are prone to local optimum, making it difficult to effectively improve prompt quality. Difficulty in adapting to complex task scenarios: in complex tasks such as instruction following, code generation, and mathematical reasoning, existing prompt optimization methods are difficult to adapt to the diversity and complexity of tasks, and cannot effectively improve the performance of LLMs in these scenarios. Difficulty in controlling prompt optimization direction: during prompt optimization, prompts tend to optimize in the direction of containing more correct examples, which may lead to overfitting and reduce the generalization ability of the model, and there is currently a lack of effective methods to control this optimization direction. Lack of targeted model selection: when selecting models for prompt optimization and task execution, the performance differences between large models and small models on different task complexities are not fully considered, resulting in resource waste when using large models for simple tasks and inability to meet task requirements when using small models for complex tasks, leading to unreasonable resource utilization and poor overall optimization effect. SUMMARY

[0004] The technical problem solved by the present application is to provide a large language model prompt word automatic optimization method to at least solve part of the above technical problems.

[0005] To achieve the above object, the technical scheme adopted by the present application is as follows:

[0006] A large language model prompt word automatic optimization method comprises the following steps:

[0007] S1, set a prompt word as an initial prompt word; construct training data, gradient generation prompt word template, prompt word editing template, optimizer model and task model;

[0008] S2, randomly sample small batch data from the training data as a training set, and the task model predicts the answer of the sample in the training set according to the initial prompt word; compare the answer with the sample label of the training set piece by piece to identify the prediction error example; collect the prediction error example to form an error example set;

[0009] S3, input the error example set and the initial prompt word into the gradient generation prompt word template to generate a gradient analysis request; the optimizer model receives and analyzes the gradient analysis request to generate a second natural language gradient;

[0010] S4, input the second natural language gradient and the initial prompt word into the prompt word editing template, and the optimizer model modifies the initial prompt word according to the editing prompt word template to generate a second candidate prompt word.

[0011] Further, it further comprises:

[0012] S5, use the bundle search algorithm to screen the second candidate prompt word to obtain an optimized prompt word;

[0013] S6, use the task model to evaluate the optimized prompt word on the pre-constructed test set to determine whether the optimized prompt word is effective;

[0014] S7, determine whether the optimized prompt word meets the termination condition; if the termination condition is met, output the optimized prompt word; if the termination condition is not met, repeat steps S2-S7 with the optimized prompt word as the initial prompt word.

[0015] Further, in S1, the optimizer model is a 70B large language model, and the task model is a 7B large language model.

[0016] Further, S3 comprises:

[0017] S31, input the error example set and the initial prompt word into a gradient generation prompt word template to generate a gradient analysis request; the gradient generation prompt word template includes structured requirements: the initial prompt word, specific samples of the error example set, the number of error causes of the error example, and a fixed format output constraint;

[0018] S32, the optimizer model receives the gradient analysis request and performs the following analysis: identifying common features in the error examples, analyzing the causal relationship between the initial prompt word and the error type, and diagnosing specific defects existing in the initial prompt word, to generate a first natural language gradient containing multiple lines of natural language text; the content of the first natural language gradient includes: defect type classification, specific defect description sentences, related error example evidence, and improvement direction suggestions;

[0019] S33, according to the fixed format output constraint in the gradient generation prompt word template, use regular expressions to extract the same number of improvement direction suggestions as the number of error causes of the error example from the first natural language gradient as the second natural language gradient.

[0020] Further, S4 includes:

[0021] S41, input the second natural language gradient and the initial prompt word into the prompt word editing template;

[0022] S42, the prompt word editing template integrates elements, including: the initial prompt word, the error example set, the second natural language gradient, and the number of candidate prompt words to be generated;

[0023] S43, set the output format constraint in the prompt word editing template;

[0024] S44, the optimizer model modifies the initial prompt word in the direction of the second natural language gradient according to the guidance of the prompt word editing template to generate the first candidate prompt word;

[0025] S45, according to the output format constraint in the prompt word editing template, use regular expressions to extract the same number of candidate prompt words as the number of candidate prompt words to be generated from the first candidate prompt word as the second candidate prompt word.

[0026] Further, S5 includes:

[0027] S51, the task model uses the second candidate prompt word to predict all samples on the test set to obtain the first predicted answer of the task model;

[0028] S52, compare the first predicted answer with the sample labels of the test set one by one and calculate the performance index to obtain the first performance index;

[0029] S53, adopt the cluster search algorithm to select the second candidate prompt word with the optimal performance index and the preset cluster width as the optimized prompt word.

[0030] Further, S6 comprises:

[0031] S61, using the task model to predict the optimized prompt word on all samples of the test set to obtain the second predicted answer of the task model;

[0032] S62, comparing the second predicted answer of the task model with the sample labels of the test set one by one and calculating the performance index to obtain the second performance index;

[0033] S63, the task model compares and evaluates the first performance index and the second performance index, if the second performance index is greater than or equal to the first performance index, the optimized prompt word is effective; otherwise, the optimized prompt word is invalid.

[0034] Further, S7 comprises:

[0035] S71, if the optimized prompt word is effective, if the second performance index reaches the preset threshold or the second performance index does not decrease in the last 5 iterations relative to the first performance index, the optimized prompt word is output; otherwise, the optimized prompt word is repeated as the initial prompt word to repeat steps S2-S7;

[0036] S72, if the optimized prompt word is invalid, the optimized prompt word is repeated as the initial prompt word to repeat steps S2-S7.

[0037] Compared with the prior art, the present application has the following beneficial effects:

[0038] The present application is designed scientifically and reasonably, and is convenient to use. The present application generates a second natural language gradient by combining the gradient generated prompt word template and the optimizer model, accurately points out the problems of the prompt word, and makes the improvement of the prompt word more targeted and semantically reasonable. Then, the present application generates the second candidate prompt word by combining the editing prompt word template, the optimizer model and the generated second natural language gradient, and solves the technical problem of low efficiency of manually writing the prompt word.

[0039] The present application efficiently screens the second candidate prompt word by combining the task model to evaluate the performance index of the second candidate prompt word on the test set through the cluster search algorithm, improves the search efficiency while ensuring the optimization effect, and reduces unnecessary consumption of computing resources.

[0040] The present application uses the 70B large language model as the optimizer to exert its powerful language understanding and analysis capability to generate high-quality optimization suggestions. The 7B model is used as the task model to utilize its high efficiency and cost performance in simple tasks to quickly evaluate the effect of the prompt word, realize the complementary advantages of large and small models, and reduce the consumption of computing resources.

[0041] The application effectively avoids the over-inclusion of examples in the prompt word by limiting the number of candidate prompt words in the prompt word editing template, guides the selection of typical examples, enhances the generalization ability of the prompt word, and ensures that the model can perform stably on different data. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 The steps of the application are shown in the flowchart. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.

[0044] In the description of the present application, it should be noted that the terms “center”, “upper”, “lower”, “left”, “right”, “vertical”, “horizontal”, “inner”, “outer” and the like indicate the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation or be constructed and operated in a particular orientation, therefore it cannot be understood as a limitation on the present application. In addition, the terms “first”, “second”, “third” are only for descriptive purposes, and cannot be understood as indicating or implying relative importance.

[0045] In the description of the present application, it should be noted that unless otherwise explicitly specified and limited, the terms “mounting”, “connecting”, “connecting” should be understood broadly, for example, it can be fixedly connected, or it can be detachably connected, or integrally connected; of course, it can also be mechanically connected, or it can also be electrically connected; in addition, it can also be directly connected, or it can also be indirectly connected through an intermediate medium, or it can also be the internal communication of two elements. For those skilled in the art, the specific meaning of the above terms in the present application can be understood according to the specific circumstances.

[0046] As shown in Figure 1 A large language model prompt word automatic optimization method, comprising the following steps:

[0047] S1, set a prompt word as an initial prompt word; construct training data, gradient generation prompt word template, prompt word editing template, optimizer model and task model;

[0048] S2, randomly sample small batch data from the training data as a training set, and the task model predicts the answer according to the initial prompt word; compare the answer with the sample label of the training set piece by piece, identify the prediction error examples; collect the prediction error examples to form an error example set;

[0049] S3, input the error example set and the initial prompt word into the gradient generation prompt word template to generate a gradient analysis request; the optimizer model receives and analyzes the gradient analysis request to generate a second natural language gradient;

[0050] S4, input the second natural language gradient and the initial prompt word into the prompt word editing template, and the optimizer model modifies the initial prompt word according to the editing prompt word template to generate a second candidate prompt word.

[0051] The example content of the gradient generation prompt word template for the zero-shot classification task is as follows:

[0052] I am trying to write a zero-shot classifier prompt.

[0053] My current prompt is:

[0054] {prompt}

[0055] But this prompt makes mistakes when handling the following examples:

[0056] {error_samples}

[0057] Please give {num_feedbacks} reasons why this prompt may make mistakes, and use <start>and <end>Wrap each cause.

[0058] An example of a second natural language gradient is as follows:

[0059] 1. The prompt lacks a description of key features of the text;

[0060] 2. The instructions in the prompt are not clear;

[0061] 3. The prompt does not clearly understand the task;

[0062] 4. The prompt lacks effective examples;

[0063] 5. The prompt does not effectively constrain the output of the task model.

[0064] An example of a prompt editing template for a zero-shot classification task is as follows:

[0065] I am trying to write a zero-shot classifier;

[0066] My current prompt is:

[0067] {prompt}

[0068] But it is making mistakes when processing the following examples:

[0069] {error_samples}

[0070] Based on these examples, the problem with this prompt is {gradient};

[0071] Based on the above information, I have written {steps_per_gradient} different improved prompts, each of which uses <start>and <end>Package;

[0072] Note: In order to make the model output more accurate, do not include error examples and their correct answers in the new prompt words, and ensure that the number of examples (if any) in the new prompt words does not increase to avoid overfitting;

[0073] The {steps_per_gradient} new prompt words are:

[0074] The embodiment generates a second natural language gradient by combining the gradient generation prompt word template and the optimizer model, accurately points out the problems of the prompt word, and makes the improvement of the prompt word more targeted and semantically reasonable; and generates a second candidate prompt word by combining the editing prompt word template, the optimizer model and the second natural language gradient, solving the technical problem of low efficiency of manually writing prompt words.

[0075] The automatic optimization method for large language model prompt words provided by the present application comprises the following steps:

[0076] S5, filtering the second candidate prompt word by using a bundle search algorithm to obtain an optimized prompt word;

[0077] S6, evaluating the optimized prompt word on the test set by using a task model to determine whether the optimized prompt word is effective;

[0078] S7, determining whether the optimized prompt word meets a termination condition; if the termination condition is met, outputting the optimized prompt word; if the termination condition is not met, repeating steps S2-S7 with the optimized prompt word as the initial prompt word.

[0079] The embodiment can quickly find a relatively better prompt word from a large number of prompt word candidates by using the bundle search algorithm, instead of performing a second round of iteration in all prompt words by the greedy search, thereby improving the optimization efficiency and reducing the consumption of computing resources.

[0080] In one embodiment of the automatic optimization method for large language model prompt words, the optimizer model is a 70B large language model, and the task model is a 7B large language model.

[0081] The embodiment uses a 70B large language model as the optimizer to exert its powerful language understanding and analysis capability and generate high-quality optimization suggestions; and uses a 7B model as the task model to utilize its high efficiency and cost performance in simple tasks, quickly evaluate the effect of the prompt word, realize the complementary advantages of large and small models, and reduce the consumption of computing resources.

[0082] Preferably, S3 comprises:

[0083] S31, input the error example set and the initial prompt word into a gradient generation prompt word template to generate a gradient analysis request; the gradient generation prompt word template comprises a structured requirement: the initial prompt word, specific samples of the error example set, the number of error causes of the error example, and a fixed format output constraint;

[0084] S32, the optimizer model receives the gradient analysis request and performs the following analysis: identifying common features in the error examples, analyzing the causal relationship between the initial prompt word and the error type, and diagnosing specific defects existing in the initial prompt word, to generate a first natural language gradient comprising multiple lines of natural language text; the content of the first natural language gradient includes: defect type classification, specific defect description sentences, relevant error example evidence, and improvement direction suggestions;

[0085] S33, according to the fixed format output constraint in the gradient generation prompt word template, using a regular expression to extract the same number of improvement direction suggestions as the number of error causes of the error example in the gradient generation prompt word template from the first natural language gradient as a second natural language gradient.

[0086] The present application is based on the automatic optimization method of large language model prompt word, wherein in one embodiment, S4 comprises:

[0087] S41, input the second natural language gradient and the initial prompt word into a prompt word editing template;

[0088] S42, the prompt word editing template integrates elements, and the elements include: the initial prompt word, the error example set, the second natural language gradient, and the number of candidate prompt words to be generated;

[0089] S43, set the output format constraint in the prompt word editing template;

[0090] S44, the optimizer model modifies the initial prompt word in the direction of the second natural language gradient according to the guidance of the prompt word editing template to generate a first candidate prompt word;

[0091] S45, according to the output format constraint in the prompt word editing template, using a regular expression to extract the same number of candidate prompt words as the number of candidate prompt words to be generated in the prompt word editing template from the first candidate prompt word as a second candidate prompt word.

[0092] For self-owned data sets, the prompt word is optimized towards the direction of containing more correct examples. When the prompt word is iterated, the optimizer tends to put the error examples and the corresponding correct answers given to it into the optimized prompt word, which means that the task model is told as many examples as possible, and the answer is also told, which is a cheating behavior. The number of examples reaches 260. The small model combination (for example, 7B-7B) is more obvious. With the increase of iteration rounds, this phenomenon will be more serious. This is because the optimizer wants the task model to answer correctly as much as possible to highlight its position and role, so it will intentionally or unintentionally integrate the answer examples of the training set into the optimized prompt word.

[0093] The embodiment effectively avoids the over-inclusion of examples in the prompt word by limiting the number of candidate prompt words in the prompt word editing template and not adding examples (zero samples) in the prompt word editing template, guides the selection of typical examples, enhances the generalization ability of the prompt word, and ensures that the model can perform stably on different data.

[0094] The application discloses an automatic optimization method for a prompt word of a large language model, and in one embodiment, S5 comprises:

[0095] S51, the task model uses the second candidate prompt word to predict all samples on the test set to obtain the first predicted answer of the task model;

[0096] S52, compare the first predicted answer with the sample labels of the test set one by one and calculate the performance index to obtain the first performance index;

[0097] S53, the second candidate prompt word with the optimal performance index and the beam width is selected as the optimized prompt word by using the beam search algorithm.

[0098] The performance index is the accuracy or the F1 value.

[0099] The application efficiently screens the second candidate prompt word by using the beam search algorithm and combining the performance index evaluation of the second candidate prompt word on the test set by the task model, improves the search efficiency while ensuring the optimization effect, and reduces unnecessary consumption of computing resources.

[0100] The application discloses an automatic optimization method for a prompt word of a large language model, and in one embodiment, S6 comprises:

[0101] S61, using the task model to predict all samples on the test set using the optimized prompt word to obtain the second predicted answer of the task model;

[0102] S62, compare the second predicted answer of the task model with the sample labels of the test set one by one and calculate the performance index to obtain the second performance index;

[0103] S63, the task model compares and evaluates the first performance indicator and the second performance indicator, if the second performance indicator is greater than or equal to the first performance indicator, the optimized prompt word is effective; otherwise, the optimized prompt word is ineffective.

[0104] The performance indicator is the accuracy or the F1 value.

[0105] The task model has high computational efficiency and cost performance in simple tasks and can quickly give an evaluation result. For example, in the text sentiment analysis task, the task model can accurately analyze and judge the sentiment tendency of the text, so as to calculate the performance indicator according to the evaluation result. If the task is more complex, such as generating feedback on the prompt word according to the error example, the task model may not be able to accurately complete the task, because on the one hand, the task model has disadvantages in dealing with tasks that require deep logical reasoning and complex context understanding due to the more complex semantic relationship and long-distance dependence caused by the difference in parameter size, and on the other hand, the task model is unstable in multi-task learning and domain migration and has poorer adaptability to complex tasks that have not been seen. At this time, the optimized model shows its advantages in complex task processing, and its advantages in parameter size and knowledge capacity make it perform better in complex reasoning, multi-modal interaction, long text processing, high-precision question answering and other tasks.

[0106] In this embodiment, the task model is mainly used to preliminarily evaluate the effect of the optimized prompt word and provide feedback for iterative optimization.

[0107] Preferably, S7 comprises:

[0108] S71, if the optimized prompt word is effective, if the second performance indicator reaches a preset threshold or the second performance indicator does not decrease relative to the first performance indicator in five consecutive iterations, the optimized prompt word is output; otherwise, the optimized prompt word is repeated as the initial prompt word in steps S2-S7.

[0109] S72, if the optimized prompt word is ineffective, the optimized prompt word is repeated as the initial prompt word in steps S2-S7.

[0110] Finally, it should be noted that: the above embodiments are merely the preferred embodiments of the present application to illustrate the technical solutions of the present application, rather than limit, of course, is not to limit the scope of the patent of the present application; although the present application is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still be modified to the technical solutions recorded in the foregoing embodiments, or part or all of the technical features are replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application; that is to say, but whatever is made in the main design idea and spirit of the present application has no substantial significance of the change or polish, the technical problem solved is still consistent with the present application, and should be included in the protection scope of the present application; in addition, the technical solutions of the present application are directly or indirectly applied to other related technical fields, which are also included in the patent protection scope of the present application.< / end> < / start> < / end> < / start>

Claims

1. A method for automatically optimizing prompt words in a large language model, characterized in that, Includes the following steps: S1. Set a prompt word as the initial prompt word; construct training data, gradient generation prompt word template, prompt word editing template, optimizer model, and task model; S2. Randomly sample a small batch of data from the training data as the training set. The task model predicts the answer based on the initial prompt words. The answer is compared with the sample labels in the training set one by one to identify examples of incorrect prediction. Collect examples of prediction errors to form an error example set; S3. Input the set of error examples and the initial prompt words into the gradient to generate a prompt word template and generate a gradient analysis request; the optimizer model receives and analyzes the gradient analysis request and generates a second natural language gradient. S4. Input the second natural language gradient and the initial prompt word into the prompt word editing template. The optimizer model modifies the initial prompt word according to the prompt word editing template and generates the second candidate prompt word. S5. Use the cluster search algorithm to filter candidate prompt words and obtain optimized prompt words; S6. Use a task model to evaluate the optimized prompts on a pre-built test set to determine whether the optimized prompts are effective. S7. Determine whether the optimized suggestion words meet the termination condition; If the termination condition is met, output an optimization prompt. If the termination condition is not met, repeat steps S2-S7 using the optimized prompt word as the initial prompt word.

2. The method for automatic optimization of prompt words in a large language model according to claim 1, characterized in that, In S1, the optimizer model is a 70B large language model, and the task model is a 7B large language model.

3. The method for automatic optimization of prompt words in a large language model according to claim 1, characterized in that, S3 include: S31. Input the set of error examples and the initial prompt words into the gradient generation prompt word template to generate a gradient analysis request. The structured requirements of the gradient generation prompt word template are: initial prompt words, specific samples of the error example set, number of error examples and error reasons, and fixed format output constraints. S32. The optimizer model receives a gradient analysis request and performs the following analysis: The optimizer model identifies the common features of specific samples in the error example set and analyzes the causal relationship between the initial prompt words and the common features; The optimizer model diagnoses the specific defects in the initial prompt words and generates a first natural language gradient containing multiple lines of natural language text; The content of the first natural language gradient includes: defect type classification, specific defect description statements, relevant error example evidence, and suggestions for improvement. S33. Based on the fixed format output constraints in the gradient-generated prompt word template, use regular expressions to extract improvement direction suggestions from the first natural language gradient in the same number as the number of error reasons in the error examples, as the second natural language gradient.

4. The automatic optimization method for prompt words in a large language model according to claim 1, characterized in that, S4 include: S41. Input the second natural language gradient and the initial prompt word into the prompt word editing template; S42. The prompt word editing template integrates the following elements: initial prompt words, error example set, second natural language gradient, and number of candidate prompt words to be generated. S43. Set output format constraints in the prompt word editing template; S44. The optimizer model modifies the initial prompt words according to the prompt word editing template and along the direction of the second natural language gradient to generate the first candidate prompt words. S45. Based on the output format constraints in the prompt word editing template, use regular expressions to extract the same number of candidate prompt words from the first candidate prompt words as the number of candidate prompt words to be generated, and use them as the second candidate prompt words.

5. The automatic optimization method for prompt words in a large language model according to claim 1, characterized in that, S5 include: S51. The task model uses the second candidate prompt word to predict all samples on the test set, and obtains the first predicted answer of the task model. S52. Compare the first predicted answer with the sample labels of the test set one by one and calculate the performance index to obtain the first performance index. S53. Use a cluster search algorithm to select the second candidate prompt word with the best performance index and a quantity equal to the preset bundle width as the optimized prompt word.

6. The automatic optimization method for prompt words in a large language model according to claim 5, characterized in that, S6 include: S61. Use the task model to predict all samples of the optimized prompt word on the test set to obtain the second predicted answer of the task model; S62. Compare the second predicted answer of the task model with the sample labels of the test set one by one and calculate the performance index to obtain the second performance index. S63. The task model is compared and evaluated against the first performance index and the second performance index. If the second performance index is greater than or equal to the first performance index, the optimized prompt is valid; otherwise, the optimized prompt is invalid.

7. The method for automatic optimization of prompt words in a large language model according to claim 6, characterized in that, S7 includes: S71. If the optimized prompt is valid, if the second performance index reaches the preset threshold or the second performance index does not decrease relative to the first performance index in 5 consecutive iterations, then the optimized prompt will be output. Otherwise, repeat steps S2-S7 using the optimized prompt word as the initial prompt word; S72. If the optimized suggestion word is invalid, repeat steps S2-S7 using the optimized suggestion word as the initial suggestion word.

Citation Information

Patent Citations

  • Preference alignment model training method based on limited preference identifier sorting

    CN119202915A

  • Large language model optimization generation method based on optimal cue word selection

    CN119476209A

Cited By

  • Multi-agent cooperative cue word engineering optimization method, system and equipment and medium

    CN121858749A