Text generation method and device, computer equipment and storage medium

Through the combination methods of greedy decoding, forward transmission and temperature adjustment, the text generation model and the text verification model work together to solve the problem of slow generation of existing text generation methods and achieve efficient and flexible text generation.

CN119476261APending Publication Date: 2025-02-18PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411414681.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-10
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing text generation methods are slow to generate and face delay and cost challenges due to the computationally intensive and memory-intensive forward delivery process.

Method used

Using a combination of greedy decoding, forward delivery and temperature adjustment operations, the text generation model and text verification model work together to quickly generate candidate word sequences and verify and adjust until the output text of the preset length is reached.

Benefits of technology

It significantly reduces the latency of text generation, improves the efficiency of text generation, enables flexible adjustment of model size and quality to suit different tasks and scenarios, and is compatible with existing text generation models and methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119476261A_ABST
    Figure CN119476261A_ABST
Patent Text Reader

Abstract

The embodiment of the invention belongs to the technical field of artificial intelligence, and relates to a text generation method and device, computer equipment and a storage medium, the method comprises the following steps: inputting an input text into a text generation model for greedy decoding operation to obtain a candidate word sequence of a first position; carrying out forward transmission operation on the candidate word sequence at the first position according to a text verification model to obtain first probability distribution; performing temperature adjustment operation on the first probability distribution according to the temperature coefficient to obtain a first word group of the initial output text; and inputting the initial output text as an input text into a text generation model for greedy decoding operation, forward transfer operation and temperature adjustment operation until the length of the initial output text meets a preset length, thereby obtaining a target output text. According to the method, the text generation delay can be remarkably reduced, the text generation efficiency can be improved, and meanwhile, the size and quality of the text generation model can be flexibly adjusted to adapt to different tasks and scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and in particular to a text generation method, apparatus, computer equipment and storage medium. Background Art

[0002] Text generation is a technique that uses artificial intelligence models to generate natural language text based on given input. Text generation can be applied to a variety of tasks such as automatic speech recognition, translation, summarization, chatbots, etc.

[0003] At present, text generation mainly uses autoregressive models, that is, generating one word at a time and using it as input for the next generation. The advantage of this method is that it can ensure the coherence and fluency of the generated text.

[0004] However, the applicant found that the current text generation method also has a major disadvantage, which is that the generation speed is very slow. Because each word needs to run the forward pass of the model, which is a computationally intensive and memory-intensive process, especially for large models. Therefore, the existing text generation technology faces the challenges of latency and cost in practical applications. Summary of the invention

[0005] The purpose of the embodiments of the present application is to provide a text generation method, apparatus, computer device and storage medium to solve the problem of slow generation speed in current text generation methods.

[0006] In order to solve the above technical problems, the present application embodiment provides a text generation method, which adopts the following technical solution:

[0007] Receiving a text generation request carrying input text sent by a user terminal;

[0008] Inputting the input text into a text generation model for greedy decoding to obtain a candidate word sequence at the first position;

[0009] Performing a forward transfer operation on the candidate word sequence at the first position according to the text verification model to obtain a first probability distribution;

[0010] Performing a temperature adjustment operation on the first probability distribution according to the temperature coefficient to obtain a first phrase of the initial output text;

[0011] Inputting the initial output text as input text into the text generation model for greedy decoding to obtain a candidate word sequence at the second position;

[0012] Performing a forward transfer operation on the candidate word sequence at the first position according to the text verification model to obtain a second probability distribution;

[0013] Perform a temperature adjustment operation on the second probability distribution according to the temperature coefficient to obtain the first phrase of the initial output text;

[0014] Loop the greedy decoding operation, the forward pass operation, and the temperature adjustment operation until the length of the initial output text meets the preset length to obtain the target output text.

[0015] Furthermore, after each step of the temperature adjustment operation, the following steps are also included:

[0016] Perform a phrase comparison and text update operation on the current position candidate word in the current position candidate word sequence obtained by the current greedy decoding operation.

[0017] Furthermore, the formula representation of the phrase comparison and text update operation is:

