A prompt word generation method and related device

Through the method of automatically generating prompt words, the problem of insufficient automation of prompt word generation in the prior art is solved, and the performance improvement of large language models in complex tasks is achieved.

CN119167934BActive Publication Date: 2025-04-15ASIAINFO TECH CHINA INC
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411650094.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-19
Publication Date
2025-04-15
Estimated Expiration
2044-11-19

AI Technical Summary

Technical Problem

In the prior art, the degree of automation of the prompt word generation process has resulted in limited performance of large language models when processing large-scale data sets or performing complex tasks, and requires a lot of manual adjustments and experiments to find the optimal prompt word.

Method used

By obtaining the target prompt words and data sets, inputting them into the large language model, calculating the output quality score, and determining whether to generate a prompt word. If not, a prompt word problem template will be generated based on the comparison of the model output data and the target output data, update the prompt word, and repeat the above process until the optimal prompt word is generated.

Benefits of technology

The process of automatically generating the optimal prompt words is realized, reducing the time and cost of manual adjustment and experimentation, and improving the performance of large language models when processing large-scale data sets or performing complex tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119167934B_ABST
    Figure CN119167934B_ABST
Patent Text Reader

Abstract

The present application discloses a prompt word generation method and related devices, which relate to the field of artificial intelligence, including: obtaining a target prompt word and a data set; inputting the target prompt word and the target input data into a first language model to obtain a plurality of model output data; calculating the output quality score of the first language model according to the model output data and the target output data; judging whether to generate the prompt word of the first language model; if so, obtaining the prompt word of the first language model according to the output quality score; if not, comparing the model output data with the target output data to obtain a prompt word question template, updating the target prompt word based on the prompt word question template, and then executing the input of the target prompt word and the target input data into the first language model. The present application can find the optimal prompt word without a lot of manual adjustment and experimentation, and achieves the purpose of automatically generating prompt words.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a prompt word generation method and related devices. Background Art

[0002] With the development of big data and deep learning technology, large language models have attracted much attention due to their powerful text processing capabilities and wide range of application scenarios. In practical applications, large language models require effective prompt words to guide them to generate more accurate and relevant text output. Prompt word writing usually requires a lot of manual adjustments and experiments to find the optimal prompt words. Whenever encountering new tasks or fields, new prompt words usually need to be designed from scratch, which is not only time-consuming and labor-intensive, but also difficult to quickly generalize to other scenarios. The lack of automation in the prompt word generation process limits the performance of large language models when processing large-scale data sets or performing complex tasks. Summary of the invention

[0003] In view of the above problems, the present application provides a prompt word generation method and related devices to achieve the purpose of automatically generating prompt words. The specific scheme is as follows:

[0004] The first aspect of the present application provides a method for generating a prompt word, comprising:

[0005] Obtaining a target prompt word and a data set; the data set includes a plurality of input-output pairs, each of which includes target input data and target output data;

[0006] Inputting the target prompt word and the target input data into a first large language model to obtain a plurality of model output data;

[0007] Calculating an output quality score of the first large language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data;

[0008] Determine whether to generate a prompt word for the first largest language model; if so, obtain the prompt word for the first largest language model according to the output quality score; if not, compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute the step of inputting the target prompt word and the target input data into the first largest language model.

[0009] In a possible implementation, comparing the model output data with the target output data to obtain a prompt word question template includes:

[0010] Comparing the model output data with the target output data to determine whether the model output data is consistent with the target output data;

[0011] If the model output data is inconsistent with the target output data, the model output data is associated with the target output data corresponding to the model output data to obtain an associated data pair;

[0012] A prompt word question template is generated according to the associated data pair.

[0013] In a possible implementation, updating the target prompt word based on the prompt word question template includes:

[0014] Arrange the output quality scores of the first largest language model obtained in each updating process in descending order;

[0015] Filter the target prompt words corresponding to the first S output quality scores to obtain the filtered target prompt words;

[0016] The screened target prompt words and the prompt word question template corresponding to the screened target prompt words are input into the second largest language model, and the target prompt words are updated by using an evolutionary algorithm.

[0017] In a possible implementation, the determining whether to generate a prompt word of the first language model includes:

[0018] When the change in the output quality score of the first large language model calculated in the M consecutive updating processes is less than a preset change, or when the number of times the target prompt word is updated reaches a preset number, a prompt word of the first large language model is generated.

