Text generation method and device and storage medium
Through the reverse prompt method, the pre-trained language model is used to generate and modify the prompt template, which solves the problem that existing text generation models are difficult to accurately control the generated content, and achieves higher personalized and targeted text generation, which improves user satisfaction .
Patent Information
- Application Number
- CN202310768487.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-27
- Publication Date
- 2024-12-27
AI Technical Summary
The existing text generation model is difficult to accurately control the generated content, cannot effectively meet the specific needs of users, and is prone to generate meaningless or inconsistent text.
Through the reverse prompt method, the text information entered by the user, including instructions and news text, uses the pre-trained language model to generate and modify the prompt template, randomly combine and input to generate and train the model, ensuring that the generated text meets user expectations.
Accurate control of generated text is achieved, personalization and targeted text is improved, meaningless or unsatisfactory generation is avoided, and user satisfaction and model flexibility is enhanced.
Smart Images

Figure CN119203986A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a text generation method, device and storage medium. Background Art
[0002] News generation is a very challenging task as it requires generating coherent, accurate, credible, and attractive news content. However, current models are often black boxes, and we cannot control the generated content or guarantee that the generated content meets our expectations.
[0003] In the field of artificial intelligence, prompts refer to input prompts or text snippets used to generate natural language text, which can generate corresponding output text based on the initial text and contextual information provided by the user. Take GPT-3 (Generative Pre-trained Transformer 3) as an example. It is a large-scale language model based on the Transformer architecture. After receiving the prompt, it uses the learned knowledge and data to generate qualified text responses. Prompts are one of the important links connecting human and computer interaction. It can help reduce the workload of manually writing code or rules, especially when it comes to large-scale data and complex scenarios. In addition, prompts can also improve the quality and efficiency of text generation, making the interaction between computers and humans smoother and more natural.
[0004] However, it is not easy to write good prompts so that the model can generate text that meets user expectations. One feasible way is to use prompt reverse engineering. Prompt reverse engineering refers to the process of generating specific text content by inferring the model results. Specifically, it aims to crack the hidden rules and knowledge in the language model, and by analyzing the intention and structure of a specific text, infer the prompts that can achieve control and customization of text generation. This method can be used in scenarios such as generating false information, fraudulent text, malicious attacks, etc., and can also be used as one of the methods to evaluate and improve language models. Summary of the invention
[0005] The present invention provides a text generation method, device and storage medium.
[0006] A first aspect of an embodiment of the present disclosure provides a text generation method, which is applied to an electronic device, and the method includes:
[0007] Acquire text information input by a user; wherein the text information includes instruction information and a first news text;
[0008] Inputting the expected instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template;
[0009] Acquire the modified first prompt template to obtain a second prompt template;
[0010] Inputting the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template;
[0011] Randomly combining the first news attribute and the third prompt template to obtain a fourth prompt template;
[0012] Inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model;
[0013] Input the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model;
[0014] The news attribute input by the user is combined with the third prompt template and input into the trained language model to obtain the desired third news text.
[0015] Based on the above scheme, the instruction information is: please analyze the theme, keywords, source, emotion, style, tone and / or length characteristics of the following news, and provide a prompt template for generating news based on the characteristics.
[0016] Based on the above solution, the first prompt template is composed of: including information of the first news attribute.
[0017] Based on the above scheme, the second prompt template is: Please write an article of [style] [length] with [tone] for [source], the theme is [topic], and it contains [keywords].
[0018] Based on the above scheme, the third prompt template is: write a news report related to [topic], including the following keywords [keywords], news source [source], emotion [emotion], style [style], tone [tone], length [length].
[0019] Based on the above solution, the fourth prompt template includes: detailed information of the subject, the keywords, the source, the emotion, the style, the tone and the length in the first news attribute.
[0020] Based on the above scheme, the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text are input into the pre-trained language model as training data to obtain a trained language model, including:
[0021] Mixing data pairs according to the fourth prompt template and the second news text generated by the model, the corresponding first prompt template and the corresponding first news text;
[0022] The mixed data is used as training data to train the language model to obtain the trained language model.
[0023] A second aspect of the present disclosure provides a text generation device, characterized in that it is applied to an electronic device, and the device includes:
[0024] A first acquisition module, used to acquire text information input by a user; wherein the text information includes instruction information and a first news text;
[0025] A first generating module, configured to input the instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template;
[0026] A second acquisition module, used to acquire the modified first prompt template to obtain a second prompt template;
[0027] A second generating module is used to input the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template;
[0028] A third generating module, configured to randomly combine the first news attribute and the third prompt template to obtain a fourth prompt template;
[0029] A fourth generating module, used for inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model;
[0030] A training module, used for inputting the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model;
[0031] The fifth generation module is used to combine the news attributes input by the user and the third prompt template, and input them into the trained language model to obtain the expected third news text.
[0032] A third aspect of an embodiment of the present disclosure provides a non-temporary computer-readable storage medium. When instructions in the storage medium are executed by a processor of a computer, the computer is enabled to execute any of the text generation methods described above.
[0033] The technical solution provided by the embodiments of the present disclosure may have the following beneficial effects:
[0034] The disclosed embodiment proposes a text generation method for improving the quality of generated text. Unlike traditional generation models, reverse prompts take the target output text as input, which can more accurately control the content of the generated text. This method can avoid generating meaningless or unexpected text. Reverse prompts can customize the generated text well according to the user's needs and input data, so that the generated text is closer to the user's actual needs and requirements, and has higher personalization and pertinence. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.
[0036] Figure 1 is a flowchart of a text generation method according to an exemplary embodiment;
[0037] Figure 2 It is a flowchart of a text generation method according to an exemplary embodiment. DETAILED DESCRIPTION
[0038] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices consistent with some aspects of the present disclosure as detailed in the appended claims.
[0039] The current method of generating prompts is usually manually written based on templates or rules. Among them, the template-based method is the most common, which generates the corresponding text content through predefined text templates and rules. Since a large number of templates and rules need to be manually written, the scalability of this method is poor.
[0040] The second is a rule-based approach, which uses grammatical and semantic rules to generate text, and can generate specific text responses based on given contexts and conditions. Although it is more flexible than the template-based approach, it requires constant updating and maintenance of the rules.
[0041] Existing template- or rule-based methods need to be designed based on manual experience, rely on prior knowledge and require a long debugging time, and it is difficult to design the optimal prompt.
[0042] Existing methods are unable to cope with complex language phenomena. Natural language is highly diverse and flexible. It is difficult to cover all language phenomena and expressions through rule-based description prompts. They lack flexibility and are difficult to dynamically adjust according to context and conditions, thus failing to achieve better generalization capabilities.
[0043] Secondly, rule description prompts require manual writing of a large number of rules and templates, which need to be constantly updated and maintained. The demand for manually written rules is high, the workload is huge, and loopholes and errors are prone to occur, resulting in poor quality of the generated text.
[0044] In addition, describing prompts through rules requires knowing the type and characteristics of the target task in advance. In some cases, it may not be possible to accurately describe the task requirements, thus affecting the quality of the generated results.
[0045] Therefore, the embodiments of the present disclosure provide the following method.
[0046] like Figure 1 As shown, an embodiment of the present disclosure provides a text generation method, which is applied to an electronic device, and the method includes:
[0047] S110: Acquire text information input by a user; wherein the text information includes instruction information and a first news text;
[0048] S120: Inputting the expected instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template;
[0049] S130: Acquire the modified first prompt template to obtain a second prompt template;
[0050] S140: Inputting the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template;
[0051] S150: randomly combining the first news attribute and the third prompt template to obtain a fourth prompt template;
[0052] S160: Inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model;
[0053] S170: Input the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model;
[0054] S180: Combining the news attribute input by the user with the third prompt template, and inputting the combined combination into the trained language model to obtain the desired third news text.
[0055] The electronic device may be any mobile terminal or fixed terminal. For example, the mobile terminal may include various smart home devices, wearable devices, tablet computers, smart office equipment, or mobile phones. The fixed terminal may be a desktop computer, etc. The embodiments of the present disclosure do not specifically limit the electronic device.
[0056] In one embodiment, according to the actual application scenario, a batch of reference news texts expected to be generated are input to the model, and the model is required to write prompts. The reference news text information expected to be generated here includes the above-mentioned expected instruction information and the first news text.
[0057] For example, the desired instruction information in the text information input by the user is “Please analyze the following news’s theme, keywords, source, emotion, style, tone, length, etc., and combine these characteristics to provide a prompt template that can generate this news. It can be understood that based on the news writing template (i.e., the first prompt template) given by the pre-trained language model in step S130, a general prompt (i.e., the second prompt template) is manually modified and written, and the news features analyzed in step S120 are input as placeholders to the pre-trained language model to generate more prompts.
[0069] For example, the manually written template (i.e., the second prompt template) is: “Please write an article for [source] with [tone] of [style] of [length], the subject is [topic], and contains [keywords].”
[0070] The template output by the pre-trained language model (i.e., the third prompt template): "Write a news report related to [topic], which needs to include the following keywords [keywords], the news comes from [source], emotion [emotion], style [style], tone [tone], and length [length]."
[0071] It can be understood that the prompt generated by the pre-trained language model (ie, the third prompt template) is input into the pre-trained language model again, so that the pre-trained language model generates more news text (ie, the fourth prompt template) according to the prompt.
[0073] In one embodiment, the "news→prompt template" data pair generated from the original news text input in S110 and the "prompt template→news" data pair generated by the model-generated news text in S150 are mixed and input into a pre-trained language model as training data, and the pre-trained language model is fine-tuned to obtain a language model for news generation (i.e., a trained language model).
[0074] Based on the prompt template of step S130, the news topic and features to be generated are input into the fine-tuned language model to generate the expected news text.
[0075] The method provided by the embodiment of the present disclosure can generate and optimize prompts. With the help of the model, based on simple templates and the analysis ability of the model, the efficiency of prompt generation and testing can be greatly improved. However, in the key steps, human intervention is still required to provide some clear thinking directions and limiting conditions for the model.
[0076] The present invention proposes a method to improve the quality of generated text: Unlike traditional generation models, reverse prompts take the target output text as input, which can more accurately control the content of the generated text. This method can avoid generating meaningless or unexpected text. Reverse prompts can customize the generated text well according to the user's needs and input data, so that the generated text is closer to the user's actual needs and requirements, and has higher personalization and pertinence.
[0077] In some embodiments, the expected instruction information is: please analyze the subject, keywords, source, emotion, style, tone and / or length characteristics of the following news, and provide a prompt template for generating news based on the characteristics.
[0078] In some embodiments, the first prompt template is composed of: including information of the first news attribute.
[0079] In some embodiments, the second prompt template is: Please write an article for [source] with [tone], [style], [length], the subject is [topic], and contains [keywords].
[0080] In some embodiments, the third prompt template is: write a news report related to [topic], containing the following keywords [keywords], news source [source], emotion [emotion], style [style], tone [tone], length [length].
[0081] In some embodiments, the fourth prompt template includes: detailed information of the subject, the keywords, the source, the emotion, the style, the tone and the length in the first news attribute.
[0082] In some embodiments, Figure 2 As shown, the S170 includes:
[0083] S171: Mixing data pairs according to the fourth prompt template and the second news text generated by the model, the corresponding first prompt template and the corresponding first news text;
[0084] S172: Using the mixed data as training data to train the language model, and obtaining the trained language model.
[0085] The present disclosure provides a text generation device 200, which is applied to an electronic device. The device includes:
[0086] A first acquisition module, used to acquire text information input by a user; wherein the text information includes instruction information and a first news text;
[0087] A first generating module, configured to input the instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template;
[0088] A second acquisition module, used to acquire the modified first prompt template to obtain a second prompt template;
[0089] A second generating module is used to input the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template;
[0090] A third generating module, configured to randomly combine the first news attribute and the third prompt template to obtain a fourth prompt template;
[0091] A fourth generating module, used for inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model;
[0092] A training module, used for inputting the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model;
[0093] The fifth generation module is used to combine the news attributes input by the user and the third prompt template, and input them into the trained language model to obtain the expected third news text.
[0094] In some embodiments, the expected instruction information is: please analyze the subject, keywords, source, emotion, style, tone and / or length characteristics of the following news, and provide a prompt template for generating news based on the characteristics.
[0095] In some embodiments, the first prompt template is composed of information prefixed with the feature in the expected instruction information.
[0096] In some embodiments, the second prompt template is: Please write an article for [source] with [tone], [style], [length], the subject is [topic], and contains [keywords].
[0097] In some embodiments, the third prompt template is: write a news report related to [topic], containing the following keywords [keywords], news source [source], emotion [emotion], style [style], tone [tone], length [length].
[0098] In some embodiments, the fourth prompt template includes: detailed information of the subject, the keywords, the source, the emotion, the style, the tone and the length in the third prompt template.
[0099] In some embodiments, the training module is specifically used to mix data pairs according to the fourth prompt template and the second news text generated by the model, the first prompt template and the first news text; use the mixed data as training data to train the language model to obtain the trained language model.
[0100] The disclosed embodiment provides a prompt reverse engineering method for language model text generation. Compared with the existing methods, the present invention has the following advantages:
[0101] 1) Inverse prompts can better understand user input, thereby generating more accurate and targeted responses, allowing the model to better interact with users and provide better services.
[0102] 2) Using reverse hints can speed up model building and testing time. By using existing models and language datasets, developers can develop and test new natural language generation models more quickly, reducing model building and testing time.
[0103] 3) Reverse prompts can help developers better expand the model's functionality. By adding new prompts to increase the model's knowledge base, the model can better understand and respond to user needs.
[0104] 4) Ultimately, using reverse prompts can improve user satisfaction, and better understanding and answering user questions can provide better service. This can further promote user trust and loyalty, thereby improving the efficiency and effectiveness of the entire business.
[0105] The present disclosure provides a non-temporary computer-readable storage medium. When the instructions in the storage medium are executed by the processor of the UE, the UE or the base station can execute the text generation method provided in any of the above embodiments, and can execute Figure 1 and Figure 2 At least one of any of the methods shown.
[0106] A text generation method applied to an electronic device may include: obtaining text information input by a user; wherein the text information includes instruction information and a first news text; inputting the expected instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template; obtaining the modified first prompt template to obtain a second prompt template; inputting the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template; randomly combining the first news attribute and the third prompt template to obtain a fourth prompt template; inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model; using the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data, and inputting them into the pre-trained language model to obtain a trained language model; combining the news attribute input by the user and the third prompt template, and inputting them into the trained language model to obtain an expected third news text.
[0107] It can be understood that the instruction information is: please analyze the subject, keywords, source, emotion, style, tone and / or length characteristics of the following news, and provide a prompt template for generating news based on the characteristics.
[0108] It can be understood that the first prompt template is composed of: including information of the first news attribute.
[0109] Understandably, the second prompt template is: Please write an article for [source] in [tone], [style], [length], with the theme of [topic], and containing [keywords].
[0110] Understandably, the third prompt template is: write a news report related to [topic], containing the following keywords [keywords], news source [source], emotion [emotion], style [style], tone [tone], length [length].
[0111] It can be understood that the fourth prompt template includes: detailed information of the subject, the keywords, the source, the emotion, the style, the tone and the length in the first news attribute.
[0112] It can be understood that the fourth prompt template and the second news text generated by the model as well as the first prompt template and the first news text are input into the pre-trained language model as training data to obtain the trained language model, including:
[0113] Mixing data pairs according to the fourth prompt template and the second news text generated by the model, the corresponding first prompt template and the corresponding first news text;
[0114] The mixed data is used as training data to train the language model to obtain the trained language model.
[0115] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0116] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A text generation method, characterized in that: Applied in an electronic device, the method comprises: Acquire text information input by a user; wherein the text information includes instruction information and a first news text; Inputting the expected instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template; Acquire the modified first prompt template to obtain a second prompt template; Inputting the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template; Randomly combining the first news attribute and the third prompt template to obtain a fourth prompt template; Inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model; Input the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model; The news attribute input by the user is combined with the third prompt template and input into the trained language model to obtain the desired third news text.
2. The method according to claim 1, characterized in that The instruction information is: please analyze the subject, keywords, source, emotion, style, tone and / or length characteristics of the following news, and provide a prompt template for generating news based on the characteristics.
3. The method according to claim 1, characterized in that The first prompt template is composed of: including information of the first news attribute.
4. The method according to claim 1, characterized in that: The second prompt template is: Please write an article for [source] in [tone], [style], [length], with the theme of [topic], and containing [keywords].
5. The method according to claim 1, characterized in that The third prompt template is: write a news report related to [topic], including the following keywords [keywords], news source [source], emotion [emotion], style [style], tone [tone], length [length].
6. The method according to claim 5, characterized in that The fourth prompt template includes detailed information of the subject, the keyword, the source, the emotion, the style, the tone and the length in the first news attribute.
7. The method according to claim 1, characterized in that The fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text are input as training data into the pre-trained language model to obtain a trained language model, including: Mixing data pairs according to the fourth prompt template and the second news text generated by the model, the corresponding first prompt template and the corresponding first news text; The mixed data is used as training data to train the language model to obtain the trained language model.
8. A text generation device, characterized in that: Applied in electronic equipment, the device comprises: A first acquisition module, used to acquire text information input by a user; wherein the text information includes instruction information and a first news text; A first generating module, configured to input the instruction information and the first news text into a pre-trained language model to obtain a first news attribute and a first prompt template; A second acquisition module, used to acquire the modified first prompt template to obtain a second prompt template; A second generating module is used to input the second prompt template into the pre-trained language model for expansion operation to obtain a third prompt template; A third generating module, configured to randomly combine the first news attribute and the third prompt template to obtain a fourth prompt template; A fourth generating module, used for inputting the fourth prompt template into the pre-trained language model to obtain a second news text generated by the model; A training module, used for inputting the fourth prompt template and the second news text generated by the model, as well as the first prompt template and the first news text as training data into the pre-trained language model to obtain a trained language model; The fifth generation module is used to combine the news attributes input by the user and the third prompt template, and input them into the trained language model to obtain the expected third news text.
9. A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a computer, enables the computer to execute the text generation method according to any one of claims 1 to 7.