[0018] \text{if} w = z_p \text{then} y = y + w, p = p + 1

[0019] \text{else} z = z_{<p}, C = C - I

[0020] Where, \text{if} w = z_p \text{then} y = y + w, p = p + 1 means that if the words generated by the text verification model and the text generation model are the same, add it to the output sequence and update the current position; \text{else} z = z_{<p}, C = C - I means that if they are different, delete the subsequent part of the candidate sequence and reduce the candidate length.

[0021] Furthermore, the formula representation of the greedy decoding operation is:

[0022] z_i = \arg\max_{w} A(y_{<p}, w)

[0023] Where, z_i represents the i-th word in the candidate sequence, y_{<p} represents the first p - 1 words in the output sequence, w represents all possible words, and A(y_{<p}, w) represents the probability that the next word given by the text generation model is w.

[0024] Furthermore, the formula representation of the forward pass operation is:

[0025] P(w|y_{<i}) = M(y_{<i}, w)

[0026] Where, P(w|y_{<i}) represents the probability that the next word is w given the first i - 1 words in the output sequence, and M(y_{<i}, w) represents the probability given by the text verification model.

[0027] Further, the formula representation of the temperature adjustment operation is as follows:

[0028] P_T(w|y_{<i})=\frac{P(w|y_{<i})^{1 / T}}{\sum_{w'}P(w'|y_{<i}

[0029] )^{1 / T}}w\simP_T(w|y_{<i})

[0030] where P_T(w|y_{<i}) represents the probability distribution after temperature adjustment, \sum_{w'}P(w'|y_{<i})^{1 / T} represents the normalization factor, and \sim represents sampling from the distribution.

[0031] To solve the above technical problems, the embodiment of the present application further provides a text generation device, which adopts the following technical solutions:

[0032] A request acquisition module, configured to receive a text generation request carrying input text sent by a user terminal;

[0033] A first greedy decoding module, configured to input the input text into a text generation model for greedy decoding operation to obtain a candidate word sequence at the first position;

[0034] A first forward propagation module, configured to perform a forward propagation operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution;

[0035] A first temperature adjustment module, configured to perform a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text;

[0036] A second greedy decoding module, configured to input the initial output text as the input text into the text generation model for greedy decoding operation to obtain a candidate word sequence at the second position;

[0037] A second forward propagation module, configured to perform a forward propagation operation on the candidate word sequence at the first position according to a text verification model to obtain a second probability distribution;

[0038] A second temperature adjustment module, configured to perform a temperature adjustment operation on the second probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text;

[0039] A target output text acquisition module, configured to loop the greedy decoding operation, the forward propagation operation, and the temperature adjustment operation until the length of the initial output text meets a preset length, and then obtain the target output text.

[0040] Furthermore, the device also includes:

[0041] The comparison and update module is used to perform phrase comparison and text update operations on the candidate words at the current position in the candidate word sequence at the current position obtained by the current greedy decoding operation.

[0042] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0043] The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the text generation method as described above when executing the computer-readable instructions.

[0044] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0045] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the text generation method described above are implemented.

[0046] The present application provides a text generation method, comprising: receiving a text generation request carrying input text sent by a user terminal; inputting the input text into a text generation model for greedy decoding operation to obtain a candidate word sequence at a first position; performing a forward transfer operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; performing a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain a first phrase of an initial output text; inputting the initial output text as input text into the text generation model for greedy decoding operation to obtain a candidate word sequence at a second position; performing a forward transfer operation on the candidate word sequence at the first position according to the text verification model to obtain a second probability distribution; performing a temperature adjustment operation on the second probability distribution according to the temperature coefficient to obtain a first phrase of the initial output text; and looping the greedy decoding operation, the forward transfer operation, and the temperature adjustment operation until the length of the initial output text meets a preset length, thereby obtaining a target output text. Compared with the existing technology, the present application can significantly reduce the delay of text generation and improve the efficiency of text generation; the size and quality of the text generation model can be flexibly adjusted to adapt to different tasks and scenarios; it can be compatible with existing text generation models and methods without the need to modify or retrain them. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0048] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0049] Figure 2 It is a flow chart of the implementation of the text generation method provided by this application;

