Text generation method and device, equipment, storage medium and product

By using heuristic search algorithms and dynamic programming algorithms in large model decoding, we optimize the priority and selection of candidate words, and solve the problem of low text accuracy in large model decoding, and achieve higher text generation accuracy and correlation.

CN119940311APending Publication Date: 2025-05-06CHINA MERCHANTS BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510029451.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-08
Publication Date
2025-05-06

AI Technical Summary

Technical Problem

The accuracy of large-scale model decoding generates text is low. The existing greedy search strategy and probabilistic random sampling methods are each insufficient, and it is impossible to ensure the generation of accurate text sequences.

Method used

The heuristic search algorithm is used to assign priority to the candidate words generated by the big model, determine the target candidate words with the highest priority, and select the text generation path with the greatest joint probability through the dynamic programming algorithm to decode and generate the target text.

Benefits of technology

The accuracy of large-scale model decoding generates text is improved, and the generated text is optimized to ensure that the generated text is more accurate and relevant by optimizing the selection process of candidate words.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119940311A_ABST
    Figure CN119940311A_ABST
Patent Text Reader

Abstract

The invention discloses a text generation method and device, equipment, a storage medium and a product, and relates to the technical field of computers.The text generation method comprises the steps that when a first reply candidate word generated by a large model is received, a priority is allocated to the first reply candidate word according to a preset heuristic search algorithm, and the first reply candidate word is selected according to the priority; determining a first target candidate word with the highest priority; obtaining a second reply candidate word generated by the large model of the last round, selecting the second reply candidate word with the maximum joint probability for generating the first target candidate word according to a preset dynamic programming algorithm, and storing the second reply candidate word as a father node word of the first target candidate word; and when the first target candidate word meets a preset termination condition, obtaining a text generation path according to the corresponding father node word, and decoding to generate a target text. According to the method, the optimal text path of the candidate word is determined by adopting the heuristic search algorithm and the dynamic programming algorithm, and the target text is decoded, so that the accuracy of the text generated by large-model decoding is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to text generation methods, devices, equipment, storage media and products. Background Art

[0002] In the current application of large model training results, the decoding process usually uses greedy search or probability-based random sampling to generate text. Among them, the greedy search strategy (Greedy Search) selects the word with the highest probability each time, which is simple and easy to implement but often cannot generate the optimal solution. The random sampling strategy (Sampling) can increase the diversity of generation, but it also has serious defects, that is, randomly selecting the word with the lowest probability as the next word may lead to poor results.

[0003] The greedy search strategy or the decoding method based on probability random sampling in the related art each has its own shortcomings and cannot guarantee the generation of accurate text sequences, resulting in low accuracy of text generated by large model decoding. Summary of the invention

[0004] The main purpose of this application is to provide a text generation method, device, equipment, storage medium and product, aiming to solve the technical problem of low accuracy of text generated by large model decoding.

[0005] To achieve the above purpose, the present application proposes a text generation method, which comprises:

[0006] When receiving the first reply candidate word generated by the large model, assigning priorities to the first reply candidate words according to a preset heuristic search algorithm, and determining the first target candidate word with the highest priority;

[0007] Obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to the preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words;

[0008] When the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is generated by decoding.

[0009] In one embodiment, the step of assigning priorities to the first response candidate words according to a preset heuristic search algorithm and determining the first target candidate word with the highest priority includes:

[0010] Based on a preset greedy decision algorithm, quickly generate text for the first reply candidate word, and use the joint probability during text generation as a heuristic estimation cost;

[0011] The probability of selecting the first response candidate word is taken as the actual cost;

[0012] Combining the actual cost with the heuristic estimated cost to obtain a total cost of the first response candidate word;

[0013] According to the total cost, the first response candidate words are prioritized and allocated to determine the first target candidate word with the highest priority.

[0014] In one embodiment, the step of assigning a priority to the first reply candidate word includes:

[0015] Obtain a set of historical target candidate words and a set of historical response candidate words;

[0016] Traverse all the first reply candidate words, and determine whether the first reply candidate word is in the historical target candidate word set and the historical reply candidate word collection, wherein, if the first reply candidate word is included in the historical target candidate word set, skip the rest of the current loop and start the next loop iteration of the first reply candidate word.

