Model cue word optimization method and device, electronic equipment and storage medium

By generating multiple prompt words using a large language model with different temperature parameter values ​​and selecting the best one based on test results, automatic optimization of prompt words is achieved, solving the problems of low efficiency and low quality in existing technologies. The generated prompt words are suitable for various task scenarios and cover a wider range of semantics.

CN121052249APending Publication Date: 2025-12-02INTELLINDUST INFORMATION TECH (SHENZHEN) CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202511199517.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-26
Publication Date
2025-12-02

AI Technical Summary

Technical Problem

In existing technologies, prompt word optimization methods are inefficient and of low quality, cannot quickly adapt to new natural language processing tasks, require long manual debugging, generate limited variations through template filling or synonym replacement, and have a single optimization level.

Method used

Multiple prompt words are generated using two large language models with different temperature parameter values. The best prompt word is selected based on the test results, achieving automatic optimization and generating prompt words that cover a wider range of semantics.

Benefits of technology

It improves the efficiency and quality of prompt word optimization, reduces manual intervention, and the generated prompt words can adapt to different task scenarios and cover a wider range of semantics.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121052249A_ABST
    Figure CN121052249A_ABST
Patent Text Reader

Abstract

Embodiments of the invention provide a model cue word optimization method and apparatus, an electronic device and a storage medium. The method comprises the steps of obtaining an initial cue word; inputting the initial cue word into a first large language model to generate a plurality of first cue words; inputting the initial cue word into a second large language model to generate a plurality of second cue words; respectively testing the initial cue word, each first cue word and each second cue word to obtain respective corresponding test results; based on the respective corresponding test results, determining whether a prompt word meeting a preset condition exists at present; if not, determining a plurality of candidate cue words based on the first cue words and the second cue words, respectively taking the initial cue words and the candidate cue words as new initial cue words, and returning to execute the step of inputting the initial cue words into the first large language model until the cue words meeting preset conditions exist; if yes, the cue word meeting the preset condition serves as the target cue word, and the optimization efficiency and the optimization quality of the cue word are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of natural language processing technology, and in particular to a method, apparatus, electronic device, and storage medium for optimizing model prompt words. Background Technology

[0002] A Large Language Model (LLM) is a deep learning model trained on a large amount of text data, enabling it to generate natural language text or understand the meaning of language text. Currently, LLMs typically input prompts that describe various natural language processing tasks (such as text classification and image recognition), allowing the LLM to perform the corresponding task and output the corresponding natural language processing result.

[0003] In related technologies, there are two main methods for optimizing prompt words in large language models: one is based on manual methods to write or modify prompt words, adjusting their expression through multiple trials and errors. This method relies solely on manual debugging and optimization, which is time-consuming, inefficient, and cannot quickly adapt to new natural language processing tasks. The other method generates prompt words through template filling or synonym replacement. While this method can easily expand the prompt words, it can only generate a limited number of variations, resulting in a single optimization level and affecting the overall optimization quality. Summary of the Invention

[0004] The purpose of this invention is to provide a method, apparatus, electronic device, and storage medium for optimizing model prompt words, so as to improve the optimization efficiency and quality of prompt words. The specific technical solution is as follows:

[0005] This invention provides a method for optimizing model prompt words, the method comprising:

[0006] Get the initial prompt word;

[0007] The initial prompt words are input into the first large language model to generate multiple initial prompt words;

[0008] The initial prompt word is input into the second language model to generate multiple second prompt words; wherein, the temperature parameter value of the first language model is less than the temperature parameter value of the second language model, and the temperature parameter value is a parameter value used to control the diversity of prompt words generated by the first language model and the second language model;

[0009] The initial prompt word, each of the first prompt words, and each of the second prompt words are tested respectively to obtain the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words.

[0010] Based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words, determine whether there is a prompt word that meets the preset conditions.

[0011] If it does not exist, then based on each of the first prompt words and each of the second prompt words, multiple candidate prompt words are determined, and the initial prompt word and the candidate prompt words are respectively used as new initial prompt words. Then, the process returns to the step of inputting the initial prompt word into the first language model until a prompt word that meets the preset conditions exists.

[0012] If it exists, the prompt word that meets the preset conditions will be used as the target prompt word.

[0013] Optionally, testing the initial prompt word to obtain the test result corresponding to the initial prompt word includes:

[0014] Using pre-set test cases, the third language model is invoked to test the initial prompt word, and the test results corresponding to the initial prompt word are obtained; the third language model is a pre-trained model used to perform the preset task.

[0015] Optionally, the step of using pre-set test cases to call a third language model to test the initial prompt word and obtain the test results corresponding to the initial prompt word includes:

[0016] The third language model is invoked, and the test samples in the test cases and the initial prompt words are input into the third language model to obtain the test answer output by the third language model;

[0017] The test answer is compared with the labeled answer corresponding to the test sample to determine whether the test answer is accurate;