[0019] In a possible implementation, calculating the output quality score of the first large language model according to the model output data and the target output data includes:

[0020] Inputting the model output data and the target output data into a second largest language model to obtain a first score;

[0021] Calculate an F1 score based on the model output data and the target output data to obtain a second score;

[0022] Calculate a Bleu score according to the model output data and the target output data to obtain a third score;

[0023] Calculate a Rouge score according to the model output data and the target output data to obtain a fourth score;

[0024] Calculate a similarity score using an Embedding model according to the model output data and the target output data to obtain a fifth score;

[0025] The first score, the second score, the third score, the fourth score and the fifth score are weightedly summed to obtain an output quality score of the first large language model.

[0026] In a possible implementation, obtaining the target prompt word includes:

[0027] Acquire a target template; the target template includes reference input data and reference output data;

[0028] The target template is input into the first large language model to obtain the target prompt word.

[0029] The second aspect of the present application provides a prompt word generation system, comprising:

[0030] A data acquisition module, used to acquire a target prompt word and a data set; the data set includes a plurality of input-output pairs, each of which includes target input data and target output data;

[0031] A model processing module, used for inputting the target prompt word and the target input data into a first large language model to obtain a plurality of model output data;

[0032] A score calculation module, used to calculate an output quality score of the first large language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data;

[0033] A judgment module, used for judging whether to generate a prompt word of the first language model; if so, executing a prompt word generation module; if not, executing a prompt word update module;

[0034] The prompt word generation module is used to obtain the prompt word of the first language model according to the output quality score;

[0035] The prompt word updating module is used to compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute the model processing module.

[0036] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the prompt word generation method of the first aspect or any implementation manner of the first aspect.

[0037] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0038] The memory is used to store computer programs;

[0039] The processor is used to execute the computer program so that the electronic device can implement the prompt word generation method of the first aspect or any implementation manner of the first aspect.

[0040] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can generate a prompt word according to the first aspect or any implementation method of the first aspect.

[0041] By means of the above technical scheme, the prompt word generation method and related device provided by the present application input the target prompt word and the target input data into the first large language model to obtain multiple model output data; calculate the output quality score of the first large language model according to the model output data and the target output data; determine whether to generate the prompt word of the first large language model; if so, obtain the prompt word of the first large language model according to the output quality score; if not, compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute the input of the target prompt word and the target input data into the first large language model. The present application updates the prompt word through the questions generated by the model output data obtained by different prompt words, and calculates the output quality scores of the large language model corresponding to different prompt words, so as to find the prompt word that realizes the optimal output data. The process does not require a lot of manual adjustments and experiments to find the optimal prompt word, and achieves the purpose of automatically generating prompt words. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0043] Figure 1 A flow chart of a prompt word generation method provided in this application;

[0044] Figure 2 A schematic diagram of the structure of a prompt word generation system provided in this application;

[0045] Figure 3 A schematic diagram of the structure of an electronic device provided in this application. DETAILED DESCRIPTION

[0046] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0047] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0048] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0049] The embodiment of the present application provides a prompt word generation method. The prompt word generation method of the embodiment of the present application is described in detail below with reference to the accompanying drawings.

[0050] Reference Figure 1 , Figure 1 A schematic diagram of a method for generating a prompt word provided in an embodiment of the present application is shown in FIG. Figure 1 As shown, a prompt word generation method provided in an embodiment of the present application may include steps 101 to 106, and these steps are described in detail below.

[0051] Step 101: Obtain a target prompt word and a data set; the data set includes a plurality of input-output pairs, each of which includes target input data and target output data.

[0052] The target input data may be an input question, and the target output data may be an answer to the input question. In practical applications, the number of input-output pairs in the data set may be 30 or other numbers.

[0053] In a possible implementation, obtaining a target prompt word includes:

[0054] Obtaining a target template; the target template includes reference input data and reference output data;

[0055] The target template is input into the first language model to obtain the target prompt word.

[0056] The target cue word can guide the first language model to produce the expected result.

[0057] The target template may be a forward generation template, which is a template used to guide a large language model to generate a specific output. This template usually contains some fixed text structures to prompt the model how to understand and process input data and generate expected output.

[0058] The target template includes reference input data and reference output data, which are exemplary input-output pairs, and the target template also includes task instructions. For example, the target template may be:

[0059] Please follow an instruction, and take the following 'Input' as theInput to the instruction, the instruction will output the following 'Output'.

[0060] Input: [example input 1]

[0061] Output: [example output 1]

[0062] Input: [example input 2]

[0063] Output: [example output 2]

[0064] …

[0065] So what is this instruction?

[0066] The square brackets `[]` are used to indicate the parts that need to be filled when the model is generated. The example input in [] is the reference input data, and the example output is the reference output data.

[0067] The target template is input into the first large language model to obtain a target prompt word. The first large language model may be an LLM (Large Language Model) applied in a business scenario. The first large language model may also be a model with a relatively large number of parameters, such as 32B, 72B or a commercial online model, to ensure the quality of the generated prompt word, so that the obtained target prompt word is the initial prompt word.

[0068] It should be noted that the above process is a step for obtaining the initial prompt word. After the target prompt word is updated once, the updated target prompt word is directly obtained.

[0069] Step 102: Input the target prompt word and the target input data into the first language model to obtain a plurality of model output data.

[0070] For each target input data, the first large language model will output a corresponding model output data, and the number of target input data input into the large language model is equal to the number of model output data output by the large language model.

[0071] Step 103: Calculate the output quality score of the first language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data.

[0072] The output quality score of the first large language model reflects the consistency between the model output data and the target output data, which can reflect the model performance. The higher the output quality score, the better the performance of the large language model, and the lower the output quality score, the worse the performance of the large language model.

[0073] In a possible implementation, calculating the output quality score of the first language model according to the model output data and the target output data includes:

[0074] Input the model output data and the target output data into the second largest language model to obtain a first score;

[0075] Calculate the F1 score based on the model output data and the target output data to obtain a second score;

[0076] Calculate the Bleu score based on the model output data and the target output data to obtain a third score;

[0077] Calculate the Rouge score based on the model output data and the target output data to obtain a fourth score;

[0078] According to the model output data and the target output data, the similarity score is calculated using the Embedding model to obtain the fifth score;

[0079] The first score, the second score, the third score, the fourth score and the fifth score are weightedly summed to obtain the output quality score of the first language model.

[0080] The formula for calculating the output quality score of the first language model can be:

[0081]

[0082]

[0083] In the formula, is the output quality score of the first language model, To input the first large language model, is the first score, is the F1 score, which is the second score, is the Bleu fraction, the third fraction, is the Rouge fraction, which is the fourth fraction, is the similarity score, which is the fifth score, is the target output data. If the number of target output data is multiple, Output data set for the target, is the model output data. If the model output data is multiple, Output data set for the model, is the first weight coefficient, is the second weight coefficient, is the third weight coefficient, is the fourth weight coefficient, is the fifth weight coefficient.

[0084] The second largest language model can be the same as the first largest language model or different from the first largest language model. The second largest language model can use a model with a larger consideration, such as 72B or a commercial online model, to ensure the accuracy and objectivity of the scoring. In practical applications, the model output data and the target output data are input into the second largest language model, and the output .

[0085] F1-Score is a measurement indicator for classification problems. It can be used as an evaluation method for scenarios where the output is a finite enumeration type. It is the harmonic mean of precision and recall, with a maximum of 1 and a minimum of 0. In practical applications, the F1 score is calculated based on the model output data and the target output data. .

[0086] The Bleu metric is a commonly used metric for evaluating the quality of machine translation, especially for automatically evaluating the closeness of the translated text to human translation. Its value range is from 0 to 1, and the higher the score, the closer the translation quality is to human translation. The calculation method is as follows:

[0087] The Bleu score is calculated based on n-gram precision, where an n-gram is a sequence of n consecutive items in a text (such as words, characters, etc.). Multiple n-grams of different lengths are considered for the calculation (usually 1-grams, 2-grams, 3-grams, and 4-grams). For each n-gram length, the number of n-grams in the machine translation output that match the reference translation is calculated and then divided by the total number of n-grams in the machine translation output.

[0088] To penalize translations that are too short, if the total length of the machine translation output is less than the length of the reference translation, the BLEU score is multiplied by a contraction factor (Brevity Penalty, BP).

[0089] The BP calculation formula is:

[0090]

[0091] Where cand_len is the length of the machine translation and ref_len is the length of the reference translation.