[0050] Figure 3 It is a structural schematic diagram of the text generation device provided by the present application;

[0051] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0052] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0053] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0054] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0055] like Figure 1As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0056] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0057] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to the laptop computer 1011, tablet computer 1012 or mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.

[0058] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .

[0059] It should be noted that the text generation method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the text generation device is generally arranged in the server / terminal device.

[0060] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0061] Continue to refer Figure 2 , shows a flow chart of an embodiment of a text generation method according to the present application. The text generation method comprises: step S201, step S202, step S203, step S204, step S205, step S206, step S207 and step S208.

[0062] In step S201, a text generation request carrying input text sent by a user terminal is received.

[0063] In the embodiments of the present application, the user terminal refers to a terminal device for executing the image processing method for preventing document abuse provided by the present application. The user terminal may be a mobile terminal such as a mobile phone, a smart phone, a laptop computer, a digital broadcast receiver, a PDA (Personal Digital Assistant), a PAD (Tablet Computer), a PMP (Portable Multimedia Player), a navigation device, etc., and a fixed terminal such as a digital TV, a desktop computer, etc. It should be understood that the examples of the user terminal here are only for convenience of understanding and are not used to limit the present application.

[0064] In step S202, the input text is input into the text generation model for greedy decoding operation to obtain the candidate word sequence at the first position.

[0065] In the embodiments of the present application, the text generation model is a pre-trained model that can generate subsequent text content based on the given text (i.e., the text input by the user). Greedy decoding is a strategy that selects the word with the highest current probability as the output at each step without considering the influence of subsequent steps. In this way, according to the text input by the user, the model will generate multiple candidate words at the first position (i.e., the first word immediately following the user input text) to form a candidate word sequence.

[0066] In the embodiments of the present application, the text generation model A is used to perform greedy decoding on y. Starting from position p, C candidate words are generated to obtain the candidate sequence z. Greedy decoding is a text generation strategy that selects the most likely word as the next word each time until the end symbol is generated or the maximum length is reached. The advantage of greedy decoding is that it can ensure the coherence and fluency of the generated text, but it also has a disadvantage that it may fall into a repetitive or meaningless loop. The reason for using greedy decoding is to match the text generation model to accelerate text generation.

[0067] In some optional implementation manners of the embodiments of the present application, the formula for greedy decoding is:

[0068] z_i = \arg\max_{w}A(y_{<p},w)

[0069] where z_i represents the i-th word in the candidate sequence, y_{<p} represents the first p - 1 words in the output sequence, w represents all possible words, and A(y_{<p},w) represents the probability that the next word given by the text generation model is w.

[0070] In step S203, according to the text verification model, a forward pass operation is performed on the candidate word sequence at the first position to obtain the first probability distribution.

[0071] In the embodiments of the present application, the text verification model is used to evaluate the quality or rationality of the generated text. It takes the candidate word sequence output by the text generation model as input, and calculates the probability of each candidate word being a reasonable output through a forward pass operation (i.e., the model processes the input step by step according to a preset hierarchical structure until an output is generated), and finally obtains a probability distribution, indicating the possibility of each candidate word being selected.

[0072] In the embodiments of the present application, the text verification model M is used to perform a forward pass on y to obtain the probability distribution corresponding to the next word at all positions.

[0073] In some alternative implementation manners of the embodiments of the present application, the formula for the forward pass is:

[0074] P(w|y_{<i})=M(y_{<i},w)

[0075] where P(w|y_{<i}) represents the probability that the next word is w after the first i - 1 words in the given output sequence, and M(y_{<i},w) represents the probability given by the text verification model.

[0076] In step S204, a temperature adjustment operation is performed on the first probability distribution according to the temperature coefficient to obtain the first phrase of the initial output text.

[0077] In the embodiments of the present application, the temperature coefficient is a parameter used to control the "sharpness" of the probability distribution. In the temperature adjustment operation, by adjusting the temperature coefficient, the shape of the probability distribution can be changed, making the probability distribution more uniform (increasing the temperature) or more concentrated (decreasing the temperature). The purpose of this step is to sample from the adjusted probability distribution and select the most likely word or phrase as the first phrase of the initial output text.