[0018] Based on the number of accurate test answers, the accuracy rate of the initial prompt word is calculated, and the test result corresponding to the initial prompt word is obtained.

[0019] Optionally, determining whether there is a prompt word that meets the preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words includes:

[0020] Determine whether the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words reaches a preset threshold.

[0021] When the highest accuracy rate reaches a preset threshold, it is determined that there are currently prompt words that meet the preset conditions, and the prompt words corresponding to the highest accuracy rate are determined as prompt words that meet the preset conditions.

[0022] If the highest accuracy rate does not reach the preset threshold, it is determined that there are currently no prompt words that meet the preset conditions.

[0023] Optionally, determining that there are currently no prompt words that meet the preset conditions when the highest accuracy rate does not reach the preset threshold includes:

[0024] If the highest accuracy does not reach the preset threshold, determine whether the current iteration count has reached the preset number of iterations;

[0025] If the current iteration count reaches the preset number, determine that there are currently prompt words that meet the preset conditions, and determine the prompt word corresponding to the highest accuracy as the prompt word that meets the preset conditions;

[0026] If the current iteration count has not reached the preset number, it is determined that there are currently no prompt words that meet the preset conditions.

[0027] Optionally, determining multiple candidate prompt words based on each of the first prompt words and each of the second prompt words includes:

[0028] Based on the test results corresponding to each of the first prompt words and the test results corresponding to each of the second prompt words, the first prompt words and the second prompt words are sorted in descending order of accuracy.

[0029] Select a preset number of prompt words that rank highly as candidate prompt words.

[0030] Optionally, the target prompt word is a prompt word used for image recognition; the method further includes:

[0031] Obtain the image to be identified and the corresponding identification label of the image to be identified;

[0032] The image to be identified and the target prompt word are input into the image recognition model to obtain the recognition result output by the image recognition model;

[0033] Based on the identification label corresponding to the image to be identified, determine whether the identification result is accurate.

[0034] This invention also provides a model prompt word optimization device, the device comprising:

[0035] The first acquisition module is used to acquire the initial prompt words;

[0036] The first generation module is used to input the initial prompt words into the first large language model to generate multiple first prompt words;

[0037] The second generation module is used to input the initial prompt word into the second large language model to generate multiple second prompt words; wherein, the temperature parameter value of the first large language model is less than the temperature parameter value of the second large language model, and the temperature parameter value is a parameter value used to control the diversity of prompt words generated by the first large language model and the second large language model;

[0038] The first testing module is used to test the initial prompt word, each of the first prompt words and each of the second prompt words respectively, and to obtain the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words and the test results corresponding to each of the second prompt words;

[0039] The optimization module is used to determine whether there is a prompt word that meets the preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words. If there is no prompt word, multiple candidate prompt words are determined based on each of the first prompt words and each of the second prompt words, and the initial prompt word and the candidate prompt words are respectively used as new initial prompt words. This triggers the first generation module to input the initial prompt word into the first large language model until a prompt word that meets the preset conditions is found. If a prompt word that meets the preset conditions is found, it is used as the target prompt word.

[0040] This invention also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;

[0041] Memory, used to store computer programs;

[0042] A processor, when executing a program stored in memory, implements any of the methods described above.

[0043] This invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements any of the methods described above.

[0044] This invention also provides a computer program product containing instructions that, when run on a computer, cause the computer to perform any of the methods described above.

[0045] Beneficial effects of the embodiments of the present invention:

[0046] This invention provides a method, apparatus, electronic device, and storage medium for optimizing model prompt words. It utilizes a first language model with a lower temperature parameter value to generate semantically stable first prompt words, and a second language model with a higher temperature parameter value to generate more diverse second prompt words. This expands the scope of prompt word optimization, enabling the generated prompt words to cover a wider range of semantics and adapt to different task scenarios, thus improving the optimization quality. Furthermore, the initial prompt words, first prompt words, and second prompt words are tested. Based on the test results, the optimal prompt word is selected and iterative optimization is performed without manual intervention, achieving automatic prompt word optimization and improving both optimization efficiency and quality.

[0047] Of course, implementing any product or method of the present invention does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description

[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings.

[0049] Figure 1 This is a schematic flowchart of a model prompt word optimization method provided in an embodiment of the present invention;

[0050] Figure 2 This is a flowchart illustrating a prompt word testing method provided in an embodiment of the present invention;

[0051] Figure 3 This is another flowchart illustrating the model prompt word optimization method provided in an embodiment of the present invention;

[0052] Figure 4 This is another flowchart illustrating the model prompt word optimization method provided in this embodiment of the invention;

[0053] Figure 5 This is a schematic diagram of a model prompt word optimization device provided in an embodiment of the present invention;

[0054] Figure 6 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0055] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of the present invention.

