Text classification method and system
By combining the absolute majority voting method and the soft voting method to fuse the processing results of multiple text classification models, the problem of bias and low credibility of the text classification model in the existing technology when the distribution of data types is uneven is solved, and a more complete solution is achieved. Reliable prediction results generation.
Patent Information
- Application Number
- CN202410790575.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-19
- Publication Date
- 2024-09-13
AI Technical Summary
Existing text classification models have obvious bias and low credibility problems when the distribution of data types is uneven. In particular, the absolute majority voting method cannot generate prediction results without fusion.
Use multiple text classification models to train and process data, and fuse the processing results by combining the absolute majority voting method and the soft voting method. The fusion is based on the number of occurrences and scores of text types. If the maximum number of votes exceeds half, an absolute majority will be used. Voting method, otherwise soft voting method is used to improve prediction credibility.
It effectively solves the bias problem of a single classification model when the distribution of data types is uneven, avoids the defect that the absolute majority voting method cannot be integrated, and improves the credibility and robustness of the prediction results.
Smart Images

Figure CN118643373A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of text classification, and in particular to a text classification method and system. Background Art
[0002] Text classification refers to the process by which a computer maps text containing information to a pre-given category or several categories of topics. The text classification problem is a classic problem in the field of natural language processing. According to different predefined categories, text classification is divided into two types: binary classification and multi-classification. From the perspective of the annotated category of the text, text classification can be divided into single-label and multi-label. The text classification method of the present invention belongs to multi-classification single-label.
[0003] In the prior art, commonly used text classification methods include: traditional machine learning methods (rule-based models, probability-based models, statistics-based models), deep learning methods, etc. Each method uses different data structures and processing flows, and can obtain multiple implementation schemes. Using the same implementation scheme to train models on different data sets, due to differences in data characteristics and distribution, the generated model has obvious bias. On the test set with large differences in characteristics and distribution from the original training data, the reasoning effect of the model is significantly degraded.
[0004] However, the voting method is an integrated learning model that follows the principle of "the minority obeys the majority". It reduces variance through the integration of multiple models, thereby improving the robustness and generalization ability of the model. Voting methods are divided into hard voting and soft voting; hard voting can be divided into absolute majority voting and relative majority voting. The final output category of the former is the category that obtains more than half of the votes. If no category obtains more than half of the votes, the prediction result is rejected; the final output category of the latter is the category with the most votes. Compared with the absolute majority voting method, there is one less option to reject the prediction result. The prediction result of the soft voting method is the category with the largest probability sum among all voting results. In text classification, the text type that appears more than half of the times is regarded as the fused text type. If no text type appears more than half of the times, the prediction result is rejected; the relative voting method regards the text type that appears most as the fused text type. In comparison, the absolute voting method has higher support votes than the relative voting method and is more credible; however, the absolute voting method cannot be fused. The prediction scores of different text types indicate the credibility of the test sample belonging to the corresponding text type. The maximum score method regards the text type with the highest score as the fused text type. However, if the data type distribution is uneven and the model has obvious bias, the prediction credibility of this method is not high. Summary of the invention
[0005] The purpose of the present invention is to provide a text classification method and system to solve the problems raised in the above background technology.
[0006] To achieve the above object, the present invention provides the following technical solution: a text classification method, the method comprising the following steps:
[0007] S1: Train multiple text classification models;
[0008] S2: Use multiple text classification models to process data;
[0009] S3: The processing results of integrating multiple text classification models;
[0010] S4: Extract text classification information from the fusion results.
[0011] Preferably, S1: the specific operation of training multiple text classification models includes:
[0012] Use the training set TEXT train Train M text classification models i , 1≤i≤M.
[0013] Preferably, S2: the specific operation of using multiple text classification models to process data includes:
[0014] Use the trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤M, for TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The j-th text type and its corresponding score obtained after inference, 1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types, and the text type with the largest score and its corresponding score are marked as (Tag i ,Score i ).
[0015] Preferably, S3: the specific operation of fusing the processing results of multiple text classification models includes:
[0016] Comprehensive absolute majority voting and soft voting fusion test set TEXT test M processing results of any text Str in [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )], 1≤i≤M, 1≤j≤N, with (Tag meg ,Score meg ) represents the fusion result, |x| represents the rounding operation of x, and Count j Indicates the number of times text type j appears, represented by k (Tag i ,Score i ), 1≤i≤M, the text type number that appears most times, and t represents the text type number with the largest sum of the scores of the M processing results.
[0017] Preferably, step S3 specifically includes:
[0018] S31: Read TEXT test The first text to be processed Str;
[0019] S32: Read M processing results of Str [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N;
[0020] S33: Calculate the text type j in M processing results (Tag i ,Score i ) appears in Count j , 1≤j≤N;
[0021] S34: Count j The maximum value of
[0022] S35: If Then go to S36, otherwise go to S3A;
[0023] S36: Calculate the text type number with the most occurrences
[0024] S37: Determine the text type tag after fusion meg = k;
[0025] S38: Determine the score after fusion based on the principle of the largest number of occurrences Transfer to S3E;
[0026] S3A: Calculate the sum of the scores of text type j in M processing results
[0027] S3B: Calculate the text type number with the largest sum of scores
[0028] S3C: Determine the address type tag after fusion meg =t;
[0029] S3D: Determine the fusion score based on the maximum score principle
[0030] S3E: Determine the fusion result of Str (Tag meg ,Score meg );
[0031] S3F: If TEXT test There is still unprocessed text in the file. Read TEXT test The next text to be processed Str in the middle will be transferred to S32, otherwise it will be transferred to S3G;
[0032] S3G: Return test set TEXT test The fusion result of all texts in .
[0033] A text classification system, the system consists of a model training module, a data processing module, a result fusion module and an information extraction module;
[0034] Model training module, used to train multiple text classification models.
[0035] The data processing module uses multiple text classification models to process data.
[0036] The result fusion module is used to fuse the processing results of multiple text classification models.
[0037] The information extraction module is used to extract text classification information from the fusion results.
[0038] Preferably, the model training module uses the training set TEXT train Train M text classification models i , 1≤i≤M.
[0039] Preferably, the data processing module uses a trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤M, for TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The j-th text type and its corresponding score obtained after inference, 1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types, and the text type with the largest score and its corresponding score are marked as (Tag i ,Score i ).
[0040] Preferably, the result fusion module integrates the absolute majority voting method and the soft voting method to fuse the test set TEXT test M processing results of any text Str in [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )], 1≤i≤M, 1≤j≤N, with (Tag meg ,Score meg ) represents the fusion result, |x| represents the rounding operation of x, and Count j Indicates the number of times text type j appears, represented by k (Tag i ,Score i), 1≤i≤M, the text type number that appears most times, and t represents the text type number with the largest sum of the scores of the M processing results.
[0041] Preferably, the result fusion module further includes:
[0042] S31: Read TEXT test The first text to be processed Str;
[0043] S32: Read M processing results of Str [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N;
[0044] S33: Calculate the text type j in M processing results (Tag i ,Score i ) appears in Count j , 1≤j≤N;
[0045] S34: Count j The maximum value of
[0046] S35: If Then go to S36, otherwise go to S3A;
[0047] S36: Calculate the text type number with the most occurrences
[0048] S37: Determine the text type tag after fusion meg = k;
[0049] S38: Determine the score after fusion based on the principle of the largest number of occurrences Transfer to S3E;
[0050] S3A: Calculate the sum of the scores of text type j in M processing results
[0051] S3B: Calculate the text type number with the largest sum of scores
[0052] S3C: Determine the address type tag after fusionmeg =t;
[0053] S3D: Determine the fusion score based on the maximum score principle
[0054] S3E: Determine the fusion result of Str (Tag meg ,Score meg );
[0055] S3F: If TEXT test There is still unprocessed text in the file. Read TEXT test The next text to be processed Str in the middle will be transferred to S32, otherwise it will be transferred to S3G;
[0056] S3G: Return test set TEXT test The fusion result of all texts in .
[0057] Compared with the prior art, the present invention has the following beneficial effects:
[0058] The text classification method and system proposed in the present invention first count the number of votes for all text types, and if the maximum number of votes exceeds half of the total number of votes, then the absolute majority voting method is used for fusion, otherwise it indicates that the bias of the prediction result is relatively weak, and then the soft voting method is used for fusion; by combining the advantages of the two methods, the present invention solves the problem of obvious bias and low credibility of a single classification model when the data type distribution is uneven, and solves the problem that the absolute majority voting method cannot be integrated when the number of votes for all text classification results does not exceed half. BRIEF DESCRIPTION OF THE DRAWINGS
[0059] Figure 1 is a flow chart of the method of the present invention;
[0060] Figure 2 This is a specific step flow chart of step S3 of the present invention. DETAILED DESCRIPTION
[0061] In order to make the purpose and technical solution of the present invention clearly and completely described, and the advantages more clearly understood, the embodiments of the present invention are further described in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are part of the embodiments of the present invention, rather than all of the embodiments, and are only used to explain the embodiments of the present invention, and are not used to limit 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.
[0062] Embodiment 1
[0063] See also Figure 1 to Figure 2The present invention provides a technical solution: a text classification method, the method comprising the following steps:
[0064] Suppose training set TEXT train Contains 4000 annotated texts, test set TEXT test Contains 1000 unlabeled texts, TEXT train and TEXT test The Chinese text categories are the same, and the text categories are: finance, realty, stocks, education, science, and the corresponding text category numbers are 1, 2, 3, 4, 5 respectively.
[0065] Execute S1: Based on the training set TEXT train For the annotated texts in , use TextCNN, TextRNN, FastText, TextRCNN, Transformer, and Bert to train text classification models Model1, Model2, Model3, Model4, Model5, and Model6 respectively.
[0066] Execute S2: Use the trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤6. For TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The text type j and its corresponding score obtained after inference (1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types), where the text type with the largest score and its corresponding score are marked as (Tag i ,Score i );
[0067] Execute S3: Use the absolute majority voting method and soft voting method to merge the test set TEXT test The six processing results of any text Str in [(Tag i,1 ,Scorei,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤6, 1≤j≤5. Calculate the number of text type j in M processing results (Tag i ,Score i ) appears in Count j If the maximum value exceeds 3, the text type corresponding to the maximum value is set as the text type Tag of the fusion result meg , meet the Tag i =Tag meg Score i The maximum value of is set as the score of the fusion result Score meg ; If the maximum value does not exceed 3, then calculate the sum of the scores of the M processing results of each category, and set the category with the largest sum of scores as the text type Tag of the fusion result meg , set the maximum score corresponding to the text type to the score of the fusion result meg ; According to Tag meg and Score meg , determine the fusion result of the text Str (Tag meg ,Score meg ).
[0068] The following uses the text in the test set "Summary of Examination Schedules for Various Subjects in National College Entrance Examinations in 2011" as an example to demonstrate the fusion process.
[0069] Text classification model i The processing results of the text are shown in Table 1, 1≤i≤6.
[0070] Table 1 The processing results of the text "Summary of the examination time of each subject of the college entrance examination in 2011 across the country" under different models
[0071]
[0072] The integration process of the text "Summary of the examination time of each subject of the college entrance examination in 2011 across the country" is as follows:
[0073] Execute S32: Read the 6 processing results of "2011 National College Entrance Examination Subjects Examination Time Summary" [(Tag i,1 ,Score i,1),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N;
[0074] Execute S33: Count the number of times text type j appears in the 6 results j , 1≤j≤5, the results are as follows:
[0075] Count1=0, Count2=0, Count3=0, Count4=3, Count5=3.
[0076] Execute S34: Calculate Count j The maximum value of
[0077] Execute S35: Because Dissatisfied So transfer S3A;
[0078] Execute S3A: Calculate the sum of the scores of text type j in M processing results The results are as follows:
[0079] S1=0.110, S2=0.196, S3=0.183, S4=3.666, S5=1.845;
[0080] Execute S3B: Calculate the text type number with the largest sum of scores
[0081] Execute S3C: Determine the fused text type tag meg =4;
[0082] Execute S3D: Determine the fusion score based on the maximum score principle
[0083]
[0084] Execute S3E: determine the fusion result of Str (4, 0.868);
[0085] Execute S4: extract the text type and its score from the text to be processed according to the text classification fusion result.
[0086] The text classification fusion result of the text "Summary of the examination time of each subject of the college entrance examination in 2011 across the country" is (4, 0.868), the corresponding text type is Tag = "education", and the score is Score = 0.868.
[0087] Embodiment 2
[0088] Based on the first embodiment, a text classification system is proposed, which consists of a model training module, a data processing module, a result fusion module and an information extraction module;
[0089] Model training module, used to train multiple text classification models, using the training set TEXT train Train M text classification models i , 1≤i≤M.
[0090] The data processing module uses multiple text classification models to process data and uses the trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤M, for TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The j-th text type and its corresponding score obtained after inference, 1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types, and the text type with the largest score and its corresponding score are marked as (Tag i ,Score i ).
[0091] The result fusion module is used to fuse the processing results of multiple text classification models, and integrate the absolute majority voting method and soft voting method to fuse the test set TEXT test M processing results of any text Str in [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tagi,j ,Score i,j ),......,(Tag i,N ,Score i,N )], 1≤i≤M, 1≤j≤N, with (Tag meg ,Score meg ) represents the fusion result, |x| represents the rounding operation of x, and Count j Indicates the number of times text type j appears, represented by k (Tag i ,Score i ), 1≤i≤M, the text type number that appears most times, and t represents the text type number with the largest sum of the scores of the M processing results;
[0092] Also includes:
[0093] S31: Read TEXT test The first text to be processed Str;
[0094] S32: Read M processing results of Str [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N;
[0095] S33: Calculate the text type j in M processing results (Tag i ,Score i ) appears in Count j , 1≤j≤N;
[0096] S34: Count j The maximum value of
[0097] S35: If Then go to S36, otherwise go to S3A;
[0098] S36: Calculate the text type number with the most occurrences
[0099] S37: Determine the text type tag after fusion meg = k;
[0100] S38: Determine the score after fusion based on the principle of the largest number of occurrences Transfer to S3E;
[0101] S3A: Calculate the sum of the scores of text type j in M processing results
[0102] S3B: Calculate the text type number with the largest sum of scores
[0103] S3C: Determine the address type tag after fusion meg =t;
[0104] S3D: Determine the fusion score based on the maximum score principle
[0105] S3E: Determine the fusion result of Str (Tag meg ,Score meg );
[0106] S3F: If TEXT test There is still unprocessed text in the file. Read TEXT test The next text to be processed Str in the middle will be transferred to S32, otherwise it will be transferred to S3G;
[0107] S3G: Return test set TEXT test The fusion result of all texts in .
[0108] The information extraction module is used to extract text classification information from the fusion results.
[0109] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A text classification method, characterized by: The method comprises the following steps: S1: Train multiple text classification models; S2: Use multiple text classification models to process data; S3: The processing results of integrating multiple text classification models; S4: Extract text classification information from the fusion results.
2. A text classification method according to claim 1, characterized in that: S1: The specific operations for training multiple text classification models include: Use the training set TEXT train Train M text classification models i , 1≤i≤M.
3. A text classification method according to claim 2, characterized in that: S2: the specific operation of using multiple text classification models to process data includes: Use the trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤M, for TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The j-th text type and its corresponding score obtained after inference, 1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types, and the text type with the largest score and its corresponding score are marked as (Tag i ,Score i ).
4. A text classification method according to claim 3, characterized in that: S3: The specific operations of fusing the processing results of multiple text classification models include: Comprehensive absolute majority voting and soft voting fusion test set TEXT test M processing results of any text Str in [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )], 1≤i≤M, 1≤j≤N, with (Tag meg ,Score meg ) represents the fusion result, |x| represents the rounding operation of x, and Count j Indicates the number of times text type j appears, represented by k (Tag i ,Score i ), 1≤i≤M, the text type number that appears most times, and t represents the text type number with the largest sum of the scores of the M processing results.
5. A text classification method according to claim 4, characterized in that: Step S3 specifically includes: S31: Read TEXT test The first text to be processed Str; S32: Read M processing results of Str [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N; S33: Calculate the text type j in M processing results (Tag i ,Score i ) appears in Count j , 1≤j≤N; S34: Count j The maximum value of S35: If Then go to S36, otherwise go to S3A; S36: Calculate the text type number with the most occurrences S37: Determine the text type tag after fusion meg = k; S38: Determine the score after fusion based on the principle of the largest number of occurrences Transfer to S3E; S3A: Calculate the sum of the scores of text type j in M processing results S3B: Calculate the text type number with the largest sum of scores S3C: Determine the address type tag after fusion meg =t; S3D: Determine the fusion score based on the maximum score principle S3E: Determine the fusion result of Str (Tag meg ,Score meg ); S3F: If TEXT test There is still unprocessed text in the file. Read TEXT test The next text to be processed Str in the middle will be transferred to S32, otherwise it will be transferred to S3G; S3G: Return test set TEXT test The fusion result of all texts in .
6. A text classification system according to the text classification method according to any one of claims 1 to 5, characterized in that: The system consists of a model training module, a data processing module, a result fusion module and an information extraction module; Model training module, used to train multiple text classification models; The data processing module uses multiple text classification models to process data; Result fusion module, used to fuse the processing results of multiple text classification models; The information extraction module is used to extract text classification information from the fusion results.
7. A text classification system according to claim 6, characterized in that: The model training module uses the training set TEXT train Train M text classification models i , 1≤i≤M.
8. A text classification system according to claim 7, characterized in that: The data processing module uses the trained text classification model Model i Processing test set TEXT test The text in, 1≤i≤M, for TEXT test The text to be processed in Str, Model i The processing result is expressed as [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )],Tag i,j and Score i,j Use Model respectively i The j-th text type and its corresponding score obtained after inference, 1≤j≤N, 1≤Tag i,j ≤N, N is the number of text types, and the text type with the largest score and its corresponding score are marked as (Tag i ,Score i ).
9. A text classification system according to claim 8, characterized in that: The result fusion module combines the absolute majority voting method and the soft voting method to integrate the test set TEXT test M processing results of any text Str in [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )], 1≤i≤M, 1≤j≤N, with (Tag meg ,Score meg ) represents the fusion result, |x| represents the rounding operation of x, and Count j Indicates the number of times text type j appears, represented by k (Tag i ,Score i ), 1≤i≤M, the text type number that appears most times, and t represents the text type number with the largest sum of the scores of the M processing results.
10. A text classification system according to claim 9, characterized in that: The result fusion module further includes: S31: Read TEXT test The first text to be processed Str; S32: Read M processing results of Str [(Tag i,1 ,Score i,1 ),(Tag i,2 ,Score i,2 ),......,(Tag i,j ,Score i,j ),......,(Tag i,N ,Score i,N )] and (Tag i ,Score i ), 1≤i≤M, 1≤j≤N; S33: Calculate the text type j in M processing results (Tag i ,Score i ) appears in Count j , 1≤j≤N; S34: Count j The maximum value of S35: If Then go to S36, otherwise go to S3A; S36: Calculate the text type number with the most occurrences S37: Determine the text type tag after fusion meg = k; S38: Determine the score after fusion based on the principle of the largest number of occurrences Transfer to S3E; S3A: Calculate the sum of the scores of text type j in M processing results S3B: Calculate the text type number with the largest sum of scores S3C: Determine the address type tag after fusion meg =t; S3D: Determine the fusion score based on the maximum score principle S3E: Determine the fusion result of Str (Tag meg ,Score meg ); S3F: If TEXT test There is still unprocessed text in the file. Read TEXT test The next text to be processed Str in the middle will be transferred to S32, otherwise it will be transferred to S3G; S3G: Return test set TEXT test The fusion result of all texts in .
Citation Information
Patent Citations
Address unit analysis method and device
CN116304799A