[0078] In the embodiments of the present application, the temperature coefficient T is used to adjust the probability distribution and sample the next word w from it. The temperature coefficient is a parameter used to adjust the probability distribution in text generation, and it can affect the diversity and creativity of the generated text. The smaller the value of the temperature coefficient, the sharper the probability distribution, and the more the generated text tends to select the most likely word. The larger the value of the temperature coefficient, the flatter the probability distribution, and the more the generated text tends to select less likely words. After the forward pass of the text verification model, the reason for adjusting and sampling through the temperature coefficient is to control the quality and diversity of the generated text. If the temperature coefficient is not used, the generated text may be too monotonous and repetitive, or too chaotic and meaningless. By using the temperature coefficient, the creativity of the text can be increased while ensuring the rationality of the text. The sampling method is a method of randomly selecting the next word from the probability distribution, which can increase the uncertainty and diversity of the generated text.

[0079] In some alternative implementation manners of the embodiments of the present application, the formula for temperature adjustment and sampling is:

[0080] P_T(w|y_{<i})=\frac{P(w|y_{<i})^{1 / T}}{\sum_{w'}P(w'|y_{<i}

[0081] )^{1 / T}}w\simP_T(w|y_{<i})

[0082] where P_T(w|y_{<i}) represents the probability distribution after temperature adjustment, \sum_{w'}P(w'|y_{<i})^{1 / T} represents the normalization factor, and \sim represents sampling from the distribution.

[0083] In step S205, the initial output text is used as the input text and input into the text generation model for greedy decoding operation to obtain the candidate word sequence at the second position.

[0084] In step S206, according to the text verification model, a forward propagation operation is performed on the candidate word sequence at the first position to obtain the second probability distribution.

[0085] In step S207, according to the temperature coefficient, a temperature adjustment operation is performed on the second probability distribution to obtain the first phrase of the initial output text.

[0086] In step S208, the greedy decoding operation, the forward propagation operation, and the temperature adjustment operation are looped until the length of the initial output text meets the preset length, and the target output text is obtained.

[0087] In the embodiments of the present application, this process will be continuously repeated. Each time, the text generated last time is added to the input to generate the candidate word sequence at the next position, and these candidate words are evaluated through the text verification model, and then the most suitable word or phrase is selected through temperature adjustment until the length of the generated text reaches the preset length.

[0088] In the embodiments of the present application, through the above loop process, a text that meets the preset length will finally be generated. This text is the target output text. Based on the original text input by the user, through the combined action of the text generation model and the text verification model, as well as strategies such as greedy decoding, forward propagation, and temperature adjustment, a new text that conforms to both grammatical rules and rationality is generated.

[0089] In the embodiments of the present application, the core idea of the present application is to use a smaller model as the text generation model to quickly generate a candidate word sequence, and then use a larger model as the text verification model to verify the correctness of the candidate word sequence and make corrections.

[0090] In the embodiment of the present application, the forward transfer of the text verification model is the most time-consuming and resource-consuming part. For example, suppose that the text generation model has generated five candidate words, namely "a", "b", "c", "d", and "e". Then, the text verification model performs a forward transfer on each candidate word to obtain the probability distribution of the next word. Suppose that the text verification model has selected "b" as the next word, and it is found that it is the same as the second candidate word generated by the text generation model. Then, the text verification model can add "b" to the output sequence and skip the forward transfer of the subsequent three candidate words. In this way, the time and resources of the three forward transfers of the text verification model can be saved. If the text verification model has selected a word that is different from any candidate word generated by the text generation model, then all candidate words need to be deleted, and the text generation model needs to be requested again to generate a new candidate word sequence. In this way, the use of wrong or invalid candidate words can be avoided, and the quality of the output sequence can be guaranteed.

