A text style transfer method based on decoupled module mining

Through a method based on decoupled module mining, sentences are divided into content modules and attribute modules, and specific loss functions are designed to optimize prefix parameters, solving the problems of insufficient semantic preservation and inaccurate style in existing text style migration, and achieving It achieves text style transfer effect with high style accuracy and high semantic preservation.

CN118378612BActive Publication Date: 2024-09-27ARTIFICIAL INTELLIGENCE RES INST OF HEFEI COMPREHENSIVE NAT SCI CENT (ANHUI ARTIFICIAL INTELLIGENCE LAB)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410810413.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-27
Estimated Expiration
2044-06-21

AI Technical Summary

Technical Problem

Due to the lack of parallel data, existing text style transfer methods result in insufficient semantic preservation and inaccurate style in the conversion process, with high semantic divergence and poor transfer quality.

Method used

Using a method based on decoupling module mining, sentences are divided into content modules and attribute modules. Only prefix parameters are trained through pre-training language models with frozen parameters. BLEU scores are used to measure semantic preservation, and comparative learning losses and sequences are designed. to sequence loss, and optimize prefix parameters to achieve text style transfer with high style accuracy and high semantic preservation.

Benefits of technology

It achieves text style transfer with high style accuracy and high semantic preservation. The generated sentences are more precise in style and more complete in semantics, which solves the problems of insufficient semantic preservation and imprecise style in existing methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118378612B
    Figure CN118378612B
Patent Text Reader

Abstract

The invention discloses a text style transfer method based on decoupling module mining, wherein any given sentence and target style are input into a pre-trained language model, and a sentence containing target style attributes is generated while the content of the input sentence remains unchanged; the pre-trained language model splices a prefix token as a virtual token before the input sentence, and maps the prefix token to the prefix embedding of each layer through a trainable matrix #imgabs0#, and the matrix #imgabs1# is the only trainable prefix parameter, so that only continuous prefix parameters are trained and adjusted while the pre-trained language model parameters are frozen; the text style transfer method realizes text style transfer with high style accuracy and high semantic preservation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of text processing, and in particular to a text style transfer method based on decoupling module mining. Background Art

[0002] Text style transfer is a key task in the field of natural language generation, which aims to preserve the core semantics of a sentence while changing its style attributes, including but not limited to sentiment, politeness, and format. This task can not only be used to neutralize offensive speech, but is also beneficial to a variety of downstream tasks such as unsupervised summarization, translation, and even speech recognition.

[0003] Due to the lack of parallel data as supervisory information, existing mainstream methods are designed in an unsupervised manner. These methods introduce additional style embeddings into the Transformer architecture and construct at least three complex losses to create supervision, such as cycle consistency loss, self-reconstruction loss, and style loss. However, due to the lack of parallel data as supervisory information, the conversion process often has high semantic divergence, resulting in poor migration quality, which is specifically reflected in the insufficient semantic preservation and imprecise style of the converted sentences. Summary of the invention

[0004] Based on the technical problems existing in the background technology, the present invention proposes a text style transfer method based on decoupled module mining, which realizes text style transfer with high style accuracy and high semantic preservation.

[0005] The present invention proposes a text style transfer method based on decoupled module mining, which inputs a given arbitrary sentence and a target style into a pre-trained language model, and generates a sentence containing the target style attributes while keeping the content of the input sentence unchanged;

[0006] The pre-trained language model concatenates the prefix token as a virtual token before the input sentence and uses a trainable matrix , mapping the prefix token to the prefix embedding of each layer, then the matrix is the only prefix parameter to be trained, so that only the continuous prefix parameters are trained and adjusted while the pre-trained language model parameters are frozen, the prefix token represents the prefix token, and the prefix embedding represents the prefix embedding vector;

[0007] The training process of the pre-trained language model is as follows:

[0008] Step 1: Obtain multiple original sentences, decouple each original sentence based on the decoupling large model to mine the original attribute module corresponding to the original sentence, and divide the original sentence into an original attribute module and a content module, wherein the content module is the part of the original sentence without the original attribute module;