[0056] In the field of Natural Language Processing (NLP), LLM (Local Language Module) performs exceptionally well across various application scenarios. It can perform not only simple language tasks such as grammar correction but also complex tasks like text summarization, machine translation, sentiment analysis, text generation, and content recommendation, demonstrating its broad potential. In NLP tasks, users typically need to design high-quality prompts for LLM to achieve optimal results.

[0057] In related technologies, manually writing or modifying prompt words is time-consuming, inefficient, and relies on the professional debugging experience of personnel. It cannot quickly adapt to new natural language processing tasks. Generating prompt words through template filling or synonym replacement can only generate limited variations of prompt words, resulting in a single optimization level and affecting the optimization quality of prompt words.

[0058] To improve the efficiency and quality of prompt word optimization, this invention provides a model prompt word optimization method, apparatus, electronic device, and storage medium. The model prompt word optimization method provided by this invention can be applied to any task scenario requiring prompt word design. It is executed by an electronic device, which can be implemented through software and / or hardware, such as a client device or a server device.

[0059] The model prompt word optimization method provided in the embodiments of the present invention will be described in detail below.

[0060] like Figure 1 As shown, an embodiment of the present invention provides a method for optimizing model prompt words, including:

[0061] S101, Obtain initial prompt words;

[0062] S102, Input the initial prompt words into the first large language model to generate multiple initial prompt words;

[0063] S103, Input the initial prompt words into the second language model to generate multiple second prompt words;

[0064] Among them, the temperature parameter value of the first language model is smaller than that of the second language model. The temperature parameter value is used to control the diversity of prompt words generated by the first and second language models.

[0065] S104, Test the initial prompt word, each first prompt word and each second prompt word respectively, and obtain the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word and the test results corresponding to each second prompt word;

[0066] S105, based on the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word, determine whether there is a prompt word that meets the preset conditions;

[0067] S106, if there is no prompt word that meets the preset conditions, then based on each first prompt word and each second prompt word, determine multiple candidate prompt words, and use the initial prompt word and the candidate prompt words as new initial prompt words respectively, and return to the step of S102 to input the initial prompt word into the first language model until there is a prompt word that meets the preset conditions;

[0068] S107. If there is a prompt word that meets the preset conditions, then the prompt word that meets the preset conditions will be used as the target prompt word.

[0069] This invention utilizes a first language model with a lower temperature parameter value to generate semantically stable first prompt words, and a second language model with a higher temperature parameter value to generate more diverse second prompt words. This expands the scope of prompt word optimization, enabling the generated prompt words to cover a wider range of semantics and adapt to different task scenarios, thus improving the optimization quality of the prompt words. Furthermore, the initial prompt words, the first prompt words, and the second prompt words are tested. Based on the test results, the optimal prompt word is selected and iterative optimization is performed without manual intervention, achieving automatic prompt word optimization. This improves the optimization efficiency and quality of the prompt words and reduces the time spent on manual debugging.

[0070] In step S101, the initial prompt can be a brief description or explanatory text provided by the user for the target task, such as image recognition, image classification, text recognition, or object recognition. The initial prompt can be a single word or a short sentence.

[0071] In step S102, the initial prompt word input by the user is used to generate multiple first prompt words corresponding to the initial prompt word using the first large language model. The first large language model can be a pre-trained large language model for generating prompt words, or it can be an open-source large language model with prompt word generation functionality. Specifically, the first large language model is invoked, and the initial prompt word obtained in step S101 is input into the first large language model, which then outputs multiple first prompt words.

[0072] In step S103, the initial prompt word input by the user is used to generate multiple second prompt words corresponding to the initial prompt word using a second large language model. The second large language model can be a pre-trained large language model for generating prompt words, or it can be an open-source large language model with prompt word generation functionality. Specifically, the second large language model is invoked, and the initial prompt word obtained in step S101 is input into the second large language model, which then outputs multiple second prompt words.

[0073] Steps S102 and S103 can be executed synchronously or asynchronously, and this embodiment of the invention does not limit this.

[0074] In one example, the first large language model can be a large language model with a relatively small temperature parameter value, and the second large language model can be a large language model with a relatively high temperature parameter value. The temperature parameter value of the first large language model is smaller than that of the second large language model.

[0075] The temperature parameter, a hyperparameter used to control the diversity of prompt words generated by the large language model, is typically between 0 and 1. It influences the probability distribution of sampled and predicted words when the large language model generates text. Higher temperature parameter values ​​(e.g., 0.8, 1, or higher) tend to generate more diverse, riskier, and more creative text, increasing text diversity and innovation, but may also produce more errors and incoherent text. Lower temperature parameter values ​​(e.g., 0.2, 0.3, etc.) tend to select more certain and common words to generate text, resulting in smoother and more coherent text, but may sacrifice some creativity and diversity. In prompt word generation scenarios, low temperature parameter values ​​ensure that the generated prompt words accurately describe what the user wants to express, thus generating prompt words with consistent semantics; while high temperature parameter values ​​can encourage the large language model to create different content, resulting in semantically more diverse prompt words.