[0017] In one embodiment, after the step of determining whether the first reply candidate word is in the historical target candidate word set and the historical reply candidate word set, the step further includes:

[0018] If the first reply candidate word is not included in the historical reply candidate word set, calculating and assigning a priority of the first reply candidate word in the current cycle, and adding the first reply candidate word in the current cycle to the historical reply candidate word set;

[0019] If the first reply candidate word is included in the historical reply candidate word set, the priority of the first reply candidate word in the current cycle is calculated and updated.

[0020] In one embodiment, the step of obtaining the second reply candidate word generated by the large model in the previous round, selecting the second reply candidate word with the largest joint probability of generating the first target candidate word according to a preset dynamic programming algorithm, and saving it as the parent node word of the first target candidate word includes:

[0021] Get the second reply candidate words generated by the big model in the previous round;

[0022] Generate a large model text for the second response candidate word, and screen the second response candidate word that generates the first target candidate word;

[0023] According to a preset dynamic programming algorithm, the second response candidate word with the largest joint probability of generating the first target candidate word is selected and saved as the parent node word of the first target candidate word.

[0024] In one embodiment, when the first target candidate word meets a preset termination condition, the step of obtaining a text generation path according to the corresponding parent node word and decoding to generate a target text includes:

[0025] When the first target candidate word meets a preset termination condition, determining the parent node of the first target candidate word, recursively acquiring the parent node until the parent node is empty, and obtaining a text generation path;

[0026] According to the text generation path, the target text is generated by decoding.

[0027] In addition, to achieve the above-mentioned purpose, the present application also proposes a text generation device, which includes:

[0028] An allocation module, configured to, when receiving the first reply candidate word generated by the large model, allocate a priority to the first reply candidate word according to a preset heuristic search algorithm, and determine a first target candidate word with the highest priority;

[0029] A selection module is used to obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to a preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words;

[0030] A decoding module is used to obtain a text generation path according to the corresponding parent node word and decode to generate a target text when the first target candidate word meets a preset termination condition.

[0031] In addition, to achieve the above-mentioned purpose, the present application also proposes a text generation device, which includes: 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 text generation method described above.

[0032] 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 a processor, the steps of the text generation method described above are implemented.

[0033] 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, the steps of the text generation method described above are implemented.

[0034] One or more technical solutions proposed in this application have at least the following technical effects:

[0035] Compared with the related art, the greedy search strategy or the decoding method based on probability random sampling has its own shortcomings, which cannot guarantee the generation of accurate text sequences, resulting in low accuracy of text generated by large model decoding. When receiving the first reply candidate word generated by the large model, the present application assigns priority to the first reply candidate word according to the preset heuristic search algorithm, and determines the first target candidate word with the highest priority; obtains the second reply candidate word generated by the large model in the previous round, and selects the second reply candidate word with the largest joint probability of generating the first target candidate word according to the preset dynamic programming algorithm, and saves it as the parent node word of the first target candidate word; when the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is decoded. It can be understood that the present application adopts a heuristic search algorithm to determine the candidate word with the highest priority, and determines the text generation path with the highest joint probability of the candidate word with the highest priority through a dynamic programming algorithm, and then decodes it into the target text, which can improve the accuracy of text generated by large model decoding. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] 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.

[0037] In order to more clearly illustrate the embodiments of the present application 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, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0038] Figure 1 A flowchart of the first embodiment of the method for generating text of the present application is provided;

[0039] Figure 2 A flowchart of the second embodiment of the method for generating text of this application is provided;

[0040] Figure 3 A flowchart of the third embodiment of the method for generating text of this application is provided;

[0041] Figure 4 This is a schematic diagram of the module structure of the text generation device according to an embodiment of the present application;

[0042] Figure 5 Schematic diagram of the device structure of the hardware operating environment involved in the text generation method in the embodiment of the present application.

[0043] 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

[0044] 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.

[0045] 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.

[0046] The main solutions of the embodiments of this application are:

[0047] When receiving the first reply candidate word generated by the large model, assigning priorities to the first reply candidate words according to a preset heuristic search algorithm, and determining the first target candidate word with the highest priority;

