Controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning

Through the method of fine-grained planning mechanism and instruction fine-tuning, the problems of incoherence and logical contradiction in text generation in the existing technology are solved, precise control and logical consistency of text are achieved, and the controllability and user review of generated text are enhanced. ability.

CN118410795BActive Publication Date: 2024-09-13UNIV OF SCI & TECH OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410879525.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-09-13
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

Existing controllable text generation technology does not control the content of the generated text well. The generated text may have problems such as incoherence and logical contradictions, and it is impossible to finely control the structure of the generated text.

Method used

Using a method based on fine-grained planning mechanism and instruction fine-tuning, by generating multi-level fine-grained outlines as control signals, combined with causal language modeling, the large language model is trained to achieve precise control and logical consistency of the text.

Benefits of technology

It achieves precise control over generated text, with strong logical coherence without introducing additional model or training overhead. It increases the controllability of generated text and facilitates human review and revision.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118410795B
    Figure CN118410795B
Patent Text Reader

Abstract

The present invention relates to the technical field of controllable text generation, and discloses a controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning; a multi-level fine-grained outline is generated based on subject-text data; structured instruction fine-tuning data is constructed: some seed instructions are manually written, and then an instruction fine-tuning data set consisting of multiple complete instructions is obtained; based on the instruction fine-tuning data set, a large language model is trained in the form of causal language modeling, so that the large language model has the ability to plan an outline according to a subject and write a text with the outline as a control signal; an instruction containing a subject is input into the trained large language model, and the large language model can plan an outline according to the subject and generate a text according to the outline; the present invention does not introduce additional overhead, and the outline fine-grainedly restricts the style, content, and position of the text content, and can effectively realize the content controllability of the generated text.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of controllable text generation, and in particular to a controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning. Background Art

[0002] Text generation is one of the key research issues in the field of natural language processing, and has important applications in human-computer interaction, intelligent writing, and other fields. With the development of artificial intelligence technology, people have higher and higher requirements for text generation technology. For example, to assist in the creation of high-quality news reports and advertising copy, high-quality and controllable text generation technology is required. Controllable text generation is to increase the control of some attributes, style, key information, etc. of the generated text on the basis of traditional text generation, so that the generated text meets certain expectations, improves the quality and usability of the generated text, and helps to achieve more accurate and effective text generation in various application scenarios. For example, in the field of automated writing, controllable text generation technology can make the generated news reports or advertising copy more in line with the needs of the target audience by controlling the tone, emotional tendency, key information and other attributes of the generated text, thereby improving the quality and effect of the text. Therefore, how to perform high-quality and refined controllable text generation has a high research value.

[0003] Existing controllable text generation technology is mainly based on pre-trained language models, which use the massive knowledge they have learned to process the model input or output to achieve controllable text generation. The current controllable text generation methods are generally divided into two types: (1) Processing and correcting the model output to meet certain expectations, such as correcting the output of the pre-trained language model through an additional attribute control model to achieve the purpose of controlling the attributes of the generated text; (2) Using the requirements for text content as instructions to control generation, and the target text as output, the pre-trained language model is fine-tuned to enable the model to generate the required text under specific instructions. These two methods have poor control over the content of the generated text. The generated text may have problems such as incoherence and logical contradictions, and it is impossible to fine-tune the structure of the generated text. Summary of the invention

[0004] In order to solve the above technical problems, the present invention provides a controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning. Compared with the existing controllable text generation technology, the present invention uses a planning-generation method to complete the task. The method has the following advantages: (1) Text attribute control is completed from the perspective of training data and task form. The model training and reasoning process is no different from the ordinary instruction fine-tuning model, and no additional model, training and reasoning overhead are introduced; (2) The present invention can achieve precise control of the text by generating a multi-level fine-grained outline as a control signal, and the generated text is logically coherent and consistent; (3) The method proposed by the present invention is easy to introduce human review and revision, which increases the controllability of the generated text.

[0005] In order to solve the above technical problems, the present invention adopts the following technical solutions:

[0006] A controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning includes the following steps:

[0007] Step 1: Generate a multi-level fine-grained outline based on the topic-text data, which includes the following steps:

[0008] S11, from the text dataset Select some data consisting of topics and texts, and manually write outlines according to the designed outline template as an example ; Text dataset ,in is the i-th topic, is the ith text, Is a positive integer; write instructions to generate an outline ;

[0009] S12, the theme ,text , instructions for generating an outline and examples Connect and input into the large language model M to generate the corresponding outline : ;

[0010] S13, traversing the text dataset , and repeat step S12 to construct a triple data consisting of topic, outline and text Collection : ;

[0011] Step 2: Construct structured instruction fine-tuning data: manually write some seed instructions; based on the seed instructions, generate multiple instructions through a large language model to form an instruction set ; The seed instruction and the instruction generated by the large language model include the topic variable slot {topic}, the outline variable slot {outline}, and the text variable slot {passage}; Each triplet of data in the instruction set Randomly select an instruction from the dataset, and fill the topic, outline, and text in the ternary data into the corresponding topic variable slots {topic}, outline variable slots {outline}, and text variable slots {passage} in the instruction to obtain a complete instruction; then obtain an instruction fine-tuning dataset consisting of multiple complete instructions ;