[0009] Step 2: The original attribute module of the original sentence is modified into the target attribute module while retaining the content module, so as to transform the style of the original sentence and obtain a synthetic parallel sentence;

[0010] Step 3: Use BLEU scores to measure the semantic preservation of synthetic parallel sentences, thereby filtering out synthetic parallel sentences with low semantic preservation, and obtaining multiple sets of high-quality parallel data and their decoupling module sets. , will be collected As a training set to train the pre-trained language model, the Indicates The original sentence, Indicates The original attribute module corresponding to the original sentence, Indicates The synthetic parallel sentences corresponding to the original sentences are Indicates The target attribute module corresponding to the original attribute module, is the number of synthesized parallel sentences, and the BLEU score represents the similarity score between the original sentence and the synthesized parallel sentences;

[0011] Step 4: The original sentences in the training set and the original attribute module As a set of positive example pairs, the original sentence and compound parallel sentences As a set of negative example pairs, the original sentence and the target properties module As a set of negative example pairs; take the representation of each sentence in the training set as , based on contrastive learning to train the pre-trained language model to optimize the prefix parameters, the representation Including the original sentence, the original attribute module, the synthetic parallel sentence and the corresponding representation of the target attribute module;

[0012] Step 5: Pre-training language model During the training process, based on the original sentence Synthesize parallel sentences , a sequence-to-sequence loss is used to perform gradient updates on the log-likelihood objective to optimize the prefix parameter.

[0013] Furthermore, the BLEU score is used to measure the semantic preservation of the synthesized parallel sentences, specifically:

[0014] Assume that you want to sample into parallel sentences, and yes The maximum length of the combined parallel sentences;

[0015] First, The groups are divided into Group, of which The group contains The length is The synthetic parallel sentences, ;

[0016] For Combined into parallel sentences, the number of samples with the highest BLEU score is The in-group samples are sampled by synthetic parallel sentence lengths to ensure that the decoupled large model can learn transformation patterns with high semantic preservation under different sentence lengths.

[0017] Furthermore, in step 4, the pre-trained language model is trained based on contrastive learning to optimize the prefix parameters, specifically:

[0018]

[0019] in, represents the contrastive learning loss, represents the temperature coefficient, represents a set of positive example sentences composed of the original attribute modules as positive examples, Represents the set of positive sentences In the positive sentence, represents a set of negative example sentences consisting of synthetic parallel sentences as negative examples and target attribute modules as negative examples, Represents the original sentence The representation of Indicates a positive sentence The representation of Expressing sentences The representation of Represents the set of positive sentences And the set of negative sentences Any sentence in .

[0020] Furthermore, in step 5, a gradient update is performed on the log-likelihood objective based on the sequence-to-sequence loss to optimize the prefix parameter, specifically including:

[0021]

[0022] in, represents the sequence-to-sequence loss, represents the length of the synthetic parallel sentence, Indicates the synthesis of parallel sentences Middle Words, Indicates the synthesis of parallel sentences The front Words, represents the original sentence, According to the original sentence Before the synthetic parallel sentence words to generate synthetic parallel sentences The probability of a word.

[0023] Furthermore, the total loss of the pre-trained language model is:

[0024]

[0025] represents the total loss of the pre-trained language model, Represents the balance parameter used to balance the contrastive learning loss and sequence-to-sequence loss .

[0026] The advantages of the text style transfer method based on decoupling module mining provided by the present invention are as follows: the text style transfer method based on decoupling module mining provided in the structure of the present invention includes a decoupling data synthesis paradigm and a decoupling learning method. In the decoupling data synthesis paradigm, the decoupling idea is used to design the thinking chain prompt, so as to guide the decoupling large model to convert the text style while preserving the original text semantics, thereby synthesizing the scarce high-quality parallel data in the field of text style transfer; in the decoupling learning method, two losses are designed ( ) solve the text style transfer problem from two important aspects. Among them, contrastive learning loss It can improve the attention of the text style transfer model to the attribute features of the sentence, which is beneficial to the style accuracy in the style transfer process. The output semantic space can be constrained and the knowledge within the pre-trained language model can be fully utilized, which is beneficial to the semantic preservation during the style transfer process. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 It is a structural schematic diagram of the present invention;

