Pre-training Model Text Generation Method Based on Reverse Hints
By introducing a reverse prompt mechanism and an improved bundle scoring function in the pretrained model, the problem of the large-scale pretrained model generation results deviating from the topic is solved, and higher generation correlation and controllability are achieved.
Patent Information
- Application Number
- CN202110750492.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-02
- Publication Date
- 2025-06-10
- Estimated Expiration
- 2041-07-02
AI Technical Summary
The generation results of large-scale pre-trained models are easily deviated from the input topic content. The existing methods have limited effects when entering additional prompts, and limit the creativity of the model and the consistency of the text.
A pre-trained model text generation method based on reverse prompt is proposed. By improving the bundle scoring function in bundle search, the dual process is used to enhance the correlation and controllability of text generation, and directly use the original language model to improve the generation ability.
It effectively solves the problem of deviation from the content of the input topic, improves the relevance and context of the generated text and the input topic, provides better controllability, and achieves better results in practical applications.
Smart Images

Figure CN113761846B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of pre-trained models, and particularly to a method for generating pre-trained model texts based on reverse prompts and a computer device. Background Art
[0002] In recent years, the emergence of large-scale pre-trained models has brought natural language processing (NLP) into a new era. It has made great progress in various downstream NLP tasks such as text generation, text classification, and machine reading comprehension, and has gradually become the mainstream model in the NLP field. Large-scale pre-trained models have proven their powerful ability to generate realistic texts, but the generated results often deviate from the theme as the length of the generated text increases. How to control the generation results of large-scale pre-trained models is an urgent problem to be solved. Currently, the mainstream solution is to add prompt information, but the prompt information is far from sufficient to generate controllable texts. It is not uncommon for language models to deviate from the original prompts and generate texts on unrelated topics.
[0003] Language models have been widely used as pre-training objectives and have shown strong generalization capabilities. Starting from word embedding methods, pre-training methods have shown increasing importance in the field of natural language processing. These models are more general and require less domain-specific data to achieve strong performance. Specifically, the main types of pre-trained models are autoregressive language models. Generative Pre-trained Transformer (GPT) and Transformer-XL have made significant improvements in complexity and also improved the generation quality, and have been adapted to different languages.
[0004] Although it is now possible to automatically generate realistic texts through large-scale pre-trained models, how to solve the deviation of the generated results from the input theme content is still a challenging problem. Currently, the relatively mainstream solution is to input additional prompt content related to the subject, but this method has certain limitations in improving the relevance between the generated results and the theme. This additional prompt only improves the relevance of the text generation results in the initial paragraph, and optimizes the text generation in subsequent generations. Another commonly used improvement method is to use artificially defined patterns to make generation selections when generating texts. This method limits the creativity of the model and the coherence of the text content. CTRL proposes to use control codes to condition the language model. PPLM performs backpropagation during testing to adjust the generation to maximize the score given by the attribute model.
[0005] The dual process is a method to enhance the quality of AI generation by the dual characteristics of input and output under the premise that the output and input are reversed. Xia et al. introduced dual learning for machine translation tasks, which uses multiple different models to form a translation loop and hopes that the context will remain unchanged after passing through the loop. Summary of the Invention
[0006] This application aims to solve at least one of the technical problems in the related art to some extent.
[0007] To this end, the first object of this application is to propose a pre-trained model text generation method based on reverse prompts, which solves the technical problem that the generation results of large-scale pre-trained models in the existing methods deviate from the input topic content. At the same time, it also solves the technical problem that the improvement of the relevance between the generation results and the topic by inputting additional prompts related to the main body in the existing methods is limited. By proposing a reverse prompt method and improving the beam scoring function in beam search, the relevance between the prompt and the generated text is enhanced, providing better controllability. At the same time, the reverse prompt method proposed in this application uses a dual process to enhance the text generation ability of artificial intelligence, does not require additional attribute model training or manual definition of patterns, directly uses the original language model itself to improve its generation ability, and has achieved good results in practical applications.
[0008] The second object of this application is to propose a computer device.
[0009] The third object of this application is to propose a non-transitory computer-readable storage medium.
[0010] To achieve the above object, the first aspect embodiment of this application proposes a pre-trained model text generation method based on reverse prompts, including: Step S1: Input the initial prompt text into a large-scale pre-trained model for text generation to generate multiple candidate sentences for the first sentence; Step S2: Screen the multiple candidate sentences, and select a preset number of candidate sentences as alternative sentences in the order of the scores of the candidate sentences from high to low; Step S3: Input each alternative sentence as the above text of the next sentence into the large-scale pre-trained model to generate multiple candidate sentences for the next sentence; Step S4: Repeat Step S2 and Step S3 until the sentence generation ends, and select the combination of sentences with the highest score as the final generated text.
[0011] Optionally, in an embodiment of this application, the large-scale pre-trained model is used to perform text generation according to the input text, and the text generation is specifically:
[0012] Given a language model with a probability distribution, maximize the conditional probability through beam search to complete text generation.
[0013] Optionally, in an embodiment of the present application, text screening of multiple candidate statements includes:
[0014] Construct multiple pairs of reverse prompt texts according to the current input statement of the large-scale pre-trained model and the corresponding multiple generated candidate statements, where the number of candidate statements is the same as the number of reverse prompt texts, and each pair of reverse prompt texts includes an input text and an evaluation text. The input text is the current input statement, and the evaluation text is one of the multiple generated candidate statements;
[0015] Input the reverse prompt text into the large-scale pre-trained model to generate new text;
[0016] Calculate the similarity between the vector center of the model encoding of the new text and the vector center of the evaluation text, and the obtained value is used as the score of the corresponding candidate statement, where the score of the candidate statement is positively correlated with the similarity between the candidate statement and the input statement;
[0017] Select a preset number of candidate statements as alternative statements according to the scores of the candidate statements.
[0018] Optionally, in an embodiment of the present application, an improved beam search scoring function is used for similarity calculation, and the improved beam search scoring function is expressed as:
[0019] f(c g |c p )=logp(c' p |c' g )
[0020] where c' p is the evaluation text in the reverse prompt text, c' g is the reverse prompt text in the new format, c g is the text generated by the model, c p is the prompt text, and p(·) is the maximum conditional probability.
[0021] Optionally, in an embodiment of the present application, an initial prompt text is randomly selected, and the large-scale pre-trained model is used to generate the final generated text, and then the large-scale pre-trained model of the final generated text is fine-tuned, and the loop is performed multiple times to achieve the purpose of training the large-scale pre-trained model.
[0022] To achieve the above object, an embodiment of the second aspect of the present application proposes a computer device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the above-mentioned method for generating text of the pre-trained model based on reverse prompts is implemented.
[0023] To achieve the above object, an embodiment of the third aspect of the present application proposes a non - transitory computer - readable storage medium. When the instructions in the storage medium are executed by a processor, a text generation method based on reverse prompting for a pre - trained model can be executed.
[0024] The text generation method based on reverse prompting for a pre - trained model, computer device, and non - transitory computer - readable storage medium according to the embodiments of the present application solve the technical problem that the generation result of the existing large - scale pre - trained model deviates from the input theme content. At the same time, it also solves the technical problem that the existing method has limitations in improving the relevance between the generation result and the theme by inputting additional prompts related to the subject. By proposing a reverse prompting method and improving the beam scoring function in beam search, the relevance between the prompt and the generated text is enhanced, providing better controllability, and also improving the relevance between the text generated by the large - scale pre - trained model and the input theme, maintaining the coherence of the context. At the same time, the reverse prompting method proposed in the present application uses a dual process to enhance the text generation ability of artificial intelligence, without the need for additional attribute model training or manual definition of patterns, directly using the original language model itself to improve its generation ability, and has achieved good results in practical applications.
[0025] Some of the additional aspects and advantages of the present application will be given in the following description, some will become obvious from the following description, or will be understood through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The above - mentioned and / or additional aspects and advantages of the present application will become obvious and easy to understand from the following description of the embodiments in conjunction with the drawings, where:
[0027] Figure 1 is a flowchart of a text generation method based on reverse prompting for a pre - trained model provided by Embodiment 1 of the present application;
[0028] Figure 2 is a detailed illustration diagram of language model generation and language model reverse prompting of the text generation method based on reverse prompting for a pre - trained model according to the embodiment of the present application;
[0029] Figure 3 is a schematic diagram of the text generation process of the text generation method based on reverse prompting for a pre - trained model according to the embodiment of the present application;
[0030] Figure 4 is a diagram for constructing prompt scores of the text generation method based on reverse prompting for a pre - trained model according to the embodiment of the present application;
[0031] Figure 5 is a diagram for screening candidate sentences of the text generation method based on reverse prompting for a pre - trained model according to the embodiment of the present application;
[0032] Figure 6 Flowchart for generating a Chinese traditional poem titled "New York" by the reverse prompt-based pre-trained model text generation method of the embodiments of the present application. Detailed implementation manners
[0033] The embodiments of the present application will be described in detail below. Examples of the embodiments are shown in the accompanying drawings, where the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by referring to the accompanying drawings are exemplary and are intended to explain the present application and should not be construed as limiting the present application.
[0034] The reverse prompt-based pre-trained model text generation method and apparatus of the embodiments of the present application will be described below with reference to the accompanying drawings.
[0035] Figure 1 Flowchart of a reverse prompt-based pre-trained model text generation method provided in Embodiment 1 of the present application.
[0036] As Figure 1 shown, the reverse prompt-based pre-trained model text generation method includes the following steps:
[0037] Step 101: Input the initial prompt text into the large-scale pre-trained model for text generation to generate multiple candidate sentences for the first sentence;
[0038] Step 102: Screen the multiple candidate sentences, and select a preset number of candidate sentences as alternative sentences in the order of the scores of the candidate sentences from high to low;
[0039] Step 103: Input each alternative sentence as the previous text of the next sentence into the large-scale pre-trained model to generate multiple candidate sentences for the next sentence;
[0040] Step 104: Repeat Step 102 and Step 103 until the sentence generation ends, and select the combination of sentences with the highest score as the final generated text.
[0041] The method for generating text of a pre-trained model based on reverse prompting according to the embodiments of the present application includes the following steps: Step S1: Input the initial prompt text into a large-scale pre-trained model for text generation to generate multiple candidate sentences for the first sentence; Step S2: Screen the multiple candidate sentences, and select a preset number of candidate sentences as alternative sentences in the order of the scores of the candidate sentences from high to low; Step S3: Input each alternative sentence as the above text of the next sentence into the large-scale pre-trained model to generate multiple candidate sentences for the next sentence; Step S4: Repeat Step S2 and Step S3 until the sentence generation ends, and select the combination of sentences with the highest score as the final generated text. Thus, it can solve the technical problem that the generation result of the large-scale pre-trained model in the existing method deviates from the input theme content, and at the same time, it can also solve the technical problem that the improvement of the relevance between the generation result and the theme by inputting additional prompts related to the main body in the existing method has limitations. By proposing a reverse prompting method and improving the beam scoring function in beam search, the relevance between the prompt and the generated text is enhanced, providing better controllability. At the same time, the reverse prompting method proposed in the present application uses a dual process to enhance the text generation ability of artificial intelligence, does not require additional attribute model training or manual definition of patterns, directly uses the original language model itself to improve its generation ability, and has achieved good results in practical applications.
[0042] Further, in the embodiments of the present application, the large-scale pre-trained model is used to generate text according to the input text, and the text generation is specifically as follows:
[0043] Given a language model with a probability distribution, text generation is completed by maximizing the conditional probability through beam search.
[0044] Further, in the embodiments of the present application, screening the multiple candidate sentences includes:
[0045] Construct multiple pairs of reverse prompt texts according to the current input sentence of the large-scale pre-trained model and the multiple candidate sentences generated correspondingly. Among them, the number of candidate sentences is the same as the number of reverse prompt texts. Each pair of reverse prompt texts includes an input text and an evaluation text. The input text is the current input sentence, and the evaluation text is one of the multiple candidate sentences generated correspondingly;
[0046] Input the reverse prompt text into the large-scale pre-trained model to generate new text;
[0047] Calculate the similarity between the vector center of the model encoding of the new text and the vector center of the evaluation text, and the calculated value is used as the score of the corresponding candidate sentence. Among them, the score of the candidate sentence is positively correlated with the similarity between the candidate sentence and the input sentence;
[0048] Select a preset number of candidate sentences as alternative sentences according to the scores of the candidate sentences.
[0049] Input the initial prompt text, and the model starts to generate text. For each sentence generated (when a punctuation mark is generated and the number of words generated in this sentence is greater than 25, it is defined as a sentence), text screening for this group needs to be performed. In the machine poetry writing application, the initial prompt text is: "Theme Author: Author's Name Genre: Poetry Title: Theme Body:". (The italicized and bold parts are variable inputs). For example, if you want the model to write a poem about mountains by Li Bai, the prompt text is: "Mountains Author: Li Bai Genre: Poetry Title: Mountains Body:".
[0050] When generating each sentence, generate 10 candidate sentences for this sentence, and construct 10 pairs of corresponding reverse prompt texts for each candidate sentence and the initial prompt text according to the specific application characteristics. The reverse prompt text has two parts, one part is the input text, and the other part is the evaluation text. The reverse prompt text is constructed from a given piece of generated text. Specifically, after inputting the prompt text: "Mountains Author: Li Bai Genre: Poetry Title: Mountains Body:", the large-scale pre-trained model can output the first sentence of this poem. Here, 4 candidate sentences are set, namely "In the morning, I enter the mountains", "In the morning, I lie horizontally on the hard bed", "In the morning, the floating clouds enter the moss", and "Between the cold mountain stream and the blue color of the sun". Based on these 4 candidate sentences and the original input prompt text, construct the reverse prompt text. Therefore, the reverse prompt text consists of two parts, one is 4 reverse prompt input texts, and the other is 1 reverse prompt evaluation text.
[0051] Input the 10 pairs of reverse prompt texts of this group into the model to generate n texts, and then calculate the similarity between the vector centers of the model encodings of these 10 generated texts and the vector center of the evaluation text respectively, and use this value as the score of the corresponding candidate sentence. In the machine poetry writing application of "open-domain Chinese poetry generation", according to the pre-trained model, calculate the given reverse prompt c p when the original prompt c g The conditional likelihood function of is denoted as f(c g |c p ). The conditional likelihood function f(c g |c p ) can be used as the beam search scoring function f(·) in beam search to select the best candidate sentence, that is:
[0052]
[0053] Input the generated reverse prompt input texts into the model respectively, output the vector representation of the generated text, and then calculate the central vector s’∈c of each sentence respectively g, at the same time, vectorize and encode the reverse prompt evaluation text with the model, and calculate the center vector c' p , finally calculate these two center vectors c' p and the beam search scoring function f(·) of s', and use this similarity calculation as the score of each sentence to form a group of candidate sentences.
[0054] Select the m sentences with the highest scores (m can be preset) from this group of candidate sentences as the previous context of the next sentence and input them into the model respectively.
[0055] Further, in the embodiment of the present application, an improved beam search scoring function is used for similarity calculation, and the improved beam search scoring function is expressed as:
[0056] f(c g |c p ) = logp(c' p |c' g )
[0057] where c' p is the evaluation text in the reverse prompt text, c' g is the reverse prompt text in the new format, c g is the text generated by the model, c p is the prompt text, and p(·) is the maximum conditional probability.
[0058] Given a language model with a probability distribution p, a simple and widely used method for text generation is to maximize the conditional probability p(c g |c p ). This is usually achieved through beam search. In the case of a beam size of n, beam search keeps the top n sequences during decoding according to the beam search scoring function f(·). The commonly used beam scoring function is defined using the log-likelihood function, that is, f(c g |c p ) = logp(c g |c p ).
[0059] An important reason affecting the quality of the generated text is that as the text is continuously generated, the text gradually becomes irrelevant to the given prompt. When the distance between the given prompt and the generated sentence becomes larger, it will prevent the generator from maintaining a close connection with the prompt. To alleviate this problem, a novel beam search scoring function f(·) is proposed, such as the formula f(c g |c p ) = logp(c p |c g) As defined, this function can evaluate the reverse log-likelihood; if prompts can be generated from the text, the prompts should be highly relevant to each other.
[0060] Simply reading the text in reverse, the text will necessarily be unsmooth. A simple reverse definition may lead to learning failure. Due to the nature of natural language, there are methods to rearrange the context so that they appear correctly in the reverse order. To implement reverse prompts, an improved beam search scoring function f(c g |c p ) = logp(c' p |c' g ) is adopted. Reverse prompts sort different beams according to the likelihood function of the beam, thus generating the original prompts in reverse to facilitate the generation of the most relevant text. Reverse prompts can be used as long as the language supports reverse structures to rearrange the prompts and context appropriately.
[0061] The technology for "open-domain Chinese poetry generation" in large-scale pre-trained models randomly generates clauses according to the language model LM and uses reverse prompts for beam search at the clause level. Reverse prompts are applied to each clause and summed. To make the generated context smooth, the scores are combined with the normalized forward perplexity. In addition, a poetic term l format (c g ) is added to the beam search, which penalizes the context according to the degree to which the context violates the rhythm or tone. The scoring function of the beam search for "open-domain Chinese poetry generation" is defined as follows:
[0062]
[0063] Furthermore, in the embodiments of the present application, the initial prompt text is randomly selected, the large-scale pre-trained model is used to generate the final generated text, and then the large-scale pre-trained model of the final generated text is fine-tuned, and the loop is repeated multiple times to achieve the purpose of training the large-scale pre-trained model.
[0064] "Open-domain Chinese poetry generation" requires AI to generate long and in-depth contexts based on relatively short prompts, demonstrating the excellent performance of reverse prompts. A large-scale language model pre-trained on a general corpus is adopted, and reverse prompts are used to enhance its generation quality.
[0065] Since this model is trained on modern Chinese texts that contain very little text in poetic form, it can hardly generate text that fully adheres to the poetic form while also maintaining a high degree of relevance to the given title. Therefore, to improve its performance, the generation and fine-tuning self-training protocol in AlphaGo-Zero was attempted to complete this task. First, 1500 titles were randomly selected, and then the model was made to generate poems based on them. Then, the model in these generated poems was fine-tuned for 2000 steps. This cycle can be repeated multiple times. The fine-tuned model is more likely to generate sentences with better poetic form and other poem-specific attributes (such as aesthetics) without losing their relevance to the given title.
[0066] Figure 2 This is a detailed illustration diagram for the language model generation and language model reverse prompting of the pre-trained model text generation method based on reverse prompting in the embodiments of this application.
[0067] As Figure 2 shown, in the pre-trained model text generation method based on reverse prompting, the reverse prompt sorts different beams according to the likelihood function of the beam, thereby generating the original prompt in a reverse manner to facilitate the generation of the most relevant text. As long as the language supports a reverse structure to rearrange the prompt and context in an appropriate way, reverse prompting can be used. Reverse prompting is a simple and easy-to-implement method that does not require additional model or data processing. The reverse prompt score can be simply calculated through the same generative language model. Reverse prompting greatly improves the quality of the generated text.
[0068] Figure 3 This is a schematic diagram of the text generation process of the pre-trained model text generation method based on reverse prompting in the embodiments of this application.
[0069] As Figure 3 shown, the pre-trained model text generation method based on reverse prompting includes: Step 1, the model outputs the initial prompt text. Input the initial prompt text, and the model starts to generate text; Step 2, construct the reverse prompt text. According to the candidate sentence and the initial prompt text, construct the reverse prompt text. The reverse prompt text has 2 parts, 1 part is the input text, and 1 part is the evaluation text; Step 3, screen the candidate sentences. Input the reverse prompt text into the model to generate n texts. Calculate the similarity between the vector center encoded by the model of the generated text and the vector center of the evaluation text respectively, and use this value as the score of the corresponding candidate sentence; Step 4, determine the next input. Select the m sentences with the highest scores (m can be preset) as the previous text of the next sentence and input them into the model respectively; Step 5, obtain the final generated text. Repeat steps two to four until the sentence generation ends. Finally, select the combination of sentences with the highest scores as the final generation of this text.
[0070] Figure 4 This is the construction prompt score graph for the pre-trained model text generation method based on reverse prompts in the embodiments of this application.
[0071] As Figure 4 shown, in the machine poetry writing application, for the pre-trained model text generation method based on reverse prompts, 4 reverse prompt input texts and 1 reverse prompt evaluation text are respectively generated according to 4 candidate sentences. Specifically, after inputting the prompt text: "Great Mountains, Author: Li Bai, Genre: Poetry, Title: Great Mountains, Text:", the large-scale pre-trained model can output the first sentence of this poem. Here, there are 4 set candidate sentences, namely "Entering the mountain in the morning break", "Lying horizontally in the middle in the morning", "Floating clouds entering the moss in the morning", and "Between the cold stream and the blue color in the sunlight". According to these 4 candidate sentences and the original input prompt text, reverse prompt texts are constructed. The reverse prompt texts consist of two parts, one is 4 reverse prompt input texts, and the other is 1 reverse prompt evaluation text.
[0072] Figure 5 This is the candidate sentence screening graph for the pre-trained model text generation method based on reverse prompts in the embodiments of this application.
[0073] As Figure 5 shown, in the application of machine poetry writing for "open-domain Chinese poetry generation", according to the pre-trained model, when calculating the conditional likelihood function of the original prompt c p for the given reverse prompt c g , it is denoted as f(c g |c p ). The generated reverse prompt input texts are respectively input into the model to output the vector representation of the generated text, and then the central vector s’∈c g of each sentence is calculated respectively. At the same time, the reverse prompt evaluation text is encoded with the model for vector representation, and the central vector c’ p is calculated. Finally, the beam search scoring function f(·) of these 2 central vectors c’ p and s’ is calculated, and this similarity calculation is used as the score of each sentence to form this group of candidate sentences.
[0074] Figure 6 This is the generation flow chart of Chinese traditional poetry with New York as the title for the pre-trained model text generation method based on reverse prompts in the embodiments of this application.
[0075] As Figure 6As shown, to more detailedly illustrate the entire process of machine poetry writing, the machine poetry writing application generates traditional Chinese poems with the title of New York, which not only combines modern concepts of New York, such as Manhattan and the financial center, but also combines traditional forms, such as the traditional poetic imagery of clouds and rain. In this task, the evaluation by human experts shows that the effect of reverse prompting is significantly better than the prompting baseline.
[0076] In the Turing test (also known as the imitation game), human interrogators are required to distinguish between the generated poems and human poems. An online game platform where any player can participate without restriction. In the game, each player is given several pairs of poems, each pair containing a poem written by a human poet and another generated by AI under the same title. In the game, players need to figure out which poem was written by the human poet, generating 1,500 pairs of poems and randomly displaying 5 pairs of poems for each game. 1,656 game records were collected from 370 different users, with an average response time of 23.9 seconds. Each game record involves a binary choice between a human poem and an AI poem. 45.2% of the user records selected the AI poem, and the remaining 54.8% selected the human poem, indicating that the quality of the poems generated through reverse prompting + self-training with domain-specific titles may be close to the human level for ordinary online users.
[0077] To implement the above embodiments, the present application also proposes a computer device, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the method for generating text of the pre-training model based on reverse prompting in the above embodiments.
[0078] To implement the above embodiments, the present application also proposes a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by the processor, it implements the method for generating text of the pre-training model based on reverse prompting in the above embodiments.
[0079] In the description of this specification, the description with reference to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0080] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In the description of the present application, "a plurality of" means at least two, such as two, three, etc., unless otherwise specifically defined.
[0081] Any process or method description represented in a flowchart or otherwise described herein can be understood to represent a module, segment, or portion of code that includes one or more executable instructions for implementing a customized logical function or process. The scope of the preferred embodiments of the present application includes additional implementations, where functions may be performed in a substantially simultaneous manner or in a reverse order according to the functions involved, rather than in the order shown or discussed, which should be understood by those skilled in the technical field to which the embodiments of the present application pertain.
[0082] The logic and / or steps represented in a flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing a logical function, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device), or in conjunction with such instruction execution systems, apparatus, or devices. For the purposes of this specification, a "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (non-exhaustive list) of computer-readable media include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer diskette (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can even be paper or other suitable media on which the program can be printed, as the program can be obtained electronically, for example, by optically scanning the paper or other media, followed by editing, interpretation, or other appropriate processing as necessary, and then stored in a computer memory.
[0083] It should be understood that each part of the present application can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, any one of the following techniques known in the art or a combination thereof can be used: discrete logic circuits having logic gate circuits for implementing logic functions on data signals, application-specific integrated circuits having appropriate combinational logic gate circuits, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0084] Those of ordinary skill in the art can understand that all or part of the steps carried by the methods of the above embodiments can be completed by instructing relevant hardware through a program, and the program can be stored in a computer-readable storage medium. When the program is executed, it includes one or a combination of the steps of the method embodiments.
[0085] In addition, in each embodiment of the present application, the functional units can be integrated into a processing module, or each unit can exist physically alone, or two or more units can be integrated into one module. The above integrated module can be implemented in the form of hardware or in the form of a software functional module. When the above integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium.
[0086] The above-mentioned storage medium can be a read-only memory, a magnetic disk, an optical disk, etc. Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and should not be construed as limiting the present application. Those of ordinary skill in the art can make changes, modifications, substitutions, and variations to the above embodiments within the scope of the present application.
Claims
1. A method for generating text of a pre-trained model based on reverse prompts, characterized in that, it includes the following steps: Step S1: Input the initial prompt text into a large-scale pre-trained model for text generation to generate multiple candidate sentences for the first sentence; Step S2: Screen the multiple candidate sentences, and select a preset number of candidate sentences in descending order of the scores of the candidate sentences as alternative sentences; Step S3: Input each alternative sentence as the context of the next sentence into the large-scale pre-trained model to generate multiple candidate sentences for the next sentence; Step S4: Repeat Step S2 and Step S3 until the sentence generation ends, and select the combination of sentences with the highest score as the final generated text; wherein, screening the multiple candidate sentences includes: Constructing multiple pairs of reverse prompt texts according to the current input sentence of the large-scale pre-trained model and the multiple candidate sentences generated correspondingly, wherein the number of candidate sentences is the same as the number of reverse prompt texts, and each pair of reverse prompt texts includes an input text and an evaluation text, the input text is the current input sentence, and the evaluation text is one of the multiple candidate sentences generated correspondingly; Inputting the reverse prompt text into the large-scale pre-trained model to generate new text; Calculating the similarity between the vector center of the model encoding of the new text and the vector center of the evaluation text, and taking the calculated value as the score of the corresponding candidate sentence, wherein the score of the candidate sentence is positively correlated with the similarity between the candidate sentence and the input sentence; Selecting a preset number of candidate sentences as alternative sentences according to the scores of the candidate sentences.
2. The method according to claim 1, characterized in that, the large-scale pre-trained model is used to generate text according to the input text, and the text generation is specifically: Given a language model with a probability distribution, text generation is completed by maximizing the conditional probability through beam search.
3. The method according to claim 1, characterized in that, the improved beam search scoring function is used for the similarity calculation, and the improved beam search scoring function is expressed as: f(c g |c p ) = logp(c' p |c' g ) Among them, c' p is the evaluation text in the reverse prompt text, c' g is the reverse prompt text in the new format, c g is the text generated by the model, c p is the prompt text, and p(·) is the maximized conditional probability.
4. The method according to claim 1, characterized in that, Randomly select the initial prompt text, use the large-scale pre-trained model to generate the final generated text, and then fine-tune the large-scale pre-trained model of the final generated text, and loop multiple times to achieve the purpose of fine-tuning the large-scale pre-trained model.
5. A computer device, characterized in that, it includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the method described in any one of claims 1-4 is implemented.
6. A non-transitory computer-readable storage medium, on which a computer program is stored, characterized in that, when the computer program is executed by a processor, the method described in any one of claims 1-4 is implemented.
Citation Information
Patent Citations
Language representation model system, pre-training method and device of language representation model, equipment and medium
CN111914551A
Language generation model based on composition theory feature classifier and writing support method
CN112182210A