[0076] In this embodiment of the invention, the temperature parameter value of the first large language model is smaller than that of the second large language model. For example, the temperature parameter value of the first large language model is 0.3, and the temperature parameter value of the second large language model is 1. Accordingly, the first large language model is used to generate prompt words whose semantics are not off-target, while the second large language model is used to generate prompt words with more diverse semantics. Of course, the temperature parameter value of the first large language model can also be larger than that of the second large language model. In this case, the first large language model is used to generate prompt words with more diverse semantics, while the second large language model is used to generate prompt words whose semantics are not off-target.

[0077] Because the prompts generated by the large language model have uncertainty, step S104 can utilize pre-set test cases to test the initial prompt, each first prompt, and each second prompt, respectively, to obtain the test results corresponding to the initial prompt, each first prompt, and each second prompt, thereby determining the accuracy of the initial prompt, each first prompt, and each second prompt. The pre-set test cases may include test samples and the corresponding labeled answers.

[0078] Further, step S105 determines whether there is a prompt word that meets the preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word. Step S106, if there is no prompt word that meets the preset conditions, selects multiple candidate prompt words from the first and second prompt words based on their respective test results, and uses the initial prompt word and candidate prompt words as new initial prompt words to enrich the input for prompt word optimization. Then, it returns to step S102, which inputs the initial prompt words into the first large language model, to iteratively optimize the prompt words until a prompt word that meets the preset conditions exists. Step S107, if a prompt word that meets the preset conditions exists, uses it as the target prompt word to obtain the optimized prompt word.

[0079] In one possible implementation, the method for testing the initial prompt word and obtaining the test result corresponding to the initial prompt word in step S104 above includes:

[0080] Using pre-set test cases, the third language model is invoked to test the initial prompt words and obtain the test results corresponding to the initial prompt words. The third language model is a pre-trained multimodal large model used to perform preset tasks, or an open-source multimodal large model, such as the Tongyi Qianwen large model.

[0081] The embodiments of this invention are illustrated using image recognition as an example, but this does not constitute a limitation of the invention. Other tasks can also be used, such as summary generation, text / image classification, etc.

[0082] For example, the pre-set test cases include test samples as sample images, the labeled answers corresponding to the test samples as labeled image recognition results, the preset task as an image recognition task, and the initial prompt words as prompt words for performing the image recognition task. Correspondingly, the third large language model is a multimodal large model for performing the image recognition task. Therefore, the process of testing the initial prompt words can be as follows: using the sample images and their corresponding labeled image recognition results included in the pre-set test cases, the multimodal large model is called to test the initial prompt words, obtaining the test results corresponding to the initial prompt words.

[0083] In this embodiment of the invention, pre-set test cases are used to call a third language model to test the initial prompt words, so as to quickly and accurately obtain the test results corresponding to the initial prompt words.

[0084] In one possible implementation, such as Figure 2 As shown, the implementation process of using pre-set test cases to call the third language model to test the initial prompt words and obtain the test results corresponding to the initial prompt words includes:

[0085] S201, call the third language model, input the test samples and initial prompts from the test cases into the third language model, and obtain the test answer output by the third language model.

[0086] In one example, a multimodal large-scale model is invoked to perform an image recognition task. Sample images from the test cases and initial prompts are input into the multimodal large-scale model one by one or in batches. The predicted image recognition results, i.e., the test answers, are obtained by the multimodal large-scale model under the guidance of the initial prompts and within the limitations of its own output format. Test cases can contain positive and negative sample images and their corresponding labeled answers; that is, the test samples in a test case are positive and negative sample images.

[0087] For example, the initial prompt is a warning tape, the positive sample image is an image containing the warning tape, and the corresponding labeled answer for the positive sample image is "yes" or "1". The negative sample image is an image without the warning tape, and the corresponding labeled answer for the negative sample image is "no" or "0". Then, the multimodal large model is invoked, and the positive and negative sample images from the test cases, along with the initial prompt, are input into the multimodal large model one by one or in batches. This yields the test answers corresponding to the positive and negative sample images output by the multimodal large model under the guidance of the initial prompt and the limitations of the multimodal large model's own output format (e.g., outputting 1 or 0). This embodiment of the invention uses binary image recognition as an example for illustration, but it can also be applied to multi-class text / image processing, etc., and this embodiment of the invention does not limit the application to these applications.

[0088] S202, compare the test answer with the labeled answer corresponding to the test sample to determine whether the test answer is accurate.

[0089] For example, the accuracy of a test answer can be determined by calculating the text similarity between the test answer and the labeled answer corresponding to the test sample, or the distance between feature vectors.

[0090] S203, based on the number of accurate test answers, calculate the accuracy of the initial prompt words and obtain the test results corresponding to the initial prompt words.

