A method for transferring user offensive comment style based on unsupervised learning

Through the UCST-UL model, the bidirectional encoding attention mechanism and generator-discriminator adversarial training are utilized to solve the problem of lack of corpus in the style conversion of offensive comments on social media platforms, and achieve high-accuracy text style conversion and content preservation.

CN115544245BActive Publication Date: 2025-10-03SOUTHEAST UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210390821.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-14
Publication Date
2025-10-03
Estimated Expiration
2042-04-14

AI Technical Summary

Technical Problem

Existing technologies lack parallel corpora on social media platforms, resulting in low accuracy in text style conversion of offensive comments and an inability to effectively retain the semantics and style labels of the text content.

Method used

The unsupervised learning-based user offensive comment style transfer method UCST-UL is adopted. The bidirectional encoding attention mechanism is used to capture the contextual information of the text sequence, the generator-discriminator is used for adversarial training, and a reconstruction loss algorithm is constructed to ensure the accuracy of style transfer and content retention.

Benefits of technology

The accuracy of converting offensive comments into non-offensive comments has been improved to 93%-95%, effectively retaining the important information of user comments and the accuracy of style labels.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115544245B_ABST
    Figure CN115544245B_ABST
Patent Text Reader

Abstract

This paper discloses a method for transferring the style of user offensive comments based on unsupervised learning. The method first encodes the input comment text using a bidirectional encoding-attention mechanism. The bidirectional encoding is used to capture the contextual information of the text sequence, and the attention mechanism is used to preserve the core information of the text. Secondly, the method uses a generator-discriminator adversarial training to address the lack of specific keywords in non-parallel corpora. Finally, the method constructs a reconstruction loss algorithm through recurrent reinforcement learning to ensure the accuracy of the style labels of the converted offensive comments, as well as the integrity and readability of the text content. This method can effectively address the problems of semantic loss, lack of parallel corpora, and low content retention in the style transfer of offensive comments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method for converting the style of user offensive comments based on unsupervised learning, and belongs to the technical field of Internet and artificial intelligence. Background Art

[0002] With the rapid development of social media platforms, online social networking has become a mainstream form of communication. Convenient communication platforms enrich users' intellectual landscape, and the diversity and ubiquity of social media allow users from diverse industries and knowledge bases to freely express their opinions. However, due to factors such as the anonymity of user identities on social platforms, the emotional blockage in the real world, and the media effect of social networks, offensive behavior such as verbal abuse is common on social networks, seriously undermining public order and morality in cyberspace. Therefore, text style conversion for offensive comments posted by social media users is a key task in cyberspace content governance.

[0003] Due to the high complexity of user comment data on major social media platforms and the high cost of building parallel corpora, there is a lack of supervised parallel corpora for text style transfer of offensive comments. Current neural network models used for text style transfer primarily rely on large amounts of corpora for training, and the lack of large amounts of parallel corpora makes it difficult to guarantee accurate model training results. Furthermore, existing text style transfer techniques cannot address the loss of sentence semantics caused by the discrete and sequential nature of text data, resulting in low content retention after text style transfer. Furthermore, most of these studies are based on non-parallel corpus databases without specific style tag keywords, resulting in limited improvement in text style transfer accuracy.

[0004] To address the problems of semantic loss, lack of parallel corpora, and low content retention in offensive comment style transfer, this paper proposes a User-offensive Comment Style Transfer based on Unsupervised Learning (UCST-UL) method. First, the paper proposes a bidirectional encoding attention mechanism to encode the input comment text. Bidirectional encoding captures the contextual information of the text sequence, while the attention mechanism retains the core information of the text. Second, the paper uses adversarial training with a generator-discriminator to address the lack of specific keywords in non-parallel corpora. Finally, the paper constructs a reconstruction loss algorithm through recurrent reinforcement learning to ensure the accuracy of the style labels, the integrity of the text content, and the readability of the converted offensive comments. Summary of the Invention

[0005] In response to the problems and shortcomings of the existing technology, the present invention proposes a user offensive comment style conversion method UCST-UL based on unsupervised learning. This method can perform text style conversion on user offensive comments. Compared with the existing methods, it can accurately convert offensive comments into non-offensive comments while more effectively retaining important information in user comments.