[0048] Obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to the preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words;

[0049] When the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is generated by decoding.

[0050] In this embodiment, the present application uses a text generation device as the execution subject. For ease of description, it is specifically described below as "device".

[0051] Since the greedy search strategy or the decoding method based on probability random sampling in the related technology has its own shortcomings and cannot guarantee the generation of accurate text sequences, the accuracy of the text generated by large model decoding is low.

[0052] The present application provides a solution, which adopts a heuristic search algorithm to determine the candidate word with the highest priority, determines the text generation path with the highest joint probability of the candidate word with the highest priority through a dynamic programming algorithm, and then decodes it into a target text, which can improve the accuracy of text generation by decoding a large model.

[0053] Based on this, the present application embodiment provides a text generation method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the text generation method of this application.

[0054] In this embodiment, the text generation method includes steps S10 to S30:

[0055] Step S10, when receiving the first reply candidate word generated by the large model, assigning a priority to the first reply candidate word according to a preset heuristic search algorithm, and determining a first target candidate word with the highest priority;

[0056] It should be noted that the large model refers to a model with a large number of parameters obtained through deep learning training in the field of natural language processing, which can understand and generate natural language text. The first reply candidate word is a word or phrase generated by the large model in the text generation process. These words or phrases are preliminary choices in response to a certain input or context. The heuristic search algorithm is an algorithm that uses empirical rules or approximate methods to guide the search process so as to find an approximate solution to the problem within a reasonable time, and is used to evaluate and assign priorities to the first reply candidate words. The priority is the priority assigned among the candidate words according to specific criteria (such as relevance, semantic matching, etc.), which is used to determine which words are more likely to be selected as the final output. The first target candidate word is the candidate word with the highest priority determined by the heuristic search algorithm among all the first reply candidate words.

[0057] Exemplarily, when the large model receives an input request (e.g., a query or a text), a series of possible response candidate words will be generated. These candidate words are potential responses predicted by the model based on its training data and algorithm. Faced with the generated first response candidate word set, the device applies a preset heuristic search algorithm. This algorithm assigns a priority score to each candidate word based on a series of predefined rules or evaluation criteria (such as semantic relevance, grammatical correctness, user preferences, etc.). The heuristic search algorithm will score each candidate word and generate a priority list. This list is sorted from high to low according to the score of the candidate word. From the sorted priority list, the candidate word with the highest priority score is selected as the first target candidate word, that is, the most appropriate response in the current context. Once the first target candidate word is determined, the word will be used as the starting point for the next step of text generation. If further text generation is required, the system will continue to generate subsequent candidate words based on this first target candidate word, and may apply a dynamic programming algorithm to optimize the entire text sequence.

[0058] It can be understood that by assigning priorities to candidate words and selecting the optimal first target candidate word, the accuracy and efficiency of text generation can be improved.

[0059] Step S20, obtaining the second reply candidate word generated by the large model in the previous round, selecting the second reply candidate word with the largest joint probability of generating the first target candidate word according to the preset dynamic programming algorithm, and saving it as the parent node word of the first target candidate word;

[0060] It should be noted that the second reply candidate word is a word or phrase generated by the large model in the previous round of text generation. The dynamic programming algorithm is a method for solving complex problems by decomposing them into simpler sub-problems, and avoiding repeated calculations by storing the solutions to the sub-problems, which is used to optimize the problem-solving process. The parent node word is the previous word pointing to the current word in the text generation path, and is used to record the generation path and context information.

[0061] It is understandable that due to the adoption of a non-greedy strategy, each decision step of dynamic programming will consider the joint probability of the current candidate word calculated from the candidate word in the previous step. By selecting the path with the largest joint probability, the accuracy and efficiency of text generation can be improved.

[0062] Step S30, when the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is generated by decoding.

[0063] It should be noted that the termination condition is a condition preset during the execution of the algorithm.

[0064] For example, during the entire text generation process, the device will continuously check whether the preset termination conditions are met. These conditions include reaching a specific text length, completing a semantically complete sentence or paragraph, or a user-specified termination symbol. Once the termination condition is met, the device will extract the text generation path through the parent node word according to the determined candidate words and priorities, and decode to generate the final target text.

