Hyper-parameter optimization method of cue word optimization model and related equipment
By optimizing the hyperparameters of the prompt words, combining the character length and privacy noise level, and using a multi-objective optimization algorithm, the problem of inference time and privacy leakage caused by prompt word optimization in the existing technology is solved, and efficient and safe prompt word optimization is achieved. .
Patent Information
- Application Number
- CN202410886517.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-10-08
AI Technical Summary
In the existing technology, when optimizing the inference performance of a large language model by increasing the length of prompt words, it will increase the inference time and cost, and there is a risk of leaking private information. How to optimize the prompt words while avoiding privacy leaks and reducing inference costs? is a technical challenge.
A hyperparameter optimization method for the prompt word optimization model is proposed. By obtaining the character length and privacy noise level of the prompt word, the inference cost and privacy loss are calculated, and the output answer of the target large model is used to determine the inference performance, using a multi-objective optimization algorithm. Targeting privacy loss, inference performance and inference cost, hyperparameters are optimized to obtain optimal prompt words.
While optimizing prompt words, it is possible to improve the inference performance of large models, avoid privacy leaks, reduce inference costs, and obtain optimal hyperparameters that take into account inference performance, privacy security, and cost.
Smart Images

Figure CN118747533A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a hyperparameter optimization method and related equipment for a prompt word optimization model. Background Art
[0002] At present, with the development of artificial intelligence, large language models for text question answering are widely used. Among them, the large model prompt words, as the communication link between users and the large model, play an important role in guiding the large model to output high-quality content. That is, the quality of the large model's response is highly correlated with the quality of the prompt words used by users.
[0003] In the related art, a pre-trained prompt word optimization model is usually used to optimize the prompt words input into the large language model. Specifically, the prompt word optimization model increases the length of the prompt word so that it contains more relevant information, thereby improving the reasoning performance of the model. However, in this method, as the length of the prompt word increases, the amount of data that the large model needs to process increases, which leads to an increase in the reasoning time and reasoning cost of the large model; and this method directly sends the prompt word and the examples involved to the large model server, which poses a risk of exposing user privacy information. Therefore, how to achieve the prompt word optimization model. The optimized prompt word can not only improve the reasoning performance of the large model, but also avoid privacy leakage and reduce the reasoning cost. This is a technical problem that needs to be solved urgently.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are related technologies. Summary of the invention
[0005] The main purpose of this application is to provide a hyperparameter optimization method and related equipment for a prompt word optimization model, aiming to solve the technical problem in the related technology of how to realize the prompt word optimization model so that the optimized prompt words can not only improve the reasoning performance of large models, but also avoid privacy leakage and reduce the reasoning cost.
[0006] To achieve the above purpose, the present application proposes a method for optimizing hyperparameters of a prompt word optimization model. The method for optimizing hyperparameters of the prompt word optimization model includes:
[0007] Obtaining a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word;
[0008] Based on the character length, calculating the inference cost of the hyperparameter to be optimized, and based on the privacy noise level, calculating the privacy loss of the hyperparameter to be optimized;
[0009] Inputting the target prompt word into the target large model to obtain a prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer;
[0010] Based on the inference cost, the inference performance and the privacy loss, the optimal hyperparameter is selected from the hyperparameters to be optimized through a preset multi-objective optimization algorithm, and the optimal hyperparameter is used as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
[0011] In one embodiment, the step of inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the inference performance of the hyperparameter to be optimized based on the prediction task answer includes:
[0012] Obtaining an optimized sample set corresponding to the target prompt word and a task answer label corresponding to the optimized sample set;
[0013] Based on the privacy noise level, performing noise disturbance processing on the optimized sample set to obtain a disturbed optimized sample set;
[0014] Inputting the target prompt word and the optimized sample set after disturbance into the target large model to obtain the prediction task answer output by the target large model;
[0015] The difference between the predicted task answer and the task answer label is calculated to obtain a target difference, and based on the target difference, the inference performance of the hyperparameter to be optimized is calculated.
[0016] In one embodiment, the hyperparameter includes the number of optimization iterations, and the step of selecting the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance, and the privacy loss through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter includes:
[0017] Based on the privacy loss, the inference performance, and the inference cost, selecting a preset first number of optimal hyperparameters from the hyperparameters to be optimized;
[0018] Get the current iteration cycle, and determine whether the current iteration cycle reaches the optimization iteration number. If the current iteration cycle does not reach the optimization iteration number, use the optimal hyperparameter as the hyperparameter to be optimized for the next iteration, return to the step of calculating the inference cost of the hyperparameter to be optimized based on the character length, and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise layer, until the current iteration cycle reaches the optimization iteration number, then stop selecting the optimal hyperparameter, and use the first number of optimal hyperparameters of this round as the optimized hyperparameters.
[0019] In one embodiment, the step of selecting an optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance, and the privacy loss through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter includes:
[0020] Based on the inference cost, the inference performance, and the privacy loss, sorting the non-dominated solutions of the hyperparameters to be optimized to obtain sorted hyperparameters to be optimized;
[0021] A preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
[0022] In one embodiment, the step of selecting a preset first number of hyperparameters as optimal hyperparameters from the sorted hyperparameters to be optimized in descending order includes:
[0023] Calculating the congestion degree of the sorted hyperparameters to be optimized to obtain congestion degree information;
[0024] Based on the congestion information, a preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
[0025] In one embodiment, after the step of obtaining the hyperparameters to be optimized of the prompt word optimization model and the target prompt words corresponding to the hyperparameters to be optimized, the method includes:
[0026] A pair of hyperparameters to be optimized are randomly selected from the hyperparameters to be optimized to perform cross-replacement processing on the parameters to obtain newly added hyperparameters;
[0027] Repeat the step of selecting any pair of hyperparameters from the hyperparameters to be optimized to perform cross-replacement processing on the hyperparameters to obtain newly added hyperparameters until a preset second number of newly added hyperparameters are obtained, and merge the hyperparameters to be optimized and the newly added hyperparameters to obtain expanded hyperparameters to be optimized;
[0028] Based on a preset replacement probability and a preset parameter library, parameter transformation is performed on the amplified hyperparameter to be optimized to obtain a transformed hyperparameter to be optimized.
[0029] In addition, to achieve the above purpose, the present application also proposes a hyperparameter optimization device for a prompt word optimization model, and the hyperparameter optimization device for the prompt word optimization model includes:
[0030] an acquisition module, used for acquiring a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used for optimizing the prompt word to be optimized after receiving the prompt word to be optimized, and outputting the optimized prompt word;
[0031] A calculation module, used to calculate the inference cost of the hyperparameter to be optimized based on the character length, and calculate the privacy loss of the hyperparameter to be optimized based on the privacy noise layer;
[0032] A determination module, used for inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer;
[0033] An optimization module is used to select the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss through a preset multi-objective optimization algorithm, and use the optimal hyperparameter as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a hyperparameter optimization device for a prompt word optimization model, the device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the hyperparameter optimization method for the prompt word optimization model as described above.
[0035] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the hyperparameter optimization method of the prompt word optimization model as described above are implemented.
[0036] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of the hyperparameter optimization method of the prompt word optimization model as described above.
[0037] One or more technical solutions proposed in this application have at least the following technical effects:
[0038] Compared with the high inference time and cost of the large model in the related art, and the risk of exposing user privacy information, the present application calculates the inference cost and privacy loss of the hyperparameters of the prompt word optimization model by including the prompt word character length and the privacy noise layer of the prompt word optimization model, and uses the target large model to answer the task corresponding to the target prompt word corresponding to the input hyperparameter to be optimized, and determines the inference performance of the hyperparameter to be optimized, thereby determining the inference cost, privacy loss and inference performance of each hyperparameter to be optimized. It can be understood that the inference cost, privacy loss and inference performance of the hyperparameter to be optimized respectively reflect It reflects the reasoning cost, privacy security and reasoning performance involved in the prompt word process after the optimization of the prompt word optimization model of the large model reasoning (the prompt word optimization model after using the hyperparameters). Therefore, this application optimizes the hyperparameters of the prompt word optimization model through a multi-objective optimization algorithm with privacy loss, reasoning performance and reasoning cost as optimization targets, so that the optimized hyperparameters are the optimal hyperparameters that take into account the reasoning cost, privacy security and reasoning performance of the large model at the same time. After the hyperparameters are applied to the prompt word optimization model, the generated prompt words can not only improve the reasoning performance of the large model, but also avoid privacy leakage and reduce the reasoning cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0041] Figure 1 A flowchart diagram of the first embodiment of the hyperparameter optimization method of the prompt word optimization model of the present application;
[0042] Figure 2 A flowchart diagram of a second embodiment of a method for optimizing hyperparameters of a prompt word optimization model of the present application;
[0043] Figure 3 A schematic diagram of the module structure of a hyperparameter optimization device for a prompt word optimization model according to an embodiment of the present application;
[0044] Figure 4Schematic diagram of the device structure of the hardware operating environment involved in the hyperparameter optimization method of the prompt word optimization model in the embodiment of the present application.
[0045] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0046] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0047] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0048] The main solution of the embodiment of the present application is: obtaining the hyperparameters to be optimized of the prompt word optimization model and the target prompt words corresponding to the hyperparameters to be optimized, wherein the hyperparameters to be optimized include the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word; based on the character length, calculating the inference cost of the hyperparameter to be optimized, and based on the privacy noise layer, calculating the privacy loss of the hyperparameter to be optimized; inputting the target prompt word into the target large model to obtain the prediction task answer output by the target large model, and determining the inference performance of the hyperparameter to be optimized based on the prediction task answer; based on the inference cost, the inference performance and the privacy loss, selecting the optimal hyperparameter from the hyperparameters to be optimized through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization targets.
[0049] In this embodiment, for ease of description, the following description is made by taking the hyperparameter optimization device of the prompt word optimization model as the execution subject.
[0050] Since the related technology usually uses a pre-trained prompt word optimization model to optimize the prompt words input into the large language model, the prompt word optimization model specifically increases the length of the prompt word so that it contains more relevant information, thereby improving the model's reasoning performance. However, in this method, as the length of the prompt word increases, the amount of data that the large model needs to process increases, which leads to an increase in the reasoning time and reasoning cost of the large model; and this method directly sends the prompt word and the examples involved to the large model server, which poses a risk of exposing user privacy information. Therefore, how to achieve a prompt word optimization model so that the optimized prompt word can both improve the reasoning performance of the large model and avoid privacy leakage and reduce the reasoning cost is a technical problem that needs to be solved urgently.
[0051] The present application provides a solution to achieve hyperparameter optimization of the prompt word optimization model, so that the optimized hyperparameter is the optimal hyperparameter that takes into account the large model reasoning cost, privacy security and reasoning performance. After the prompt word optimization model applies the hyperparameter, the generated prompt words can not only improve the large model reasoning performance, but also avoid privacy leakage and reduce the reasoning cost.
[0052] From the above embodiments, it can be seen that the present application calculates the inference cost and privacy loss of the hyperparameters of the prompt word optimization model by using the hyperparameters to be optimized of the prompt word optimization model including the prompt word character length and the privacy noise layer, and uses the target large model to output the task answer corresponding to the target prompt word corresponding to the input hyperparameter to be optimized, and determines the inference performance of the hyperparameter to be optimized, thereby determining the inference cost, privacy loss and inference performance of each hyperparameter to be optimized. It can be understood that the inference cost, privacy loss and inference performance of the hyperparameter to be optimized respectively reflect the inference cost, privacy security and inference performance involved in the process of optimizing the prompt word by the large model inference prompt word optimization model (the prompt word optimization model after using the hyperparameter). Therefore, the present application optimizes the hyperparameters of the prompt word optimization model through a multi-objective optimization algorithm with privacy loss, inference performance and inference cost as optimization targets, so that the optimized hyperparameter is the optimal hyperparameter that takes into account the inference cost, privacy security and inference performance of the large model at the same time, and then after the prompt word optimization model applies the hyperparameter, it can be achieved that the generated prompt word can not only improve the inference performance of the large model, but also avoid privacy leakage and reduce the inference cost.
[0053] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a terminal system, etc. The following takes the hyperparameter optimization device of the prompt word optimization model as an example to illustrate this embodiment and the following embodiments.
[0054] Based on this, the present application embodiment provides a hyperparameter optimization method for a prompt word optimization model, referring to Figure 1 , Figure 1 Schematic diagram of the process of the first embodiment of the hyperparameter optimization method of the prompt word optimization model of the present application.
[0055] In this embodiment, the hyperparameter optimization method of the prompt word optimization model includes steps S100 to S300:
[0056] Step S100, obtaining a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise level, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word;
[0057] In a specific implementation, the hyperparameter optimization method of the prompt word optimization model of the present application can be applied in multiple scenarios. For example, in the financial field, the user needs to analyze a financial statement through a large model, and use the prompt word optimization model to input the optimized prompt words into the large model. The device optimizes the hyperparameters of the prompt word optimization model to reduce the inference cost while considering the inference performance of the large model and protect the privacy of the user. That is, the present application can optimize the hyperparameters of the prompt word optimization model so that the optimized hyperparameters are the optimal hyperparameters that take into account the inference cost, privacy security and inference performance of the large model. After the prompt word optimization model applies the hyperparameters, the generated prompt words can not only improve the inference performance of the large model, but also avoid privacy leakage and reduce the inference cost.
[0058] It should be noted that the hyperparameters to be optimized refer to the hyperparameters set before the optimization algorithm to be optimized is run, wherein the hyperparameters include but are not limited to the maximum length of the prompt word, the level of noise required to protect privacy, and the number of optimization iterations; the device obtains the hyperparameters to be optimized by receiving a group of hyperparameters to be optimized sent by the user.
[0059] Furthermore, the target prompt word corresponding to the hyperparameter to be optimized refers to a prompt word set constrained by the hyperparameter to be optimized. Specifically, the hyperparameter includes the maximum length of the prompt word, and the prompt word set includes prompt words whose character length does not exceed the hyperparameter, wherein the prompt word set is used to input into the big model for query interaction. The device may obtain the target prompt word by receiving the target prompt word set sent by the user, or may generate the corresponding target prompt word set based on the big model. For example, the user inputs "generate a prompt word set about financial statements, the character length of the prompt word cannot exceed X" into the big model, and the big model will generate the prompt word set to be optimized accordingly.
[0060] It is understandable that the prompt word optimization model is used to optimize the prompt words to be optimized after receiving them, and output the optimized prompt words. The main influencing factor of the optimization quality of the prompt words is the hyperparameters of the prompt word optimization model. Therefore, the present application can improve the quality of the optimized prompt words by optimizing the hyperparameters of the prompt word optimization model, so that the optimized prompt words meet the corresponding requirements (the requirements include that the generated prompt words can not only improve the reasoning performance of the large model, but also avoid privacy leakage and reduce the reasoning cost).
[0061] In a specific implementation, after the device obtains the step of obtaining the hyperparameter to be optimized of the prompt word optimization model and the target prompt word corresponding to the hyperparameter to be optimized, the method includes:
[0062] The device arbitrarily selects a pair of hyperparameters to be optimized from the hyperparameters to be optimized and performs cross-replacement processing on the parameters to obtain newly added hyperparameters; repeats the step of arbitrarily selecting a pair of hyperparameters from the hyperparameters to be optimized and performing cross-replacement processing on the parameters to obtain newly added hyperparameters until a preset second number of newly added hyperparameters are obtained, and merges the hyperparameters to be optimized and the newly added hyperparameters to obtain amplified hyperparameters to be optimized; based on a preset replacement probability and a preset parameter library, performs parameter transformation on the amplified hyperparameters to be optimized to obtain transformed hyperparameters to be optimized.
[0063] In a specific implementation, the device randomly selects a pair of hyperparameters from the hyperparameter group to be optimized (the hyperparameters are of the same category, such as hyperparameters of the same prompt word length) for crossover replacement processing to obtain a new prompt word, wherein common crossover operations include single-point crossover, double-point crossover, and multi-point crossover. For example, in single-point crossover, first randomly select two hyperparameter groups, then randomly select a position to divide the hyperparameter group into two parts, and then cross the two hyperparameter groups to generate a new hyperparameter group.
[0064] Furthermore, after the device amplifies the hyperparameters through the crossover operation, it also performs a mutation operation on the amplified hyperparameters to be optimized, wherein the mutation operation specifically refers to randomly selecting a hyperparameter group and transforming each hyperparameter in the hyperparameter group with probability v. The probability v is usually very small, such as 1%. It should be noted that the present application achieves the transformation of a small number of hyperparameters by setting a small probability hyperparameter transformation, thereby preventing the problem of poor results caused by transforming a large number of hyperparameters, and further amplifying the hyperparameters.
[0065] Step S200, calculating the inference cost of the hyperparameter to be optimized based on the character length, and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise level;
[0066] In a specific implementation, the inference cost of the hyperparameter to be optimized refers to the inference cost formed after the prompt word corresponding to the hyperparameter to be optimized is input into the large model. The longer the character length of the prompt word, the higher the inference cost. Specifically, the inference cost corresponding to the hyperparameter to be optimized can be calculated based on the length of the prompt word corresponding to the hyperparameter to be optimized, wherein the inference cost is calculated by multiplying the length of the prompt word by the character cost coefficient to obtain the inference cost of the hyperparameter to be optimized, wherein the character cost coefficient represents the inference cost corresponding to one character.
[0067] In a specific implementation, the privacy noise level is used to disturb the text, so as to reduce the accuracy of the text description, wherein the larger the privacy noise level, the lower the accuracy of the text description; the privacy loss of the hyperparameter to be optimized refers to the privacy loss caused by the sample after the privacy attack, and in this application, the privacy loss is negatively correlated with the privacy noise level, that is, the larger the privacy noise level, the smaller the privacy loss and the higher the privacy security; the smaller the privacy noise level, the greater the privacy loss and the higher the privacy security. However, the larger the privacy noise level, the better. The larger the privacy noise level, the greater the disturbance of the prompt word, which will lead to inaccurate answers from the large model, that is, reduce the reasoning performance of the large model.
[0068] Furthermore, the device calculates the privacy loss of the hyperparameter to be optimized based on the privacy noise level by substituting the privacy noise level into a preset privacy loss calculation formula to calculate the privacy loss of the hyperparameter to be optimized, wherein the privacy loss calculation formula is obtained by the developer through experiments for the application scenario. Specifically, the privacy loss calculation formula is as follows:
[0069]
[0070] Among them, σ represents the privacy noise layer, ε represents the privacy budget, and Z is a constant. The specific value of Z is obtained by developers through experiments based on application scenarios.
[0071] Step S300, inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer;
[0072] It should be noted that the target large model can be a target large language model used for query interaction, such as GPT4, or a locally created large language model; the predicted task answer refers to the answer output by the target large model after reasoning based on the input target prompt word.
[0073] For example, in a specific application scenario, the target prompt word input by the device to GPT4 is "Give the sentiment classification of the following sentence and specify a sentiment label from [0-4]. 0 means 'bad', 1 means 'not good', 2 means 'ok', 3 means 'good', and 4 means 'great'." The prediction task answer output by GPT4 is 2.
[0074] Furthermore, the reasoning performance refers to the performance evaluation of the target large model in the process of generating the corresponding answer based on the input target prompt word, wherein the closer the answer made by the target large model based on the prompt word is to the manually labeled answer, the better the reasoning performance corresponding to the prompt word is.
[0075] In a specific implementation, the device inputs the target prompt word into the target large model, obtains the prediction task answer output by the target large model, and determines the inference performance of the hyperparameter to be optimized based on the prediction task answer, including:
[0076] The device obtains an optimized sample set corresponding to the target prompt word and a task answer label corresponding to the optimized sample set; performs noise perturbation processing on the optimized sample set based on the privacy noise layer to obtain the perturbed optimized sample set; inputs the target prompt word and the perturbed optimized sample set into a target large model to obtain a predicted task answer output by the target large model; calculates the difference between the predicted task answer and the task answer label to obtain a target difference, and calculates the inference performance of the hyperparameter to be optimized based on the target difference.
[0077] It should be noted that the optimized sample set is a data set for optimizing prompt words, denoted as D, D contains N (x, y) training samples, x is a text sample composed of characters, y corresponds to the task answer label corresponding to the sample, wherein the task answer label is an accurate task answer manually annotated; the inference cost is determined according to the length of the prompt word under the hyperparameter, the longer the prompt word is, the more relevant information it contains, and the higher the inference cost of the model, and the device determines the inference cost corresponding to the prompt word according to the length of the hyperparameter prompt word; the target large model can be a commercial target large language model for query interaction, such as GPT4, or it can be a locally created large language model; the privacy noise layer is a noise used to disturb the text, thereby reducing the accuracy of its text description, wherein the larger the privacy noise layer, the lower the accuracy of the text description.
[0078] In a specific implementation, since the present application involves the privacy security of prompt words, before sending the optimized sample set to the target large model, the device needs to perform noise disturbance processing on the optimized sample set based on the privacy noise level of each hyperparameter to be optimized to obtain the disturbed optimized sample set, and then the device inputs the hyperparameter to be optimized and the disturbed optimized sample set into the target large model to obtain the predicted task answer output by the target large model, and calculates the reasoning performance and privacy loss corresponding to the hyperparameter to be optimized based on the predicted task answer and the task answer label. In a specific scenario, the device randomly replaces each token in the input text x with another token with similar semantics based on the noise level to obtain the disturbed input text x'. Use x' to access the target large model to obtain the corresponding answer r. Finally, the device calculates the performance loss based on the answer r based on the specific task, and then obtains the reasoning performance corresponding to the hyperparameter to be optimized.
[0079] Specifically, the device obtains a corresponding difference by calculating the difference between the predicted task answer and the preset task answer label. The difference reflects the difference between the predicted answer and the manually labeled task answer label. The difference is the loss of reasoning performance. The smaller the loss of reasoning performance, the better the reasoning performance of the prompt word to be optimized. That is, the device determines the reasoning performance of the hyperparameter to be optimized through the loss of reasoning performance (the difference between the predicted answer and the manually labeled task answer label).
[0080] For example, assuming that the task is a sentiment reasoning task, a prompt word for a hyperparameter to be optimized is: "Given the sentiment classification of the following sentence, specify a sentiment label from [0-4]. 0 means 'bad', 1 means 'bad', 2 means 'ok', 3 means 'good', and 4 means 'great'. A (x, y) training sample is: x = "a fascinating movie showing American tragedy"; x' = "an interesting TV show showing American tragedy"; y = "4"; the answer output by the final target large model is 2, then the effect loss is 4-2 = 2, and then the device calculates the performance loss of (x', y); the device calculates the privacy loss caused by x' based on a privacy attack (for example, an embedding vector inversion attack). Specifically, the device calculates the number of tokens involved in the prompt word of the hyperparameter to be optimized, which is used to represent the cost of the prompt word of the hyperparameter to be optimized, and the device further calculates the average performance loss and the average privacy loss of all samples.
[0081] Step S400, based on the inference cost, the inference performance and the privacy loss, through a preset multi-objective optimization algorithm, select the optimal hyperparameter from the hyperparameters to be optimized, and use the optimal hyperparameter as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
[0082] It should be noted that the multi-objective optimization algorithm is an optimization algorithm used to solve multiple objective functions. The goal of the multi-objective optimization algorithm is to find a balance between multiple potentially conflicting objectives and ultimately obtain an approximate optimal solution set for the multi-objective optimization problem. The multi-objective optimization algorithm includes but is not limited to a genetic algorithm, a particle swarm algorithm, a differential evolution algorithm, and a simulated annealing algorithm.
[0083] Furthermore, the multi-objective optimization algorithm in the present application is preferably a genetic algorithm, wherein the hyperparameter optimization problem of the prompt word optimization model based on the multi-objective optimization algorithm is specifically expressed by the following formula:
[0084] θ * =argmin θ L(θ),ε p (θ),ε e (θ),ε c(θ)
[0085]
[0086] st
[0087] ε c (θ)<φ c ,
[0088] ε p (θ)<φ p ,
[0089] Among them, D val represents the prompt word optimization dataset (including the optimized sample set and the task answer label corresponding to the optimized sample set), g θ represents the hyperparameters of the prompt word optimization model, f ω represents the target large model, S represents the computational utility loss function, pt represents the prompt word, v represents the multi-objective optimization algorithm, ε c represents the inference cost, φ c represents the cost threshold, ε p represents the inference privacy, φ p Represents the privacy threshold.
[0090] In this embodiment, the multi-objective optimization algorithm is an optimization algorithm with inference performance, inference cost and privacy loss as optimization targets, that is, the multi-objective optimization algorithm involves the objective function of inference performance, the objective function of inference cost and the objective function of privacy loss. Preferably, the multi-objective optimization algorithm adopted is a multi-objective genetic algorithm. Specifically, the device selects the optimal hyperparameter from the hyperparameters to be optimized by using a preset multi-objective optimization algorithm. First, the first objective solution (calculated based on the objective function of inference performance), the second objective solution (calculated based on the objective function of inference cost) and the third objective solution (calculated based on the objective function of privacy loss) of the prompt word corresponding to each hyperparameter are calculated respectively, and then the fitness evaluation of each hyperparameter is determined based on the first objective solution, the second objective solution and the third objective solution, and the optimal hyperparameter is selected based on the fitness evaluation of each hyperparameter, wherein the hyperparameter with the highest fitness evaluation is the optimal hyperparameter.
[0091] Furthermore, the device determines the fitness evaluation of each prompt word based on the first target solution, the second target solution and the third target solution, and selects the optimal hyperparameter based on the fitness evaluation of each prompt word in the following manner: (1) randomly generating different weights for all individuals in the hyperparameter to be optimized, and then calculating the fitness evaluation of each hyperparameter based on the first target solution, the second target solution, the third target solution and the weight value, and finally performing an iterative hyperparameter selection operation until the optimal hyperparameter is obtained; (2) dividing the hyperparameter to be optimized into three subpopulations of equal size, setting target weights in different subpopulations according to different objective functions, and calculating the fitness evaluation of each hyperparameter, and finally performing an iterative hyperparameter selection operation until the optimal hyperparameter is obtained; (3) selecting the hyperparameter of a non-dominated solution from the hyperparameter to be optimized based on the first target solution, the second target solution and the third target solution (the hyperparameter of a non-dominated solution refers to a hyperparameter for which no other hyperparameter in the population has a first target solution, a second target solution and a third target solution that are completely higher than itself), and then manually selecting the hyperparameter of the non-dominated solution to obtain the optimal hyperparameter.
[0092] In the specific implementation, this application proposes a multi-objective optimization algorithm with privacy loss, reasoning performance and reasoning cost as optimization objectives to optimize the hyperparameters to be optimized, and obtain the optimized hyperparameters. The optimized hyperparameters are the optimal hyperparameters that take into account the reasoning cost, privacy security and reasoning performance of the large model. After the hyperparameters are applied to the prompt word optimization model, the generated prompt words can not only improve the reasoning performance of the large model, but also avoid privacy leakage and reduce the reasoning cost.
[0093] In a specific implementation, the present application has a variety of application scenarios. For example, if a user needs to analyze a financial statement through a large model, then the prompt words for the analysis of the financial statement need to be carefully designed to achieve good performance. If the prompt words are designed manually, it will be time-consuming and labor-intensive, and the manually designed prompt words are often redundant and will bring higher costs. Therefore, it is proposed in the related art that manual intervention can be reduced and the efficiency of optimizing prompt words can be improved through automatic prompt word optimization. However, the automatic prompt word optimization usually involves accessing a large model server, which may leak user privacy. The present application proposes an automatic optimization prompt word optimizer so that the generated prompt word optimizer can optimize the prompt word cost and privacy while optimizing the prompt word performance.
[0094] In a specific implementation, the device selects the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss through a preset multi-objective optimization algorithm, and uses the optimal hyperparameter as the optimized hyperparameter, including:
[0095] Based on the inference cost, the inference performance and the privacy loss, non-dominated solutions are sorted for each of the hyperparameters to be optimized to obtain sorted hyperparameters to be optimized; and a preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as the optimal hyperparameters.
[0096] It should be noted that the non-dominated solution sorting is a method of sorting individuals in a population based on the dominance relationship between individuals. The non-dominated sorting divides individuals into multiple levels. The higher the level, the better the individual. Among them, individuals dominated by other individuals are ranked lower.
[0097] In a specific implementation, an individual under the non-dominated solution sorting refers to a hyperparameter, and non-dominated solutions are sorted based on each hyperparameter, wherein the non-dominated solution sorting of the hyperparameter is sorted according to the target solutions calculated by the hyperparameter with respect to multiple objective functions. Specifically, the device first calculates the first target solution (calculated by the target function based on the reasoning performance), the second target solution (calculated by the target function based on the reasoning cost), and the third target solution (calculated by the target function based on the privacy loss) of the prompt word corresponding to each hyperparameter, and then sorts the non-dominated solutions of the hyperparameter based on the first target solution, the second target solution, and the third target solution.
[0098] Further, after determining the first target solution, the second target solution and the third target solution corresponding to each hyperparameter, based on the first target solution, the second target solution and the third target solution of each hyperparameter, each hyperparameter is used as a benchmark to perform traversal comparison with the first target solution, the second target solution and the third target solution of other hyperparameters, wherein if there is no other hyperparameter whose first target solution, the second target solution and the third target solution are all greater than the benchmark hyperparameter, it means that the benchmark hyperparameter is not dominated, and the benchmark hyperparameter is a non-dominated solution; if there is another hyperparameter whose first target solution, the second target solution and the third target solution are all greater than the benchmark hyperparameter, it means that the benchmark hyperparameter is dominated, and the benchmark hyperparameter is a dominated solution. It should be noted that the rank of the non-dominated individual (hyperparameter) is higher than that of the dominated individual, and the traversal comparison process needs to be continued for multiple rounds to obtain multiple rounds of non-dominated solutions. The smaller the round, the higher the rank of the non-dominated solution. Therefore, by continuously traversing the hyperparameters to be optimized, the non-dominated solution sorting of the hyperparameters to be optimized is achieved.
[0099] In the specific implementation, the non-dominated solution sorting method is an effective sorting method for multi-objective optimization, which can improve the accuracy of selecting the optimal hyperparameters, that is, improve the quality of the optimal hyperparameters.
[0100] In a specific implementation, the step of selecting a preset first number of hyperparameters as optimal hyperparameters from the sorted hyperparameters to be optimized in descending order includes:
[0101] The congestion degree of the sorted hyperparameters to be optimized is calculated to obtain congestion degree information; based on the congestion degree information, a preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
[0102] In a specific implementation, after sorting the non-dominated solutions of the hyperparameters to be optimized, the device also calculates the crowding degree of individuals at each level. The crowding degree measures the density around the individual, that is, the distance between the individual and its neighboring individuals, wherein the higher the crowding degree, the more crowded the area where the individual is located.
[0103] For example, the first group of non-dominated solutions includes A, C, and D, and the second group of non-dominated solutions includes B and E. It can be determined that the level of the first group of non-dominated solutions is higher than that of the second group of non-dominated solutions, but the quality of A, C, and D cannot be further distinguished, and the sorting cannot be further refined. Therefore, the present application proposes to calculate the congestion of the non-dominated solutions in the group, and based on the congestion information, select a preset first number of hyperparameters from the sorted hyperparameters to be optimized in order from large to small as the optimal hyperparameters.
[0104] In a specific implementation, the present application calculates the crowding degree of individuals at each level and achieves a more detailed sorting of the prompt words at each level, thereby improving the accuracy of selecting the optimal hyperparameters, that is, improving the quality of the optimal hyperparameters.
[0105] Compared with the high inference time and cost of the large model in the related art, and the risk of exposing user privacy information, the present application calculates the inference cost and privacy loss of the hyperparameters of the prompt word optimization model by including the prompt word character length and the privacy noise layer of the prompt word optimization model, and uses the target large model to answer the task corresponding to the target prompt word corresponding to the input hyperparameter to be optimized, and determines the inference performance of the hyperparameter to be optimized, thereby determining the inference cost, privacy loss and inference performance of each hyperparameter to be optimized. It can be understood that the inference cost, privacy loss and inference performance of the hyperparameter to be optimized respectively reflect It reflects the reasoning cost, privacy security and reasoning performance involved in the prompt word process after the optimization of the prompt word optimization model of the large model reasoning (the prompt word optimization model after using the hyperparameters). Therefore, this application optimizes the hyperparameters of the prompt word optimization model through a multi-objective optimization algorithm with privacy loss, reasoning performance and reasoning cost as optimization targets, so that the optimized hyperparameters are the optimal hyperparameters that take into account the reasoning cost, privacy security and reasoning performance of the large model at the same time. After the hyperparameters are applied to the prompt word optimization model, the generated prompt words can not only improve the reasoning performance of the large model, but also avoid privacy leakage and reduce the reasoning cost.
[0106] Based on the above first embodiment, the present application also proposes another embodiment, referring to Figure 2 The hyperparameter optimization method of the prompt word optimization model includes:
[0107] The device selects a preset first number of optimal hyperparameters from the hyperparameters to be optimized based on the privacy loss, the inference performance, and the inference cost, and uses the preset first number of optimal hyperparameters as the optimized hyperparameters, including:
[0108] Step A100, selecting a preset first number of optimal hyperparameters from the hyperparameters to be optimized based on the privacy loss, the inference performance, and the inference cost;
[0109] In the specific implementation, this step has been specifically described in the first embodiment, and reference may be made to the first embodiment above, and will not be repeated here.
[0110] Step A200, obtain the current iteration cycle, and determine whether the current iteration cycle reaches the optimization iteration number. If the current iteration cycle does not reach the optimization iteration number, use the optimal hyperparameter as the hyperparameter to be optimized for the next iteration, return to the step of calculating the inference cost of the hyperparameter to be optimized based on the character length, and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise layer, until the current iteration cycle reaches the optimization iteration number, then stop selecting the optimal hyperparameter, and use the first number of optimal hyperparameters of this round as the optimized hyperparameters.
[0111] It should be noted that the present application proposes to adopt an iterative selection method for screening the optimal hyperparameters, and through multiple cycles of iterative selection of the optimal hyperparameters, the selected hyperparameters are continuously close to the optimal.
[0112] In a specific implementation, the iteration stop condition is to meet a certain iteration cycle, for example, the selection of the optimal prompt word is stopped after reaching 20 iteration cycles. That is, if the algorithm reaches the end requirement, the algorithm is terminated, otherwise, the optimal hyperparameter is used as the hyperparameter to be optimized for the next iteration, and the step of calculating the inference cost of the hyperparameter to be optimized based on the character length and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise layer is returned.
[0113] In the specific implementation, the present application proposes that in the optimization process of the prompt words, the selected optimal hyperparameters be used as the optimization target of the prompt words, and restrictions on privacy loss, prompt word length, and number of optimization iterations be provided. In the process of selecting a preset second number of optimal prompt words, the goal of the optimal hyperparameters needs to be met at the same time.
[0114] In a specific implementation, the present application combines multi-objective optimization with automatic optimization of the prompt word optimizer. The prompt word optimizer is optimized by optimizing the hyperparameter of the prompt word optimizer, so that the prompt word optimizer can optimize the prompt word cost and privacy while optimizing the prompt word performance.
[0115] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the hyperparameter optimization method of the prompt word optimization model of the present application. More forms of simple transformations based on this technical concept are all within the scope of protection of the present application.
[0116] This application also provides a hyperparameter optimization device for a prompt word optimization model, please refer to Figure 3 , the hyperparameter optimization device of the prompt word optimization model includes:
[0117] The acquisition module 10 is used to acquire the hyperparameters to be optimized of the prompt word optimization model and the target prompt word corresponding to the hyperparameters to be optimized, wherein the hyperparameters to be optimized include the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word;
[0118] A calculation module 20, configured to calculate the inference cost of the hyperparameter to be optimized based on the character length, and calculate the privacy loss of the hyperparameter to be optimized based on the privacy noise level;
[0119] A determination module 30, configured to input the target prompt word into a target large model, obtain a prediction task answer output by the target large model, and determine the reasoning performance of the hyperparameter to be optimized based on the prediction task answer;
[0120] The optimization module 40 is used to select the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss through a preset multi-objective optimization algorithm, and use the optimal hyperparameter as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
[0121] Optionally, the determining module 30 includes:
[0122] A sample acquisition module, used to acquire an optimized sample set corresponding to the target prompt word and a task answer label corresponding to the optimized sample set;
[0123] A disturbance module, configured to perform noise disturbance processing on the optimized sample set based on the privacy noise layer to obtain a disturbed optimized sample set;
[0124] An answer determination module, used for inputting the target prompt word and the optimized sample set after disturbance into the target large model to obtain the prediction task answer output by the target large model;
[0125] The inference performance calculation module is used to calculate the difference between the predicted task answer and the task answer label to obtain a target difference, and calculate the inference performance of the hyperparameter to be optimized based on the target difference.
[0126] Optionally, the optimization module 40 includes:
[0127] A selection module, configured to select a preset first number of optimal hyperparameters from the hyperparameters to be optimized based on the privacy loss, the inference performance, and the inference cost;
[0128] An iterative optimization module is used to obtain the current iteration cycle and determine whether the current iteration cycle has reached the optimization iteration number. If the current iteration cycle has not reached the optimization iteration number, the optimal hyperparameter is used as the hyperparameter to be optimized for the next iteration, and the steps of calculating the inference cost of the hyperparameter to be optimized based on the character length and the privacy loss of the hyperparameter to be optimized based on the privacy noise layer are returned until the current iteration cycle reaches the optimization iteration number. Then, the selection of the optimal hyperparameter is stopped, and the optimal hyperparameter of the first number in this round is used as the optimized hyperparameter.
[0129] Optionally, the optimization module 40 further includes:
[0130] A sorting module, used for sorting the non-dominated solutions of the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss, to obtain sorted hyperparameters to be optimized;
[0131] The hyperparameter determination module is used to select a preset first number of hyperparameters as optimal hyperparameters from the sorted hyperparameters to be optimized in descending order.
[0132] Optionally, the hyperparameter determination module includes:
[0133] A congestion calculation module is used to calculate the congestion of the sorted hyperparameters to be optimized to obtain congestion information;
[0134] The optimal hyperparameter determination module is used to select a preset first number of hyperparameters as the optimal hyperparameters from the sorted hyperparameters to be optimized in descending order based on the congestion information.
[0135] Optionally, the hyperparameter optimization device of the prompt word optimization model further includes:
[0136] A newly added module is used to select any pair of hyperparameters to be optimized from the hyperparameters to be optimized to perform cross-replacement processing on the hyperparameters to obtain newly added hyperparameters;
[0137] an expansion module, configured to repeat the step of selecting any pair of hyperparameters from the hyperparameters to be optimized to perform cross-replacement processing on the hyperparameters to obtain newly added hyperparameters, until a preset second number of newly added hyperparameters are obtained, and merging the hyperparameters to be optimized and the newly added hyperparameters to obtain expanded hyperparameters to be optimized;
[0138] The parameter transformation module is used to perform parameter transformation on the amplified hyperparameters to be optimized based on a preset replacement probability and a preset parameter library to obtain transformed hyperparameters to be optimized.
[0139] The hyperparameter optimization device of the prompt word optimization model provided by the present application adopts the hyperparameter optimization method of the prompt word optimization model in the above embodiment, which can solve the technical problem of hyperparameter optimization of the prompt word optimization model. Compared with the related art, the beneficial effect of the hyperparameter optimization device of the prompt word optimization model provided by the present application is the same as the beneficial effect of the hyperparameter optimization method of the prompt word optimization model provided by the above embodiment, and the other technical features in the hyperparameter optimization device of the prompt word optimization model are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0140] The present application provides a hyperparameter optimization device for a prompt word optimization model, and the hyperparameter optimization device for the prompt word optimization model includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the hyperparameter optimization method for the prompt word optimization model in the above-mentioned embodiment 1.
[0141] Reference below Figure 4 , which shows a schematic diagram of the structure of a hyperparameter optimization device suitable for implementing the prompt word optimization model of the embodiment of the present application. The hyperparameter optimization device of the prompt word optimization model in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4The hyperparameter optimization device of the prompt word optimization model shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0142] like Figure 4 As shown, the hyperparameter optimization device of the prompt word optimization model may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the hyperparameter optimization device of the prompt word optimization model are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 may allow the hyperparameter optimization device of the prompt word optimization model to communicate wirelessly or wired with other devices to exchange data. Although the hyperparameter optimization device of the prompt word optimization model with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0143] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0144] The hyperparameter optimization device of the prompt word optimization model provided by the present application adopts the hyperparameter optimization method of the prompt word optimization model in the above embodiment, which can solve the technical problem of hyperparameter optimization of the prompt word optimization model. Compared with the related art, the beneficial effect of the hyperparameter optimization device of the prompt word optimization model provided by the present application is the same as the beneficial effect of the hyperparameter optimization method of the prompt word optimization model provided by the above embodiment, and the other technical features in the hyperparameter optimization device of the prompt word optimization model are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0145] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0146] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0147] The present application provides a computer-readable storage medium having computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute to implement the hyperparameter optimization method of the prompt word optimization model as described below:
[0148] Obtaining a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word;
[0149] Based on the character length, calculating the inference cost of the hyperparameter to be optimized, and based on the privacy noise level, calculating the privacy loss of the hyperparameter to be optimized;
[0150] Inputting the target prompt word into the target large model to obtain a prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer;
[0151] Based on the inference cost, the inference performance and the privacy loss, the optimal hyperparameter is selected from the hyperparameters to be optimized through a preset multi-objective optimization algorithm, and the optimal hyperparameter is used as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
[0152] In one embodiment, the step of inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the inference performance of the hyperparameter to be optimized based on the prediction task answer includes:
[0153] Obtaining an optimized sample set corresponding to the target prompt word and a task answer label corresponding to the optimized sample set;
[0154] Based on the privacy noise level, performing noise disturbance processing on the optimized sample set to obtain a disturbed optimized sample set;
[0155] Inputting the target prompt word and the optimized sample set after disturbance into the target large model to obtain the prediction task answer output by the target large model;
[0156] The difference between the predicted task answer and the task answer label is calculated to obtain a target difference, and based on the target difference, the inference performance of the hyperparameter to be optimized is calculated.
[0157] In one embodiment, the hyperparameter includes the number of optimization iterations, and the step of selecting the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance, and the privacy loss through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter includes:
[0158] Based on the privacy loss, the inference performance, and the inference cost, selecting a preset first number of optimal hyperparameters from the hyperparameters to be optimized;
[0159] Get the current iteration cycle, and determine whether the current iteration cycle reaches the optimization iteration number. If the current iteration cycle does not reach the optimization iteration number, use the optimal hyperparameter as the hyperparameter to be optimized for the next iteration, return to the step of calculating the inference cost of the hyperparameter to be optimized based on the character length, and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise layer, until the current iteration cycle reaches the optimization iteration number, then stop selecting the optimal hyperparameter, and use the first number of optimal hyperparameters of this round as the optimized hyperparameters.
[0160] In one embodiment, the step of selecting an optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance, and the privacy loss through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter includes:
[0161] Based on the inference cost, the inference performance, and the privacy loss, sorting the non-dominated solutions of the hyperparameters to be optimized to obtain sorted hyperparameters to be optimized;
[0162] A preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
[0163] In one embodiment, the step of selecting a preset first number of hyperparameters as optimal hyperparameters from the sorted hyperparameters to be optimized in descending order includes:
[0164] Calculating the congestion degree of the sorted hyperparameters to be optimized to obtain congestion degree information;
[0165] Based on the congestion information, a preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
[0166] In one embodiment, after the step of obtaining the hyperparameters to be optimized of the prompt word optimization model and the target prompt words corresponding to the hyperparameters to be optimized, the method includes:
[0167] A pair of hyperparameters to be optimized are randomly selected from the hyperparameters to be optimized to perform cross-replacement processing on the parameters to obtain newly added hyperparameters;
[0168] Repeat the step of selecting any pair of hyperparameters from the hyperparameters to be optimized to perform cross-replacement processing on the hyperparameters to obtain newly added hyperparameters until a preset second number of newly added hyperparameters are obtained, and merge the hyperparameters to be optimized and the newly added hyperparameters to obtain expanded hyperparameters to be optimized;
[0169] Based on a preset replacement probability and a preset parameter library, parameter transformation is performed on the amplified hyperparameter to be optimized to obtain a transformed hyperparameter to be optimized.
[0170] The specific implementation method of the storage medium of the present application is basically the same as the various embodiments of the hyperparameter optimization method of the above-mentioned prompt word optimization model, and will not be repeated here.
[0171] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0172] The computer-readable storage medium may be included in the hyperparameter optimization device of the prompt word optimization model; or may exist independently without being assembled into the hyperparameter optimization device of the prompt word optimization model.
[0173] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the hyperparameter optimization device of the prompt word optimization model, the hyperparameter optimization device of the prompt word optimization model performs hyperparameter optimization of the prompt word optimization model.
[0174] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0175] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0176] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0177] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the hyperparameter optimization method of the above-mentioned prompt word optimization model, and can solve the technical problem of hyperparameter optimization of the prompt word optimization model. Compared with the related art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the hyperparameter optimization method of the prompt word optimization model provided by the above-mentioned embodiment, and will not be repeated here.
[0178] The present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of the hyperparameter optimization method of the prompt word optimization model as described above.
[0179] The computer program product provided by the present application can solve the technical problem of optimizing the hyperparameters of the prompt word optimization model. Compared with the related art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the hyperparameter optimization method of the prompt word optimization model provided by the above embodiment, which will not be repeated here.
[0180] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A hyperparameter optimization method for a prompt word optimization model, characterized in that: The method for optimizing the hyperparameters of the prompt word optimization model includes: Obtaining a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used to optimize the prompt word to be optimized after receiving the prompt word to be optimized, and output the optimized prompt word; Based on the character length, calculating the inference cost of the hyperparameter to be optimized, and based on the privacy noise level, calculating the privacy loss of the hyperparameter to be optimized; Inputting the target prompt word into the target large model to obtain a prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer; Based on the inference cost, the inference performance and the privacy loss, the optimal hyperparameter is selected from the hyperparameters to be optimized through a preset multi-objective optimization algorithm, and the optimal hyperparameter is used as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
2. The hyperparameter optimization method of the prompt word optimization model according to claim 1, characterized in that: The step of inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer includes: Obtaining an optimized sample set corresponding to the target prompt word and a task answer label corresponding to the optimized sample set; Based on the privacy noise level, performing noise disturbance processing on the optimized sample set to obtain a disturbed optimized sample set; Inputting the target prompt word and the optimized sample set after disturbance into the target large model to obtain the prediction task answer output by the target large model; The difference between the predicted task answer and the task answer label is calculated to obtain a target difference, and based on the target difference, the inference performance of the hyperparameter to be optimized is calculated.
3. The hyperparameter optimization method of the prompt word optimization model according to claim 1, characterized in that: The hyperparameter includes the number of optimization iterations, and the step of selecting the optimal hyperparameter from the hyperparameters to be optimized through a preset multi-objective optimization algorithm based on the inference cost, the inference performance, and the privacy loss, and using the optimal hyperparameter as the optimized hyperparameter includes: Based on the privacy loss, the inference performance, and the inference cost, selecting a preset first number of optimal hyperparameters from the hyperparameters to be optimized; Get the current iteration cycle, and determine whether the current iteration cycle reaches the optimization iteration number. If the current iteration cycle does not reach the optimization iteration number, use the optimal hyperparameter as the hyperparameter to be optimized for the next iteration, return to the step of calculating the inference cost of the hyperparameter to be optimized based on the character length, and calculating the privacy loss of the hyperparameter to be optimized based on the privacy noise layer, until the current iteration cycle reaches the optimization iteration number, then stop selecting the optimal hyperparameter, and use the first number of optimal hyperparameters of this round as the optimized hyperparameters.
4. The hyperparameter optimization method of the prompt word optimization model according to claim 1, characterized in that: The step of selecting the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss through a preset multi-objective optimization algorithm, and using the optimal hyperparameter as the optimized hyperparameter includes: Based on the inference cost, the inference performance, and the privacy loss, sorting the non-dominated solutions of the hyperparameters to be optimized to obtain sorted hyperparameters to be optimized; A preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
5. The hyperparameter optimization method of the prompt word optimization model according to claim 4, characterized in that: The step of selecting a preset first number of hyperparameters as optimal hyperparameters from the sorted hyperparameters to be optimized in descending order includes: Calculating the congestion degree of the sorted hyperparameters to be optimized to obtain congestion degree information; Based on the congestion information, a preset first number of hyperparameters are selected from the sorted hyperparameters to be optimized in descending order as optimal hyperparameters.
6. The hyperparameter optimization method of the prompt word optimization model according to claim 1, characterized in that: After the step of obtaining the hyperparameters to be optimized of the prompt word optimization model and the target prompt words corresponding to the hyperparameters to be optimized, the method includes: A pair of hyperparameters to be optimized are randomly selected from the hyperparameters to be optimized to perform cross-replacement processing on the parameters to obtain newly added hyperparameters; Repeat the step of selecting any pair of hyperparameters from the hyperparameters to be optimized to perform cross-replacement processing on the hyperparameters to obtain newly added hyperparameters until a preset second number of newly added hyperparameters are obtained, and merge the hyperparameters to be optimized and the newly added hyperparameters to obtain expanded hyperparameters to be optimized; Based on a preset replacement probability and a preset parameter library, parameter transformation is performed on the amplified hyperparameter to be optimized to obtain a transformed hyperparameter to be optimized.
7. A hyperparameter optimization device for a prompt word optimization model, characterized in that: The device comprises: an acquisition module, used for acquiring a hyperparameter to be optimized of a prompt word optimization model and a target prompt word corresponding to the hyperparameter to be optimized, wherein the hyperparameter to be optimized includes the character length of the prompt word and the privacy noise layer, and the prompt word optimization model is used for optimizing the prompt word to be optimized after receiving the prompt word to be optimized, and outputting the optimized prompt word; A calculation module, used to calculate the inference cost of the hyperparameter to be optimized based on the character length, and calculate the privacy loss of the hyperparameter to be optimized based on the privacy noise layer; A determination module, used for inputting the target prompt word into the target large model, obtaining the prediction task answer output by the target large model, and determining the reasoning performance of the hyperparameter to be optimized based on the prediction task answer; An optimization module is used to select the optimal hyperparameter from the hyperparameters to be optimized based on the inference cost, the inference performance and the privacy loss through a preset multi-objective optimization algorithm, and use the optimal hyperparameter as the optimized hyperparameter, wherein the multi-objective optimization algorithm is an optimization algorithm with privacy loss, inference performance and inference cost as optimization objectives.
8. A hyperparameter optimization device for a prompt word optimization model, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the hyperparameter optimization method of the prompt word optimization model according to any one of claims 1 to 6.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the hyperparameter optimization method of the prompt word optimization model according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the hyperparameter optimization method of the prompt word optimization model according to any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Chinese cue word compression method and device
CN117725036A
Optimization method for large model system
CN117910582A
Question and answer optimization method and device, equipment, storage medium and product
CN118052288A
Data evaluation method and device based on large language model, equipment and storage medium
CN118196567A
Optimization apparatus and optimization method for hyper parameter
US20190228335A1
Cited By
Large model sensitive expression fuzzification processing method and system and computer equipment
CN119918510A
Large electric power model performance optimization method and system based on declarative self-prompt
CN120764697A