[0006] To achieve the above objectives, the present invention proposes a method for converting the style of user offensive comments based on unsupervised learning. This method primarily involves a bidirectional encoding attention mechanism for comment text, adversarial training, and reconstruction loss. This method accurately captures the contextual information of text sequences, preserves the core semantics of the sequence, and improves the accuracy and content retention of the converted style. The method primarily involves three steps, as follows:

[0007] Step 1: Use a bidirectional encoding attention mechanism to obtain highly semantically preserved encodings. Taking the preprocessed user review text as input, we first perform forward and backward semantic encoding on the text using a bidirectional gate recurrent unit (BiGRU). We then assign probability weights to each word vector and use an attention mechanism to capture long-term dependencies in the sequence, highlighting the importance of different words to the overall text style, and obtaining key context vectors.

[0008] Step 2: Use the generator-discriminator module for model adversarial training. First, use GRURNN as the generator, or decoder, taking the hidden state vector obtained from the bidirectional encoding attention mechanism and the target style label as input to calculate the sentence vector after style conversion. Then, use CNN as the discriminator, or classifier, to output the style label probability distribution of the converted sentence and feed it back to the generator.

[0009] Step 3: Reinforcement learning is used to construct a reconstruction loss. In generator-discriminator adversarial training, a reconstruction loss and a classification loss are defined. The reconstruction loss measures the generator's text generation capabilities and imposes constraints on the generated text to ensure the preservation of the source sentence's content after style conversion. Furthermore, the classification loss function is optimized to measure the accuracy of the style labeling of the converted text, indicating the effectiveness of the current decoder in converting the sentence to the target style. Ultimately, fluent, readable, and non-offensive user reviews are obtained.

[0010] Compared with the prior art, the present invention has the following beneficial effects:

[0011] 1. The proposed UCST-UL model can capture the contextual information of the text sequence and retain important semantic information during the encoding process. At the same time, it constructs a cyclic reconstruction loss and a classification loss to ensure the content retention and style label accuracy of the target text.

[0012] 2. This method uses adversarial training. In the absence of parallel corpus, new text is generated based on existing corpus as input to the discriminator. At the same time, the discriminator's output returns the judgment result to the generator, providing the generator with an effective feedback signal, improving the accuracy of aggressive text style transfer, thereby solving the problem of corpus scarcity in text style transfer.

[0013] 3. This method introduces the style conversion scenario of offensive comments from various social media users, which can effectively improve the generalization ability of the model and at the same time improve the accuracy of offensive comment style conversion to 93%-95%. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] Figure 1 This is an overall framework diagram of the method according to an embodiment of the present invention.

[0015] Figure 2 Flowchart of a method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0016] In order to deepen the understanding of the present invention, the present invention is further illustrated in conjunction with specific examples. Figure 1 and Figure 2 As shown, the specific implementation steps are as follows: A method for converting the style of user offensive comments based on unsupervised learning, the method is as follows: Step 1, use a bidirectional encoding attention mechanism to obtain a highly preserved semantic encoding, specifically as follows, the original text will be converted into a computer-understandable vectorized representation at the input layer. Assume that the non-offensive text dataset in social media is Where m is the non-offensive text dataset X 0 The size of the offensive text is Where n is X 1 The size of the text style is {S0, S1}. Therefore, the dataset of aggressive text style conversion is in Indicates that the style tag is S i The kth sentence of , N = m + n is the total size of the dataset, i∈{0,1} represents the style label as non-offensive and offensive respectively. The original text is bidirectionally encoded based on the attention mechanism. The implementation process of this step is divided into two sub-steps:

[0017] Sub-step 1-1, use the bidirectional gate recurrent unit BiGRU to capture the contextual information of the text sequence. The hidden state of BiGRU at the current time t is determined by the current input x t , the forward hidden layer state output at the previous moment (t-1) and the backward hidden state output The three parts jointly determine the hidden state output of the BiGRU encoding layer at time t can be obtained by weighted summation of the forward hidden state and the backward hidden state:

[0018]

