Parameter optimization method and device, text generation method and device, equipment and medium
Through the genetic algorithm, the sampling parameters of the pre-trained language model are automatically tuned, which solves the problem of low tuning efficiency in the existing technology, and realizes the language style of the generative answer text and the baseline answer text, which improves the generation of the model quality.
Patent Information
- Application Number
- CN202411388413.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-10
AI Technical Summary
In the prior art, the sampling parameter tuning efficiency of the pre-trained language model is low, and it is difficult to ensure that the language style of the generative answer text is consistent with the baseline answer text.
The genetic algorithm is used to automatically tune the sampling parameters. By obtaining the question text, baseline answer text and each set of sampling parameters in the parameter pool, the similarity between the generated answer text and the baseline answer text is calculated, and the genetic algorithm is used to update the parameter pool. Sampling parameters until the preset stop condition is met.
It improves the tuning efficiency of the sampling parameters of the pre-trained language model, ensures that the generative answer text fits the baseline answer text in language style, and improves the generation quality of the model.
Smart Images

Figure CN119293180A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence, and in particular to a parameter optimization method, a text generation method, a device, a equipment and a medium. Background Art
[0002] With the continuous development of artificial intelligence technology, pre-trained language models are gradually being applied in various fields. The model can automatically generate corresponding generative answer texts based on the input question texts. Among them, the model has sampling parameters, which are used to control the language style of the generative answer texts.
[0003] In the related art, the above sampling parameters are usually manually adjusted by R&D personnel based on experience. However, this usually leads to low tuning efficiency and it is difficult to ensure that the pre-trained language model can reliably generate generative answer texts in a specified language style. Summary of the invention
[0004] The purpose of the present invention is to provide a parameter optimization method, a text generation method, an apparatus, a device and a medium, which can realize automatic tuning of sampling parameters and ensure that the generative answer text generated by the pre-trained language model fits the baseline answer text in terms of language style, thereby improving the tuning efficiency of the sampling parameters of the pre-trained language model.
[0005] In order to solve the above technical problems, the present invention provides a parameter optimization method, comprising:
[0006] Obtaining a question text, a baseline answer text corresponding to the question text, a pre-trained language model, and a parameter pool; wherein the parameter pool includes multiple sets of sampling parameters;
[0007] For each set of sampling parameters in the parameter pool, the question text is input into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text, and the fitness of the sampling parameters is determined according to the similarity between the generated answer text and the baseline answer text;
[0008] Using a genetic algorithm and the fitness to update sampling parameters of the parameter pool;
[0009] If the parameter pool does not meet the preset update stop condition, the step of inputting the question text into the pre-trained language model for which the sampling parameters have been set to obtain a generated answer text is entered;
[0010] If the parameter pool satisfies the preset update stop condition, the sampling parameter with the best fitness is set as the best sampling parameter.
[0011] Optionally, the step of inputting the question text into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text comprises:
[0012] Using the sampling parameters to adjust the parameters of the pre-trained language model;
[0013] The question text is input into the pre-trained language model with adjusted parameters, so that the pre-trained language model performs sampling processing according to the adjusted sampling parameters to obtain the generated answer text.
[0014] Optionally, determining the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text includes:
[0015] Calculating similarity between the baseline answer text and the generated answer text using a plurality of preset evaluation algorithms to obtain a plurality of similarities;
[0016] The fitness of the sampling parameters is determined using the multiple similarities.
[0017] Optionally, there are multiple question-answer text groups formed by the question text and the baseline answer text;
[0018] The using the multiple similarities to determine the fitness of the sampling parameters includes:
[0019] Determine the sub-fitness of the sampling parameter for each question and answer text group by using a plurality of similarities corresponding to the baseline answer text in each question and answer text group;
[0020] The fitness of the sampling parameters is determined using all of the sub-fitnesses.
[0021] Optionally, after the sampling parameters in the parameter pool are updated by using the genetic algorithm and the fitness, the method further includes:
[0022] Determine whether the cumulative update number corresponding to the parameter pool reaches a preset value;
[0023] If the cumulative update times reaches the preset value, it is determined that the parameter pool meets the preset optimization stop condition;
[0024] If the cumulative number of updates does not reach the preset value, then calculating the fitness difference generated by the parameter pool in the two most recent updates, and determining whether the fitness difference is less than a preset threshold;
[0025] If the fitness difference is less than the preset threshold, it is determined that the parameter pool meets the preset optimization stop condition;
[0026] If the fitness difference is not less than the preset threshold, it is determined that the parameter pool does not meet the preset optimization stop condition.
[0027] Optionally, the fitness is positively correlated with the similarity;
[0028] The step of setting the sampling parameter with the best fitness as the best sampling parameter comprises:
[0029] The sampling parameter with the maximum fitness is set as the optimal sampling parameter.
[0030] Optionally, the updating of sampling parameters of the parameter pool by using a genetic algorithm and the fitness comprises:
[0031] Convert each set of sampling parameters in the parameter pool into a chromosome vector; wherein the chromosome vector contains each parameter value of the sampling parameter;
[0032] Comparing the fitness of the chromosome vectors in pairs, and filtering out chromosome vectors with smaller fitness, so as to retain a preset number of parent chromosome vectors; wherein the preset number is less than the total number of the sampling parameters;
[0033] Among the parent chromosome vectors, cross processing is performed on the parent chromosome vectors in pairs to obtain a first new chromosome vector;
[0034] In the parent chromosome vector, according to the preset numerical adjustment range corresponding to each parameter value, randomly select parameter values from the parent chromosome vector for random numerical adjustment to obtain a second new chromosome vector;
[0035] An updated sampling parameter is determined using the parent chromosome vector, the first new chromosome vector, and the second new chromosome vector.
[0036] Optionally, the step of obtaining a question text, a baseline answer text corresponding to the question text, a pre-trained language model, and a parameter pool includes:
[0037] Outputting a preset display interface to a display device; wherein the display interface includes a plurality of input controls;
[0038] Receive the input question-answering dataset file path, pre-trained language model file path and initial sampling parameters through the input control;
[0039] Acquire a question and answer dataset according to the question and answer dataset file path, and acquire the question text and the baseline answer text from the question and answer dataset;
[0040] Load the pre-trained language model according to the pre-trained language model file path;
[0041] The parameter pool is created according to the initial sampling parameters.
[0042] The present invention also provides a text generation method, comprising:
[0043] Obtaining optimal sampling parameters; wherein the optimal sampling parameters are generated using the parameter optimization method described above;
[0044] Using the optimal sampling parameters to adjust the parameters of the pre-trained language model;
[0045] The input user question text is obtained, the pre-trained language model with adjusted input parameters of the user question text is input to obtain a generative answer text, and the generative answer text is output.
[0046] The present invention also provides a parameter optimization device, comprising:
[0047] An acquisition module, used to acquire a question text, a baseline answer text corresponding to the question text, a pre-trained language model and a parameter pool; wherein the parameter pool includes multiple sets of sampling parameters;
[0048] A testing module, for inputting the question text into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text for each set of sampling parameters in the parameter pool, and determining the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text;
[0049] An updating module, used for updating the sampling parameters of the parameter pool by using a genetic algorithm and the fitness;
[0050] A loop control module, configured to, if the parameter pool does not satisfy a preset update stop condition, enter a step of inputting the question text into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text;
[0051] The setting module is used to set the sampling parameter with the best fitness as the best sampling parameter if the parameter pool meets the preset update stop condition.
[0052] The present invention also provides a text generation device, comprising:
[0053] A parameter acquisition module, used to acquire optimal sampling parameters; wherein the optimal sampling parameters are generated by using the parameter optimization method as described above;
[0054] A parameter adjustment module, used to adjust the parameters of the pre-trained language model using the optimal sampling parameters;
[0055] The online service module is used to obtain an input user question text, input the user question text into a pre-trained language model with adjusted input parameters to obtain a generated answer text, and output the generated answer text.
[0056] The present invention also provides an electronic device, comprising:
[0057] Memory for storing computer programs;
[0058] A processor is used to implement the parameter optimization method and / or the text generation method as described above when executing the computer program.
[0059] The present invention also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are loaded and executed by a processor, the parameter optimization method and / or the text generation method as described above are implemented.
[0060] The present invention provides a parameter optimization method, comprising: obtaining a question text, a baseline answer text corresponding to the question text, a pre-trained language model and a parameter pool; the parameter pool contains multiple groups of sampling parameters; for each group of sampling parameters in the parameter pool, inputting the question text into the pre-trained language model with the sampling parameters set to obtain a generated answer text, and determining the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text; updating the sampling parameters of the parameter pool by using a genetic algorithm and the fitness; if the parameter pool does not meet a preset update stop condition, entering the step of inputting the question text into the pre-trained language model with the sampling parameters set to obtain a generated answer text; if the parameter pool meets the preset update stop condition, setting the sampling parameters with the best fitness as the best sampling parameters.
[0061] It can be seen that the present invention can first obtain the question text, the baseline answer text corresponding to the question text, the pre-trained language model and the parameter pool, wherein the parameter pool contains multiple sets of sampling parameters. Subsequently, for each set of sampling parameters in the parameter pool, the present invention inputs the question text into the pre-trained language model with the sampling parameters set to obtain the generated answer text, and determines the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text, so as to test the similarity of the generated answer text generated by each set of sampling parameters and the baseline answer text in terms of language style. Subsequently, the present invention can use the genetic algorithm and fitness to update the sampling parameters of the parameter pool, so as to update the potential sampling parameters with better fitness from the parameter pool based on the genetic algorithm. Furthermore, if the parameter pool does not meet the preset update stop condition, the parameter pool can continue to be updated; if the parameter pool meets the preset update stop condition, the sampling parameters with the best fitness are set as the best sampling parameters. In this way, the present invention can realize the automatic tuning of the sampling parameters, and can ensure that the generated answer text generated by the pre-trained language model fits the baseline answer text in terms of language style, thereby improving the tuning efficiency of the sampling parameters of the pre-trained language model. The present invention also provides a text generation method, a parameter optimization device, a text generation device, an electronic device and a computer-readable storage medium, which have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS
[0062] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0063] Figure 1 A flow chart of a parameter optimization method provided by an embodiment of the present invention;
[0064] Figure 2 A flowchart of a text generation method provided by an embodiment of the present invention;
[0065] Figure 3 A schematic diagram of a processing flow of a pre-trained language model inference optimization system provided by an embodiment of the present invention;
[0066] Figure 4 A structural block diagram of a parameter optimization device provided by an embodiment of the present invention;
[0067] Figure 5 A structural block diagram of a text generation device provided by an embodiment of the present invention;
[0068] Figure 6The present invention provides a structural block diagram of an electronic device. DETAILED DESCRIPTION
[0069] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0070] Pre-trained language models are machine learning models used to understand and generate natural language. Common pre-trained language models include large language models (LLM). When generating text content, such models usually parse the input text first, predict tokens one by one based on the parsing results, and then decode the obtained token sequence into natural language text. Among them, token is the encoding form of the smallest text unit, which can be a word, a punctuation mark, a number, a character, a subword, etc. When predicting the next token, the pre-trained language model usually generates multiple candidate tokens and samples these multiple candidate tokens to select a suitable token. Among them, the effect of sampling processing is affected by sampling parameters. Commonly used sampling parameters include temperature parameters, top-k and top-p. The temperature parameter can adjust the standard deviation of the model prediction distribution, thereby affecting the creativity and conservatism of the generated text, while top-k and top-p further control the uncertainty of the generated content by limiting the number of words considered from the probability distribution. In other words, the sampling parameters work together in the process of model text generation to regulate the randomness and relevance of the generated text.
[0071] Take news summary generation and creative writing as examples. For news summary generation, it needs to accurately and objectively reflect the original content, and may prefer a lower temperature and smaller top-k and top-p values to ensure that the generated summary is highly consistent with the original text. For creative writing, it requires higher creativity and diversity, and may need to increase the temperature and increase the top-k and top-p values to encourage the model to generate more novel and unique expressions.
[0072] In the related art, in order to ensure that the pre-trained language model outputs a generative answer text in a specified language style, it is usually necessary to tune the above-mentioned sampling parameters. However, the tuning of this parameter is usually manually adjusted by R&D personnel based on experience. Obviously, this is usually prone to lower tuning efficiency, and it is difficult to ensure that the pre-trained language model can reliably generate a generative answer text in a specified language style. In view of this, in order to address the technical problem of how to efficiently optimize the sampling parameters of a pre-trained language model, the present invention can provide a parameter optimization method that can achieve automatic tuning of the sampling parameters, and can ensure that the generative answer text generated by the pre-trained language model fits the baseline answer text in terms of language style, thereby improving the tuning efficiency of the sampling parameters of the pre-trained language model.
[0073] For easier understanding, please refer to Figure 1 , Figure 1 A flow chart of a parameter optimization method provided by an embodiment of the present invention, the method may include:
[0074] S101. Obtain a question text, a baseline answer text corresponding to the question text, a pre-trained language model, and a parameter pool; wherein the parameter pool includes multiple groups of sampling parameters.
[0075] In this step, first, the question text, the baseline answer text corresponding to the question text, the pre-trained language model and the parameter pool can be obtained. Among them, the question text and the baseline answer text form a question and answer text group, and there can be multiple groups of question and answer text groups. The baseline answer text has a specified language style. Ideally, the pre-trained language model needs to generate a generative answer text with a language style close to the baseline answer text. The pre-trained language model has been trained using a large amount of training data. It should be pointed out that this embodiment only adjusts the sampling parameters in the model, and does not adjust other model parameters. The parameter pool contains multiple groups of sampling parameters, each group of sampling parameters can include the above-mentioned temperature parameters, top-k, top-p and other parameter values, and these sampling parameters can be set manually or generated randomly. In this embodiment, the performance of different sampling parameters in the pre-trained language model is tested to select the best performing sampling parameter combination, so this parameter pool is set to store different sampling parameter combinations.
[0076] It should be noted that this embodiment does not limit the number of question and answer text groups and the actual text content, which can be set according to actual application requirements. This embodiment also does not limit the number of sampling parameter groups that can be included in the parameter pool, which can also be set according to actual application requirements.
[0077] Furthermore, for the convenience of users, a display interface can be provided, and multiple input controls can be set in the interface to facilitate users to input the specified question and answer dataset (including the above-mentioned question and answer text group), pre-trained language model and initial sampling parameters. The above-mentioned input controls can include input boxes, sliders, buttons, etc. Users input the question and answer dataset file path, pre-trained language model file path, and initial sampling parameters through the above-mentioned input controls; and the execution device of this method can receive information through the input controls and perform corresponding search and loading operations.
[0078] Based on this, the step of obtaining the question text, the baseline answer text corresponding to the question text, the pre-trained language model and the parameter pool may include:
[0079] Step 11: Output a preset display interface to a display device; wherein the display interface includes a plurality of input controls.
[0080] Step 12: Receive the input question-answering dataset file path, pre-trained language model file path and initial sampling parameters through the input control.
[0081] Step 13: Obtain a question and answer dataset according to the question and answer dataset file path, and obtain the question text and the baseline answer text from the question and answer dataset.
[0082] Step 14: Load the pre-trained language model according to the pre-trained language model file path.
[0083] Step 15: Create the parameter pool according to the initial sampling parameters.
[0084] It should be noted that the present embodiment does not limit the specific display interface form and input control form, which can be set according to actual application requirements.
[0085] S102. For each set of sampling parameters in the parameter pool, the question text is input into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text, and the fitness of the sampling parameters is determined according to the similarity between the generated answer text and the baseline answer text.
[0086] In this step, for each set of sampling parameters in the parameter pool, this embodiment first needs to determine its corresponding fitness, which is a quantitative representation of the performance of this set of sampling parameters in guiding text generation. Specifically, this step can input the question text into a pre-trained language model with set sampling parameters to obtain a generative answer text, and determine the fitness of the sampling parameters based on the similarity between the generative answer text and the baseline answer text. In other words, this embodiment first needs to use the sampling parameters to adjust the parameters of the pre-trained language model so that the pre-trained language model performs sampling processing according to the adjusted sampling parameters, and then the question text can be input into the pre-trained language model with adjusted parameters to obtain generative answer texts of different language styles corresponding to the same question text.
[0087] Based on this, the step of inputting the question text into the pre-trained language model for which the sampling parameters have been set to obtain the generated answer text may include:
[0088] Step 21: Using the sampling parameters to adjust the parameters of the pre-trained language model;
[0089] Step 22: Input the question text into the pre-trained language model with adjusted parameters, so that the pre-trained language model performs sampling processing according to the adjusted sampling parameters to obtain the generated answer text.
[0090] Furthermore, this step can calculate the similarity between different generated answer texts and the baseline answer text corresponding to the same question text, which indicates the degree of similarity between the two texts in terms of language style. Furthermore, the fitness of the sampling parameters can be determined based on the similarity to quantify its expressiveness.
[0091] It should be pointed out that this embodiment does not limit the numerical correlation form between fitness and similarity. For example, fitness and similarity can be positively correlated, that is, the greater the similarity, the greater the fitness; fitness and similarity can also be negatively correlated, that is, the greater the similarity, the smaller the fitness. It can be set according to actual application requirements.
[0092] Furthermore, this embodiment does not limit the calculation method of text similarity, and reference may be made to related technologies. For example, both the generated answer text and the baseline answer text may be converted into vector form, and the similarity between the vectors may be used as the text similarity; the METEOR indicator (Metric for Evaluation of Translation with Explicit Ordering) may also be used to determine the similarity between the generated answer text and the baseline answer text, wherein this indicator, as an evaluation indicator, may comprehensively consider factors such as vocabulary matching, word order, and synonyms, and the higher the value, the closer the generated text is to the reference text in semantics and expression, thereby reflecting a better quality of the generated result. It is worth noting that this embodiment may aggregate the similarities obtained in a variety of ways into the fitness of the sampling parameters, that is, the similarity between the generated answer text and the baseline answer text in terms of wording and sentence structure may be evaluated from multiple dimensions, thereby improving the reliability of the fitness.
[0093] Based on this, determining the adaptability of the sampling parameters according to the similarity between the generated answer text and the baseline answer text may include:
[0094] Step 31: Calculate similarity between the baseline answer text and the generated answer text using multiple preset evaluation algorithms to obtain multiple similarities;
[0095] Step 32: Determine the fitness of the sampling parameters using the multiple similarities.
[0096] It should be noted that this embodiment does not limit how to use the multiple similarities to determine the fitness of the sampling parameters. For example, it can be determined by weighted calculation or simply by numerical averaging. It can be set according to actual application requirements.
[0097] Furthermore, considering that there may be multiple question-answer text groups, and the sampling parameters may perform differently for different question-answer text groups. In order to improve the comprehensiveness of fitness, this embodiment can use multiple similarities corresponding to the baseline answer texts in each question-answer text group to determine the sub-fitness of the sampling parameters for each question-answer text group, and use all the sub-fitnesses to determine the overall fitness of the sampling parameters.
[0098] Based on this, there are multiple question-answer text groups formed by the question text and the baseline answer text; the use of the multiple similarities to determine the fitness of the sampling parameters may include:
[0099] Step 41: using a plurality of similarities corresponding to the baseline answer texts in each question and answer text group, determining the sub-fitness of the sampling parameter for each question and answer text group;
[0100] Step 42: Determine the fitness of the sampling parameters using all the sub-fitnesses.
[0101] It should be noted that this embodiment does not limit how to use all the sub-fitnesses to determine the fitness of the sampling parameters. For example, it can be determined by weighted calculation or simply by numerical averaging. It can be set according to actual application requirements.
[0102] S103: Update sampling parameters of the parameter pool using a genetic algorithm and the fitness.
[0103] This step will use genetic algorithms and fitness to update the sampling parameters of the parameter pool. Among them, the genetic algorithm is a computational model of the biological evolution process that simulates the natural selection and genetics mechanism of biological evolution. When solving more complex combinatorial optimization problems, it can be optimized from the perspective of population evolution. The genetic algorithm is an iterative update algorithm, and each round of update can include three steps: individual selection, chromosome crossover, and chromosome mutation. For this embodiment, the individual selection step can first screen out some sampling parameters with better fitness performance from the sampling pool, and screen out the remaining sampling parameters with poor fitness performance; then, the chromosome crossover and chromosome mutation steps can be based on the retained sampling parameters to further expand new sampling parameter combinations. Obviously, the genetic algorithm has a wider sampling parameter matching search range, and can adaptively optimize the sampling parameters, which helps this embodiment to achieve reliable automatic optimization of sampling parameters.
[0104] Furthermore, the present embodiment does not limit the iterative stop condition of the genetic algorithm (hereinafter referred to as the preset update stop condition), which can be set according to actual application requirements. For example, the maximum number of updates can be set, and when the cumulative number of updates of the parameter pool reaches the maximum value, the iterative update is stopped; for another example, the fitness difference generated by the parameter pool in the last two updates can be detected, and it can be determined whether the fitness difference is less than the preset threshold. If it is less than, it means that the fitness change has slowed down, and the iterative update can be stopped; if it is not less than, it means that the fitness change is drastic and it is necessary to continue the iterative update. Among them, the fitness difference can be either the difference of the best fitness or the difference of the fitness tie value. Of course, the above conditions can also be used in combination to save parameter optimization time as much as possible.
[0105] Based on this, after the sampling parameters in the parameter pool are updated by using the genetic algorithm and the fitness, the following steps may also be included:
[0106] Step 51: Determine whether the cumulative update times corresponding to the parameter pool reaches a preset value; if the cumulative update times reaches the preset value, proceed to step 52; if the cumulative update times does not reach the preset value, proceed to step 53.
[0107] Step 52: Determine whether the parameter pool satisfies the preset optimization stop condition.
[0108] Step 53: Calculate the fitness difference generated by the parameter pool in the two most recent updates, and determine whether the fitness difference is less than a preset threshold; if the fitness difference is less than the preset threshold, proceed to step 54; if the fitness difference is not less than the preset threshold, proceed to step 55.
[0109] Step 54: Determine whether the parameter pool satisfies the preset optimization stop condition.
[0110] Step 55: Determine whether the parameter pool satisfies the preset optimization stop condition.
[0111] It should be noted that this embodiment does not preset the specific values of the numerical values or the preset threshold values, which can be set according to actual application requirements.
[0112] S104, judging whether the parameter pool satisfies the preset update stop condition, if so, proceeding to step S102, if not, proceeding to step S105.
[0113] In this step, if the parameter pool does not meet the preset update stop condition, step S102 can be re-entered to determine the fitness corresponding to each updated sampling parameter; if the parameter pool does not meet the preset update stop condition, the sampling parameter with the best fitness can be set as the best sampling parameter.
[0114] S105: If the parameter pool satisfies the preset update stop condition, the sampling parameter with the best fitness is set as the best sampling parameter.
[0115] In this step, for example, when the fitness is positively correlated with the similarity, the sampling parameter with the maximum fitness may be set as the optimal sampling parameter.
[0116] Based on the above embodiments, the present invention can first obtain a question text, a baseline answer text corresponding to the question text, a pre-trained language model and a parameter pool, wherein the parameter pool contains multiple sets of sampling parameters. Subsequently, for each set of sampling parameters in the parameter pool, the present invention inputs the question text into the pre-trained language model with the sampling parameters set to obtain a generated answer text, and determines the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text, so as to test the similarity of the generated answer text generated by each set of sampling parameters with the baseline answer text in terms of language style. Subsequently, the present invention can use a genetic algorithm and fitness to update the sampling parameters of the parameter pool, so as to update potential sampling parameters with better fitness from the parameter pool based on the genetic algorithm. Furthermore, if the parameter pool does not meet the preset update stop condition, the parameter pool can continue to be updated; if the parameter pool meets the preset update stop condition, the sampling parameters with the best fitness are set as the best sampling parameters. In this way, the present invention can realize automatic tuning of the sampling parameters, and can ensure that the generated answer text generated by the pre-trained language model fits the baseline answer text in terms of language style, thereby improving the tuning efficiency of the sampling parameters of the pre-trained language model.
[0117] Based on the above embodiment, the specific steps of updating the sampling parameters of the parameter pool using the genetic algorithm and the fitness are introduced below. Based on this, the updating of the sampling parameters of the parameter pool using the genetic algorithm and the fitness may include:
[0118] Step 61: Convert each set of sampling parameters in the parameter pool into a chromosome vector; wherein the chromosome vector contains each parameter value of the sampling parameters.
[0119] In this step, each set of sampling parameters in the parameter pool can first be converted into a chromosome vector for subsequent individual selection, chromosome crossover and chromosome mutation. The chromosome vector contains each parameter value of the sampling parameter. It can be seen that the parameter pool constitutes a population, and each individual in the population is each set of sampling parameters.
[0120] Step 62: Compare the fitness of the chromosome vectors in pairs, and filter out chromosome vectors with smaller fitness, so as to retain a preset number of parent chromosome vectors; wherein the preset number is less than the total number of the sampling parameters.
[0121] In this step, chromosome vectors with better fitness can be screened and retained, and the remaining chromosome vectors with poor fitness can be screened out to retain a small number of high-quality parent chromosome vectors. The individual selection process adopts a competitive strategy, that is, the fitness of chromosome vectors is compared two by two, chromosome vectors with larger fitness are retained, and chromosome vectors with smaller fitness are screened out, thereby retaining a preset number of parent chromosome vectors.
[0122] Step 63: among the parent chromosome vectors, cross processing is performed on the parent chromosome vectors in pairs to obtain a first new chromosome vector.
[0123] In this step, the parent chromosome vectors may be cross-processed in pairs to obtain the first new chromosome vector through chromosome interaction.
[0124] Step 64: In the parent chromosome vector, according to the preset numerical adjustment range corresponding to each parameter value, randomly select parameter values from the parent chromosome vector for random numerical adjustment to obtain a second new chromosome vector.
[0125] In this step, parameter values may be randomly selected from the parent chromosome vector, and the selected parameter values may be randomly adjusted within a corresponding adjustment range to achieve a chromosome mutation effect, thereby obtaining a second new chromosome vector.
[0126] It is worth noting that both step 63 and step 64 are used to expand the population size from the preset number to the original size to expand the search range of the sampling parameters.
[0127] Step 65: Determine updated sampling parameters using the parent chromosome vector, the first new chromosome vector and the second new chromosome vector.
[0128] Based on the above embodiment, the text generation method provided by the embodiment of the present invention is introduced below. Figure 2 , Figure 2 A flowchart of a text generation method provided by an embodiment of the present invention, the method may include:
[0129] S201, obtaining optimal sampling parameters; wherein the optimal sampling parameters are generated using the parameter optimization method as described above;
[0130] S202, adjusting parameters of the pre-trained language model using the optimal sampling parameters;
[0131] S203, obtaining an input user question text, applying the user question text to a pre-trained language model after adjusting input parameters to obtain a generative answer text, and outputting the generative answer text.
[0132] In this embodiment, since the optimal sampling parameters have been debugged using the above method, it can be ensured that the pre-trained language model can achieve the desired text generation effect when performing text generation tasks of the same language style type proposed by the user, thereby ensuring the user experience.
[0133] Based on the above embodiments, the above parameter optimization method and text generation method are introduced below based on specific schematic diagrams. Figure 3 , Figure 3 A schematic diagram of a processing flow of a pre-trained language model reasoning optimization system provided by an embodiment of the present invention. The present invention proposes a pre-trained language model reasoning optimization and reasoning system for generating high-quality answers, which may include:
[0134] 1. Create a parameter initialization module that is designed to receive and process the preprocessed relevance and general question-answering datasets.
[0135] The user inputs the path of the pre-trained language model, the pre-processed relevance and general question-answering dataset path, and the initial values of temperature, top_p, and top_k into this module. All of this input information is written in the corresponding positions on the interface.
[0136] Use a code editor to design a display interface (GUI), which may include adding input controls such as input boxes, sliders, and buttons to receive user input of model sampling parameters such as initial values of temperature, top_p, and top_k. The temperature parameter controls the randomness of the generated text, while top_p and top_k are used to limit the selection range of candidate words during the sampling process to optimize the quality and diversity of the generated text. Next, the first model inference is performed using the input model, dataset, and initial parameter values. During the inference process, the model generates the corresponding answer based on the input question and context, combined with the set sampling parameters. The generated answer is then captured by the system and automatically saved to the specified file for subsequent analysis, evaluation, or presentation.
[0137] 2. Parameter optimization module, which aims to optimize the quality of generated text by automatically adjusting sampling parameters (such as temperature, top_p, top_k, etc.).
[0138] This module is connected to the parameter initialization module in step 1. After completing the first inference and saving the inference result in step 1, it will return the "Inference Completed" prompt message to the interface in step 1. At this time, the user clicks the "OK" button in the interface to send the file path for saving the inference result to the parameter optimization module.
[0139] Next, the module reads two key data sources: one is the generated result file saved by the first inference in step 1, and the other is the "baseline answer text" of the input data in step 1, which is regarded as a reference and high-quality text output. In order to quantify the similarity between the generated text and the reference text, the module can calculate the METEOR score and cosine similarity between the two.
[0140] As an evaluation indicator, the METEOR score takes into account factors such as vocabulary matching, word order, and synonyms. The higher the value, the closer the generated text is to the reference text in terms of semantics and expression, thus reflecting the better quality of the generated result. Cosine similarity is a measure of the degree of similarity between two vectors in direction, and its value range is [-1, 1]. In the context of text similarity, text is usually converted into vectors (for example, through bag-of-words models, TF-IDF (termfrequency–inverse document frequency), or word embedding), and then cosine similarity is used to evaluate the proximity of the two text vectors in the semantic space.
[0141] Based on the goal of maximizing the METEOR score and cosine similarity close to 1, the module uses a genetic algorithm to iteratively select the best sampling parameters. First, define the encoding method and search space of the sampling parameters, randomly generate the initial population, and each individual represents a set of sampling parameter configurations. Then, use the large language model to infer the data set in step 1 based on these parameters to generate text, and calculate the METEOR score and cosine similarity between the generated text and the reference text, so as to construct a fitness function to evaluate individual performance.
[0142] Next, the genetic algorithm enters the iterative optimization phase. In each generation, individuals with high fitness are retained as parents through selection operations, and offspring are generated by exchanging genetic information between parents through crossover operations, and randomness is introduced through mutation operations to increase population diversity. This process aims to explore and develop high-quality areas in the solution space.
[0143] As the iterations proceed, the population gradually adapts to the goal of maximizing the METEOR score and cosine similarity, and the fitness of the optimal individual continues to improve. When the preset stop condition is met (such as reaching the maximum number of iterations or the fitness improvement tends to be flat), the algorithm terminates and outputs the individual with the highest current fitness as the optimal sampling parameter combination.
[0144] During this process, for a specific type of input problem, this module will explore and determine a set of sampling parameter combinations that can produce the highest METEOR score and a cosine similarity close to 1, thereby improving the pertinence and effectiveness of the generated results.
[0145] For example, when a scientific question is input in step (1), after being processed by this module, when temperature is set to 0.8, top_p is 0.95, and top_k is 50, the METEOR score between the generated scientific text and the reference text reaches the highest and the cosine similarity is close to 1, indicating that this set of parameters is the best for generating scientific questions.
[0146] 3. Result output module: This module receives and applies a set of optimal sampling parameters determined in step 2. These parameters are carefully adjusted for specific types of problems, aiming to maximize the quality and efficiency of generated text.
[0147] Receive a new question of the same type as in step 1 as input, then load the optimization model and its weight information and the optimal sampling parameters obtained in step 2 for inference.
[0148] This reasoning process makes full use of the optimized sampling parameters, which can guide the model to focus more on producing relevant and high-quality output when generating text. By using optimized models and sampling parameters for reasoning, the result output module can significantly improve the reasoning efficiency of large language models. The optimized parameter combination reduces the randomness and uncertainty of the model during the generation process, allowing the model to converge to high-quality answers more quickly, thereby reducing unnecessary computational overhead. Taking medical consultation as an example, when a new question about disease diagnosis is input, the result output module will use the sampling parameters optimized for the medical field to guide the pre-trained language model to quickly generate accurate and detailed condition analysis and suggestions, providing patients with high-quality medical services while ensuring efficient use of computing resources.
[0149] The parameter optimization device, text generation device, electronic device, computer program product, and computer-readable storage medium provided in the embodiments of the present invention are introduced below. The parameter optimization device, text generation device, electronic device, computer program product, and computer-readable storage medium described below can be referenced to each other with the parameter optimization method and text generation method described above.
[0150] Please refer to Figure 4 , Figure 4 A structural block diagram of a parameter optimization device provided by an embodiment of the present invention, the device may include:
[0151] An acquisition module 401 is used to acquire a question text, a baseline answer text corresponding to the question text, a pre-trained language model and a parameter pool; the parameter pool includes multiple groups of sampling parameters;
[0152] The testing module 402 is used for inputting the question text into the pre-trained language model for which the sampling parameters have been set to obtain a generated answer text for each set of sampling parameters in the parameter pool, and determining the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text;
[0153] An updating module 403 is used to update the sampling parameters of the parameter pool by using a genetic algorithm and the fitness;
[0154] A loop control module 404 is used for, if the parameter pool does not meet the preset update stop condition, entering the step of inputting the question text into the pre-trained language model with the sampling parameters set to obtain a generated answer text;
[0155] The setting module 405 is configured to set the sampling parameter with the best fitness as the best sampling parameter if the parameter pool meets the preset update stop condition.
[0156] Optionally, the testing module 402 includes:
[0157] A parameter adjustment submodule, used to adjust the parameters of the pre-trained language model using the sampling parameters;
[0158] The model testing submodule is used to input the question text into the pre-trained language model with adjusted parameters, so that the pre-trained language model performs sampling processing according to the adjusted sampling parameters to obtain the generated answer text.
[0159] Optionally, the testing module 402 includes:
[0160] A similarity calculation submodule, used to calculate the similarity between the baseline answer text and the generated answer text using multiple preset evaluation algorithms to obtain multiple similarities;
[0161] The fitness calculation submodule is used to determine the fitness of the sampling parameters using the multiple similarities.
[0162] Optionally, there are multiple question-answer text groups formed by the question text and the baseline answer text;
[0163] The fitness calculation submodule includes:
[0164] A sub-fitness calculation unit, used to determine the sub-fitness of the sampling parameter for each question and answer text group by using multiple similarities corresponding to the baseline answer text in each question and answer text group;
[0165] A fitness calculation unit is used to determine the fitness of the sampling parameters using all the sub-fitnesses.
[0166] Optionally, the device may further include:
[0167] A first judgment module is used to judge whether the cumulative update number corresponding to the parameter pool reaches a preset value; if the cumulative update number reaches the preset value, it is determined that the parameter pool meets the preset optimization stop condition;
[0168] The second judgment module is used to calculate the fitness difference generated by the parameter pool in the two most recent updates if the cumulative number of updates does not reach the preset value, and judge whether the fitness difference is less than a preset threshold; if the fitness difference is less than the preset threshold, it is judged that the parameter pool meets the preset optimization stop condition; if the fitness difference is not less than the preset threshold, it is judged that the parameter pool does not meet the preset optimization stop condition.
[0169] Optionally, the fitness is positively correlated with the similarity;
[0170] The setting module 405 can be used to:
[0171] The sampling parameter with the maximum fitness is set as the optimal sampling parameter.
[0172] Optionally, the updating module 403 includes:
[0173] A conversion submodule, used for converting each set of sampling parameters in the parameter pool into a chromosome vector; wherein the chromosome vector includes each parameter value of the sampling parameter;
[0174] An individual selection submodule, used for comparing the fitness of the chromosome vectors in pairs, and filtering out chromosome vectors with smaller fitness, so as to retain a preset number of parent chromosome vectors; wherein the preset number is less than the total number of the sampling parameters;
[0175] A chromosome crossover submodule, used for performing crossover processing on the parent chromosome vectors in pairs among the parent chromosome vectors to obtain a first new chromosome vector;
[0176] A chromosome mutation submodule, used for randomly selecting parameter values from the parent chromosome vector to perform random numerical adjustment according to a preset numerical adjustment range corresponding to each parameter value in the parent chromosome vector, so as to obtain a second new chromosome vector;
[0177] A submodule is provided, for determining updated sampling parameters using the parent chromosome vector, the first new chromosome vector and the second new chromosome vector.
[0178] Optionally, the acquisition module 401 includes:
[0179] A display submodule, used to output a preset display interface to a display device; wherein the display interface includes a plurality of input controls;
[0180] A receiving submodule, used to receive the input question and answer dataset file path, pre-trained language model file path and initial sampling parameters through the input control;
[0181] An acquisition submodule, used to acquire a question-and-answer dataset according to the question-and-answer dataset file path, and acquire the question text and the baseline answer text from the question-and-answer dataset;
[0182] A loading submodule, used to load the pre-trained language model according to the pre-trained language model file path;
[0183] A creation submodule is used to create the parameter pool according to the initial sampling parameters.
[0184] Please refer to Figure 5 , Figure 5 A structural block diagram of a text generation device provided by an embodiment of the present invention, the device may include:
[0185] The parameter acquisition module 501 is used to acquire the optimal sampling parameters; wherein the optimal sampling parameters are generated by using the parameter optimization method as described above;
[0186] A parameter adjustment module 502, configured to adjust parameters of a pre-trained language model using the optimal sampling parameters;
[0187] The online service module 503 is used to obtain an input user question text, obtain a generated answer text by inputting the user question text into a pre-trained language model after adjusting the input parameters, and output the generated answer text.
[0188] Please refer to Figure 6 , Figure 6 This is a structural block diagram of an electronic device provided in an embodiment of the present invention. The embodiment of the present invention provides an electronic device 10, including a processor 11 and a memory 12; wherein the memory 12 is used to store a computer program; and the processor 11 is used to execute the parameter optimization method and / or text generation method provided in the aforementioned embodiment when executing the computer program.
[0189] For the specific process of the above-mentioned parameter optimization method and text generation method, reference may be made to the corresponding contents provided in the aforementioned embodiments, which will not be elaborated here.
[0190] Furthermore, the memory 12 as a carrier for storing resources may be a read-only memory, a random access memory, a magnetic disk or an optical disk, etc., and the storage method may be temporary storage or permanent storage.
[0191] In addition, the electronic device 10 also includes a power supply 13, a communication interface 14, an input / output interface 15 and a communication bus 16; wherein the power supply 13 is used to provide working voltage for each hardware device on the electronic device 10; the communication interface 14 can create a data transmission channel between the electronic device 10 and an external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present invention, and is not specifically limited here; the input / output interface 15 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs, and is not specifically limited here.
[0192] An embodiment of the present invention further provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the parameter optimization method and / or text generation method described in the above embodiments.
[0193] Since the embodiments of the computer program product part correspond to the embodiments of the parameter optimization method and text generation method part, please refer to the description of the embodiments of the parameter optimization method and text generation method part for the embodiments of the computer program product part, and will not be repeated here.
[0194] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the parameter optimization method and / or text generation method described in the above embodiment is implemented.
[0195] Since the embodiments of the computer-readable storage medium part correspond to the embodiments of the parameter optimization method and the text generation method part, the embodiments of the storage medium part refer to the description of the embodiments of the parameter optimization method and the text generation method part, which will not be repeated here.
[0196] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description.
[0197] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0198] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0199] The above is a detailed introduction to a parameter optimization method, a text generation method, a device, an equipment and a medium provided by the present invention. Specific examples are used herein to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of the present invention, the present invention can also be improved and modified in a number of ways, and these improvements and modifications also fall within the scope of protection of the present invention.
Claims
1. A parameter optimization method, characterized in that: include: Obtaining a question text, a baseline answer text corresponding to the question text, a pre-trained language model, and a parameter pool; wherein the parameter pool includes multiple sets of sampling parameters; For each set of sampling parameters in the parameter pool, the question text is input into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text, and the fitness of the sampling parameters is determined according to the similarity between the generated answer text and the baseline answer text; Using a genetic algorithm and the fitness to update sampling parameters of the parameter pool; If the parameter pool does not meet the preset update stop condition, the step of inputting the question text into the pre-trained language model for which the sampling parameters have been set to obtain a generated answer text is entered; If the parameter pool satisfies the preset update stop condition, the sampling parameter with the best fitness is set as the best sampling parameter.
2. The parameter optimization method according to claim 1, characterized in that: The step of inputting the question text into a pre-trained language model having the sampling parameters set to obtain a generated answer text comprises: Using the sampling parameters to adjust the parameters of the pre-trained language model; The question text is input into the pre-trained language model with adjusted parameters, so that the pre-trained language model performs sampling processing according to the adjusted sampling parameters to obtain the generated answer text.
3. The parameter optimization method according to claim 1, characterized in that: The step of determining the adaptability of the sampling parameters according to the similarity between the generated answer text and the baseline answer text includes: Calculating similarity between the baseline answer text and the generated answer text using a plurality of preset evaluation algorithms to obtain a plurality of similarities; The fitness of the sampling parameters is determined using the multiple similarities.
4. The parameter optimization method according to claim 1, characterized in that: After the sampling parameters in the parameter pool are updated by using the genetic algorithm and the fitness, the method further includes: Determine whether the cumulative update number corresponding to the parameter pool reaches a preset value; If the cumulative update times reaches the preset value, it is determined that the parameter pool meets the preset optimization stop condition; If the cumulative number of updates does not reach the preset value, then calculating the fitness difference generated by the parameter pool in the two most recent updates, and determining whether the fitness difference is less than a preset threshold; If the fitness difference is less than the preset threshold, it is determined that the parameter pool meets the preset optimization stop condition; If the fitness difference is not less than the preset threshold, it is determined that the parameter pool does not meet the preset optimization stop condition.
5. The parameter optimization method according to claim 1, characterized in that: The fitness is positively correlated with the similarity; The step of setting the sampling parameter with the best fitness as the best sampling parameter comprises: The sampling parameter with the maximum fitness is set as the optimal sampling parameter.
6. The parameter optimization method according to claim 5, characterized in that: The updating of sampling parameters of the parameter pool by using the genetic algorithm and the fitness comprises: Convert each set of sampling parameters in the parameter pool into a chromosome vector; wherein the chromosome vector contains each parameter value of the sampling parameter; Comparing the fitness of the chromosome vectors in pairs, and filtering out chromosome vectors with smaller fitness, so as to retain a preset number of parent chromosome vectors; wherein the preset number is less than the total number of the sampling parameters; Among the parent chromosome vectors, cross processing is performed on the parent chromosome vectors in pairs to obtain a first new chromosome vector; In the parent chromosome vector, according to the preset numerical adjustment range corresponding to each parameter value, randomly select parameter values from the parent chromosome vector for random numerical adjustment to obtain a second new chromosome vector; An updated sampling parameter is determined using the parent chromosome vector, the first new chromosome vector, and the second new chromosome vector.
7. The parameter optimization method according to claim 1, characterized in that: The obtaining of the question text, the baseline answer text corresponding to the question text, the pre-trained language model and the parameter pool includes: Outputting a preset display interface to a display device; wherein the display interface includes a plurality of input controls; Receive the input question-answering dataset file path, pre-trained language model file path and initial sampling parameters through the input control; Acquire a question and answer dataset according to the question and answer dataset file path, and acquire the question text and the baseline answer text from the question and answer dataset; Load the pre-trained language model according to the pre-trained language model file path; The parameter pool is created according to the initial sampling parameters.
8. A text generation method, characterized in that: include: Obtaining optimal sampling parameters; wherein the optimal sampling parameters are generated using the parameter optimization method according to any one of claims 1 to 7; Using the optimal sampling parameters to adjust the parameters of the pre-trained language model; The input user question text is obtained, the pre-trained language model with adjusted input parameters of the user question text is input to obtain a generative answer text, and the generative answer text is output.
9. A parameter optimization device, characterized in that: include: An acquisition module, used to acquire a question text, a baseline answer text corresponding to the question text, a pre-trained language model and a parameter pool; wherein the parameter pool includes multiple sets of sampling parameters; A testing module, for inputting the question text into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text for each set of sampling parameters in the parameter pool, and determining the fitness of the sampling parameters according to the similarity between the generated answer text and the baseline answer text; An updating module, used for updating the sampling parameters of the parameter pool by using a genetic algorithm and the fitness; A loop control module, configured to, if the parameter pool does not satisfy a preset update stop condition, enter a step of inputting the question text into a pre-trained language model for which the sampling parameters have been set to obtain a generated answer text; The setting module is used to set the sampling parameter with the best fitness as the best sampling parameter if the parameter pool meets the preset update stop condition.
10. A text generation device, characterized in that: include: A parameter acquisition module, used to acquire optimal sampling parameters; wherein the optimal sampling parameters are generated by using the parameter optimization method according to any one of claims 1 to 7; A parameter adjustment module, used to adjust the parameters of the pre-trained language model using the optimal sampling parameters; The online service module is used to obtain an input user question text, input the user question text into a pre-trained language model with adjusted input parameters to obtain a generated answer text, and output the generated answer text.
11. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the parameter optimization method as described in any one of claims 1 or 7 and / or the text generation method as described in claim 8 when executing the computer program.
12. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by the processor, the parameter optimization method according to any one of claims 1 or 7 and / or the text generation method according to claim 8 are implemented.
Citation Information
Patent Citations
Controllable text generation method based on generative pre-training model parameter fine adjustment
CN114297382A
Cross-language question answering system construction method and device based on generative multi-language model
CN115795009A
RAG block parameter optimization method based on genetic algorithm
CN118689977A
Method and system for analyzing and establishing trust in systems that include artificical intelligence systems
US20240202405A1
Cited By
Model iteration method and device based on evolutionary algorithm, equipment and storage medium
CN121145997A
Parameter optimization method and device based on grid search, equipment and medium
CN121858795A