[0028] Figure 2 This is a schematic diagram of the structure corresponding to the decoupled data synthesis paradigm;

[0029] Figure 3 A schematic diagram of a case study of the decoupling idea in the text style transfer task. DETAILED DESCRIPTION

[0030] Below, the technical solution of the present invention is described in detail through specific embodiments. Many specific details are set forth in the following description to facilitate a full understanding of the present invention. However, the present invention can be implemented in many other ways different from those described herein, and those skilled in the art can make similar improvements without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific implementation disclosed below.

[0031] like Figures 1 to 3 As shown, the present invention proposes a text style transfer method based on decoupled module mining, which inputs a given arbitrary sentence and a target style into a pre-trained language model, and generates a sentence containing the target style attributes while keeping the content of the input sentence unchanged.

[0032] In order to improve the quality of text style transfer, this embodiment proposes a new framework for text style transfer, creates a decoupled data synthesis paradigm (decoupled large model), and proposes a decoupled learning method (pre-trained language model) to learn from synthetic data. It is believed that a sentence has a target style mainly because some parts show the characteristics of the style. These parts are defined as attribute modules. The remaining parts have the content characteristics of the sentence and are defined as content modules. Figure 3 These are three examples of decoupling ideas in text style transfer tasks. Obviously, the modification of the attribute module determines the accuracy of the style, while the retention of the content module determines the degree of semantic preservation. These two modules naturally exist in all sentences in the text style transfer task, indicating that this task can be completed from a decoupled perspective, thereby achieving text style transfer with high style accuracy and high semantic preservation.

[0033] In this embodiment, the training process of the pre-trained language model is as follows:

[0034] Step 1: Obtain multiple original sentences, decouple each original sentence based on the decoupling large model to mine the original attribute module corresponding to the original sentence, and divide the original sentence into an original attribute module and a content module, wherein the content module is the part of the original sentence without the original attribute module;

[0035] Step 2: The original attribute module of the original sentence is modified into the target attribute module while retaining the content module, so as to transform the style of the original sentence and obtain a synthetic parallel sentence;

[0036] Step 3: Use BLEU scores to measure the semantic preservation of synthetic parallel sentences, thereby filtering out synthetic parallel sentences with low semantic preservation, and obtaining multiple sets of high-quality parallel data and their decoupling module sets. , will be collected As a training set to train the pre-trained language model, the Indicates The original sentence, Indicates The original attribute module corresponding to the original sentence, Indicates The synthetic parallel sentences corresponding to the original sentences are Indicates The target attribute module corresponding to the original attribute module, is the number of synthetic parallel sentences;

[0037] Step 4: The original sentences in the training set and the original attribute module As a set of positive example pairs, the original sentence and compound parallel sentences As a set of negative example pairs, the original sentence and target properties module As a set of negative example pairs; take the representation of each sentence in the training set as , based on contrastive learning to train the pre-trained language model to optimize the prefix parameters, the representation Including the original sentence, the original attribute module, the synthetic parallel sentence and the corresponding representation of the target attribute module;

[0038] Step 5: Pre-training language model During the training process, based on the original sentence Synthesize parallel sentences , a sequence-to-sequence loss is used to perform gradient updates on the log-likelihood objective to optimize the prefix parameter.

[0039] (A) For steps 1 to 3, the synthesized parallel sentences are obtained based on the decoupled data synthesis paradigm (decoupled large model), specifically:

[0040] The goal of the decoupled data synthesis paradigm is to synthesize parallel data and its corresponding decoupled modules, and use them as supervisory information to constrain the output semantic space and increase the model's attention to attribute modules. This embodiment uses the decoupling idea to design the thought chain prompt to guide the decoupled large model to transform the style of the sentence while preserving the original semantics, and then builds an error detection component to filter out poor quality synthetic data to ensure data quality.