[0091] In practical applications, when using GPT-4 and Pythia-160M ​​as text verification models and text generation models, the present application can reduce the delay by 10 times while maintaining the quality comparable to the original model, thereby significantly reducing the delay of text generation and improving the efficiency of text generation; the present application can select a suitable text generation model according to the requirements of the task and the conditions of the hardware to achieve the best balance between speed and quality, so that the size and quality of the text generation model can be flexibly adjusted to adapt to different tasks and scenarios; the present application can use any autoregressive model as a text verification model, and only needs to select a suitable text generation model for it, and then the method of the present application can be used for acceleration. The present application can also be combined with other text generation technologies, such as caching, batch processing, tensor parallelism, etc., to further improve performance, so as to be compatible with existing text generation models and methods without the need to modify or retrain them.

[0092] The number of forward passes of the text verification model can be reduced, thereby accelerating text generation. The method also introduces a heuristic algorithm to dynamically adjust the length of the candidate word sequence to balance speed and quality.

[0093] In an embodiment of the present application, a text generation method is provided, including: receiving a text generation request carrying input text sent by a user terminal; inputting the input text into a text generation model for a greedy decoding operation to obtain a candidate word sequence at a first position; performing a forward pass operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; performing a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain the first phrase of an initial output text; using the initial output text as the input text to input into the text generation model for a greedy decoding operation to obtain a candidate word sequence at a second position; performing a forward pass operation on the candidate word sequence at the first position according to the text verification model to obtain a second probability distribution; performing a temperature adjustment operation on the second probability distribution according to the temperature coefficient to obtain the first phrase of the initial output text; repeating the greedy decoding operation, the forward pass operation, and the temperature adjustment operation until the length of the initial output text meets a preset length, and obtaining a target output text. Compared with the prior art, the present application can significantly reduce the latency of text generation and improve the efficiency of text generation; can flexibly adjust the size and quality of the text generation model to adapt to different tasks and scenarios; can be compatible with existing text generation models and methods without modifying or retraining them.

[0094] In some optional implementation manners of the embodiment of the present application, after each step of the temperature adjustment operation, the following steps are further included:

[0095] Perform a phrase comparison and text update operation on the current position candidate word in the current position candidate word sequence obtained by the current greedy decoding operation.

[0096] In the embodiment of the present application, compare whether the words at the same position in w and z are the same. If they are the same, add w to y and increase p by 1. If they are different, delete the part of z from the different position to the end and reduce C by I. The formulas for comparison and update are:

[0097] \text{if} w = z_p \text{then} y = y + w, p = p + 1 -

[0098] \text{else} z = z_{<p}, C = C - I

[0099] Among them, \text{if} w = z_p \text{then} y = y + w, p = p + 1 means that if the words generated by the text verification model and the text generation model are the same, add them to the output sequence and update the current position; \text{else} z = z_{<p}, C = C - I means that if they are different, delete the subsequent part of the candidate sequence and reduce the candidate length.

[0100] In some optional implementations of the embodiments of the present application, if C\leq0, C is set to 1. The formula for updating the candidate length is:

[0101] \text{if}C\leq0\text{then}C=1

[0102] Return: Returns the output sequence y.

[0103] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0104] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0105] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0106] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0107] Further references Figure 3 , as a response to the above Figure 2The present application provides an embodiment of a text generation device, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0108] like Figure 3 As shown, the text generation device 200 of the embodiment of the present application includes:

[0109] The request acquisition module 210 is used to receive a text generation request carrying input text sent by a user terminal;

[0110] A first greedy decoding module 220, used to input the input text into the text generation model to perform a greedy decoding operation to obtain a candidate word sequence at a first position;

[0111] A first forward transfer module 230, configured to perform a forward transfer operation on the candidate word sequence at the first position according to the text verification model to obtain a first probability distribution;

[0112] A first temperature adjustment module 240, configured to perform a temperature adjustment operation on the first probability distribution according to the temperature coefficient to obtain a first phrase of the initial output text;

[0113] A second greedy decoding module 250 is used to input the initial output text as input text into the text generation model for greedy decoding to obtain a candidate word sequence at a second position;

[0114] A second forward transfer module 260, configured to perform a forward transfer operation on the candidate word sequence at the first position according to the text verification model to obtain a second probability distribution;