[0091] The accuracy rate of the initial prompt is determined by the percentage of accurate test answers. The test result corresponding to the initial prompt is then obtained, which is the accuracy rate of the initial prompt. For example, if a test case contains 100 test samples, and 85 of the test answers obtained using the initial prompt are accurate, the percentage of accurate test answers is 85 / 100 = 0.85. Therefore, the accuracy rate of the test result corresponding to the initial prompt is 85%.

[0092] In this embodiment of the invention, pre-set test cases are used to call a third language model to test the initial prompt words, so as to quickly and accurately obtain the accuracy corresponding to the initial prompt words.

[0093] In this embodiment of the invention, the process of testing each first prompt word and each second prompt word is the same as the process of testing the initial prompt word, and the same method is used. Therefore, this embodiment of the invention will not be described again here.

[0094] like Figure 3 As shown, another model prompt word optimization method provided by an embodiment of the present invention includes:

[0095] S301, Obtain initial prompt words.

[0096] S302, input the initial prompt words into the first large language model to generate multiple first prompt words.

[0097] S303: Input the initial prompt words into the second language model to generate multiple second prompt words.

[0098] Among them, the temperature parameter value of the first language model is smaller than that of the second language model. The temperature parameter value is used to control the diversity of prompt words generated by the first and second language models.

[0099] S304, Test the initial prompt word, each first prompt word, and each second prompt word respectively, and obtain the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word.

[0100] The implementation process of steps S301-S304 is the same as that of steps S101-S104 described above, and will not be repeated here in this embodiment of the invention.

[0101] S305, determine whether the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word reaches a preset threshold.

[0102] The preset threshold can be set according to the actual situation, such as 0.95, 0.86 or 0.98.

[0103] In one example, if the accuracy of the test results corresponding to the initial prompt word reaches a preset threshold, the initial prompt word is directly used as the target prompt word, and no further optimization is needed. If the accuracy of the test results corresponding to the initial prompt word does not reach the preset threshold, it is determined whether the highest accuracy among the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word reaches the preset threshold.

[0104] S306, when the highest accuracy rate reaches a preset threshold, determine that there is a prompt word that meets the preset conditions, and determine the prompt word corresponding to the highest accuracy rate as the prompt word that meets the preset conditions.

[0105] If the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word reaches a preset threshold, it is determined that there is a prompt word that meets the preset condition. The preset condition is that the accuracy rate reaches the preset threshold.

[0106] By setting a preset threshold, if the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word reaches the preset threshold, it is determined that there is a prompt word that meets the preset conditions. Then, the prompt word that meets the preset conditions can be used as the target prompt word, the iterative optimization stops, and the optimized target prompt word is quickly obtained.

[0107] S307, if the highest accuracy rate does not reach the preset threshold, determine whether the current iteration number has reached the preset number.

[0108] The preset number of iterations is the number of times the prompt words are optimized. It can be set according to the actual situation, such as 10 times, 20 times or 30 times.

[0109] S308, if the current iteration count reaches the preset number, determine that there is a prompt word that meets the preset conditions, and determine the prompt word corresponding to the highest accuracy as the prompt word that meets the preset conditions.

[0110] If the current iteration count reaches the preset number, it is determined that there is a prompt word that meets the preset conditions. The preset conditions are that the highest accuracy rate has not reached the preset threshold, but the current iteration count has reached the preset number. At this time, it is determined that there is a prompt word that meets the preset conditions, and the iteration stops.

[0111] S309, if the current iteration count has not reached the preset number, determine that there is currently no prompt word that meets the preset conditions.

[0112] If the highest accuracy rate does not reach the preset threshold and the current iteration count does not reach the preset count, it is determined that there are no prompt words that meet the preset conditions, so as to proceed to the next iteration optimization.

[0113] S310, if there is no prompt word that meets the preset conditions, based on each first prompt word and each second prompt word, determine multiple candidate prompt words, and use the initial prompt word and the candidate prompt words as new initial prompt words respectively, and return to the step of S302 to input the initial prompt word into the first language model, until there is a prompt word that meets the preset conditions.

[0114] S311, If ​​there is a prompt word that meets the preset conditions, then the prompt word that meets the preset conditions will be used as the target prompt word.

[0115] This invention utilizes a first language model with a lower temperature parameter value to generate semantically stable first prompt words, and a second language model with a higher temperature parameter value to generate more diverse second prompt words. This expands the scope of prompt word optimization, enabling the generated prompt words to cover a wider range of semantics and adapt to different task scenarios, thus improving the optimization quality of the prompt words. Furthermore, the initial prompt words, the first prompt words, and the second prompt words are tested. Based on the test results and pre-set thresholds and preset number of iterations, customizable optimization termination conditions are supported, flexibly balancing the efficiency and effectiveness of prompt word optimization without manual intervention. This achieves automatic prompt word optimization while improving optimization efficiency and quality, and reducing the time spent on manual debugging.

[0116] In one possible implementation, the determination of multiple candidate prompt words in steps S106 and S310 based on each first prompt word and each second prompt word includes:

[0117] Based on the test results corresponding to each first prompt word and each second prompt word, the first prompt words and each second prompt word are sorted in descending order of accuracy.

[0118] Select a preset number of prompt words that rank highly as candidate prompt words.

[0119] The preset quantity can be set according to the actual situation, such as 1, 10 or 20.

[0120] If no prompt words meet the preset conditions, sort the first prompt words and the second prompt words in descending order of accuracy. Select a preset number of prompt words that rank highly as candidate prompt words. Use the initial prompt words and candidate prompt words as new initial prompt words, which are then used as inputs for the next prompt word iteration optimization. This allows for optimal input selection, enabling faster and more accurate acquisition of optimized prompt words.

[0121] In one possible implementation, the target prompt is a prompt used for image recognition, such as... Figure 4 As shown, another model prompt word optimization method provided in this embodiment of the invention includes:

[0122] S401, Obtain initial prompt words;

[0123] S402, input the initial prompt words into the first large language model to generate multiple initial prompt words;

[0124] S403, input the initial prompt words into the second language model to generate multiple second prompt words;

[0125] Among them, the temperature parameter value of the first language model is smaller than that of the second language model. The temperature parameter value is used to control the diversity of prompt words generated by the first and second language models.

[0126] S404, Test the initial prompt word, each first prompt word and each second prompt word respectively, and obtain the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word and the test results corresponding to each second prompt word;

[0127] S405, based on the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word, determine whether there is a prompt word that meets the preset conditions;

[0128] S406, if there is no prompt word that meets the preset conditions, then based on each first prompt word and each second prompt word, determine multiple candidate prompt words, and use the initial prompt word and the candidate prompt words as new initial prompt words respectively, and return to the step of S402 to input the initial prompt word into the first language model until there is a prompt word that meets the preset conditions;

[0129] S407, If there is a prompt word that meets the preset conditions, then the prompt word that meets the preset conditions will be used as the target prompt word.

[0130] The implementation process of steps S401-S407 is the same as that of steps S101-S107 described above, and will not be repeated here in this embodiment of the invention.

[0131] S408, Obtain the image to be recognized and the recognition label corresponding to the image to be recognized.

[0132] The identification label corresponding to the image to be identified is the truth label of the image to be identified. For example, if the image to be identified is an image containing a certain building, the identification label corresponding to the image to be identified is yes (1) or no (0), etc.

[0133] S409, Input the image to be recognized and the target prompt word into the image recognition model to obtain the recognition result output by the image recognition model.

[0134] Among them, the image recognition model can be a multimodal large model that performs image recognition tasks. It can not only process the image features contained in the image to be recognized, but also process the text features contained in the image to be recognized. That is, it can recognize both objects (such as objects) and text in the image.

[0135] S410, based on the recognition label corresponding to the image to be recognized, determines whether the recognition result is accurate.

[0136] By comparing the recognition result with the corresponding recognition label of the image to be recognized, specifically, the text similarity or the distance between the feature vectors of the recognition result and the corresponding recognition label of the image to be recognized can be calculated to determine whether the recognition result is accurate. An accurate recognition result means that the optimized target prompt words are relatively accurate.

[0137] This invention utilizes a first language model with a lower temperature parameter value to generate a semantically stable first prompt word, and a second language model with a higher temperature parameter value to generate more diverse second prompt words. This expands the scope of prompt word optimization, enabling the generated prompt words to cover a wider range of semantics and adapt to different task scenarios, thus improving the optimization quality of the prompt words. Furthermore, the initial prompt word, the first prompt word, and the second prompt word are tested. Based on the test results, the optimal prompt word is selected and iteratively optimized without manual intervention, achieving automatic optimization of the prompt words. This improves the optimization efficiency and quality of the prompt words and reduces the time spent on manual debugging. After optimizing to obtain the target prompt word, the target prompt word is tested using the image to be recognized to verify its accuracy.

[0138] For example, the first, second, and third language models mentioned above can adopt the Tongyi Qianwen Large Language Model, etc. In actual use, the accuracy of the model prompt word optimization method applying this embodiment of the invention is compared with that of the manual prompt word debugging method, and the results are as follows:

[0139] Table 1. Comparison of accuracy rates for prompt word optimization.

[0140]

[0141]

[0142] It is evident that the accuracy of the prompts obtained using the model-based prompt optimization method of this invention is no less than that of manually debugged prompts. Furthermore, by utilizing a first language model with a lower temperature parameter value to generate semantically stable first prompts, and a second language model with a higher temperature parameter value to generate more diverse second prompts, the scope of prompt optimization generation is expanded. This allows the generated prompts to cover a wider range of semantics, enabling multi-strategy prompt generation that can adapt to different task scenarios and improve the optimization quality of the prompts. Moreover, the initial prompts, first prompts, and second prompts are tested. Based on the test results and pre-set thresholds and preset number of iterations, customizable optimization termination conditions are supported, flexibly balancing the efficiency and effectiveness of prompt optimization. This requires no manual intervention and does not rely on personnel's professional debugging experience. While achieving automatic prompt optimization, it improves the optimization efficiency and quality, and reduces the time spent on manual debugging.

