Backdoor Removal Method for Text Classification Models Based on Data Augmentation and Knowledge Distillation
By generating augmented datasets through lexical splitting and combining attention transfer knowledge distillation techniques to remove backdoors in text classification models, this approach solves the problems of difficult defense and high computational cost in existing technologies, achieving efficient backdoor removal and defense.
Patent Information
- Application Number
- CN202410440337.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-12
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2044-04-12
AI Technical Summary
Existing technologies struggle to effectively remove backdoors from text classification models, especially since they cannot defend against word embedding layer attacks, require significant computation, and do not fully utilize attention weights.
We employ data augmentation based on lexical splitting and attention transfer knowledge distillation techniques for the Transformer architecture of text classification to generate augmented datasets and remove backdoors through knowledge distillation of attention transfer.
Without requiring large amounts of clean data and multiple distillations, it significantly reduces the success rate of backdoor attacks, defends against various word embedding layer attacks, and maintains the model's classification accuracy on clean data.
Smart Images

Figure CN118332115B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a technology in the field of information security, specifically to a backdoor removal method for text classification models based on data augmentation and knowledge distillation, applied in the field of artificial intelligence security. Background Technology
[0002] Image classification model backdoor removal methods are difficult to transfer to text classification. Therefore, new methods need to be developed to effectively remove backdoors, while also addressing the problems that existing reinitialization methods cannot defend against word embedding layer attacks, and that existing knowledge distillation methods have high computational cost and do not fully utilize attention weights.
[0003] Backdoor removal methods for text classification models face unique challenges due to their differences from image classification models in terms of input data type and model structure. Existing backdoor removal methods for text classification models have several drawbacks: re-initialization-based methods cannot defend against attacks on word embedding layers; knowledge distillation-based methods are computationally expensive and do not fully utilize backdoor triggering patterns in attention weights. Therefore, new methods are needed to effectively remove backdoors from text classification models while addressing these issues. Summary of the Invention
[0004] This invention addresses the challenges of transferring backdoor removal methods from image classification models to text classification, the inability of re-initialization-based backdoor removal methods to defend against attacks on the model's word embedding layer, and the computationally intensive and ineffective backdoor removal methods based on knowledge distillation due to the need for multiple model distillations and the failure to uncover backdoor patterns in the model's attention weights. To address these issues, a new backdoor removal method based on data augmentation and knowledge distillation is proposed. This method combines lexical splitting-based data augmentation with attention transfer-based knowledge distillation optimized for the Transformer architecture of text classification. An augmented dataset containing potential trigger patterns is generated using a small number of clean samples. This augmented dataset is then used to train the model, initially mitigating backdoors and maintaining model accuracy on clean samples. Finally, the proposed attention transfer-based knowledge distillation technique for the Transformer architecture of text classification is used to fully uncover and remove backdoor patterns from the model's attention weights.
[0005] This invention is achieved through the following technical solution:
[0006] This invention relates to a backdoor removal method for text classification models based on data augmentation and knowledge distillation. It utilizes a data augmentation method based on lexical splitting to generate an augmented dataset for training the model to be processed. Then, the original model to be processed is used as the student model, and the trained model to be processed is used as the teacher model. The backdoor-removed text classification model is obtained by using a knowledge distillation technique based on attention transfer for the Transformer architecture model for text classification.
[0007] The model to be processed refers to either a Transformer-based text classification model downloaded by the user from a third party or a model obtained by fine-tuning a Transformer-based pre-trained model using a dataset with an implanted backdoor. This model performs normally on normal data, but outputs the attacker's desired output on poisoned samples.
[0008] The augmented dataset refers to: randomly sampling from the original clean dataset to obtain a clean subset, and then performing data augmentation based on lexical splitting on the subset to obtain the augmented dataset. ,in: For random sampling function, For the original, clean dataset, This is a data augmentation function.
[0009] The aforementioned data augmentation based on lexical splitting refers to: for each piece of text data in the dataset, randomly splitting some lexical units in the text into two lexical units; specifically, for a certain character in the text with a length of... lexical elements When selected for data augmentation, then ,in: For the two generated lexical units, For data augmentation functions, , From 0 to random integers between [a certain range] , Indicates word elements The former One character.
[0010] The knowledge distillation technique based on attention transfer for the Transformer architecture model for text classification obtains the final model with backdoors removed by distilling the attention, hidden layer output and classification layer of each layer in the model. The hidden layer output refers to the output of each Transformer layer and word embedding layer.
[0011] The loss function of knowledge distillation ,in: For the total loss, For classifying losses, For the output of the model, The labels are the true values, N is the number of Transformer layers in the model, and CE(.) is the cross-entropy loss function. AT(.) is the attention transfer loss function. This is the attention matrix of the nth Transformer layer in the teacher model. Here is the attention matrix for the nth Transformer layer of the student model, where C is the number of attention heads. For the high of the attention matrix, The width of the attention matrix, , , For an attention head, the attention matrix, express Norm, |.| denotes absolute value. For the loss of the hidden layer, This is the output of the nth layer of the teacher model. This is the output of the nth layer of the student model. The time is the output of the word embedding layer. The output of the Transformer layer is given by MSE(.), which is the mean squared error loss function, and α and β are the loss balance constants. The order of magnitude is generally The order of magnitude of β is generally 1000. .
[0012] Technical effect
[0013] This invention employs data augmentation based on lexical splitting and knowledge distillation based on attention transfer, optimized for the Transformer model architecture, to remove backdoors. Compared to existing technologies, this method can fully uncover and remove backdoors in the Transformer architecture model for text classification without using large amounts of clean data or multiple distillation stages. The model repaired by this invention maintains its clean data classification accuracy while significantly reducing the success rate of backdoor attacks and providing excellent defense against various backdoor attacks, including those targeting the word embedding layer. Attached Figure Description
[0014] Figure 1 This is a schematic diagram of the overall process of the present invention;
[0015] Figure 2 This is a schematic diagram illustrating the method for generating the backdoor model in the embodiment;
[0016] Figure 3 This is a flowchart illustrating the generation of the enhanced dataset in this invention;
[0017] Figure 4 This is a schematic diagram of knowledge distillation in this invention;
[0018] Figure 5 This is a schematic diagram illustrating the performance of the normal sample classification task of the present invention;
[0019] Figure 6 This is a schematic diagram illustrating the defensive effect of the present invention. Detailed Implementation
[0020] like Figure 1 As shown, the specific steps for implementing a backdoor removal method for a text classification model based on data augmentation and knowledge distillation include:
[0021] Step 1: Load the model to be processed with the implanted backdoor, such as... Figure 2 The model to be processed with the implanted backdoor shown is a pre-trained model downloaded from a third-party platform, fine-tuned using the poisoned backdoor dataset.
[0022] Step 2, as follows Figure 3 As shown, to generate the augmented dataset, firstly, clean samples are sampled from the clean SST-2 dataset to form a clean subset. For each sample in the clean subset, some tokens in the text are randomly split into two tokens. Specifically, for a character in the text with a length of... lexical elements When selected for data augmentation, then ,in: For the two generated lexical units, For data augmentation functions, , From 0 to random integers between [a certain range] , Indicates word elements The former One character.
[0023] Step 3: Train the model to be processed using the augmented dataset;
[0024] Step 4: Using the trained model to be processed as the teacher model and the model to be processed as the student model, perform attention transfer-based knowledge distillation on the attention layer, hidden layer, and classification layer. The student model obtained from knowledge distillation is the model with backdoors removed. The loss function for knowledge distillation is... ,in: For the total loss, For classifying losses, For the output of the model, The labels are the true values, N is the number of Transformer layers in the model, and CE(.) is the cross-entropy loss function. AT(.) is the attention transfer loss function. This is the attention matrix of the nth Transformer layer in the teacher model. Here is the attention matrix for the nth Transformer layer of the student model, where C is the number of attention heads. For the high of the attention matrix, The width of the attention matrix, , , For an attention head, the attention matrix, express Norm, |.| denotes absolute value. For the loss of the hidden layer, This is the output of the nth layer of the teacher model. This is the output of the nth layer of the student model. The time is the output of the word embedding layer. The output of the Transformer layer is given by MSE(.), which is the mean squared error loss function, and α and β are the loss balance constants. The order of magnitude is generally The order of magnitude of β is generally 1000. .
[0025] Experiments on the SST-2 sentiment analysis dataset demonstrate the effectiveness of this invention. This example text classification model uses Bert-base-uncase, sampling a clean dataset ratio of 0.2. For each clean data point, three augmented data samples are generated. A learning rate is set during training using the augmented dataset. The batch size for training is 32, the loss function used is cross-entropy loss, and the weight decay coefficient is... The optimizer uses the Adam optimizer, with a maximum number of training epochs. In knowledge distillation, the batch size for training is set to 32, and the learning rate is [missing information]. The largest training round In the experiment, three attack methods were selected: Badnets, LWP, and EP (LWP and EP are backdoor attacks targeting word embedding vectors). The poisoning rate of the dataset was set to 0.1, and the triggers were set to "cf", "mn", "bb", and "tq". A backdoor was implanted into the model using a combination of data poisoning and fine-tuning to obtain the model to be processed. For the Badnets attack, the learning rate for fine-tuning was... The batch size for training is 8, the loss function used is cross-entropy loss, and the weight decay coefficient is... The maximum number of training epochs is 8, and the fine-tuned learning rate is [missing information - likely a specific rate or value]. The batch size for training is 4, the loss function used is cross-entropy loss, and the weight decay coefficient is... The maximum number of training epochs is 6, and the fine-tuned learning rate for EP attacks is... The batch size for training is 8, the loss function used is cross-entropy loss, and the weight decay coefficient is... The maximum number of training epochs is 10. This invention compares with common text classification model backdoor removal and backdoor sample detection methods. The selected defense methods include ONION, BKI, STRIP, RAP, CUBE, clean data fine-tuning, and augmented data fine-tuning, with reinitialization. In the ONION method, the threshold is set to 0, the training batch size is 32, and reinitialization only randomly initializes the parameters of the last layer of the model's encoder layer. Experiments compare the clean accuracy and backdoor attack success rate of the model; the experimental results are presented in... Figure 5 and Figure 6 .like Figure 6 As shown, when using a 20% clean dataset, the model obtained in this invention exhibits the lowest backdoor attack success rate under all three attack types, with success rates for BadNets, LWP, and EP decreasing to 10.96%, 9.77%, and 9.76%, respectively. Figure 5 As shown, compared with the backdoor model, the performance of normal tasks only decreases by about 1% after the backdoor is removed using the present invention.
[0026] The above-described specific implementations can be partially adjusted by those skilled in the art in different ways without departing from the principles and spirit of the present invention. The scope of protection of the present invention is defined by the claims and is not limited to the above-described specific implementations. All implementation schemes within the scope of the claims are subject to the constraints of the present invention.
Claims
1. A backdoor removal method for text classification models based on data augmentation and knowledge distillation, characterized in that, We use data augmentation techniques to generate augmented datasets for training the model to be processed. Then, we use the original model to be processed as the student model and the trained model to be processed as the teacher model. We use knowledge distillation based on attention transfer to obtain a text classification model that removes backdoors. The data augmentation refers to: for each piece of text data in the dataset, randomly splitting some tokens in the text into two tokens; specifically, for a certain character in the text with a length of... lexical elements When selected for data augmentation, then ,in: For the two generated lexical units, For data augmentation functions, , From 0 to random integers between [a certain range] , Indicates word elements The former One character; The loss function of knowledge distillation ,in: For the total loss, For classifying losses, For the output of the model, The labels are the true values, N is the number of Transformer layers in the model, and CE(.) is the cross-entropy loss function. AT(.) is the attention transfer loss function. This is the attention matrix of the nth Transformer layer in the teacher model. Here is the attention matrix for the nth Transformer layer of the student model, where C is the number of attention heads. For the high of the attention matrix, The width of the attention matrix, , , For an attention head, the attention matrix, express Norm, |.| denotes absolute value. For the loss of the hidden layer, This is the output of the nth layer of the teacher model. This is the output of the nth layer of the student model. The time is the output of the word embedding layer. The output of the Transformer layer is denoted by MSE(.), which is the mean squared error loss function, and α and β are loss balance constants.
2. The backdoor removal method for text classification models based on data augmentation and knowledge distillation according to claim 1, characterized in that, The model to be processed refers to either a Transformer-based text classification model downloaded by the user from a third party or a model obtained by fine-tuning a Transformer-based pre-trained model using a dataset with an implanted backdoor. This model performs normally on normal data, but produces the output expected by the attacker on poisoned samples.
3. The backdoor removal method for text classification models based on data augmentation and knowledge distillation according to claim 1, characterized in that, The aforementioned data augmentation refers to: randomly sampling from the original clean dataset to obtain a clean subset, and then performing data augmentation on the subset. ,in: To enhance the dataset, For random sampling function, For the original, clean dataset, This is a data augmentation function.
4. The backdoor removal method for text classification models based on data augmentation and knowledge distillation according to claim 1, characterized in that, The knowledge distillation described herein is achieved by distilling the attention layers, hidden layer outputs, and classification layers in the model to obtain the final backdoor-removing model. Here, the hidden layer output refers to the output of each Transformer layer and word embedding layer.
Citation Information
Patent Citations
Method and device for evaluating influence of knowledge distillation on model backdoor attack
CN115495571A
Backdoor attack confrontation method and system for artificial intelligence model migration security
CN116702832A