[0012] Step 3: fine-tune the dataset based on the instructions and train the large language model using causal language modeling to obtain a controllable text generation model;

[0013] Step 4: Input instructions containing the topic into the controllable text generation model, and the controllable text generation model can plan an outline according to the topic and generate the main text according to the outline; or, input instructions containing the topic and the outline into the controllable text generation model, and the controllable text generation model can generate the main text that meets the topic requirements according to the topic and the outline.

[0014] Furthermore, in step 3, the large language model is trained using causal language modeling, specifically including:

[0015] Maximize the probability that the large language model will correctly generate the next word:

[0016] ;

[0017] in, is the trainable parameter of the large language model, For the The words output at any time, For the front The text composed of words generated at each moment, Expressed as is the maximization operation of factors, Indicates the calculation probability; the cross entropy loss function is used for training :

[0018] ;

[0019] in, The number of words contained in the sentences generated for the large language model.

[0020] Compared with the prior art, the beneficial technical effects of the present invention are:

[0021] (1) No additional overhead: The present invention uses instruction fine-tuning to perform attribute control. No additional model is introduced for attribute control, no additional training and inference overhead is introduced, and no additional weight storage space is introduced. (2) Accurate control: The outline restricts the style, content, and stance of the text in a fine-grained manner, which can effectively achieve content controllability of the generated text. (3) Convenient human-computer collaboration: The two-stage generation method allows user review and editing to be introduced during the generation process, making the generation process more controllable. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 It is the overall flow chart of the present invention. DETAILED DESCRIPTION

[0023] A preferred embodiment of the present invention is described in detail below with reference to the accompanying drawings.

[0024] Controllable text generation technology is usually defined as the process of generating subsequent text given a text prefix and specific elements such as specific attributes, style, key information, etc.

[0025] The process of the controllable text generation method proposed by the present invention is as follows Figure 1 As shown in the figure, it includes the following three parts: (1) generating a multi-level fine-grained outline based on topic-text data; (2) constructing structured instruction fine-tuning data; (3) fine-tuning the instruction on the large language model.

[0026] 1. Generate a multi-level fine-grained outline based on topic-text data.

[0027] 1) Design outline:

[0028] Note that the existing text dataset is ,in For the theme, For the main text, is the data entry number, is a positive integer; a large language model such as GPT4 is used to extract a multi-level fine-grained outline. The outline template includes:

[0029] Overall framework: summarize the overall structure of the article and the role of each paragraph;

[0030] Paragraph details: Summarize the main content and writing ideas of each paragraph.

[0031] The outline template is shown in Table 1.

[0032] Table 1

[0033]

[0034] 2) Generate outline data in batches:

[0035] The amount of text data is large, the outline writing task is complex, and the cost of manual annotation is high, so a general large language model is used to complete this task. Based on large language models such as OpenAI GPT, Wenxin Yiyan, Tongyi Qianwen, etc., the outline data is generated on a large scale using context learning and prompt learning methods. The specific methods are as follows:

[0036] From the text dataset A small amount of data is selected from the dataset and an outline is manually written as an example, which is recorded as .

[0037] Write instructions to generate an outline , provide the topic and text, so that the big language model can generate an outline based on the outline template.

[0038] For large language models ,theme ,text , which will generate the outline instructions With example Connect and input large language model , which can generate an outline :

[0039] .

[0040] Iterating over the text dataset , construct triple data consisting of topic, outline and text Collection :

[0041] .

[0042] 2. Construct structured instructions to fine-tune data.

[0043] 1) Generate diverse instructions based on self-guidance:

[0044] Since it is impossible to restrict the form of user input instructions, it is necessary to ensure that the trained large language model can understand instructions of various formats and complete the generation function. To achieve the above goals, it is necessary to construct a variety of instructions. However, manually writing instructions is time-consuming and costly, and the diversity is limited by the annotator. Therefore, this process can also be carried out using a general large language model, that is, a self-guided method.

[0045] Manually write a small number of instructions, for example: "Please plan and write an article with the theme {topic}:\nOutline: {outline}\nMain text: {passage}". Among them, {topic}, {outline}, {passage} are variable slots for subsequent filling of specific content. This part of the instructions is called seed instructions; "\n" is a line break character, which is used to increase the readability of input and output.

[0046] The general language model generates more diverse instructions based on seed instructions. For example, the instructions to complete this function are: "Here are some instructions for planning and writing articles based on topics. Please follow these instructions to write 20 more instructions with the same function, using as diverse terms as possible: {demonstrations}". After the seed instructions are listed in pieces and filled into the {demonstrations} variable slot, they are input into the large language model for expansion, and finally a large number of diverse instructions are obtained to form an instruction set. .

[0047] 2) Construct fine-tuning data:

[0048] Collection-based and instruction set , construct instruction fine-tuning dataset:

[0049] for Each triplet of data in the instruction set Randomly select an instruction and fill the subject, outline, and text into the corresponding title, outline, and passage variable slots in the instruction respectively.