[0041] (a1) Thought chain prompt

[0042] This embodiment uses the decoupling idea as a thought chain prompt to guide the decoupling large model, so that the decoupling large model first decouples the original attribute module and the content module in the original sentence, and then modifies the original attribute module into the target attribute module while retaining the content module as much as possible to achieve the modification of the sentence style while maintaining the semantic content.

[0043] Figure 2This example shows how the decoupled big model performs data synthesis under the guidance of two different thought chain prompts. The standard prompt indicates that the style transfer is performed directly through the decoupled big model. In this case, it can be found that the decoupled big model only retains a very limited amount of the original semantics. In contrast, under the guidance of the decoupled thought chain prompt, the decoupled big model first synthesizes the original negative style sentence to be converted (the original sentence). = "When George changed jobs, his situation became worse and worse" to decouple and dig out the corresponding original attribute module = "getting worse", and then decoupling the large model will modify the attribute module while retaining the content module , thereby converting the style of the original sentence to obtain a synthetic parallel sentence with a positive style = "When George changed jobs, his situation became better and better." Obviously, after using the thought chain prompt to guide the decoupled large model in a decoupled way, a more accurate style and more complete semantics will be obtained.

[0044] (a2) Error detection component

[0045] In the process of decoupling large models to synthesize data, some synthesis errors will inevitably occur. Therefore, this embodiment designs an error detection component to ensure the style accuracy and high semantic preservation of synthesized parallel sentences.

[0046] In order to ensure the style accuracy of the synthesized parallel sentences, this embodiment trains a sentiment classifier to filter out the synthesized parallel sentences with inaccurate style. In order to ensure the high semantic preservation of the synthesized parallel sentences, this embodiment uses the BLEU score to measure the semantic preservation of the sentences to filter out the synthesized data with low semantic preservation. Specifically, suppose you want to sample into parallel sentences, and yes The maximum length of parallel sentences combined; first The groups are divided into Group, of which The group contains The length is The synthetic parallel sentences, For the Combined into parallel sentences, the number of samples with the highest BLEU score is The in-group samples are sampled according to the synthetic parallel sentence length, which ensures that the decoupled large model can learn transformation patterns with high semantic preservation under different sentence lengths.

[0047] By using the decoupled data synthesis paradigm (decoupled large model) on the original non-parallel dataset (original sentences), multiple sets of high-quality parallel data and their decoupled module sets can be obtained. , will be collected As a training set to train the pre-trained language model, the Indicates The original sentence, Indicates The original attribute module corresponding to the original sentence, Indicates The synthetic parallel sentences corresponding to the original sentences are Indicates The target attribute module corresponding to the original attribute module, is the number of synthesized parallel sentences (i.e., the number of synthesized samples).

[0048] (B) Design a decoupled learning method (pre-trained language model) for steps 4 to 5

[0049] Based on synthetic data, this embodiment designs a decoupled learning method to solve the text style transfer problem from two aspects, such as Figure 1 For multiple sets of high-quality parallel data and their decoupled module sets ,The goal of the decoupled learning approach is to train a pre-trained language model that can take a template as input and then effectively generate its corresponding target sentence.

[0050] In order to save computing resources, this embodiment introduces a lightweight prefix fine-tuning network as the basic framework of the decoupled learning method. While freezing the parameters of the pre-trained language model, only the continuous prefix embedding needs to be trained and adjusted. Specifically, the pre-trained language model splices the prefix token as a virtual token before the input sentence and uses a trainable matrix (Dimensions are ) maps it to the prefix embedding of each layer, Indicates the length of the prefix virtual token. represents the hidden layer dimension of the pre-trained language model. Then the matrix is the only prefix parameter that can be trained, thereby saving computing resources. In this embodiment, two losses are designed in the decoupled learning method to optimize the prefix parameter.

[0051] (b1) Contrastive learning loss