[0092] The weighted average of the accuracies of different n-gram lengths is then multiplied by BP to obtain the final BLEU score, which is calculated as follows:

[0093]

[0094] In the formula, weight n is the weight of each n-gram length, Clip() is a function that ensures that the n-gram precision does not exceed 1, even if an n-gram in the machine translation appears multiple times in the reference translation, and n-gram_prec n is the n-gram of the reference translation, and N is the total number of items.

[0095] Rouge metrics are a set of metrics used to evaluate the quality of automatic summarization and machine translation, focusing on the overlap between machine-generated text and reference text. There are multiple variants of Rouge metrics, but the most common ones are ROUGE-N, ROUGE-L, and ROUGE-S. Unlike Bleu, which is mostly used in machine translation tasks and focuses more on the "recall" aspect, Rouge is not only used for machine translation, but also for automatic summarization, text generation and other tasks, and includes recall and precision. In practical applications, the Rouge score is calculated based on the model output data and the target output data, and the result is .

[0096] Simi represents the similarity score between the output content and the reference content semantics, which can be calculated using the Embedding vector model. The Embedding vector model is used to map words, sentences, or documents to points in the real vector space. These vectors capture the semantic and grammatical properties of the language, making it possible to perform mathematical operations and machine learning modeling on the language. This indicator makes up for the shortcomings of Bleu and Rouge in lacking semantic expression. In practical applications, the Embedding model is used to calculate the similarity score based on the model output data and the target output data, and the result is .

[0097] If there are multiple model output data and target output data, the output quality score is calculated for each set of model output data and target output data, and the output quality score of the largest language model can be obtained by weighted summing the calculated scores.

[0098] This application takes into account the complexity and diversity of different tasks, comprehensively considers scenarios such as LLM output data being lists and long texts, and comprehensively evaluates the model output quality using multiple indicators such as LLM multi-dimensional scoring, f1-score, BLEU indicator in the machine translation field, Rouge indicator, semantic similarity, etc., thereby improving the universality of the prompt word effect evaluation and thereby improving the degree of automation of prompt word generation.

[0099] Step 104: Determine whether the prompt word of the first language model is generated. If yes, execute step 106; if no, execute step 105.

[0100] In a possible implementation, determining whether to generate a prompt word of the first language model includes:

[0101] When the change in the output quality score of the first largest language model calculated in the M consecutive updating processes is less than a preset change, or when the number of updating the target prompt word reaches a preset number, a prompt word of the first largest language model is generated, where M is a positive integer greater than 1.

[0102] If the output quality score of the first language model tends to be stable and no longer improves, and the change in the output quality score obtained by updating the target prompt word for multiple times is less than the preset change, the prompt word of the first language model can be generated. Or when the number of times the target prompt word is updated reaches the preset number, the prompt word of the first language model can be generated.

[0103] Step 105: Compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute step 102.

[0104] In a possible implementation, the model output data is compared with the target output data to obtain a prompt word question template, including:

[0105] Compare the model output data with the target output data to determine whether the model output data is consistent with the target output data;

[0106] If the model output data is inconsistent with the target output data, the model output data is associated with the target output data corresponding to the model output data to obtain an associated data pair;

[0107] Generate a prompt word question template based on the associated data pairs.

[0108] Optionally, after associating the model output data with the target output data corresponding to the model output data to obtain an associated data pair, the output quality scores obtained based on the model output data and the target output data can be sorted to filter out the last P associated data pairs, thereby generating a prompt word question template.

[0109] The prompt word question template includes an associated data pair and may also include an instruction. The prompt word question template may refer to the following style:

[0110] LLm_output indicates the output result of the LLm, and Labelindicates the reference answer. Please compare the two and use summarystatements to express the main problems existing in the output result of the LLm. Note: Do not list the details of the problem.

[0111] LLm_output: [example output 1]

[0112] Label: [example label 1]

[0113] LLm_output: [example output 2]

[0114] Label: [example label 2]

[0115] …

[0116] So what are the main problems?

[0117] The square brackets `[]` are used to indicate the parts that need to be filled when the model is generated. The exampleoutput in [] is the model output data, and the examplelabel is the target output data.

[0118] In a possible implementation, updating the target prompt word based on the prompt word question template includes:

[0119] Arrange the output quality scores of the top language model obtained in each update process in descending order;