[0019] Among them, the GRU() function represents the nonlinear transformation of the input word vector, encoding the word vector into the corresponding GRU hidden layer state, w t and v t Respectively represent the forward hidden layer state corresponding to the bidirectional GRU at time t and the backward hidden state The corresponding weight, b t Indicates the bias corresponding to the hidden layer state at time t. The UCST-UL model converts a sentence and its style tag S i As the input of the bidirectional encoder, after BiGRU encodes the sentence from the forward and backward directions, a deeper semantic relationship feature between the contexts can be obtained. A hidden state sequence is obtained from BiGRU

[0020]

[0021] In substeps 1-2, the input of the attention mechanism is the output vector of the bidirectional encoder after the BiGRU neural network activation process. For the correlation between the input and output at a certain position at the current time t, it is written in the corresponding vector form and the weighted point product is:

[0022]

[0023] For e kt Performing a softmax operation to regularize it yields the distribution of attention:

[0024]

[0025] Using attention distribution α k The weighted summation can be used to obtain the hidden layer vector after the attention mechanism, namely:

[0026]

[0027] Among them, W1 represents the weight coefficient, b w is the bias; W2 represents the randomly initialized attention matrix. By introducing the attention mechanism after the dual encoder, the model can focus on all input information that is important for the next target word, greatly improving the final effect of aggressive language style transfer.

[0028] Step 2: Use the generator-discriminator module to conduct model adversarial training. Specifically, the generator-discriminator adversarial training module mainly includes two parts: the generator (G) and the discriminator (D). The generator is used to learn the mapping G(Z) that maps random noise Z to the time series X. The data G(Z) generated by the generator becomes fake data; while the discriminator is used to learn a classifier that can distinguish between the generated data G(Z) and the real data. In the adversarial training module, on the one hand, it is necessary to ensure that the generator generates generated data with the same distribution as the original sample as much as possible, and on the other hand, it is necessary to ensure that the discriminator distinguishes between fake data and real data as much as possible. Therefore, it is necessary to optimize the objective function through game theory, so that the generator can generate fake samples that are infinitely close to the real samples in the most ideal state. The objective function is shown in formula (8):

[0029]

[0030] where p data Represents the actual data distribution. The implementation process of this step is divided into two sub-steps:

[0031] Sub-step 2-1, use GRURNN as the generator, that is, the decoder. The hidden state vector obtained from the bidirectional encoding attention mechanism is and the target style label S j , j∈{0,1} is used as input and the output is calculated And change the style from S i Convert to S j The GRU uses two gate vectors, the update gate and the reset gate, to determine the information that is ultimately output by the gated recurrent unit. They can preserve long-term information in the sequence and will not become clear over time or be removed due to irrelevant predictions. Specifically, at time step t, the update gate z is first calculated using formula (9) t :

[0032]

[0033] where s t is the input vector at the t-th time step, that is, the t-th component of the style vector, which will be combined with the weight matrix W (z) Multiply to perform a linear transformation. The information stored is from the previous time step t-1, which also undergoes a linear transformation. The update gate adds these two pieces of information and applies them to the Sigmoid activation function, thereby compressing the activation result to between 0 and 1. The update gate helps the model determine how much information to pass between the previous time step and the current time step, thereby copying all information from previous time steps to reduce the risk of vanishing gradients.

[0034] The reset gate mainly determines the amount of past information that needs to be forgotten, as calculated by formula (10):

[0035]

[0036] Same as update door, reset door and s t It first undergoes a linear transformation, then adds and transmits it to the Sigmoid activation function to output the activation value.

[0037] In the use of the reset gate, the new memory content will use the reset gate to store past related information, that is:

[0038]

[0039] Calculate the reset gate r t and The Hadamard product, that is, r t and The corresponding element-wise product of .

[0040] In the final step, the network needs to calculate This vector will retain the information of the current unit and pass it to the next unit. In this process, an update gate is required, which determines the current memory content. and the previous time step The information that needs to be collected is:

[0041]

[0042] Among them, z t To update the activation result of the gate, the inflow of information is controlled in the form of gating. t and The Hadamard product represents the information retained in the final memory from the previous time step. This information plus the information retained in the final memory from the current memory is the output of the final gated recurrent unit.