[0065] This embodiment provides a text generation method, which adopts a heuristic search algorithm to determine the candidate word with the highest priority, determines the text generation path with the highest joint probability of the candidate words with the highest priority through a dynamic programming algorithm, and then decodes it into a target text, which can improve the accuracy of text generation by decoding a large model.

[0066] In a feasible implementation, step S10 may include:

[0067] Based on a preset greedy decision algorithm, quickly generate text for the first reply candidate word, and use the joint probability during text generation as a heuristic estimation cost;

[0068] The probability of selecting the first response candidate word is taken as the actual cost;

[0069] Combining the actual cost with the heuristic estimated cost to obtain a total cost of the first response candidate word;

[0070] According to the total cost, the first response candidate words are prioritized and allocated to determine the first target candidate word with the highest priority.

[0071] It should be noted that the greedy decision algorithm is an algorithm strategy that takes the current optimal choice in each step of selection without considering the possible impact in the future, in the hope that the final result is also optimal. The first response candidate word is the first batch of possible words or phrases generated by the large model during the text generation process. These words or phrases are preliminary choices in response to a certain input or context. The joint probability refers to the probability of two or more events occurring at the same time in probability theory. In text generation, the joint probability usually refers to the probability of multiple words or phrases appearing consecutively. The heuristic estimated cost is a pre-set evaluation criterion for estimating the cost of selecting a candidate word during the text generation process. The actual cost is the cost when a candidate word is actually selected, which is usually related to the probability of the candidate word being selected. The total cost is a comprehensive evaluation indicator obtained by combining the heuristic estimated cost and the actual cost, which is used to evaluate the overall cost of selecting a candidate word. The priority sorting and allocation is a process of sorting all candidate words according to the total cost and assigning priorities to determine which candidate words should be given priority. The first target candidate word is the candidate word with the highest priority determined according to the total cost among all first response candidate words.

[0072] Exemplarily, the device uses a preset greedy decision algorithm to quickly generate text for the first reply candidate words generated by the large model. The device uses the joint probability when the text is generated as the heuristic estimation cost, which reflects the rationality of the candidate word sequence. The device uses the selection probability of the first reply candidate word as the actual cost, which reflects the possibility of the candidate word being selected. The device combines the heuristic estimation cost and the actual cost to calculate the total cost of each first reply candidate word. The device prioritizes and allocates all first reply candidate words according to the calculated total cost. Among the sorted candidate words, the device determines the first target candidate word with the highest priority as the basis for subsequent text generation.

[0073] Through this method, the candidate word selection process can be optimized while ensuring the text generation speed, thereby improving the quality and relevance of the generated text.

[0074] It is understandable that the heuristic search A-Star algorithm will select the best word according to the priority function at each decision step in the application process of large model decoding and generating text. The process is as follows:

[0075] The key to the heuristic search A-Star algorithm is to determine the priority function of the decision node at each stage in the current search scenario. Generally, the priority function can be expressed as:

[0076] f(n)=g(n)+h(n)

[0077] For the scenario of large model decoding generated text, on the one hand, the probability of the current candidate node is an important factor, which can be used as g(n) in the above formula; on the other hand, the "distance" from the node to the end point of the decoded generated text is another factor. Here, this "distance" can be estimated with the following method: use a greedy algorithm starting from the current candidate node, quickly make greedy decisions down to the end point, and obtain a joint probability as the "distance", that is, h(n) in the above formula.

[0078] In the initialization phase, i.e. the first step of decoding the generated text, the priority function value f(n) needs to be calculated for all candidate words to complete the decision in step 1. After that, the candidate words in each step are decided based on the calculated priority function until the end point is found, i.e. the terminal word is encountered or the word limit of the answer is exceeded.

[0079] In a feasible implementation manner, the step of assigning priorities to the first candidate reply words includes:

[0080] Obtain a set of historical target candidate words and a set of historical response candidate words;

[0081] Traverse all the first reply candidate words, and determine whether the first reply candidate word is in the historical target candidate word set and the historical reply candidate word collection, wherein, if the first reply candidate word is included in the historical target candidate word set, skip the rest of the current loop and start the next loop iteration of the first reply candidate word.