[0120] Filter the target prompt words corresponding to the first S output quality scores to obtain the filtered target prompt words; where S is a positive integer;

[0121] The screened target prompt words and the prompt word question templates corresponding to the screened target prompt words are input into the second largest language model, and the target prompt words are updated by using an evolutionary algorithm.

[0122] The second language model can be the same as or different from the first language model. The selected target prompt words and the corresponding prompt word question template are input into the second language model, and the target prompt words are updated by using the selection, crossover, mutation and replacement ideas of the evolutionary algorithm.

[0123] Evolutionary algorithms (EAs) are a type of optimization algorithm that mimics the biological evolution process and solves optimization problems by simulating biological evolution mechanisms such as natural selection, inheritance, mutation, and recombination. These algorithms are usually used to solve complex, nonlinear, multi-peak or high-dimensional optimization problems.

[0124] The evolutionary algorithm process includes initialization, evaluation, selection, crossover, mutation, replacement, iteration, and termination. Among them, initialization is to randomly generate the initial population; evaluation is to use the fitness function to evaluate the fitness of each individual in the population; selection is to select individuals for reproduction based on fitness, and commonly used selection methods include roulette selection, tournament selection, and ranking-based selection; crossover is to randomly pair selected individuals and generate new individuals by exchanging some of their genes; mutation is to perform mutation operations on newly generated individuals to introduce new genetic diversity; replacement is that the newly generated individuals may replace individuals in the current population, or merge with the current population; iteration is to repeat the evaluation, selection, crossover, and mutation steps until the termination condition is met (such as reaching the maximum number of iterations, fitness threshold, or stability standard); termination is when the termination condition is met, the algorithm terminates and outputs the individual with the highest fitness in the current population as the optimal solution.

[0125] Since prompt word optimization is essentially a discrete combinatorial optimization problem involving a combination of words, phrases, and sentences. Evolutionary algorithms are good at finding optimal solutions in large search spaces, which matches the needs of prompt word optimization. And evolutionary algorithms do not rely on gradient information, which means that they can be directly applied to large language models without the need for the internal structure or gradient information of the model. In addition, evolutionary algorithms are less sensitive to the initial conditions and specific forms of the problem and can adapt to a variety of optimization scenarios and constraints. The concept of evolutionary algorithms is intuitive, easy to implement, and can be easily applied to the prompt word optimization problem. Therefore, this application uses evolutionary algorithms to solve the prompt word optimization problem.

[0126] The present application inputs the screened target prompt words and the prompt word question template corresponding to the screened target prompt words into the second largest language model, and the following prompt template may be used:

[0127] Below are the [TopS] prompt templates and corresponding questions, with effects listed in descending order. "TopS Prompt" indicates the prompttemplate, "Problems" indicates the problems existing in the template, please carefully analyze and think about the effective method to solve the problem in each template, and then use evolutionary algorithm ideas, including: selection, crossover, mutation, replacement, generate a new template, as far as possible to solve the existing problem:

[0128] Top1 Prompt: [source prompt 1]

[0129] Problems: [problem 1]

[0130] Top2 Prompt: [source prompt 2]

[0131] Problems: [problem 2]

[0132] …

[0133] So what is the updated prompts?

[0134] The square brackets `[]` are used to indicate the parts that need to be filled in when the model is generated. TopS prompt is the target prompt word corresponding to the first S output quality scores, the source prompt in [] is the filtered target prompt word, and the problem in [] is the prompt word problem template corresponding to the filtered target prompt word.

[0135] This application introduces an evolutionary algorithm in the process of automatically generating prompt words. By evaluating the effects of historical iterative prompt words and relying on the intelligent agent ability of LLM to handle complex problems, prompt words are selected and cross-combined to automatically generate prompt words that optimize the performance of the large language model, fully tapping the application capabilities of LLM. The application of intelligent agents enables the system to dynamically adjust prompt words according to the context to adapt to different models, input, and output requirements, which is of great significance for improving user experience and system efficiency. Through intelligent agent technology, large language model prompt words can be automatically generated and optimized, thereby improving the performance and application effect of large language models in various application scenarios.

[0136] Step 106: Obtain the prompt word of the first language model according to the output quality score.

[0137] In a possible implementation, the output quality scores obtained in each updating process are sorted, and the target prompt word corresponding to the maximum output quality score is used as the prompt word of the first largest language model.