[0043] In summary, in the generator network, the converted sentence can be represented by Representation, all transformed sentences are represented as When i=j, the style label of the original sentence is consistent with the target style label to be converted, which is the generated sentence Still keep the original style label S i When i≠j, the sentence label after style conversion is inconsistent with the original sentence style label, which means the conversion is successful.

[0044] In sub-step 2-2, use the CNN classifier as the discriminator, take the generated sentence as input, output the probability distribution of the style label and feed it back to the generator, that is:

[0045]

[0046] By using a collaborative classifier, a training signal is generated that indicates the effectiveness of the current decoder in converting sentences to the target style.

[0047] From the above, we can see that the generator labels the style as S i The original sentence Convert to have target style S j Sentences The discriminator is used to judge Whether the conversion is successful The discrimination result is returned to the generator, so that the generator receives an effective feedback signal and improves the accuracy of aggressive text style conversion.

[0048] Step 3: Cycle reinforcement learning constructs reconstruction loss, specifically as follows: Construct cycle consistency reconstruction loss algorithm. The generator labels the style as S i The original sentence Convert to have target style S j Sentences If i=j, then the generator can be considered as an autoencoder. Therefore, it can be strengthened by using a standard cross entropy loss function. and The similarity between them. Define the standard cross entropy loss function as the reconstruction loss, as shown in formula (14):

[0049]

[0050] At this point, the reconstruction loss can measure the text generation ability of the generator G and ensure the content retention after the original sentence style conversion. In order to improve the classification accuracy of the discriminator D, a supervised classification function is used in the discriminator D to measure the original data. The classifier predicts:

[0051]

[0052] In addition, to measure the conversion of the original sentence X into the target sentence stylistic accuracy, i.e., the sentences and The similarity between them is used to define a classification loss as shown in formula (16):

[0053]

[0054] For the encoder-decoder, this loss provides feedback on the effectiveness of the current generator G in converting sentences to the target style; while the discriminator D obtains an additional training signal from the generated data, enabling the discriminator to be trained in a semi-supervised state.

[0055] When i≠j, due to the lack of parallel data, the above method cannot be used to define the reconstruction loss. Therefore, the transformed sentence needs to be Feedback to the generator G again, Backward conversion to X, this process is called reverse conversion. The range of reconstruction loss in reverse conversion is defined in and between:

[0056]

[0057] The reverse conversion process will convert the sentence Switch back to the original style S i ,Right now and combine it with This also implicitly imposes constraints on the generated sentences and improves content preservation.

[0058] Finally, to ensure the reverse conversion of the sentence With the correct style tag S i , define the classification loss function:

[0059]

[0060] When training the aggressive text style transfer model, the stochastic gradient descent algorithm is used to optimize the final loss function of the cycle consistency reconstruction loss algorithm.

[0061]

[0062] In summary, under the premise of lack of parallel corpus, the present invention first proposes a bidirectional encoding attention mechanism to capture the contextual information of text sequences and retain important semantic information in the encoding process; secondly, the present invention proposes a generator-discriminator network, which generates new text according to the existing corpus through adversarial training as the input of the discriminator; at the same time, the output of the discriminator returns the judgment result to the generator, so that the generator obtains an effective feedback signal, improves the accuracy of aggressive text style conversion, and thus solves the problem of corpus scarcity in text style conversion; finally, the accuracy of text style conversion and content retention are measured by the cycle consistency reconstruction loss algorithm.

[0063] Based on the same inventive concept, an embodiment of the present invention discloses a method and device for converting the style of user offensive comments based on unsupervised learning, including a memory, a processor, and a computer program stored in the memory and runnable on the processor. When the computer program is loaded into the processor, it implements the above-mentioned method and device for converting the style of user offensive comments based on unsupervised learning.

[0064] It should be noted that the above embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent modifications of the present invention by those skilled in the art fall within the scope defined by the claims attached to this application.

Claims