[0082] Exemplarily, first, the device obtains two sets of historical data: a historical target candidate word set and a historical reply candidate word collection. The historical target candidate word set contains the candidate words that were previously selected as the final output, while the historical reply candidate word collection contains all the candidate words generated before. The device traverses the first reply candidate word list currently generated. For each candidate word in the list, the system checks whether it already exists in the historical target candidate word set or the historical reply candidate word collection. If the currently traversed first reply candidate word is already included in the historical target candidate word set, the device will skip the rest of the current loop, that is, no further processing will be performed on the candidate word, and the next first reply candidate word loop iteration will be directly started.

[0083] It is understandable that the purpose of this method is to reduce the situation of repeated generation of the same candidate words and improve the efficiency and diversity of text generation. By skipping the candidate words that have already been generated, the device can focus resources on generating new and more diverse candidate words, thereby improving the overall text generation quality.

[0084] In a feasible implementation manner, after the step of determining whether the first reply candidate word is in the set of historical target candidate words and the set of historical reply candidate words, the step further includes:

[0085] If the first reply candidate word is not included in the historical reply candidate word set, calculating and assigning a priority of the first reply candidate word in the current cycle, and adding the first reply candidate word in the current cycle to the historical reply candidate word set;

[0086] If the first reply candidate word is included in the historical reply candidate word set, the priority of the first reply candidate word in the current cycle is calculated and updated.

[0087] Exemplarily, for each first reply candidate word, the device checks whether it already exists in the set of historical reply candidate words. If the first reply candidate word is not included in the set of historical reply candidate words, the device will calculate and assign a priority to the candidate word and add the candidate word to the set of historical reply candidate words. If the first reply candidate word is already included in the set of historical reply candidate words, the device will calculate and update the priority of the candidate word to reflect the latest evaluation result.

[0088] Understandably, the purpose of this approach is to improve the efficiency and quality of text generation by avoiding repeated generation of the same candidate words and dynamically adjusting the priority of candidate words to adapt to the changing context and user needs.

[0089] In a feasible implementation, step S20 may include:

[0090] Get the second reply candidate words generated by the big model in the previous round;

[0091] Generate a large model text for the second response candidate word, and screen the second response candidate word that generates the first target candidate word;

[0092] According to a preset dynamic programming algorithm, the second response candidate word with the largest joint probability of generating the first target candidate word is selected and saved as the parent node word of the first target candidate word.

[0093] It should be noted that the large model text generation is the process of generating text using large pre-trained language models (such as BERT, GPT, etc.). The first target candidate word is the most important candidate word determined among all candidate words according to preset criteria (such as priority, relevance, etc.). The dynamic programming algorithm is a method of solving complex problems by decomposing them into simpler sub-problems. It avoids repeated calculations by storing the solutions to the sub-problems and is used to optimize the problem-solving process. The parent node word is the previous word pointing to the current word in the text generation path, and is used to record the generation path and context information.

[0094] Exemplarily, first, the device obtains the second reply candidate words generated by the large model in the previous round, and these candidate words are further generated based on the first reply candidate words.

[0095] A large model text is generated for the second response candidate word, and then the second response candidate word that generates the first target candidate word is obtained by screening.

[0096] According to the preset dynamic programming algorithm, the candidate word with the largest joint probability with the first target candidate word is selected from the screened second response candidate words. This step takes advantage of the dynamic programming algorithm to optimize the candidate word selection process.

[0097] The selected second response candidate word is saved as the parent node word of the first target candidate word. This step records the text generation path and provides necessary information for subsequent text generation and path backtracking.

[0098] It can be understood that through this method, the device can optimize the quality and relevance of the generated candidate words while maintaining the efficiency of text generation, which is crucial for improving user experience and meeting personalized needs. Through the application of dynamic programming algorithms, the device can more effectively select the optimal path from a large number of candidate words, thereby improving the accuracy and coherence of text generation.

[0099] Understandably, reference Figure 2 , due to the non-greedy strategy, each decision step of dynamic programming will consider the joint probability of the current candidate word calculated from the candidate word in the previous step. As an optional optimization, it is not necessary to consider all candidate words in each step. Therefore, this application stipulates that each step only considers the top n candidate words based on the highest probability. The n in the following steps means this.