[0138] The automatic prompt word generation method of the present application updates the prompt words through the problems generated by the model output data obtained by different prompt words, and calculates the output quality scores of the large language model corresponding to different prompt words, so as to find the prompt words that achieve the optimal output data. Without the need for a large amount of manual adjustment and experimentation, the prompt words are automatically adjusted and optimized for the output data problems existing in the evolution process, and the optimal prompt words that can maximize the performance of the large language model are automatically found.

[0139] A prompt word generation method provided in an embodiment of the present application is introduced above, and a system for executing the prompt word generation method will be introduced below.

[0140] See also Figure 2 , Figure 2 This is a schematic diagram of the structure of a prompt word generation system provided in an embodiment of the present application. Figure 2As shown, the prompt word generation system includes:

[0141] The data acquisition module 201 is used to acquire a target prompt word and a data set; the data set includes a plurality of input-output pairs, each of which includes target input data and target output data.

[0142] The model processing module 202 is used to input the target prompt word and the target input data into the first language model to obtain a plurality of model output data.

[0143] The score calculation module 203 is used to calculate the output quality score of the first language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data.

[0144] The judgment module 204 is used to judge whether to generate the prompt word of the first language model; if so, the prompt word generation module 206 is executed; if not, the prompt word update module 205 is executed.

[0145] The prompt word updating module 205 is used to compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute the model processing module 202.

[0146] The prompt word generation module 206 is used to obtain the prompt word of the first language model according to the output quality score.

[0147] In a possible implementation, the prompt word updating module 205 is specifically used to:

[0148] Compare the model output data with the target output data to determine whether the model output data is consistent with the target output data;

[0149] If the model output data is inconsistent with the target output data, the model output data is associated with the target output data corresponding to the model output data to obtain an associated data pair;

[0150] Generate a prompt word question template based on the associated data pairs.

[0151] The prompt word updating module 205 is also used for:

[0152] Arrange the output quality scores of the top language model obtained in each update process in descending order;

[0153] Filter the target prompt words corresponding to the first S output quality scores to obtain the filtered target prompt words;

[0154] The screened target prompt words and the prompt word question templates corresponding to the screened target prompt words are input into the second largest language model, and the target prompt words are updated by using an evolutionary algorithm.

[0155] The judgment module 204 is specifically used for:

[0156] When the change in the output quality score of the first largest language model calculated in the M consecutive updating processes is less than a preset change, or when the number of times the target prompt word is updated reaches a preset number, a prompt word of the first largest language model is generated.

[0157] The score calculation module 203 is specifically used for:

[0158] Input the model output data and the target output data into the second largest language model to obtain a first score;

[0159] Calculate the F1 score based on the model output data and the target output data to obtain a second score;

[0160] Calculate the Bleu score based on the model output data and the target output data to obtain a third score;

[0161] Calculate the Rouge score based on the model output data and the target output data to obtain a fourth score;

[0162] According to the model output data and the target output data, the similarity score is calculated using the Embedding model to obtain the fifth score;

[0163] The first score, the second score, the third score, the fourth score and the fifth score are weightedly summed to obtain the output quality score of the first language model.

[0164] The data acquisition module 201 is specifically used for:

[0165] Obtaining a target template; the target template includes reference input data and reference output data;

[0166] The target template is input into the first language model to obtain the target prompt word.

[0167] The present application also provides an electronic device in an embodiment. Figure 3 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 3 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0168] like Figure 3 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 301, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 302 or a program loaded from a storage device 308 to a random access memory (RAM) 303. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 303. The processing device 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0169] Typically, the following devices may be connected to the I / O interface 305: an input device 306 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 307 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 308 including, for example, a memory card, a hard disk, etc.; and a communication device 309. The communication device 309 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 3 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0170] The electronic device can implement the above-mentioned prompt word generation method.

[0171] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any prompt word generation method provided in the embodiment of the present application.

[0172] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any prompt word generation method provided in the embodiment of the present application.