[0052] This embodiment designs a contrastive learning loss to improve the model's attention to sentence attribute features, which is beneficial to improving the style control ability of the text style transfer model. The original sentence and its corresponding original attribute module are regarded as a set of positive example pairs, and their representations will be pulled closer to improve the model's attention to sentence attribute features. The original sentence and its target sentence as well as the original attribute parameters and the target attribute parameters are regarded as a set of negative example pairs, and their representations will be pulled farther apart to make the representations of sentences of different styles more distinguishable between different styles. Specifically, for the set A set of sentence pairs in , the original sentence , Represents a set of positive example sentences, that is, the original attribute module is used as a positive example, and multiple positive examples constitute a set of positive example sentences , is its negative example sentence set, that is, the synthetic parallel sentence is taken as a negative example, the target attribute module is taken as a negative example, and multiple negative examples constitute the negative example sentence set .

[0053] In this embodiment, the representation of each sentence in the training set is , the characterization Including the corresponding representations of the original sentence, the original attribute module, the synthesized parallel sentence, and the target attribute module. That is to say, the input original sentence, the original attribute module, the synthesized parallel sentence, and the target attribute module are all taken as sentences to obtain the corresponding representations. Then for the original sentence The contrastive learning loss is as follows:

[0054]

[0055] in, represents the contrastive learning loss, represents the temperature coefficient, represents a set of positive example sentences composed of the original attribute modules as positive examples, Represents the set of positive sentences In the positive sentence, represents a set of negative example sentences consisting of synthetic parallel sentences as negative examples and target attribute modules as negative examples, Represents the original sentence The representation of Indicates a positive sentence The representation of Expressing sentences The representation of Represents the set of positive sentences And the set of negative sentences Any sentence in .

[0056] (b2) Sequence-to-sequence loss

[0057] This example also uses the loss in the sequence-to-sequence task as another loss function. This loss can constrain the semantic space of the output and make full use of the knowledge within the pre-trained language model, which is ultimately conducive to preserving sufficient semantics during the style transfer process. For an original sentence Its corresponding synthetic parallel sentence , this embodiment performs the following gradient update on the log-likelihood objective:

[0058]

[0059] in, represents the sequence-to-sequence loss, represents the length of the synthetic parallel sentence, Indicates synthetic parallel sentences Middle Words, Indicates synthetic parallel sentences The front Words, represents the original sentence, According to the original sentence Before the synthetic parallel sentence words to generate synthetic parallel sentences The probability of a word.

[0060] (b3) Total loss function

[0061] This example also uses contrastive learning loss With sequence-to-sequence loss to optimize the prefix parameter. The total loss is shown below.

[0062]

[0063] in, represents the total loss of the pre-trained language model, Represents the balance parameter used to balance the contrastive learning loss and sequence-to-sequence loss .

[0064] Through (A) and (B), compared with the existing methods, this embodiment proposes a text style transfer method based on decoupled module mining, which includes a decoupled data synthesis paradigm and a decoupled learning method. In the decoupled data synthesis paradigm, the decoupled idea is used to design the thinking chain prompt, so as to guide the decoupled large model to convert the text style while preserving the semantics of the original text, thereby synthesizing scarce high-quality parallel data in the field of text style transfer.

[0065] In the decoupled learning method, two losses are designed ( ) solve the text style transfer problem from two important aspects. Among them, contrastive learning loss It can improve the attention of the text style transfer model to the attribute features of the sentence, which is beneficial to the style accuracy in the style transfer process. The output semantic space can be constrained and the knowledge within the pre-trained language model can be fully utilized, which is beneficial to the semantic preservation during the style transfer process.

[0066] Compared with other methods in the current field of text style transfer, the decoupled data synthesis paradigm (decoupled large model) and the decoupled learning method (pre-trained language model) have unique designs and good application prospects. That is, this embodiment can be applied to online social media platforms to perform style conversion on any text. In terms of implementation, it can be embedded in an intelligent system in the form of software; it can also be embedded in a backend server to meet the needs of large-scale text style conversion.