[0100] Establish the dynamic programming transfer equation. Assume that the k-th decision is to be made at present. For a certain candidate word W k , in the k-1th step, after n words are selected, it may be selected in the kth step, and these words are recorded as W k-1,1 , W k-1,2 , …, W k-1,n Then, from the k-1th step to the kth step, we can establish the following state transition equation:

[0101] P(W k )=Max{p(W k-1,1 ,W k ),p((W k-1,2 ,W k ),…,p(W k-1,n ,W k )}

[0102] For the first step of decoding and generating text, assuming there are n candidate words, the probability of selecting a candidate word in the first step is equal to the probability of selecting the decoding and generating text of the word, that is, in the first step, the initial probability of each candidate word is as follows:

[0103] P(W 1,1 ),P(W 1,2 ),…,P(W 1,n )

[0104] In a feasible implementation, step S30 may include:

[0105] When the first target candidate word meets a preset termination condition, determining the parent node of the first target candidate word, recursively acquiring the parent node until the parent node is empty, and obtaining a text generation path;

[0106] According to the text generation path, the target text is generated by decoding.

[0107] It should be noted that the parent node is the previous word of the current word in the text generation path, which is used to record the generation path and context information. Recursive acquisition uses a recursive method, that is, the function calls itself, to continuously obtain the parent node of each word until a certain condition is met (such as the parent node is empty). The text generation path starts from the first target candidate word and recursively obtains all its parent nodes to form a series of words. The path represents the generation process from the initial input to the target output.

[0108] Exemplarily, when the first target candidate word meets the preset termination condition, it means that the device has found the final point for generating the target text. Determine the parent node of the first target candidate word, that is, the word that is the direct predecessor in the generation path. Recursively, starting from the first target candidate word, continuously obtain the parent node of each word until the parent node is empty. This process constructs a complete text generation path from the initial input to the target output. During the recursive process, each parent node obtained is added to the text generation path until no more parent nodes can be obtained. According to the constructed text generation path, from the initial input to the first target candidate word, the final target text is decoded and generated.

[0109] It can be understood that through this method, the device can ensure that the generated text is not only related to the initial input, but also maintains semantic coherence and logical consistency throughout the generation process. Through the application of recursion and text generation paths, the device can more accurately control the text generation process, thereby improving the quality of the final output.

[0110] For example, to help understand the implementation process of the text generation method obtained by combining this embodiment with the above-mentioned embodiment 1, please refer to Figure 3, Figure 3 A brief flowchart of a text generation method is provided, specifically:

[0111] The device first receives an input request and uses the large model to generate the first batch of possible response words or phrases, namely the first response candidate words. At the same time, the device accesses the historical response candidate word set, which records all the candidate words generated before. For each first response candidate word, the device checks whether it already exists in the historical response candidate word set.

[0112] If the first reply candidate word does not exist in the historical reply candidate word set, the device will calculate and assign a priority to the candidate word and add the candidate word to the historical reply candidate word set. If the first reply candidate word already exists in the historical reply candidate word set, the device will calculate and update the priority of the candidate word.

[0113] The device obtains the second reply candidate words generated by the large model in the previous round, generates large model texts for these second reply candidate words, and screens out the second reply candidate words that generate the first target candidate words.

[0114] According to a preset dynamic programming algorithm, a candidate word with the greatest joint probability with the first target candidate word is selected from the screened second reply candidate words, and the selected second reply candidate word is saved as a parent node word of the first target candidate word.

[0115] When the first target candidate word meets the preset termination condition, the device determines the parent node of the first target candidate word. The device recursively obtains the parent node until the parent node is empty, and constructs a complete text generation path. According to the text generation path, the device decodes and generates the target text.

[0116] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the text generation method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0117] This application also provides a text generation device, please refer to Figure 4 , the text generating device comprises:

[0118] The allocation module 10 is used for, when receiving the first reply candidate word generated by the large model, assigning a priority to the first reply candidate word according to a preset heuristic search algorithm, and determining the first target candidate word with the highest priority;