[0115] A second temperature adjustment module 270, configured to perform a temperature adjustment operation on the second probability distribution according to the temperature coefficient to obtain a first phrase of the initial output text;

[0116] The target output text acquisition module 280 is used to loop the greedy decoding operation, the forward transfer operation and the temperature adjustment operation until the length of the initial output text meets the preset length, thereby obtaining the target output text.

[0117] In an embodiment of the present application, a text generation device 200 is provided, including: a request acquisition module 210, for receiving a text generation request carrying an input text sent by a user terminal; a first greedy decoding module 220, for inputting the input text into a text generation model for greedy decoding operation to obtain a candidate word sequence at a first position; a first forward transfer module 230, for performing a forward transfer operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; a first temperature adjustment module 240, for performing a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain a first phrase of the initial output text; a second greedy decoding module 220, for performing a greedy decoding operation on the input text to a text generation model to obtain a candidate word sequence at a first position; a first forward transfer module 230, for performing a forward transfer operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; a first temperature adjustment module 240, for performing a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain a first phrase of the initial output text; Module 250, for inputting the initial output text as input text into the text generation model for greedy decoding operation, and obtaining the candidate word sequence at the second position; second forward transfer module 260, for performing forward transfer operation on the candidate word sequence at the first position according to the text verification model, and obtaining the second probability distribution; second temperature adjustment module 270, for performing temperature adjustment operation on the second probability distribution according to the temperature coefficient, and obtaining the first phrase of the initial output text; target output text acquisition module 280, for looping greedy decoding operation, forward transfer operation and temperature adjustment operation, until the length of the initial output text meets the preset length, the target output text is obtained. Compared with the prior art, the present application can significantly reduce the delay of text generation and improve the efficiency of text generation; can flexibly adjust the size and quality of the text generation model to adapt to different tasks and scenarios; can be compatible with existing text generation models and methods without modifying or retraining them.

[0118] In some optional implementations of the embodiments of the present application, the text generation device 200 further includes:

[0119] The comparison and update module is used to perform phrase comparison and text update operations on the candidate words at the current position in the candidate word sequence at the current position obtained by the current greedy decoding operation.

[0120] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of a computer device according to an embodiment of the present application.

[0121] The computer device 300 includes a memory 310, a processor 320, and a network interface 330 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 300 having components 310-330, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0122] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0123] The memory 310 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 310 can be an internal storage unit of the computer device 300, such as a hard disk or memory of the computer device 300. In other embodiments, the memory 310 can also be an external storage device of the computer device 300, such as a plug-in hard disk equipped on the computer device 300, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Of course, the memory 310 can also include both the internal storage unit of the computer device 300 and its external storage device. In the embodiment of the present application, the memory 310 is generally used to store the operating system and various application software installed on the computer device 300, such as computer-readable instructions of the text generation method, etc. In addition, the memory 310 can also be used to temporarily store various data that have been output or are to be output.

[0124] The processor 320 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 320 is generally used to control the overall operation of the computer device 300. In the embodiment of the present application, the processor 320 is used to run the computer-readable instructions stored in the memory 310 or process data, such as computer-readable instructions for running the text generation method.

[0125] The network interface 330 may include a wireless network interface or a wired network interface. The network interface 330 is generally used to establish a communication connection between the computer device 300 and other electronic devices.

[0126] The computer device provided in this application can significantly reduce the delay of text generation and improve the efficiency of text generation; can flexibly adjust the size and quality of the text generation model to adapt to different tasks and scenarios; can be compatible with existing text generation models and methods without the need to modify or retrain them.

[0127] The present application also provides another implementation, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the text generation method as described above.

[0128] The computer-readable storage medium provided in this application can significantly reduce the delay of text generation and improve the efficiency of text generation; can flexibly adjust the size and quality of the text generation model to adapt to different tasks and scenarios; and can be compatible with existing text generation models and methods without the need to modify or retrain them.