[0143] Corresponding to the above method embodiments, the present invention also provides corresponding device embodiments.

[0144] like Figure 5 As shown, the model prompt word optimization device provided in this embodiment of the invention includes:

[0145] The first acquisition module 501 is used to acquire the initial prompt word;

[0146] The first generation module 502 is used to input the initial prompt words into the first large language model and generate multiple first prompt words;

[0147] The second generation module 503 is used to input the initial prompt word into the second large language model to generate multiple second prompt words; wherein, the temperature parameter value of the first large language model is less than the temperature parameter value of the second large language model, and the temperature parameter value is a parameter value used to control the diversity of prompt words generated by the first large language model and the second large language model;

[0148] The first test module 504 is used to test the initial prompt word, each first prompt word and each second prompt word respectively, and to obtain the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word and the test results corresponding to each second prompt word.

[0149] The optimization module 505 is used to determine whether there is a prompt word that meets the preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word. If there is no prompt word, multiple candidate prompt words are determined based on each first prompt word and each second prompt word, and the initial prompt word and the candidate prompt words are used as new initial prompt words respectively. This triggers the first generation module 502 to input the initial prompt word into the first large language model until a prompt word that meets the preset conditions exists. If a prompt word that meets the preset conditions exists, it is used as the target prompt word.

[0150] Optionally, the first test module 504 is specifically used to use pre-set test cases to call the third language model to test the initial prompt word and obtain the test result corresponding to the initial prompt word; the third language model is a pre-trained model used to perform preset tasks.

[0151] Optionally, the first test module 504 described above is specifically used for:

[0152] The third language model is invoked, and the test samples and initial prompts from the test cases are input into the third language model to obtain the test answer output by the third language model.

[0153] The test answers are compared with the labeled answers corresponding to the test samples to determine whether the test answers are accurate;

[0154] Based on the number of accurate test answers, the accuracy rate of the initial prompt words is calculated, and the test results corresponding to the initial prompt words are obtained.

[0155] Optionally, the aforementioned optimization module 505 is specifically used for:

[0156] Determine whether the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each first prompt word, and the test results corresponding to each second prompt word reaches the preset threshold.

[0157] When the highest accuracy rate reaches a preset threshold, it is determined that there are currently prompt words that meet the preset conditions, and the prompt words corresponding to the highest accuracy rate are determined as prompt words that meet the preset conditions.

[0158] If the highest accuracy rate does not reach the preset threshold, it is determined that there are currently no prompt words that meet the preset conditions.

[0159] Optionally, the aforementioned optimization module 505 is specifically used for:

[0160] If the highest accuracy does not reach the preset threshold, determine whether the current iteration count has reached the preset number of iterations;

[0161] If the current iteration count reaches the preset number, determine that there are currently prompt words that meet the preset conditions, and determine the prompt word corresponding to the highest accuracy as the prompt word that meets the preset conditions;

[0162] If the current iteration count has not reached the preset number, it is determined that there are currently no prompt words that meet the preset conditions.

[0163] Optionally, the optimization module 505 is specifically used to sort the first prompt words and the second prompt words in descending order of accuracy based on the test results corresponding to each first prompt word and the test results corresponding to each second prompt word; and select a preset number of prompt words with the highest accuracy as candidate prompt words.

[0164] Optionally, the target prompt word is a prompt word used for image recognition; the device further includes:

[0165] The second acquisition module is used to acquire the image to be recognized and the recognition label corresponding to the image to be recognized;

[0166] The second testing module is used to input the image to be recognized and the target prompt word into the image recognition model and obtain the recognition result output by the image recognition model.

[0167] The determination module is used to determine whether the recognition result is accurate based on the recognition label corresponding to the image to be recognized.

[0168] This invention also provides an electronic device, such as... Figure 6 As shown, it includes a processor 601, a communication interface 602, a memory 603, and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604.

[0169] Memory 603 is used to store computer programs;

[0170] When the processor 601 executes the program stored in the memory 603, it implements the steps of any of the above method embodiments to achieve the same technical effect.

[0171] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.

[0172] The communication interface is used for communication between the aforementioned electronic devices and other devices.

[0173] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.

[0174] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0175] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores a computer program. When the computer program is executed by a processor, it implements the steps of any of the above method embodiments to achieve the same technical effect.

[0176] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to perform the steps of any of the method embodiments described above, so as to achieve the same technical effect.

[0177] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).

[0178] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0179] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device / electronic device embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0180] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.

Claims