[0119] A selection module 20 is used to obtain the second reply candidate word generated by the large model in the previous round, select the second reply candidate word with the largest joint probability of generating the first target candidate word according to a preset dynamic programming algorithm, and save it as the parent node word of the first target candidate word;

[0120] The decoding module 30 is used to obtain a text generation path according to the corresponding parent node word and decode to generate a target text when the first target candidate word meets a preset termination condition.

[0121] And / or, the allocation module 10 includes:

[0122] A first generation module, configured to quickly generate text for the first reply candidate word based on a preset greedy decision algorithm, and use the joint probability during text generation as a heuristic estimation cost;

[0123] A first selection module, configured to use the selection probability of the first reply candidate word as an actual cost;

[0124] A first combining module, configured to combine the actual cost with the heuristic estimated cost to obtain a total cost of the first reply candidate word;

[0125] The first determination module is used to prioritize and allocate the first response candidate words according to the total cost, and determine the first target candidate word with the highest priority.

[0126] And / or, the allocation module 10 includes:

[0127] A first acquisition module is used to acquire a set of historical target candidate words and a set of historical reply candidate words;

[0128] The first traversal module is used to traverse all the first reply candidate words, and determine whether the first reply candidate word is in the historical target candidate word set and the historical reply candidate word collection, wherein, if the first reply candidate word is included in the historical target candidate word set, skip the rest of the current loop and start the next loop iteration of the first reply candidate word.

[0129] And / or, the allocation module 10 includes:

[0130] A first adding module, configured to calculate and assign a priority of the first reply candidate word in the current cycle and add the first reply candidate word in the current cycle to the historical reply candidate word set if the first reply candidate word is not included in the historical reply candidate word set;

[0131] The first calculation module is used to calculate and update the priority of the first reply candidate word in the current cycle if the first reply candidate word is included in the historical reply candidate word set.

[0132] And / or, the selection module 20 includes:

[0133] The second acquisition module is used to acquire the second reply candidate words generated by the large model in the previous round;

[0134] A first screening module is used to generate a large model text for the second reply candidate words, and screen the second reply candidate words that generate the first target candidate words;

[0135] The first saving module is used to select the second reply candidate word with the largest joint probability of generating the first target candidate word according to a preset dynamic programming algorithm, and save it as the parent node word of the first target candidate word.

[0136] And / or, the decoding module 30 includes:

[0137] A first recursive module, configured to determine a parent node of the first target candidate word when the first target candidate word meets a preset termination condition, and recursively obtain the parent node until the parent node is empty, thereby obtaining a text generation path;

[0138] The first decoding module is used to generate a path according to the text and decode to generate a target text.

[0139] The text generation device provided by the present application adopts the text generation method in the above embodiment, which can solve the technical problem of low accuracy of text generation by decoding a large model. Compared with the prior art, the beneficial effects of the text generation device provided by the present application are the same as the beneficial effects of the text generation method provided by the above embodiment, and other technical features in the text generation device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0140] The present application provides a text generation device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; 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 text generation method in the above-mentioned embodiment one.

[0141] Reference below Figure 5 , which shows a schematic diagram of the structure of a text generation device suitable for implementing the embodiments of the present application. The text generation device in the embodiments of the present application may include but is not limited to mobile terminals such as mobile phones, tablet computers, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), 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 5 The text generation device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0142] like Figure 5 As shown, the text generation device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, 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 text generation device 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. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the text generation device to communicate with other devices wirelessly or by wire to exchange data. Although the text generation device 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 can 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 text generation device provided by the present application adopts the text generation method in the above embodiment, which can solve the technical problem of low accuracy of text generation by decoding a large model. Compared with the prior art, the beneficial effects of the text generation device provided by the present application are the same as the beneficial effects of the text generation method provided by the above embodiment, and the other technical features in the text generation device 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 (ie, computer programs) stored thereon, wherein the computer-readable program instructions are used to execute the text generation method in the above-mentioned embodiment.

[0148] 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.

[0149] The computer-readable storage medium may be included in the text generating device; or may exist independently without being assembled into the text generating device.

[0150] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the text generation device, the text generation device: when receiving the first reply candidate word generated by the large model, assigning a priority to the first reply candidate word according to a preset heuristic search algorithm, and determining the first target candidate word with the highest priority;