[0067] The above description is only a preferred specific implementation manner of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical scheme and inventive concept of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A text style transfer method based on decoupled module mining, characterized in that: Input any given sentence and target style into the pre-trained language model, and generate a sentence with target style attributes while keeping the content of the input sentence unchanged; The pre-trained language model concatenates the prefix token as a virtual token before the input sentence and uses a trainable matrix , mapping the prefix token to the prefix embedding of each layer, then the matrix is the only prefix parameter that is trained, so that only the continuous prefix parameters are trained and adjusted while the pre-trained language model parameters are frozen; The training process of the pre-trained language model is as follows: Step 1: Obtain multiple original sentences, decouple each original sentence based on the decoupling model guided by the thought chain prompt to mine the original attribute module corresponding to the original sentence, and divide the original sentence into an original attribute module and a content module, wherein the content module is the part of the original sentence without the original attribute module; Step 2: The original attribute module of the original sentence is modified into the target attribute module while retaining the content module, so as to transform the style of the original sentence and obtain a synthetic parallel sentence; Step 3: Use BLEU scores to measure the semantic preservation of synthetic parallel sentences, thereby filtering out synthetic parallel sentences with low semantic preservation, and obtaining multiple sets of high-quality parallel data and their decoupling module sets. , will be collected As a training set to train the pre-trained language model, the Indicates The original sentence, Indicates The original attribute module corresponding to the original sentence, Indicates The synthetic parallel sentences corresponding to the original sentences are Indicates The target attribute module corresponding to the original attribute module, is the number of synthetic parallel sentences; Step 4: The original sentences in the training set and the original attribute module As a set of positive example pairs, the original sentence and compound parallel sentences As a set of negative example pairs, the original sentence and the target properties module As a set of negative example pairs; take the representation of each sentence in the training set as , based on contrastive learning to train the pre-trained language model to optimize the prefix parameters, the representation Including the original sentence, the original attribute module, the synthetic parallel sentence and the corresponding representation of the target attribute module; Step 5: Pre-training language model During the training process, based on the original sentence Synthesize parallel sentences , a sequence-to-sequence loss is used to perform gradient updates on the log-likelihood objective to optimize the prefix parameter.

2. The text style transfer method based on decoupling module mining according to claim 1 is characterized in that: In using BLEU scores to measure the semantic preservation of synthetic parallel sentences, specifically: Assume that you want to sample into parallel sentences, and yes The maximum length of the combined parallel sentences; First, The groups are divided into Group, of which The group contains The length is The synthetic parallel sentences, ; For Combined into parallel sentences, the number of samples with the highest BLEU score is The in-group samples are sampled by synthetic parallel sentence lengths to ensure that the decoupled large model can learn transformation patterns with high semantic preservation under different sentence lengths.

3. The text style transfer method based on decoupling module mining according to claim 1 is characterized in that: In step 4, the pre-trained language model is trained based on contrastive learning to optimize the prefix parameters, specifically: in, represents the contrastive learning loss, represents the temperature coefficient, represents a set of positive example sentences composed of the original attribute modules as positive examples, Represents the set of positive sentences In the positive sentence, represents a set of negative example sentences consisting of synthetic parallel sentences as negative examples and target attribute modules as negative examples, Represents the original sentence The representation of Indicates a positive sentence The representation of Expressing sentences The representation of Represents the set of positive example sentences And the set of negative sentences Any sentence in .

4. The text style transfer method based on decoupling module mining according to claim 3 is characterized in that: In step 5, a gradient update is performed on the log-likelihood objective based on the sequence-to-sequence loss to optimize the prefix parameter, including: in, represents the sequence-to-sequence loss, represents the length of the synthetic parallel sentence, Indicates the synthesis of parallel sentences Middle Words, Indicates the synthesis of parallel sentences The front Words, represents the original sentence, According to the original sentence Before the synthetic parallel sentence words to generate synthetic parallel sentences The probability of a word.

5. The text style transfer method based on decoupling module mining according to claim 4 is characterized in that: The total loss of the pre-trained language model is: represents the total loss of the pre-trained language model, Represents the balance parameter used to balance the contrastive learning loss and sequence-to-sequence loss .