1. A method for transferring user offensive comment style based on unsupervised learning, characterized by: The method comprises the following steps: Step 1: Use the bidirectional encoding attention mechanism to obtain high-preservation semantic encoding; Step 2: Use the generator-discriminator module to perform model adversarial training. Step 3: cyclic reinforcement learning to construct reconstruction loss; Among them, step 1 is as follows: the original text will be converted into a vectorized representation that can be understood by the computer at the input layer. Assume that the non-offensive text dataset in social media is Where m is the non-offensive text dataset X 0 The size of the offensive text is Where n is X 1 The size of; Correspondingly, the style label of the text is {S0, S1}, and the dataset of aggressive text style conversion is in Indicates that the style tag is S i The kth sentence of , N = m + n is the total size of the dataset, i∈{0,1} represents the style label as non-offensive and offensive respectively, and the original text is bidirectionally encoded based on the attention mechanism. The implementation process of this step is divided into two sub-steps: Sub-step 1-1, use the bidirectional gate recurrent unit BiGRU to capture the context information of the text sequence. The hidden state of BiGRU at the current time t is determined by the current input x t , the forward hidden layer state output at the previous moment (t-1) and the backward hidden state output The three parts jointly determine, therefore, the hidden state output of the BiGRU encoding layer at time t can be obtained by the weighted sum of the forward hidden state and the backward hidden state: Among them, the GRU() function represents the nonlinear transformation of the input word vector, encoding the word vector into the corresponding GRU hidden layer state, w t and v t Respectively represent the forward hidden layer state corresponding to the bidirectional GRU at time t and the backward hidden state The corresponding weight, b t Represents the bias corresponding to the hidden layer state at time t. The UCST-UL model converts a sentence and its style tag S i As the input of the bidirectional encoder, after BiGRU encodes the sentence from the forward and backward directions, it obtains the semantic relationship features between the deeper contexts and obtains a hidden state sequence from BiGRU. In substeps 1-2, the input of the attention mechanism is the output vector of the bidirectional encoder after the BiGRU neural network activation process. For the correlation between the input and output at a certain position at the current time t, it is written in the corresponding vector form and the weighted point product is: For e kt Performing a softmax operation to regularize it yields the distribution of attention: Using attention distribution α k The weighted summation can be used to obtain the hidden layer vector after the attention mechanism, namely: Among them, W1 represents the weight coefficient, b w is the bias; W2 represents the randomly initialized attention matrix.

2. The method for converting user offensive comment style based on unsupervised learning according to claim 1 is characterized in that: Step 1: Use the bidirectional encoding attention mechanism to obtain high-preservation semantic encoding; take the preprocessed user comment text as input, first use the bidirectional gate recurrent unit to perform forward and backward semantic encoding on the text, then assign probability weights to each word vector, use the attention mechanism to capture long-term dependencies in the sequence, highlight the importance of different words to the style of the entire text, and obtain the key context vector.

3. The method for converting user offensive comments style based on unsupervised learning according to claim 1 is characterized in that: Step 2: Use the generator-discriminator module to perform model adversarial training. First, use GRURNN as the generator, i.e., the decoder, and use the hidden state vector obtained from the bidirectional encoding attention mechanism and the target style label as input to calculate the sentence vector after style conversion. Then use CNN as the discriminator, i.e., the classifier, to output the style label probability distribution of the converted sentence and feed it back to the generator.

4. The method for converting user offensive comments style based on unsupervised learning according to claim 1 is characterized in that: Step 3: Reconstruction loss is constructed through cyclic reinforcement learning. In the generator-discriminator adversarial training, reconstruction loss and classification loss are defined. On the one hand, the reconstruction loss is used to measure the text generation ability of the generator and impose constraints on the generated text to ensure the content retention after the style conversion of the source sentence. On the other hand, the classification loss function is optimized to measure the accuracy of the style label of the converted text, indicating the effectiveness of the current decoder in converting the sentence to the target style, ultimately obtaining fluent, readable and non-aggressive user reviews.