[0129] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0130] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A text generation method, characterized in that: It includes the following steps: Receiving a text generation request carrying input text sent by a user terminal; Inputting the input text into a text generation model for a greedy decoding operation to obtain a candidate word sequence at the first position; Performing a forward pass operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; Performing a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text; Taking the initial output text as the input text and inputting it into the text generation model for a greedy decoding operation to obtain a candidate word sequence at the second position; Performing a forward pass operation on the candidate word sequence at the first position according to a text verification model to obtain a second probability distribution; Performing a temperature adjustment operation on the second probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text; Looping the greedy decoding operation, the forward pass operation, and the temperature adjustment operation until the length of the initial output text meets a preset length, to obtain a target output text.

2. The text generation method according to claim 1, characterized in that: After each step of the temperature adjustment operation, the following steps are further included: Performing a phrase comparison and text update operation on the candidate word at the current position in the candidate word sequence at the current position obtained by the current greedy decoding operation.

3. The text generation method according to claim 2, characterized in that: The formula representation of the phrase comparison and text update operation is: \text{if}w=z_p\text{then}y=y+w,p=p+1 \text{else}z=z_{<p},C=C-I where \text{if}w=z_p\text{then}y=y+w,p=p+1 means that if the words generated by the text verification model and the text generation model are the same, add it to the output sequence and update the current position; \text{else}z=z_{<p},C=C-I means that if they are different, delete the subsequent part of the candidate sequence and reduce the candidate length.

4. The text generation method according to claim 1, characterized in that: The formula representation of the greedy decoding operation is: z_i=\arg\max_{w}A(y_{<p},w) where z_i represents the i-th word in the candidate sequence, y_{<p} represents the first p - 1 words in the output sequence, w represents all possible words, and A(y_{<p},w) represents the probability that the next word given by the text generation model is w.

5. The text generation method according to claim 1, characterized in that: The formula representation of the forward pass operation is: P(w|y_{<i})=M(y_{<i},w) where P(w|y_{<i}) represents the probability that the next word is w given the first i - 1 words in the output sequence, and M(y_{<i},w) represents the probability given by the text verification model.

6. The text generation method according to claim 1, characterized in that: The formula representation of the temperature adjustment operation is: P_T(w|y_{<i})=\frac{P(w|y_{<i})^{1 / T}}{\sum_{w'}P(w'|y_{<i})^{1 / T}}w\simP_T(w|y_{<i}) Among them, \(P_T(w|y_{<i})\) represents the probability distribution after temperature adjustment, \(\sum_{w'}P(w'|y_{<i})^{1 / T}\) represents the normalization factor, and \(\sim\) represents sampling from the distribution.

7. A text generation device, characterized in that: It includes: A request acquisition module, configured to receive a text generation request carrying input text sent by a user terminal; A first greedy decoding module, configured to input the input text into a text generation model for greedy decoding operation to obtain a candidate word sequence at the first position; A first forward passing module, configured to perform a forward passing operation on the candidate word sequence at the first position according to a text verification model to obtain a first probability distribution; A first temperature adjustment module, configured to perform a temperature adjustment operation on the first probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text; A second greedy decoding module, configured to input the initial output text as input text into the text generation model for greedy decoding operation to obtain a candidate word sequence at the second position; A second forward passing module, configured to perform a forward passing operation on the candidate word sequence at the first position according to a text verification model to obtain a second probability distribution; A second temperature adjustment module, configured to perform a temperature adjustment operation on the second probability distribution according to a temperature coefficient to obtain the first phrase of the initial output text; A target output text acquisition module, configured to loop the greedy decoding operation, the forward passing operation, and the temperature adjustment operation until the length of the initial output text meets a preset length, and then obtain the target output text.

8. The text generation device according to claim 7, characterized in that: The device further includes: A comparison and update module, configured to perform a phrase comparison and text update operation on the current position candidate word in the current position candidate word sequence obtained by the current greedy decoding operation.

9. A computer device comprising a memory and a processor, characterized in that: The memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the text generation method according to any one of claims 1 to 6 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the text generation method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Neural network language model and character information prediction method and device

    CN114201576A

  • Sentence generation method and device based on cluster search, equipment and storage medium

    CN116842967A