[0050] Add identifiers to the command data for format control and output extraction. Identifiers include the following: <bos> 、 <eos>, placed at the beginning and end of the entire instruction data; <endofoutline>, marking the end of the outline.

[0051] After being constructed in the above manner, a complete instruction data format is shown in Table 2.

[0052] Table 2

[0053]

[0054] After the above process, the instruction fine-tuning dataset is constructed , which will be used for model training later.

[0055] 3. Fine-tune the instructions of the large language model to obtain a controllable text generation model.

[0056] Instruction fine-tuning is to use instruction data to fine-tune the large language model, and the training task is causal language modeling. The form of this task is the same as the pre-training form of the large language model, that is, the large language model can continue to write the next context based on the given previous context. The training data is replaced with instruction data with a special format, that is, the large language model has the ability to recognize and respond to human instructions. During training, the probability of the large language model generating the correct next word is maximized. The process is expressed by the following formula, where is the trainable parameter of the large language model, For the The words output at any time, For the front Sentences composed of words generated at each moment:

[0057] .

[0058] Expressed as For the factor maximization operation, the cross entropy loss function is used for training , the formula is as follows, where Number of words contained in sentences generated for the large language model:

[0059] .

[0060] Fine-tune the dataset based on instructions , fine-tuning the large language model so that the resulting controllable text generation model has the ability to plan an outline according to the topic and use the outline as a control signal to write the main text.

[0061] In a preferred embodiment, the large language model can select a mainstream pre-trained Transformer generation model. The English large language model includes LLaMA and Mistral, and the Chinese large language model includes Qwen, Baichuan, etc.

[0062] During training, the input and labels of the large language model are both instruction data, and the labels need special processing. <bos>Please plan and write an article with the theme of... "Replace with special mask markers <mask>, only participates in the calculation of attention during the forward propagation process, and does not participate in the calculation of the loss function.

[0063] After training, input " <bos>Please plan and write an article with the theme of "...", the controllable text generation model can complete the planning and generation at the same time; and by inputting the theme and planning content into the controllable text generation model, the controllable text generation model can generate the text that meets the requirements according to the theme and planning.

[0064] Therefore, the controllable text generation model obtained after fine-tuning has two reasoning paradigms: (1) only provide the topic, so that the controllable text generation model plans the outline, manually reviews or modifies the outline to meet specific style, content, and position requirements, and then inputs the topic and outline into the controllable text generation model to generate the text; (2) provide the topic and outline, and directly let the controllable text generation model generate the text according to the outline.

[0065] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-limiting, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention, and any reference numerals in the claims should not be regarded as limiting the claims involved.

[0066] In addition, it should be understood that although this specification is described in terms of implementation methods, not every implementation method contains only one independent technical solution. This narrative method of the specification is only for the sake of clarity. Those skilled in the art should regard the specification as a whole. The technical solutions in each embodiment may also be appropriately combined to form other implementation methods that can be understood by those skilled in the art.< / bos> < / mask> < / bos> < / endofoutline> < / eos> < / bos>

Claims

1. A controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning, characterized in that: The following steps are involved: Step 1: Generate a multi-level fine-grained outline based on the topic-text data, which includes the following steps: S11, from the text dataset Select some data consisting of topics and texts, and manually write outlines according to the designed outline template as an example ; Text dataset ,in is the i-th topic, is the ith text, Is a positive integer; write instructions to generate an outline ; S12, the theme ,text , instructions for generating an outline and examples Connect and input into the large language model M to generate the corresponding outline : ; S13, traversing the text dataset , and repeat step S12 to construct a triple data consisting of topic, outline and text Collection : ; Step 2: Construct structured instruction fine-tuning data: manually write some seed instructions; based on the seed instructions, generate multiple instructions through a large language model to form an instruction set ; The seed instruction and the instruction generated by the large language model include the topic variable slot {topic}, the outline variable slot {outline}, and the text variable slot {passage}; Each triplet of data in the instruction set Randomly select an instruction from the dataset, and fill the topic, outline, and text in the ternary data into the corresponding topic variable slots {topic}, outline variable slots {outline}, and text variable slots {passage} in the instruction to obtain a complete instruction; then obtain an instruction fine-tuning dataset consisting of multiple complete instructions ; Step 3: fine-tune the dataset based on the instructions and train the large language model using causal language modeling to obtain a controllable text generation model; Step 4: Input instructions containing a topic into the controllable text generation model, and the controllable text generation model can plan an outline according to the topic and generate the main text according to the topic and the outline; or, input instructions containing a topic and an outline into the controllable text generation model, and the controllable text generation model can generate a main text that meets the requirements of the topic and the outline according to the topic and the outline.

2. The controllable text generation method based on fine-grained planning mechanism and instruction fine-tuning according to claim 1 is characterized in that: In step 3, the large language model is trained using causal language modeling, specifically including: Maximize the probability that the large language model will correctly generate the next word: ; in, is the trainable parameter of the large language model, For the The words output at any time, For the front The text composed of words generated at each moment, Expressed as is the maximization operation of factors, Indicates the calculation probability; the cross entropy loss function is used for training : ; in, The number of words contained in the sentences generated for the large language model.