Transform-based semi-supervised text classification algorithm
By introducing confidence and randomization technology into the Transformer text classification algorithm, confidence screening and randomization are used to process a small portion of annotated data, which solves the problem of a large amount of annotated data requirements, improves the efficiency of text classification, and achieves results close to the original algorithm. Effect classification results.
Patent Information
- Application Number
- CN202410714654.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Transformer-based text classification algorithms require a large amount of annotated data, resulting in limited application, especially when the number of labels is limited, and the efficiency is low.
A semi-supervised text classification algorithm based on confidence and randomization technology is used to conduct confidence screening and randomization processing on a small part of the annotated data, and the confidence screening strategy and probability ratio screening strategy are used to generate more automatically annotated corpus, and Introduce confidence screening and randomization processes in model training to reduce dependence on annotated data.
Based on a small amount of annotated data, it is close to the classification effect that originally required a large amount of annotated data, greatly improving the efficiency of text classification and reducing the need for annotated data.
Smart Images

Figure CN118585646A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text classification algorithms, and in particular to a Transformer-based semi-supervised text classification algorithm. Background Art
[0002] The Transformer structure was proposed by Google in its 2017 paper Attention Is All You Need. Its core is the Attention mechanism, which includes two parts: Encoder and Decoder. The Transformer structure solves two major problems of traditional algorithms: difficulty in parallel calculation and difficulty in capturing long-distance dependencies. It has achieved good results on many sequence data, such as text, audio and video data. Due to its outstanding performance, it has been applied to many tasks, such as text classification algorithms. In addition, the recently popular generative AI is also developed from the Transformer structure.
[0003] Depending on whether the training data set is labeled, machine learning algorithms are divided into two categories: supervised learning and unsupervised learning. Supervised learning is to learn a model from labeled training data, and then use the model to predict the label of a given new data. Supervised learning tasks mainly include classification and regression. The output label of the classification algorithm is discrete, while the output label of the regression algorithm is continuous. Common supervised learning algorithms include nearest neighbor, naive Bayes, SVM, decision tree, random forest, logistic regression, linear regression, etc. The characteristic of unsupervised learning is that the data for model learning is unlabeled. Therefore, the goal of unsupervised learning is to reveal the intrinsic characteristics and laws of the data by learning these unlabeled samples. Typical algorithms include clustering algorithms and dimensionality reduction algorithms.
[0004] Supervised learning algorithms require labeled data. In real life, due to privacy and some reasons of the data itself, such as experimental data of high-risk experiments, the number of labels is very small. Moreover, even if labeled data can be collected, it often takes a lot of time and effort. In this case, semi-supervised learning algorithms were born. In semi-supervised learning, the training data set contains a small part of labeled data and most of unlabeled data. Semi-supervised learning algorithms use these small parts of labeled data and most of unlabeled data to train the required model, and its effect is not much different from that of supervised learning.
[0005] Text classification is a process of automatically classifying and labeling text using computers. It assigns text to predetermined categories according to a certain classification system. The text classification process includes feature selection, model training, and evaluation and feedback of classification results. Text classification has many application scenarios, including sentiment analysis, topic classification, question-answering tasks, intent recognition, and natural language reasoning. Common text feature representation methods include bag-of-words models, N-gram, TF-IDF, Word2Ve, etc. Classification models can choose probabilistic graph models, K-nearest neighbors, naive Bayes, or deep learning models. Among them, the Attention-based Transformer model has the best effect and is the most widely used in the current deep learning models.
[0006] Although the Transformer-based text classification algorithm has the best effect, it requires a large amount of labeled data, which greatly limits its application. To this end, the present invention proposes a Transformer-based semi-supervised text classification algorithm. Summary of the invention
[0007] The purpose of the present invention is to provide a semi-supervised text classification algorithm based on Transformer, which utilizes confidence and randomization technology to achieve classification results close to those that originally required a large amount of labeled data based on only a small amount of labeled data, thereby greatly improving the efficiency of text classification.
[0008] To solve the above technical problems, the present invention provides a Transformer-based semi-supervised text classification algorithm, comprising the following steps:
[0009] Step 1: Data preprocessing;
[0010] Preprocess the collected text data, including data cleaning and text regularization;
[0011] Step 2: Data division: divide the preprocessed corpus into training set, test set, and validation set;
[0012] Step 3: Transformer model training;
[0013] The main framework of the model borrows the Bert model architecture and makes some minor adjustments to the model architecture. The first model training only uses one of the labeled training sets, and the remaining N-1 sets are used for the subsequent randomization process.
[0014] Step 4: Marking:
[0015] The Transformer model trained above is used to label the unlabeled training set to obtain a large amount of automatically labeled corpus. The output results include all categories and the classification probabilities of the corresponding categories.
[0016] Step 5: Confidence screening;
[0017] Introducing confidence screening into the corpus training model after automatic annotation;
[0018] Step 6: Randomization;
[0019] Randomly select 1% of the confident annotated corpus and remove it, and add 1 annotated corpus that was not used in the previous training process. The removed corpus does not contain the minority sample category corpus;
[0020] Step 7: Model training;
[0021] Continue to iterate the model;
[0022] Step 8: Model evaluation;
[0023] The validation set is used to evaluate the model. In addition, the training set is used for verification. In the early stage, the iterative test set is used to evaluate the model effect. In the later stage, both the iterative test set and the final evaluation test set are used to finally end the model iteration.
[0024] Furthermore, in step 2, the training set is divided into a labeled training set and an unlabeled training set, and the labeled training set is divided into N parts, which are used for the subsequent randomized test set to be divided into an iterative test set and a final evaluation test set.
[0025] Furthermore, the S3 is specifically:
[0026] Step 3-1: Corpus initialization: send the preprocessed corpus in step 1 to the model input part for initialization, including word2vec and adding word position information, and then concatenate them into the Encoder module without performing traditional Chinese word segmentation operations;
[0027] Step 3-2: In the encoder stage, after Multi-head Attention and forward neural network, it is repeated N times and output to the decoder;
[0028] Step 3-3: In the decoder stage, the prediction result is output after passing through Multi-head Attention and forward neural network for N times and then passing through line and softmax modules.
[0029] Step 3-4: Update the model weights, compare the predicted value with the true value, use cross entropy as the loss function, and use the reverse gradient descent algorithm to update the model weights.
[0030] Furthermore, the step 3-4 is specifically as follows: by calculating the gradient of the loss function at the current point, and then updating the weight parameter in the opposite direction of the gradient direction, so as to find the global minimum value;
[0031] The gradient is calculated by taking the partial derivatives of the loss function in the direction of each weight parameter, and then updating the values of the weight parameters through back propagation.
[0032] Furthermore, the step 4 is specifically as follows:
[0033] Step 4-1: Modify the Transformer network structure, add an activation function layer before the output layer, and use the softmax function to convert the classification results into probabilities and normalize the probabilities;
[0034] Step 4-2: During the code implementation, instead of outputting only the largest category, all categories and the corresponding probabilities of each category are output, where the original text, classification results, and corresponding probabilities are separated by tabs.
[0035] Furthermore, the step 5 is specifically as follows:
[0036] Step 5-1: Confidence sorting: sort the classification results in descending order according to the corresponding probabilities of all categories;
[0037] Step 5-2: Confidence screening is divided into two strategies, one is the maximum threshold screening strategy, the other is the probability ratio screening strategy;
[0038] The maximum threshold screening strategy presets an empirical threshold, and all the classification probabilities greater than the preset empirical threshold are selected as candidate model training corpus;
[0039] The probability ratio screening strategy allocates the corresponding screening probability according to the probability of each category, and the corpus after screening enters the subsequent model training;
[0040] The probability ratio screening strategy has a certain probability of classifying the same text into different categories during multiple iterations;
[0041] In the maximum threshold screening strategy, when the maximum classification probability of a sample does not reach the preset empirical threshold, the sample needs to be discarded directly or manually labeled;
[0042] Step 5-3: All confidence-screened corpora are merged with the original annotated training set, and shuffled to form a new annotated training set for subsequent model training.
[0043] Compared with the prior art, the beneficial effect of the present invention is that the present invention utilizes confidence and randomization technology, and can approach the classification effect that originally required a large amount of labeled data based on only a small amount of labeled data, thereby greatly improving the efficiency of text classification. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 It is the overall flow chart of the present invention;
[0045] Figure 2 A schematic diagram of confidence ranking of output content during the code implementation process of the present invention;
[0046] Figure 3 This is a schematic diagram of the classification probability sorting in the present invention;
[0047] Figure 4 Schematic diagram of the maximum threshold screening strategy in the present invention. DETAILED DESCRIPTION
[0048] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0049] See also Figure 1-4 , the present invention provides a Transformer-based semi-supervised text classification algorithm:
[0050] It includes the following steps:
[0051] Step 1: Data preprocessing: Preprocess the collected text data, including data cleaning and text regularization.
[0052] Step 2: Data division. The preprocessed corpus is divided into training set, test set, and validation set. The training set is further divided into labeled training set and unlabeled training set. The labeled training set is divided into N parts for later randomization. The test set is divided into iterative test set and final evaluation test set.
[0053] Step 3: Transformer model training: The main model framework selected by the present invention borrows the BERT model architecture. Taking into account some special processes in the present invention, some fine-tuning is done on the model architecture. In addition, the first model training only selects one of the labeled training sets, and the remaining N-1 sets are used for the subsequent randomization process.
[0054] The specific steps of model training in step 3 are as follows:
[0055] Step 3-1: Corpus initialization: send the preprocessed corpus in step 1 to the model input part for initialization, mainly including word2vec and adding word position information, and then enter the Encoder module after splicing. Note that the traditional Chinese word segmentation operation is not performed in this invention.
[0056] Step 3-2: In the encoder stage, after Multi-head Attention and forward neural network, it is repeated N times and output to the decoder.
[0057] Step 3-3: In the decoder stage, similarly, it passes through the Multi-head Attention and forward neural network, repeated N times, and then passes through the line and softmax modules to output the prediction results.
[0058] Step 3-4: Update the model weights, compare the predicted value with the true value, use cross entropy as the loss function, and use the reverse gradient descent algorithm to update the model weights. Specifically, by calculating the gradient of the current point in the loss function, and then updating the weight parameters in the opposite direction of the gradient, the global minimum is found; the gradient is calculated by respectively finding the partial derivatives of the loss function in the direction of each weight parameter, and then updating the weight parameter values through back propagation.
[0059] Step 4: Labeling: Use the trained Transformer model to label the unlabeled training set and obtain a large amount of automatically labeled corpus. Note that in the labeling process of conventional text classification models, the output results only contain the classification with the highest probability. However, considering that we will have confidence screening later, the output results should include all categories and the classification probabilities of the corresponding categories. Execute the following steps:
[0060] Step 4-1: Transform the Transformer network structure and add an activation function layer before the output layer. In this invention, we use the softmax function to convert the classification results into probabilities and perform probability normalization at the same time.
[0061] Step 4-2: During the code implementation, only the largest category is output, but all categories and the corresponding probability of each category are output. Figure 2 , Figure 2 The traditional approach is to only output text and the corresponding classification results, while the approach of the present invention is to output all categories and their probabilities, wherein the original text, classification results and corresponding probabilities are separated by tabs.
[0062] Step 5: Confidence screening: If you directly train the model with the automatically annotated corpus, then label it, and then train the model, the model will fall into a self-loop, that is, the classification effect on the initial small part of the annotated corpus will get better and better, while the effect on the other most unlabeled training sets will basically not improve. In order to prevent this phenomenon, confidence screening needs to be introduced to only screen the data sets that meet the confidence requirements for subsequent model iterative training.
[0063] In step 5, the confidence screening is performed as follows:
[0064] Step 5-1: Confidence sorting: sort the classification results in descending order according to the corresponding probabilities of all categories, as follows: Figure 3 shown.
[0065] Step 5-2: Confidence screening is divided into two strategies, one is the maximum threshold screening strategy, and the other is the probability ratio screening strategy. The maximum threshold screening strategy presets an empirical threshold, and all the classification probabilities greater than the preset empirical threshold are selected as candidate model training corpus. The probability ratio screening strategy assigns corresponding screening probabilities according to the probability of each category, and enters the subsequent model training corpus after screening. Note that the probability ratio screening strategy has a certain probability of classifying the same text into different categories during multiple iterations, which just meets our needs of randomizing a small amount of training corpus. Note that in the maximum threshold screening strategy, it is possible that the maximum classification probability of the sample does not reach the preset empirical threshold. In this case, the sample can be directly discarded or manually labeled. See the maximum threshold screening strategy. Figure 4 .
[0066] Step 5-3: All confidence-screened corpora are merged with the original annotated training set, and shuffled to form a new annotated training set for subsequent model training.
[0067] Step 6: Randomization: Randomly select 1% of the confident annotated corpus and remove it, and add 1 annotated corpus that was not used in the previous training process. Due to the imbalance of the corpus, it is possible that some categories of training corpus in the corpus for model training are very small. In this case, the removed corpus should not contain corpus of small sample categories as much as possible, so as to avoid the corpus of small sample categories not being fully trained.
[0068] Step 7: Model training: Continue to iterate the model.
[0069] Step 8: Model evaluation: In addition to using the validation set for model evaluation, the present invention also adds training set verification. In the early stage, the iterative test set can be used to evaluate the model effect. In the later stage, both the iterative test set and the final evaluation test set can be used. When the accuracy of the two test sets meets the expected effect, the model iteration is ended.
Claims
1. A Transformer-based semi-supervised text classification algorithm, characterized in that: The following steps are involved: Step 1: Data preprocessing; Preprocess the collected text data, including data cleaning and text regularization; Step 2: Data division; Divide the preprocessed corpus into training set, test set, and validation set; Step 3: Transformer model training; The main framework of the model borrows the Bert model architecture and makes some minor adjustments to the model architecture. The first model training only uses one of the labeled training sets, and the remaining N-1 sets are used for the subsequent randomization process. Step 4: Marking: The Transformer model trained above is used to label the unlabeled training set to obtain a large amount of automatically labeled corpus. The output results include all categories and the classification probabilities of the corresponding categories. Step 5: Confidence screening; Introducing confidence screening into the corpus training model after automatic annotation; Step 6: Randomization; Randomly select 1% of the confident annotated corpus and remove it, and add 1 annotated corpus that was not used in the previous training process. The removed corpus does not contain the minority sample category corpus; Step 7: Model training; Continue to iterate the model; Step 8: Model evaluation; The validation set is used to evaluate the model. In addition, the training set is used for verification. In the early stage, the iterative test set is used to evaluate the model effect. In the later stage, both the iterative test set and the final evaluation test set are used to finally end the model iteration.
2. The Transformer-based semi-supervised text classification algorithm according to claim 1, characterized in that: In step 2, the training set is divided into a labeled training set and an unlabeled training set. The labeled training set is divided into N parts, and the subsequent randomized test set is divided into an iterative test set and a final evaluation test set.
3. The Transformer-based semi-supervised text classification algorithm as claimed in claim 1, characterized in that: The S3 is specifically: Step 3-1: Corpus initialization: send the preprocessed corpus in step 1 to the model input part for initialization, including word2vec and adding word position information, and then concatenate them into the Encoder module without performing traditional Chinese word segmentation operations; Step 3-2: In the encoder stage, after Multi-head Attention and forward neural network, it is repeated N times and output to the decoder; Step 3-3: In the decoder stage, the multi-head attention and feed-forward neural networks are repeated N times, and then the linear and softmax modules are passed to output the prediction results. Step 3-4: Update the model weights, compare the predicted value with the true value, use cross entropy as the loss function, and use the reverse gradient descent algorithm to update the model weights.
4. The Transformer-based semi-supervised text classification algorithm as claimed in claim 3, characterized in that: The steps 3-4 are as follows: calculating the gradient of the loss function at the current point and then updating the weight parameters in the opposite direction of the gradient to find the global minimum value; The gradient is calculated by taking the partial derivatives of the loss function in the direction of each weight parameter, and then updating the values of the weight parameters through back propagation.
5. The Transformer-based semi-supervised text classification algorithm according to claim X, characterized in that: The step 4 is specifically as follows: Step 4-1: Modify the Transformer network structure, add an activation function layer before the output layer, and use the softmax function to convert the classification results into probabilities and normalize the probabilities; Step 4-2: During the code implementation, instead of outputting only the largest category, all categories and the corresponding probabilities of each category are output, where the original text, classification results, and corresponding probabilities are separated by tabs.
6. The Transformer-based semi-supervised text classification algorithm according to claim 1, characterized in that: The step 5 is specifically as follows: Step 5-1: Confidence sorting: sort the classification results in descending order according to the corresponding probabilities of all categories; Step 5-2: Confidence screening is divided into two strategies, one is the maximum threshold screening strategy, the other is the probability ratio screening strategy; The maximum threshold screening strategy presets an empirical threshold, and all the classification probabilities greater than the preset empirical threshold are selected as candidate model training corpus; The probability ratio screening strategy allocates the corresponding screening probability according to the probability of each category, and the corpus after screening enters the subsequent model training; The probability ratio screening strategy has a certain probability of classifying the same text into different categories during multiple iterations; In the maximum threshold screening strategy, when the maximum classification probability of a sample does not reach the preset empirical threshold, the sample needs to be discarded directly or manually labeled; Step 5-3: Merge all confidence-filtered corpora with the original annotated training set, and shuffle them to form a new annotated training set for subsequent model training.
Citation Information
Patent Citations
Semi-supervised method and device for public opinion text analysis
CN114595333A
Military equipment relation extraction method based on BERT and attention mechanism
CN114781375A
Electric power audit text entity recognition method, device and equipment and storage medium
CN116245107A
Method and system for detection of misinformation
US20220382795A1
Deep learning system for navigating feedback
WO2023224672A1