[0173] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0174] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0175] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0176] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A method for generating a prompt word, characterized in that: include: Obtain target prompt words and data sets; The data set includes a plurality of input-output pairs, each of the input-output pairs includes target input data and target output data; The step of obtaining the target prompt word includes: obtaining a target template; the target template includes reference input data and reference output data; inputting the target template into a first language model to obtain the target prompt word; the target template is a forward generation template; Inputting the target prompt word and the target input data into the first large language model to obtain a plurality of model output data; Calculating an output quality score of the first large language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data; The calculating the output quality score of the first large language model according to the model output data and the target output data includes: Inputting the model output data and the target output data into a second largest language model to obtain a first score; Calculate an F1 score based on the model output data and the target output data to obtain a second score; Calculate a Bleu score according to the model output data and the target output data to obtain a third score; Calculate a Rouge score according to the model output data and the target output data to obtain a fourth score; Calculate a similarity score using an Embedding model according to the model output data and the target output data to obtain a fifth score; performing a weighted summation of the first score, the second score, the third score, the fourth score, and the fifth score to obtain an output quality score of the first large language model; Determine whether to generate a prompt word of the first largest language model; if so, obtain the prompt word of the first largest language model according to the output quality score; if not, compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then perform the step of inputting the target prompt word and the target input data into the first largest language model; The updating of the target prompt word based on the prompt word question template includes: Arrange the output quality scores of the first largest language model obtained in each updating process in descending order; Filter the target prompt words corresponding to the first S output quality scores to obtain the filtered target prompt words; The screened target prompt words and the prompt word question template corresponding to the screened target prompt words are input into the second largest language model, and the target prompt words are updated by selection, crossover, mutation and replacement of an evolutionary algorithm.

2. The method for generating prompt words according to claim 1, characterized in that: The step of comparing the model output data with the target output data to obtain a prompt word question template includes: Comparing the model output data with the target output data to determine whether the model output data is consistent with the target output data; If the model output data is inconsistent with the target output data, the model output data is associated with the target output data corresponding to the model output data to obtain an associated data pair; A prompt word question template is generated according to the associated data pair.

3. The method for generating prompt words according to claim 1, characterized in that: The determining whether to generate a prompt word of the first language model includes: When the change in the output quality score of the first large language model calculated in the M consecutive updating processes is less than a preset change, or when the number of times the target prompt word is updated reaches a preset number, a prompt word of the first large language model is generated.

4. A prompt word generation system, characterized in that: include: A data acquisition module, used to acquire target prompt words and data sets; The data set includes a plurality of input-output pairs, each of the input-output pairs includes target input data and target output data; The step of obtaining the target prompt word includes: obtaining a target template; the target template includes reference input data and reference output data; inputting the target template into a first language model to obtain the target prompt word; the target template is a forward generation template; A model processing module, used for inputting the target prompt word and the target input data into the first large language model to obtain a plurality of model output data; A score calculation module, used to calculate an output quality score of the first large language model according to the model output data and the target output data; wherein the output quality score reflects the consistency between the model output data and the target output data; The calculating the output quality score of the first large language model according to the model output data and the target output data includes: Inputting the model output data and the target output data into a second largest language model to obtain a first score; Calculate an F1 score based on the model output data and the target output data to obtain a second score; Calculate a Bleu score according to the model output data and the target output data to obtain a third score; Calculate a Rouge score according to the model output data and the target output data to obtain a fourth score; Calculate a similarity score using an Embedding model according to the model output data and the target output data to obtain a fifth score; performing a weighted summation of the first score, the second score, the third score, the fourth score, and the fifth score to obtain an output quality score of the first large language model; A judgment module, used for judging whether to generate a prompt word of the first language model; if so, executing a prompt word generation module; if not, executing a prompt word update module; The prompt word generation module is used to obtain the prompt word of the first language model according to the output quality score; The prompt word updating module is used to compare the model output data with the target output data to obtain a prompt word question template, update the target prompt word based on the prompt word question template, and then execute the model processing module; The updating of the target prompt word based on the prompt word question template includes: Arrange the output quality scores of the first largest language model obtained in each updating process in descending order; Filter the target prompt words corresponding to the first S output quality scores to obtain the filtered target prompt words; The screened target prompt words and the prompt word question template corresponding to the screened target prompt words are input into the second largest language model, and the target prompt words are updated by selection, crossover, mutation and replacement of an evolutionary algorithm.

5. A computer program product, characterized in that The method comprises computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the prompt word generating method as claimed in any one of claims 1 to 3.

6. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the prompt word generation method as described in any one of claims 1 to 3.

7. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the prompt word generation method as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Prompt generation method and text processing method

    CN118655989A