5. The method for converting user offensive comments style based on unsupervised learning according to claim 4 is characterized in that: Step 2 is as follows: Step 2: In the generator-discriminator adversarial training module, it mainly includes two parts: the generator and the discriminator. The generator is used to learn the mapping G(Z) that maps random noise Z to the time series X. The data G(Z) generated by the generator becomes fake data; while the discriminator is used to learn a classifier that can distinguish the generated data G(Z) from the real data. The objective function is shown in formula (8): where p data Represents the actual data distribution. The implementation process of this step is divided into two sub-steps: Sub-step 2-1, using GRURNN as the generator, i.e. decoder, will get the hidden state vector from the bidirectional encoding attention mechanism and the target style label S j , j∈{0,1} is used as input and the output is calculated And change the style from S i Convert to S j The sentence vector of , at time step t, first use formula (9) to calculate the update gate z t : where s t is the input vector at the t-th time step, that is, the t-th component of the style vector, which will be combined with the weight matrix W (z) Multiply to perform linear transformation, The information stored is the information of the previous time step t-1, which also undergoes a linear transformation. The update gate adds these two parts of information and inputs them into the Sigmoid activation function, thus compressing the activation result to between 0 and 1. The reset gate mainly determines the amount of past information that needs to be forgotten, as calculated by formula (10): Same as update door, reset door and s t First, it undergoes a linear transformation, and then is added and sent to the Sigmoid activation function to output the activation value. In the use of the reset gate, the new memory content will use the reset gate to store past related information, that is: Calculate the reset gate r t and The Hadamard product, that is, r t and The corresponding element product of ; In the final step, the network needs to calculate This vector will retain the information of the current unit and pass it to the next unit. In this process, an update gate is required, which determines the current memory content. and the previous time step The information that needs to be collected is: Among them, z t To update the activation result of the gate, the inflow of information is controlled in the form of gating, z t and The Hadamard product represents the information retained in the final memory at the previous time step. This information plus the information retained in the final memory at the current time step is the output of the final gated recurrent unit. In sub-step 2-2, use the CNN classifier as the discriminator, take the generated sentence as input, output the probability distribution of the style label and feed it back to the generator, that is: By using a collaborative classifier, a training signal is generated to indicate the effectiveness of the current decoder in converting sentences to the target style; From the above, we can see that the generator labels the style as S i The original sentence Convert to have target style S j Sentences The discriminator is used to judge Whether the conversion is successful The discrimination result is returned to the generator, so that the generator receives an effective feedback signal and improves the accuracy of aggressive text style conversion.

6. The method for converting user offensive comment style based on unsupervised learning according to claim 5 is characterized in that: Step 3: cyclic reinforcement learning to construct reconstruction loss, as follows: Step 3: Construct a cycle consistency reconstruction loss algorithm. The generator labels the style as S i The original sentence Convert to have target style S j Sentences If i=j, the generator is considered to be an autoencoder, which is enhanced by using a standard cross entropy loss function. and The similarity between them is defined as the standard cross entropy loss function as the reconstruction loss, as shown in formula (14): At this time, the reconstruction loss can measure the text generation ability of the generator G and ensure the content retention after the original sentence style conversion. In order to improve the classification accuracy of the discriminator D, a supervised classification function is used in the discriminator D to measure the original data. The classifier predicts: In addition, to measure the conversion of the original sentence X into the target sentence stylistic accuracy, i.e., the sentences and The similarity between them is used to define a classification loss as shown in formula (16): When i≠j, due to the lack of parallel data, the above method cannot be used to define the reconstruction loss, so the transformed sentence needs to be Feedback to the generator G again, Backward conversion to X, this process is called reverse conversion, and the range of reconstruction loss in reverse conversion is defined in and between: The reverse conversion process will convert the sentence Switch back to the original style S i ,Right now and combine it with This also implicitly imposes constraints on the generated sentences and improves content preservation for comparison; Finally, to ensure the reverse conversion of the sentence With the correct style tag S i , define the classification loss function: When training the aggressive text style transfer model, the stochastic gradient descent algorithm is used to optimize the final loss function of the cycle consistency reconstruction loss algorithm.

Citation Information

Patent Citations

  • User personality privacy protection method based on GAN

    CN113742772A

  • Automatic generation of statement-response sets from conversational text using natural language processing

    US20200279075A1