1. A method for optimizing model prompt words, characterized in that, The method includes: Get the initial prompt word; The initial prompt words are input into the first large language model to generate multiple initial prompt words; The initial prompt word is input into the second language model to generate multiple second prompt words; wherein, the temperature parameter value of the first language model is less than the temperature parameter value of the second language model, and the temperature parameter value is a parameter value used to control the diversity of prompt words generated by the first language model and the second language model; The initial prompt word, each of the first prompt words, and each of the second prompt words are tested respectively to obtain the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words. Based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words, determine whether there is a prompt word that meets the preset conditions. If it does not exist, then based on each of the first prompt words and each of the second prompt words, multiple candidate prompt words are determined, and the initial prompt word and the candidate prompt words are respectively used as new initial prompt words. Then, the process returns to the step of inputting the initial prompt word into the first language model until a prompt word that meets the preset conditions exists. If it exists, the prompt word that meets the preset conditions will be used as the target prompt word.

2. The method according to claim 1, characterized in that, The step of testing the initial prompt word to obtain the test result corresponding to the initial prompt word includes: Using pre-set test cases, the third language model is invoked to test the initial prompt word, and the test results corresponding to the initial prompt word are obtained; the third language model is a pre-trained model used to perform the preset task.

3. The method according to claim 2, characterized in that, The process involves using pre-set test cases to call a third-party language model to test the initial prompt words, obtaining test results corresponding to the initial prompt words, including: The third language model is invoked, and the test samples in the test cases and the initial prompt words are input into the third language model to obtain the test answer output by the third language model; The test answer is compared with the labeled answer corresponding to the test sample to determine whether the test answer is accurate; Based on the number of accurate test answers, the accuracy rate of the initial prompt word is calculated, and the test result corresponding to the initial prompt word is obtained.

4. The method according to claim 3, characterized in that, The step of determining whether there is a prompt word that meets preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words includes: Determine whether the highest accuracy rate among the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words reaches a preset threshold. When the highest accuracy rate reaches a preset threshold, it is determined that there are currently prompt words that meet the preset conditions, and the prompt words corresponding to the highest accuracy rate are determined as prompt words that meet the preset conditions. If the highest accuracy rate does not reach the preset threshold, it is determined that there are currently no prompt words that meet the preset conditions.

5. The method according to claim 4, characterized in that, The step of determining that there are currently no prompt words that meet the preset conditions when the highest accuracy rate does not reach the preset threshold includes: If the highest accuracy does not reach the preset threshold, determine whether the current iteration count has reached the preset number of iterations; If the current iteration count reaches the preset number, determine that there are currently prompt words that meet the preset conditions, and determine the prompt word corresponding to the highest accuracy as the prompt word that meets the preset conditions; If the current iteration count has not reached the preset number, it is determined that there are currently no prompt words that meet the preset conditions.

6. The method according to claim 3, characterized in that, The step of determining multiple candidate prompt words based on each of the first prompt words and each of the second prompt words includes: Based on the test results corresponding to each of the first prompt words and the test results corresponding to each of the second prompt words, the first prompt words and the second prompt words are sorted in descending order of accuracy. Select a preset number of prompt words that rank highly as candidate prompt words.

7. The method according to claim 1, characterized in that, The target prompt word is a prompt word used for image recognition; the method further includes: Obtain the image to be identified and the corresponding identification label of the image to be identified; The image to be identified and the target prompt word are input into the image recognition model to obtain the recognition result output by the image recognition model; Based on the identification label corresponding to the image to be identified, determine whether the identification result is accurate.

8. A model prompt word optimization device, characterized in that, The device includes: The first acquisition module is used to acquire the initial prompt words; The first generation module is used to input the initial prompt words into the first large language model to generate multiple first prompt words; The second generation module is used to input the initial prompt word into the second large language model to generate multiple second prompt words; wherein, the temperature parameter value of the first large language model is less than the temperature parameter value of the second large language model, and the temperature parameter value is a parameter value used to control the diversity of prompt words generated by the first large language model and the second large language model; The first testing module is used to test the initial prompt word, each of the first prompt words and each of the second prompt words respectively, and to obtain the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words and the test results corresponding to each of the second prompt words; The optimization module is used to determine whether there is a prompt word that meets the preset conditions based on the test results corresponding to the initial prompt word, the test results corresponding to each of the first prompt words, and the test results corresponding to each of the second prompt words. If there is no prompt word, multiple candidate prompt words are determined based on each of the first prompt words and each of the second prompt words, and the initial prompt word and the candidate prompt words are respectively used as new initial prompt words. This triggers the first generation module to input the initial prompt word into the first large language model until a prompt word that meets the preset conditions is found. If a prompt word that meets the preset conditions is found, it is used as the target prompt word.

9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-7.

Citation Information

Cited By

  • Image processing method and device based on large model, medium, electronics and product

    CN121392544A

  • Optimization method, device and equipment for agent based on large language model

    CN121683853A

  • Optimization methods, devices, and equipment for intelligent agents based on large language models

    CN121683853B