A Restricted Domain Dynamic Category Text Classification Method
By constructing a restricted-domain dynamic category text classification method and using the forward inference probability matrix of a large model to calculate the token probability value, the method solves the problems of long annotation cycles and illusions in existing technologies, and achieves efficient and accurate text classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANDONG SYNTHESIS ELECTRONICS TECH
- Filing Date
- 2024-06-27
- Publication Date
- 2026-07-31
AI Technical Summary
Among existing text classification methods, BERT-based methods have long annotation cycles and high costs, while methods based on large models suffer from the illusion problem, resulting in low classification accuracy.
By constructing a restricted-domain dynamic category text classification method, we obtain the label category set of text data, build a large model token set, perform preprocessing and text augmentation, use the forward inference probability matrix of the large model to calculate the token probability value of each category, dynamically define category labels, and output the label with the highest probability.
It improves the accuracy of text classification, avoids the illusion problem of large models, saves on training sample labeling, and only requires updating the label category set when adapting to changes in label categories.
Smart Images

Figure QLYQS_9 
Figure QLYQS_10 
Figure QLYQS_13
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and specifically to a restricted-domain dynamic category text classification method. Background Technology
[0002] Text classification involves categorizing a piece of text into predefined categories. Currently, there are two main methods for text classification: The first is the BERT-based method, which predefines label categories, trains a model by labeling samples based on these categories, and finally obtains the trained model. The problem with this method is that the labeling cycle is generally long and the labeling cost is high, and it cannot be used in scenarios where the number of labels and their names change frequently. The second method is the large-model-based method, which designs a prompt containing the text to be classified and its category labels, and outputs the category labels based on the general capabilities of the large model. This method avoids the labeling and training of a large number of samples, but because it is a generative method, the output of the large model suffers from the illusion problem; sometimes it outputs labels unrelated to the predefined categories, and sometimes it outputs unpredictable content. Summary of the Invention
[0003] To overcome the shortcomings of the above technologies, this invention provides a restricted-domain dynamic category text classification method that avoids the illusion problem of large models and improves classification accuracy.
[0004] The technical solution adopted by this invention to overcome its technical problems is:
[0005] A restricted-domain dynamic category text classification method includes:
[0006] S1. Obtain the text data and the corresponding tag category set C. Construct a large model token set T based on the tag category set C. C ;
[0007] S2. Transfer the large model token set T C Preprocessing is performed to obtain the final token set T;
[0008] S3. Construct an enhanced text Q from the text Q to be processed. e ;
[0009] S4. Based on Enhanced Text Q e Construct a large model classification description prompt;
[0010] S5. Perform forward inference on the large model to obtain the forward inference probability matrix M. F*L ;
[0011] S6. Using the forward inference probability matrix M F*L Get the set of token probability values for each category;
[0012] S7. Calculate the probability value based on the token probability value set for each category to obtain the probability value set P of the tag category set C.
[0013] Furthermore, step S1 includes the following steps:
[0014] S1-1. Tag category set C = {c1, c2, ..., c...} i ,...,c m}, where c i Let i be the label of the i-th category, i∈{1,...,m}, where m is the number of categories;
[0015] S1-2. Label the i-th category c i Split the token by word to obtain the i-th category label c. i The token set c i ={t i1 ,t i2 ,...,t ij ,...,t in}, t ij For the i-th category label c i The j-th token in the array, j∈{1,...,n}, where n is the i-th category c. i Number of middle tokens;
[0016] S1-3. Concatenate the token sets of all m categories to obtain the large model token set T. C .
[0017] Furthermore, in step S2, the large model token set T is removed. C The duplicate tokens in the set are used to obtain the final token set T, T = {t1, t2, ..., t3}. i ,...,t F}, t i Let be the i-th token in the final token set T, where i ∈ {1,...,F} and F is the size of the restricted space.
[0018] Furthermore, step S3 includes the following steps:
[0019] S3-1. Construct text enhancement for the text Q to be processed using prompt;
[0020] S3-2. Input the constructed text enhancement into the large model to extract the key descriptions of the text Q to be processed. k ;
[0021] S3-3. Describe the key information Q kThe text Q is concatenated with the text to be processed to obtain the enhanced text Q. e The above-mentioned large model is either the Qwen model or the glm model.
[0022] Furthermore, in step S4, the enhanced text Q will be... e By concatenating the label category set C with the data, we obtain the large model classification description prompt.
[0023] Furthermore, step S5 includes the following steps:
[0024] S5-1. Calculate the maximum length L of all categories in the label category set C as the maximum number of forward inference iterations for the large model; S5-2. Perform forward inference on the large model according to the maximum number of iterations L to obtain the forward inference probability matrix M. F*L Forward inference probability matrix M F*L Each element takes a value between [0, 1].
[0025] Furthermore, in step S6, based on the i-th category label c i The token set c i ={t i1 ,t i2 ,...,t ij ,...,t in} and the final token set T = {t1, t2, ..., t i ,...,t F For the forward inference probability matrix M F*L Perform column-by-column addressing to obtain the i-th category label c. i The set of token probability values s i s i ={s i1 ,s i2 ,...,s ij ,...,s in}, s ij For the i-th category label c i The probability value of the j-th token in the dataset.
[0026] Furthermore, step S7 includes the following steps:
[0027] S7-1. Using formula p i =sum(s) i ) / len(s i ) Calculate the i-th category label c i The probability value p i In the formula sum(s) i For the i-th category label c i The set of token probability values s iThe summation operation for each element in len(s) i ) represents the i-th category label c i The set of token probability values s i The number of elements in;
[0028] S7-2. The set of probability values for all m categories of tokens constitutes the set of probability values P for the tag category set C.
[0029] P = {p1, p2, ..., p} i ,...,p m}
[0030] The beneficial effects of this invention are: by dynamically defining category labels, a character-level finite token space is constructed; during large model output, the token path of the finite token space is output; and finally, the token path with the highest probability is calculated as the final label. This fully utilizes the prior knowledge of the large model, avoids labeling massive training samples, and avoids the illusion problem inherent in large models, thereby improving classification accuracy. Detailed Implementation
[0031] The present invention will be further described below.
[0032] A restricted-domain dynamic category text classification method includes:
[0033] S1. Obtain the text data and the corresponding tag category set C. Construct a large model token set T based on the tag category set C. C .
[0034] S2. Transfer the large model token set T C Preprocessing is performed to obtain the final token set T.
[0035] S3. Construct an enhanced text Q from the text Q to be processed. e .
[0036] S4. Based on Enhanced Text Q e Construct a large model classification description prompt.
[0037] S5. Perform forward inference on the large model to obtain the forward inference probability matrix M. F*L .
[0038] S6. Using the forward inference probability matrix M F*L Get the set of token probability values for each category.
[0039] S7. Calculate the probability value based on the token probability value set for each category to obtain the probability value set P of the tag category set C.
[0040] This method is highly versatile and can be applied to, but is not limited to, multiple fields such as energy, government affairs, healthcare, law, and auditing. It fully leverages the stronger generalization and reasoning capabilities of large models while avoiding the illusion problem inherent in large models. When the label category needs to change, only the label category set needs to be updated; the above steps allow the large model to automatically generate the label with the highest probability. This fully utilizes the stronger generalization and reasoning capabilities of large models, while avoiding the illusion problem, saving on training sample labeling, reducing addressing space, and improving classification accuracy. When the sample category changes, only the label category set needs to be modified.
[0041] In one embodiment of the present invention, step S1 includes the following steps:
[0042] S1-1. Tag category set C = {c1, c2, ..., c...} i ,...,c m}, where c i Let i be the label of the i-th category, i∈{1,...,m}, where m is the number of categories.
[0043] S1-2. Label the i-th category c i Split the token by word to obtain the i-th category label c. i The token set c i ={t i1 ,t i2 ,...,t ij ,...,t in}, t ij For the i-th category label c i The j-th token in the array, j∈{1,...,n}, where n is the i-th category c. i The number of middle tokens.
[0044] S1-3. Concatenate the token sets of all m categories to obtain the large model token set T. C .
[0045] The following is a specific example to explain this embodiment:
[0046] The current dispute classification system uses a sample label category set to construct a dispute space with 10 categories. Specifically, these are "medical and health disputes, housing and homestead disputes, road traffic accident disputes, neighborhood disputes, marriage and family disputes, village affairs management disputes, environmental pollution disputes, legal disputes, and contract disputes".
[0047] Each type of dispute is tokenized, and a token set is constructed. Taking the dispute category "medical and health disputes" as an example, it is tokenized. The result is {medical, health, dispute}.
[0048] Concatenate all the token sets of each category to construct a large model token set {medical, health, disputes, housing, land, disputes...}.
[0049] In one embodiment of the present invention, step S2 involves removing the large model token set T. C The duplicate tokens in the set are used to obtain the final token set T, T = {t1, t2, ..., t3}. i ,...,t F}, t i Let be the i-th token in the final token set T, where i ∈ {1,...,F} and F is the size of the restricted space.
[0050] The following is a specific example to explain this embodiment:
[0051] Perform a set operation on the current large model token set obtained above to remove duplicate tokens, and construct the final token set T = {medical, treatment, health, disputes, housing, dwelling, base, land...}. This set T is the output constrained space generated by the large model based on the current tag category set.
[0052] In one embodiment of the present invention, step S3 includes the following steps:
[0053] S3-1. Construct text enhancement for the text Q to be processed using prompt.
[0054] S3-2. Input the constructed text enhancement into the large model to extract the key descriptions of the text Q to be processed. k .
[0055] S3-3. Describe the key information Q k The text Q is concatenated with the text to be processed to obtain the enhanced text Q. e .
[0056] The following is a specific example to explain this embodiment:
[0057] The current text is "Party A went to Party B's clinic for an injection. Party B promised a cure in three days, but after a week, the condition persisted. Party A raised an objection, which Party B disagreed with, leading to an argument." The text enhancement prompt is constructed as: "Given the event text description is {text}, please extract the key information of the event." Using this prompt as input to the larger model, the key description is obtained as Q_k = {clinic, injection, argument}. The resulting enhanced text is Q_e = "The event description is {text}, and the key description is {clinic, injection, argument}." Here, "text" refers to the aforementioned event text.
[0058] In one embodiment of the present invention, the above-mentioned large model is a Qwen model or a glm model.
[0059] In one embodiment of the present invention, in step S4, the enhanced text Q is... e By concatenating the label category set C with the data, we obtain the large model classification description prompt.
[0060] The following is a specific example to explain this embodiment:
[0061] Based on the above steps, a large-scale model classification prompt is obtained. One expression of the prompt can be: "This is a classification task. The known category label set is {C}, the event description is {text}, and the key description is Qk. Please give the category of the event based on the above information." In actual use, the above letters and symbols should be replaced with the corresponding text information.
[0062] In one embodiment of the present invention, step S5 includes the following steps:
[0063] S5-1. Calculate the maximum length L of all categories in the label category set C as the maximum number of forward inference iterations for the large model. S5-2. Perform forward inference on the large model using the maximum number of iterations L to obtain the forward inference probability matrix M. F*L Forward inference probability matrix M F*L Each element takes a value between [0, 1].
[0064] This process is the forward propagation process of a neural network. During each forward propagation, the previously generated token needs to be concatenated with the input to form the current input, thereby obtaining the current output.
[0065] In one embodiment of the present invention, step S6 is based on the i-th category label c i The token set c i ={t i1 ,t i2 ,...,t ij ,...,t in} and the final token set T = {t1, t2, ..., t i ,...,t F For the forward inference probability matrix M F*L Perform column-by-column addressing to obtain the i-th category label c. i The set of token probability values s i s i ={s i1 ,s i2 ,...,s ij ,...,s in}, sij For the i-th category label c i The probability value of the j-th token in the dataset.
[0066] The following is a specific example to explain this embodiment:
[0067] For the events mentioned in the preceding steps, taking the token "medical" in the first category "medical and health disputes" as an example, this token is the 0th token of the category and the 0th token of the final token set T. The probability value of this token is M[0][0], where the row value is the index of the token in the final set T and the column value is the index of the token in the category.
[0068] In one embodiment of the present invention, step S7 includes the following steps:
[0069] S7-1. Using formula p i =sum(s) i ) / len(s i ) Calculate the i-th category label c i The probability value p i In the formula sum(s) i For the i-th category label c i The set of token probability values s i The summation operation for each element in len(s) i ) represents the i-th category label c i The set of token probability values s i The number of elements in the array.
[0070] S7-2. The set of probability values for all m categories of tokens constitutes the set of probability values P for the tag category set C, P = {p1, p2, ..., p...} i ,...,p m}
[0071] The following is a specific example to explain this embodiment:
[0072] Taking the first category, "medical and health disputes," as an example, based on the probability of obtaining each token in the previous step, then through p... i =sum(s) i ) / len(s i Calculate the probability that the event description belongs to the category "medical and health disputes". Similarly, the probabilities of the other categories can be obtained. Construct a probability set P = {p1, p2, ..., p...} for the label category set C. i ,...,p m The label corresponding to the index of the value with the highest probability is the category of the current text.
[0073] Finally, it should be noted that the above descriptions are merely preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method of restricted field dynamic category text classification, characterized by, include: S1. Obtain the text data and the corresponding tag category set. According to the tag category set Building a large model token set ; S2. Transfer the large model token set Preprocessing is performed to obtain the final token set. ; S3. Transfer the text to be processed. Building Enhanced Text ; S4. Based on enhanced text Construct a large model classification description prompt; S5. Perform forward inference on the large model to obtain the forward inference probability matrix. ; S6. Using the forward inference probability matrix Get the set of token probability values for each category; S7. Calculate the probability value based on the token probability value set for each category to obtain the tag category set. The set of probability values ; Step S1 includes the following steps: S1-1. Tag Category Set ,in For the first Category labels, , Number of categories; S1-2. The first Category Labels Split the token by word to get the first word. Category Labels token set , For the first Category Labels The first in One token, , For the first Categories Number of middle tokens; S1-3. All The token sets of each category are concatenated to obtain the large model token set. ; Remove large model token sets in step S2 The duplicate tokens in the set are used to obtain the final token set. , , For the final set of tokens The Middle One token, , The size of the confined space; Step S5 includes the following steps: S5-1. Calculate the label category set Maximum length of all categories As the maximum number of forward inferences for a large model; S5-2. By maximum number of times Perform forward inference on the large model to obtain the forward inference probability matrix. Forward inference probability matrix Each element takes a value between [0, 1].
2. The restricted-domain dynamic category text classification method according to claim 1, characterized in that, Step S3 includes the following steps: S3-1. Transfer the text to be processed. Text enhancement is constructed using prompt; S3-2. Input the constructed text enhancement into the large model to extract the text to be processed. Key descriptions ; S3-3. Key Descriptions With the text to be processed Perform a concatenation operation to obtain enhanced text. .
3. The restricted-domain dynamic category text classification method according to claim 1, characterized in that: The large model is either the Qwen model or the glm model.
4. The restricted-domain dynamic category text classification method according to claim 1, characterized in that: In step S4, the enhanced text will be... With tag category set Perform a concatenation operation to obtain a large model classification description prompt.
5. The restricted-domain dynamic category text classification method according to claim 1, characterized in that: In step S6, based on the first Category Labels token set and the final token set Forward inference probability matrix Address column by column to obtain the first column. Category Labels The set of token probability values , , For the first Category Labels The first in The probability value of each token.
6. The restricted-domain dynamic category text classification method according to claim 5, characterized in that, Step S7 includes the following steps: S7-1. Through formula Calculate the first Category Labels probability value In the formula For the first Category Labels The set of token probability values The summation operation for each element in the array, For the first Category Labels The set of token probability values The number of elements in; S7-2. All The set of token probability values for each category constitutes the tag category set. The set of probability values , .