[0151] Obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to the preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words;

[0152] When the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is generated by decoding.

[0153] 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).

[0154] 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.

[0155] 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.

[0156] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned text generation method, and can solve the technical problem of low accuracy of text generation by decoding a large model. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the text generation method provided in the above-mentioned embodiment, and will not be repeated here.

[0157] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned text generation method when executed by a processor.

[0158] The computer program product provided by the present application can solve the technical problem of low accuracy of text generated by large model decoding. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the text generation method provided by the above embodiment, which will not be repeated here.

[0159] 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 text generation method, characterized in that: The method includes: When receiving the first reply candidate word generated by the large model, assigning priorities to the first reply candidate words according to a preset heuristic search algorithm, and determining the first target candidate word with the highest priority; Obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to the preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words; When the first target candidate word meets the preset termination condition, the text generation path is obtained according to the corresponding parent node word, and the target text is generated by decoding.

2. The method according to claim 1, characterized in that The step of assigning priorities to the first reply candidate words according to a preset heuristic search algorithm and determining the first target candidate word with the highest priority includes: Based on a preset greedy decision algorithm, quickly generate text for the first reply candidate word, and use the joint probability during text generation as a heuristic estimation cost; The probability of selecting the first response candidate word is taken as the actual cost; Combining the actual cost with the heuristic estimated cost to obtain a total cost of the first response candidate word; According to the total cost, the first response candidate words are prioritized and allocated to determine the first target candidate word with the highest priority.

3. The method according to claim 1, characterized in that The step of assigning a priority to the first candidate reply words comprises: Obtain a set of historical target candidate words and a set of historical response candidate words; Traverse all the first reply candidate words, and determine whether the first reply candidate word is in the historical target candidate word set and the historical reply candidate word collection, wherein, if the first reply candidate word is included in the historical target candidate word set, skip the rest of the current loop and start the next loop iteration of the first reply candidate word.

4. The method according to claim 3, characterized in that After the step of determining whether the first reply candidate word is in the set of historical target candidate words and the set of historical reply candidate words, the step further includes: If the first reply candidate word is not included in the historical reply candidate word set, calculating and assigning a priority of the first reply candidate word in the current cycle, and adding the first reply candidate word in the current cycle to the historical reply candidate word set; If the first reply candidate word is included in the historical reply candidate word set, the priority of the first reply candidate word in the current cycle is calculated and updated.

5. The method according to claim 1, characterized in that The step of obtaining the second reply candidate word generated by the large model in the previous round, selecting the second reply candidate word with the largest joint probability of generating the first target candidate word according to a preset dynamic programming algorithm, and saving it as the parent node word of the first target candidate word includes: Get the second reply candidate words generated by the big model in the previous round; Generate a large model text for the second response candidate word, and screen the second response candidate word that generates the first target candidate word; According to a preset dynamic programming algorithm, the second response candidate word with the largest joint probability of generating the first target candidate word is selected and saved as the parent node word of the first target candidate word.

6. The method according to claim 1, characterized in that When the first target candidate word meets the preset termination condition, the steps of obtaining a text generation path according to the corresponding parent node word and decoding to generate a target text include: When the first target candidate word meets a preset termination condition, determining the parent node of the first target candidate word, recursively acquiring the parent node until the parent node is empty, and obtaining a text generation path; According to the text generation path, the target text is generated by decoding.

7. A text generation device, characterized in that: The device comprises: An allocation module, configured to, when receiving the first reply candidate word generated by the large model, allocate a priority to the first reply candidate word according to a preset heuristic search algorithm, and determine a first target candidate word with the highest priority; A selection module is used to obtain the second reply candidate words generated by the large model in the previous round, select the second reply candidate words with the largest joint probability of generating the first target candidate words according to a preset dynamic programming algorithm, and save them as the parent node words of the first target candidate words; A decoding module is used to obtain a text generation path according to the corresponding parent node word and decode to generate a target text when the first target candidate word meets a preset termination condition.

8. A text generation device, 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 text generation method 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 text generation method 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 text generation method according to any one of claims 1 to 6 are implemented.