Method, system and server for hierarchically classifying long text network information
Through data cleaning and model prompt word format generation summary and keyword extraction, combined with ERNIE model and Focal Loss loss function, using Xgboost model and milvus vector library, the problem of text length and label quality in long text network information classification is solved, and the classification is improved. Accuracy and effectiveness.
Patent Information
- Application Number
- CN202410485315.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-22
- Publication Date
- 2024-08-23
AI Technical Summary
When the existing technology processes long text network information, there are problems such as text length exceeding the model processing limit, low text quality, inaccurate labels, too many hierarchical labels and no correlation, resulting in poor classification results.
Through data cleaning, model prompt word format generation and keyword extraction, the ERNIE model and Focal Loss loss function are used for multi-level classification, and the Xgboost model and milvus vector library are combined for feature supplementation, and the candidate label with the highest prediction probability is selected as the classification result.
Effectively handle ultra-long text, improve the accuracy and effect of classification and labeling, ensure training speed, and adapt to different fields and languages.
Smart Images

Figure CN118535728A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method, system and server for hierarchical classification of long text network information. Background Art
[0002] Text classification (labeling) is a basic task in natural language processing. With the rapid development of the Internet, a large amount of text information, such as news articles, social media posts, emails, product reviews, etc., is generated every day, covering various topics, emotions, and intentions. Classifying them has become an urgent need. Traditional processing methods are mainly rule-based manual classification, which requires a lot of human resources and expertise, and has poor adaptability to different fields and languages. With the continuous development of machine learning and natural language processing technology, text classification methods based on statistical natural language processing and deep learning have gradually become mainstream.
[0003] The current text classification task is mainly supervised learning, and the effect of text classification is mainly determined by the data and model. However, there may be some problems with the original text data generated by the company. First, the text may contain thousands or even tens of thousands of characters, which is far beyond the processing length of the traditional text classification model; second, the text quality is low. The source of the data may be text converted from speech, customer service chat records, etc., which contain a lot of colloquial content and typos; third, due to inaccurate labels, too many levels of labels, and no relationship between labels at different levels, the quality of labels in the existing data is poor. These factors have a great impact on the classification effect. Summary of the invention
[0004] In view of the deficiencies in the prior art, the present invention provides a method for hierarchical classification of long text network information, comprising the following steps:
[0005] S1, performing data cleaning on the acquired long text network information to be processed to obtain preliminary text information after preprocessing;
[0006] S2, calling a preset model prompt word format to generate a corresponding model prompt sentence according to the preliminary text information, inputting the preliminary text information into the first model to extract a summary and text-specified keywords, and obtaining a text summary and a scene keyword group;
[0007] S3, using the trained text classification model to perform multi-level classification and labeling according to the text summary and scene keyword group, and selecting the candidate label with the largest prediction probability as the multi-level classification result of the sample.
[0008] Preferably, the step S1 specifically includes: deleting irrelevant format content in the long text network information, converting the text content into lowercase format, identifying and deleting each stop word in the text content according to a stored stop word list, and forming preprocessed preliminary text information, wherein the stop words are configured to have no effect on the core meaning expression of the text content after deletion.
[0009] Preferably, step S2 specifically includes: when the text length of the long text network information exceeds the position coding limit of the NLP model, calling the preset first model prompt word format to generate a corresponding first model prompt sentence according to the preliminary text information, and inputting the first model prompt sentence into the large language model to extract text summary information; using the acquired text summary as input text, combining the input text and each selected keyword attribute according to the preset second model prompt word format to generate a corresponding second model prompt sentence, and inputting the second model prompt sentence into the large language model to extract multiple keywords in the input text to form a scene keyword group corresponding to the input text.
[0010] Preferably, the text classification model is based on the Ernie model, and a fully connected layer is used in the output layer of the Ernie model, wherein the output dimension corresponds to the number of categories required for classification of a specific task.
[0011] Preferably, the text classification model uses a Focal Loss loss function, and the Focal Loss loss function is:
[0012] FL(p t )=-α t (1-p t ) γ log(p t ), where p t It is the probability value of the result predicted by the model and calculated by the softmax function, α t It is the category weight coefficient and is a vector whose length is equal to the number of categories. It is used to store the weight of each category.
[0013] Preferably, the method further comprises using an Xgboost model to predict a correct label from a plurality of candidate labels predicted by the text classification model, and using the correct label as the multi-level classification result of the sample, wherein the training process of the Xgboost model specifically comprises the following:
[0014] Construct the features of the Xgboost model, predict the sample data through the text classification model, select the samples whose maximum probability predicted by the text classification model is lower than the set threshold, obtain the top N prediction results and corresponding probabilities of each sample, and arrange them in descending order according to the prediction probability of each candidate label; segment all the texts in the dataset based on the Jieba word segmentation library, count the high-frequency words in the dataset, count the K popular words in the dataset and construct K features; for the text after extracting the summary, extract the hidden state of the model output as the semantic information of the sample, and use it as part of the input features of Xgboost.
[0015] Select samples whose prediction probability is lower than the set threshold in the text classification model, predict the top N candidate labels, construct the position ID and corresponding prediction probability of the top N candidate labels, the hidden state output of the text classification model, and the hot word features; the sample label is the position of the correct label in these N candidate labels. If the correct label is not in these TopN labels, the label is zero. Use the above samples and sample labels as training sets to train the Xgboost model.
[0016] Preferably, the method also includes: for the summaries corresponding to all samples in the training set, using the Embedding model to obtain the Embedding vector corresponding to each sample, and storing it in the milvus vector library; for the test set samples, obtaining the summary and key information of the sample, using the Embedding model to calculate the Embedding vector of the summary information, and recalling the labels corresponding to the top N samples most similar to the Embedding vector of the test sample in the miluvs vector library; and supplementing the multiple candidate labels recalled in the milvus vector library and the corresponding recall probabilities as features of the Xgboot model.
[0017] The present invention also discloses a system for hierarchical classification of long text network information, comprising a data cleaning module, an information extraction module and a classification labeling module, wherein the data cleaning module is used to perform data cleaning on the acquired long text network information to be processed, and obtain the pre-processed preliminary text information; the information extraction module is used to call a preset model prompt word format to generate a corresponding model prompt sentence according to the preliminary text information, input the preliminary text information into a first model to perform summary extraction and text-specified keyword extraction, and obtain a text summary and a scene keyword group; the classification labeling module is used to use a trained text classification model to perform multi-level classification labeling according to the text summary and the scene keyword group, and select the candidate label with the largest prediction probability as the multi-level classification result of the sample.
[0018] The present invention also discloses a server, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the aforementioned methods when executing the computer program.
[0019] The present invention also discloses a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any of the aforementioned methods are implemented.
[0020] The method, system and server for hierarchical classification of long text network information disclosed in the present invention perform data cleaning on the acquired pre-processed long text network information, and use a preset model to perform summary and specified keyword extraction after cleaning, so as to effectively process invalid information of super-long text, and input the extracted summary and scene keyword group into a trained text classification model for multi-level classification and labeling, and select the candidate label with the largest prediction probability as the multi-level classification structure of the sample, so as to effectively improve the accuracy and effect of long text classification and labeling while ensuring the training speed.
[0021] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0023] Figure 1 The figure is a schematic diagram of the steps of a method for hierarchically classifying long text network information disclosed in an embodiment of the present invention.
[0024] Figure 2 The present invention is a flowchart of a method for hierarchically classifying long text network information disclosed in an embodiment of the present invention.
[0025] Figure 3 This is a schematic diagram of specific steps of step S2 disclosed in one embodiment of the present invention.
[0026] Figure 4 The Ernie3.0 model architecture disclosed in one embodiment of the present invention.
[0027] Figure 5 The FastText classification model architecture disclosed in another embodiment of the present invention.
[0028] Figure 6A schematic diagram of the steps of using the milvus vector library to supplement the features of the Xgboot model disclosed in one embodiment of the present invention.
[0029] Figure 7 This is a structural block diagram of a system for hierarchical classification of long text network information disclosed in another embodiment of the present invention.
[0030] Figure 8 A structural block diagram of a server for executing a method for hierarchical classification of long text network information disclosed in another embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the embodiment of the present invention clearer, the technical solution of the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings of the embodiment of the present invention. Obviously, the described embodiment is a part of the embodiment of the present invention, not all of the embodiments. Based on the described embodiment 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.
[0032] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0033] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may include that the first and second features are in direct contact, or may include that the first and second features are not in direct contact but are in contact through another feature between them. Moreover, a first feature being "above", "above" and "above" a second feature includes that the first feature is directly above and obliquely above the second feature, or simply indicates that the first feature is higher in level than the second feature. A first feature being "below", "below" and "below" a second feature includes that the first feature is directly below and obliquely below the second feature, or simply indicates that the first feature is lower in level than the second feature.
[0034] Unless otherwise defined, the technical or scientific terms used herein shall have the common meanings understood by persons with ordinary skills in the field to which the present invention belongs. The words "first", "second" and similar words used in the patent application specification and claims of the present invention do not indicate any order, quantity or importance, but are only used to distinguish different components. Similarly, words such as "one" or "a" do not indicate a quantity limitation, but indicate the existence of at least one.
[0035] Text classification (labeling) is a basic task in natural language processing. With the rapid development of the Internet, a large amount of text information, such as news articles, social media posts, emails, product reviews, etc., is generated every day, covering various topics, emotions, and intentions. Classifying them has become an urgent need. Traditional processing methods are mainly rule-based manual classification, which requires a lot of human resources and expertise, and has poor adaptability to different fields and languages. With the continuous development of machine learning and natural language processing technology, text classification methods based on statistical natural language processing and deep learning have gradually become mainstream.
[0036] The current text classification task is mainly supervised learning, and the effect of text classification is mainly determined by the data and model. However, there may be some problems with the original text data generated by the company. First, the text may contain thousands or even tens of thousands of characters, which is far beyond the processing length of the traditional text classification model; second, the text quality is low. The source of the data may be text converted from speech, customer service chat records, etc., which contain a lot of colloquial content and typos; third, due to inaccurate labels, too many levels of labels, and no relationship between labels at different levels, the quality of labels in the existing data is poor. These factors have a great impact on the classification effect.
[0037] Therefore, if the attached Figure 1 As shown, this embodiment discloses a method for hierarchically classifying long text network information, including the following steps.
[0038] Step S1, performing data cleaning on the acquired long text network information to be processed to obtain preliminary text information after preprocessing.
[0039] As attached Figure 2 As shown, after obtaining the long text network information to be processed, data cleaning is first performed to improve the stability, accuracy and robustness of the subsequent text classification model. In this embodiment, the data cleaning process includes a first cleaning step, a second cleaning step, a third cleaning step and a fourth cleaning step.
[0040] The first cleaning step is configured to remove irrelevant formatting content in the long text network information. The irrelevant formatting content includes, but is not limited to, extra spaces, punctuation marks, and special characters.
[0041] The second cleaning step is configured to convert the text content to lowercase format to avoid the model being affected by case.
[0042] The third cleaning step is configured to identify and remove each stop word in the text content according to the stored stop word list. The stop word is configured to be a word that has no impact on expressing the core meaning of the text content after deletion. For example, for stop words such as "de", "he", etc. that appear frequently and are meaningless for expressing the text content, they can be removed to shorten the input length of the sample, reduce the complexity and training time of the model. Among them, the stop word list can be obtained through word segmentation strategies, statistical analysis, and manual screening according to the dataset of a specific task, or an open-source stop word list can be used.
[0043] The fourth cleaning step is configured to remove text information with too short a text length. A too short text length indicates that the possibility of having valid information in the text information is too low, which has no contribution to the training and prediction of the model. Filtering it out can make the model more stable and accurate.
[0044] Step S2: Call the preset model prompt format to generate a corresponding model prompt statement according to the preliminary text information, input it into the first model to extract the summary of the preliminary text information and extract the specified keywords of the text, and obtain the text summary and the scene keyword group.
[0045] Open-source large models such as ChatGLM3-6B and Baichuan2-7B have achieved good results in tasks such as extracting summaries and summarizing documents. Therefore, when the length of the extracted preliminary text information exceeds the position encoding limit of natural language processing (NLP) models such as BERT, open-source large models such as ChatGLM3-6B and Baichuan2-7B can be used. Through their language understanding and generation capabilities, they can effectively process and compress long texts, correct spelling mistakes, Chinese grammar, punctuation marks, etc. in long texts, extract the main content and specific information in the long text, and organize the information into an accurate and smooth text.
[0046] At the same time, to make the most of the capabilities of the large model, a suitable prompt needs to be constructed to guide the large model to extract information. The prompt is a way of prompting input information in the large model, used to guide the model to generate specific outputs or perform specific tasks, and can be expressed as a piece of text, a sentence, or a question, etc. When training supervised or unsupervised learning models, the prompt can help the model better understand the intent of the input and make corresponding responses. Then, in this embodiment, as shown in the appendix Figure 3 As shown, step S2 specifically includes the following contents.
[0047] Step S21, when the text length of the long text network information exceeds the position encoding limit of the NLP model, the preset first model prompt word format is called to generate the corresponding first model prompt sentence according to the preliminary text information, and the first model prompt sentence is input into the large language model to extract text summary information. The first model prompt sentence is a prompt, and in this embodiment, it is configured to guide the model to perform zero-shot learning reasoning. Zero-shot learning allows the model to use its learned knowledge to identify and classify new categories that are not included in the training data without being exposed to the same category data set as the test phase during the training phase. For example, a trained model can recognize horses, tigers and pandas, but if it is required to recognize zebras, although the model has not directly seen photos of zebras during the training phase, it can recognize it by combining the characteristics of known animals and descriptions of zebras. This ability has broad application prospects in image recognition, natural language processing and other fields, because it can help models quickly adapt to new tasks or categories. Then the first model prompt sentence can be shown in the following example:
[0048] Prompt1: "'Extract the main information from the following content and write it into a paragraph.
[0049] Enter text:
[0050] {text}
[0051] Extract the main information from the above content and write it into a paragraph.
[0052] The number of characters should be within 256. ”'
[0053] In another embodiment, the first model prompt statement can also be configured to guide the model to perform few-shot learning (Few-shot) reasoning. Few-shot learning allows the model to be exposed to a small number of samples during reasoning, but does not allow weight updates. In few-shot learning, the model is provided with a small number of examples (usually K samples, K is usually between 10 and 100), and the model is expected to generate corresponding results based on these examples. This learning method greatly reduces the model's demand for task-specific data and reduces the risk of learning an overly narrow distribution from a fine-tuning dataset. The second model prompt statement can be shown in the example below, which puts forward some specific output requirements and gives three examples so that the large model can answer according to the output requirements and example format:
[0054] Prompt2: "'Extract the following text and write the summary into a paragraph.
[0055] Output requirements:
[0056] (1) Output summary in human tone.
[0057] (2) Retain keywords in the input text, such as information about participation in activities, mobile phone packages, user complaints, etc.
[0058] (3) The number of characters should be within 256.
[0059] Example 1:
[0060] Input text: XXXXXXXXXXX......
[0061] Output: XXXXXXXXXXX
[0062] Example 2:
[0063] Input text: XXXXXXXXXXX......
[0064] Output: XXXXXXXXXXX
[0065] Example 3:
[0066] Input text: XXXXXXXXXXX......
[0067] Output: XXXXXXXXXXX"'
[0068] By inputting the prompt model prompt statement into the open source large model, the long text is compressed into a shorter summary containing key information, so as to further reduce the invalid information in the text information, reduce the text processing length of the model, and increase the processing effect of the model. At the same time, the output word count requirement of prompt can be set to 128, 256, etc., so that each long text can be extracted from summary texts of different granularities according to different prompt word count requirements through large models such as chatglm3-6B and baichuan2-7B, so as to achieve the effect of data enhancement with less data.
[0069] Step S22, taking the acquired text summary as input text, combining the input text and each selected keyword attribute according to the preset second model prompt word format to generate a corresponding second model prompt sentence, and inputting the second model prompt sentence into the large language model to extract multiple keywords in the input text to form a scene keyword group corresponding to the input text. The second model prompt sentence is also a prompt, which can be shown as follows in this embodiment:
[0070] ”'Extract the keywords from the input text and answer according to the following requirements. The answer format refers to the example.
[0071] Require:
[0072] (1) Output the extracted keywords. Multiple keywords are separated by “,”.
[0073] (2) Keep information such as location, amount, and package.
[0074] Example 1:
[0075] Enter text: XXXXXXXXXXXXXXXXXXXXX...
[0076] Output: [keyword 1, keyword 2, keyword 3, keyword 4...]
[0077] Example 2:
[0078] Enter text: XXXXXXXXXXXXXXXXXXXXX...
[0079] Output: [keyword 1, keyword 2, keyword 3, keyword 4…]
[0080] Enter text:
[0081] Output: ″′
[0082] By extracting keyword information from the summary text extracted by the large model, multiple keywords can be extracted from each sample and added to the summary information, which can further enrich the information content of the summary and make it contain more key content related to the original text, achieving the effect of data enhancement. In addition, the emotions, time, and location of the characters in the text can also be extracted.
[0083] Step S3, using the trained text classification model to perform multi-level classification and labeling according to the text summary and the scene keyword group, and selecting the candidate label with the largest prediction probability as the multi-level classification result of the sample.
[0084] The multi-level classification labeling classifies and labels data or text according to different levels. For example, the three-level classification label is news-sports-football. The first-level label is news, the second-level label is sports, and the third-level label is football.
[0085] The more labels that need to be labeled and the larger the label level, the more samples are needed and the worse the model effect. Therefore, open source models such as BERT, ERNIE and Fasttext are used to adjust the combined input content to make it meet the requirements of the model. At the same time, the focalLoss loss function is used to alleviate the sample imbalance, and the model parameters such as batch_size and model structure are tuned and configured.
[0086] In this embodiment, the text classification model is based on the Ernie model. Specifically, it is based on the Ernie 3.0 architecture. The Ernie 3.0 model architecture is shown in the attached Figure 4 As shown in the figure, it includes a two-layer network structure, namely, a universal representation module and a task-specific representation module. The universal representation module is shared in each mode and can capture some common features; the task-specific representation module is specifically adapted to tasks of different modes to extract different features. In the fine-tuning stage, the universal representation module can be fixed and only the parameters of the task-specific representation module can be fine-tuned to reduce the number of parameters that need to be optimized and improve training efficiency.
[0087] In this embodiment, in order to improve the long text level effect, the output layer of the text classification model of the ernie3.0 model architecture is subjected to a first architecture adjustment and a second architecture adjustment.
[0088] The first architecture adjustment is configured to add a fully connected layer inside the output layer of the Ernie model, and the output dimension of the connection layer is configured to be the number of categories required for classification of the specific task. Compared with the method of training multiple models to predict each level of labels separately and then combining multiple levels of labels, adding a fully connected layer to the value-added model can treat multiple levels of labels as a whole and directly predict multiple levels of labels, so that the training effect is better and the training speed is faster.
[0089] The second architecture adjustment is configured to use the Focal Loss loss function in the text classification model. The Focal Loss loss function is: FL(p t )=-α t (1-p t ) γ log(p t ), where p t It is the probability value of the result predicted by the model and calculated by the softmax function, α t is the category weight coefficient and is a vector whose length is equal to the number of categories. It is used to store the weights of each category. Focal Loss is a loss function used to deal with category imbalance and difficult sample mining that is difficult to be classified by the model. t ) is -log(p in the cross entropy loss t ), so the corresponding p in the current sample category t The smaller the value, the larger the cross entropy loss function, which proves that the prediction result is less accurate. At this time, the (1-p t )γ The term will also increase at the same time. t ) γ As the coefficient of difficult samples, the less accurate the prediction, the more the focal loss tends to regard this sample as a difficult sample, so that the difficult sample has a greater contribution to the loss and gradient, and the model pays more attention to this type of difficult samples during training. In addition, α t When the data set categories are unbalanced, the sample data can be balanced by assigning high weights to categories with small amounts of data.
[0090] Since the distribution of categories in actual sample data is not balanced, a small number of categories may occupy most of the samples. The use of Focal Loss function can solve the problems of category imbalance and imbalance of difficult and easy samples by adjusting the loss weights of different samples, thereby improving the performance and robustness of the model.
[0091] In another embodiment, the text classification model can also be based on the FastText classification model. The FastText model is a fast text classification algorithm, and its architecture is shown in the attached Figure 5 As shown in the figure, X1, X2…Xn represent n-gram vectors in a text respectively, and each feature is the average value of word vectors. Embedding is to vectorize each word in the vocabulary of the data set. 2-gram and 3-gram are to vectorize the 2-gram and 3-gram of the input text. The above three parts are concat combined and the prediction result (output) is obtained through two hidden layers (fully connected layer hidden and fully connected layer hidden2).
[0092] Specifically, N-gram is an algorithm based on a statistical language model. Its basic idea is to perform a sliding window operation of size N on the text content according to bytes to form a sequence of byte fragments of length N. Each byte fragment is called a gram, N is called the n in n-gram, and the set of all grams of length N is called N-grams. The N-gram model has a wide range of applications in natural language processing. It can help us understand the relationship between words and predict the words that may appear next in the text. The N-gram model uses the first N-1 words to predict the probability of the Nth word appearing. For example, in the text "I like to learn natural language processing", using the bigram (2-gram) model, we can get the word pairs "I / like, like / learn, learn / natural language processing, etc." and their probability of occurrence.
[0093] Compared with the classification algorithm based on neural network, FastText model has fast training speed, can converge to a better level in a short time, can speed up training and testing while maintaining high accuracy, can train word vectors by itself without pre-trained word vectors, and supports longer input texts, but is weaker than the first solution based on Ernie model in terms of overall effect on hierarchical multi-classification tasks. The solution based on Ernie model is also better than the hierarchical multi-classification model based on Bert-base-Chinese.
[0094] Since the text classification model cannot be completely correct, the prediction accuracy for some categories may not be high, and the model may not cover all labels, there may be samples whose maximum prediction probability of the text classification model is too low. In this case, post-processing strategies can be used to optimize it.
[0095] In this embodiment, the post-processing strategy adopts the Xgboost model. The method also includes using the Xgboost model to predict a correct label from multiple candidate labels predicted by the text classification model, and use it as the multi-level classification result of the sample. The specific prediction process includes the following content.
[0096] Step S101, constructing Xgboost features for samples whose maximum prediction probability in the text classification model is less than a set threshold, wherein the Xgboost features include but are not limited to the position IDs of the TopN candidate tags predicted by the text classification model and their corresponding probabilities, model hidden state outputs, and hot word features.
[0097] Specifically, constructing the Xgboost model features includes the following contents.
[0098] Step S201, obtain the top N prediction results and corresponding probabilities of the sample, and arrange them in descending order according to the predicted probability of each candidate label to obtain the ranking IDs of the top N candidate labels and their corresponding probabilities. For example, the probabilities of multiple candidate labels predicted by the text multi-classification model are [label A: 0.4, label B: 0.3, label C: 0.2, label D: 0.1]. By sorting them in descending order according to the predicted probability, the ranking IDs of these four candidate labels can be obtained: [label A: 1, label B: 2, label C: 3, label D: 4]. According to the ranking IDs and predicted probabilities of these four candidate labels, 4*2=8 features can be obtained.
[0099] Step S202, segment all texts in the data set based on the Jieba word segmentation library, count the high-frequency words in the data set, count the K popular words in the data set and construct K features. For example, "Today, we are so good" is 3 popular words, and three features need to be constructed, and the default value of the features is 0. When the input sample is "The weather is so good today", the popular words "today" and "really good" appear in the sample and appear once, then the feature values of these two words are 1; "we" does not appear in the sample, then the feature value of the word is 0, and the three-dimensional feature obtained is [1,0,1]. Among them, the words separated by the Jieba word segmentation library are generally two Chinese characters, but the specific business may contain special words with a length greater than 2. By modifying the Jieba word segmentation library source code, the length of the separated words can be made greater than 2. The number of K is obtained by manual setting.
[0100] Step S203: for the text after the summary is extracted, the hidden state output by the model is extracted as the semantic information of the sample, which is used as part of the input features of Xgboost.
[0101] Step S102, using the trained Xgboost model to predict a correct label from multiple candidate labels predicted by the text classification model according to the constructed Xgboost features.
[0102] Specifically, the training process includes: constructing Xgboost features for samples whose prediction probability is lower than a set threshold in the text classification model, and using the constructed Xgboost features of the sample and its sample label as a training set to train the Xgboost model. The sample label is configured as the position of the correct label among the N candidate labels. When the correct label is not in the TopN labels of the sample, the label is configured as 0.
[0103] Select samples whose prediction probability is lower than the set threshold in the text classification model, predict the top N candidate labels, construct the position ID and corresponding prediction probability of the top N candidate labels, the hidden state output of the text classification model, and the hot word features. The sample label is the position of the correct label in these N candidate labels. If the correct label is not in these TopN labels, the label is zero. Use the above samples and sample labels as training sets to train the Xgboost model.
[0104] By using the text classification model + Xgboost candidate label screening strategy, all labels can be covered without affecting the inference speed, which can meet current needs.
[0105] In another embodiment, the milvus vector library recall strategy can also be used to supplement the features of the Xgboot model to improve the overall effect of the Xgboost model, as shown in the attached Figure 6 As shown, the specific contents include the following.
[0106] Step S301: For the summaries corresponding to all samples in the training set, use the Embedding model to obtain the Embedding vector corresponding to each sample and store it in the milvus vector library.
[0107] Step S302: For the test set sample, obtain the summary and key information of the sample, use the Embedding model to calculate the Embedding vector of the summary information, and recall the labels corresponding to the top N samples that are most similar to the Embedding vector of the test sample in the miluvs vector library.
[0108] Step S303: multiple candidate labels and corresponding recall probabilities recalled from the milvus vector library are supplemented as features of the Xgboot model. The label corresponding to the sample with the highest probability of being recalled from the milvus vector library can also be used as the label of the test sample.
[0109] By using the milvus vector library recall method, the accuracy of the Xgboost model in predicting samples with a prediction probability lower than the set threshold is further improved, thereby improving the overall classification accuracy.
[0110] The method, system and server for hierarchical classification of long text network information disclosed in the present invention perform data cleaning on the acquired pre-processed long text network information, and use a preset model to perform summary and specified keyword extraction after cleaning, so as to effectively process invalid information of super-long text, and input the extracted summary and scene keyword group into a trained text classification model for multi-level classification and labeling, and select the candidate label with the largest prediction probability as the multi-level classification structure of the sample, so as to effectively improve the accuracy and effect of long text classification and labeling while ensuring the training speed.
[0111] In another embodiment, as shown in the attached Figure 7 As shown, a system for hierarchical classification of long text network information is also disclosed, including a data cleaning module 1, an information extraction module 2 and a classification labeling module 3. Among them, the data cleaning module 1 is used to perform data cleaning on the acquired long text network information to be processed, and obtain the pre-processed preliminary text information. The information extraction module is used to call the preset model prompt word format to generate a corresponding model prompt sentence according to the preliminary text information, input the preliminary text information into the first model to perform summary extraction and text specified keyword extraction, and obtain the text summary and scene keyword group. The classification labeling module is used to use the trained text classification model to perform multi-level classification labeling according to the text summary and scene keyword group, and select the candidate label with the largest prediction probability as the multi-level classification result of the sample.
[0112] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and similar parts between the various embodiments can be referred to each other. As for the hierarchical classification system for long text network information disclosed in the embodiment, since it corresponds to the hierarchical classification method for long text network information disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the aforementioned method part.
[0113] In some other embodiments, a server is also provided, such as the attached Figure 8 As shown, it includes a memory 404, a processor 403, and a computer program stored in the memory and executable on the processor, characterized in that: when the processor executes the computer program, each step of the method for hierarchical classification of long text network information as described in the above embodiments is implemented. The server may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the schematic diagram is merely an example of a server and does not constitute a limitation on the server, and may include more or fewer components than shown in the diagram, or a combination of certain components, or different components.
[0114] If the server for hierarchical classification of long text network information is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned embodiments of the method for hierarchical classification of long text network information can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory, random access memory, electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.
[0115] In conclusion, the above is only a preferred embodiment of the present invention, and all equivalent changes and modifications made according to the scope of the patent application of the present invention should fall within the scope of the patent of the present invention.
Claims
1. A method for hierarchical classification of long text network information, characterized in that: The steps include: S1, performing data cleaning on the acquired long text network information to be processed to obtain preliminary text information after preprocessing; S2, calling a preset model prompt word format to generate a corresponding model prompt sentence according to the preliminary text information, inputting the preliminary text information into the first model to extract a summary and text-specified keywords, and obtaining a text summary and a scene keyword group; S3, using the trained text classification model to perform multi-level classification and labeling according to the text summary and scene keyword group, and selecting the candidate label with the largest prediction probability as the multi-level classification result of the sample.
2. The method for hierarchically classifying long text network information according to claim 1, characterized in that: The step S1 specifically includes: Delete irrelevant format content in long text network information, convert the text content into lowercase format, identify and delete stop words in the text content according to the stored stop word list, and form preprocessed preliminary text information, wherein the stop words are configured to have no effect on the core meaning expression of the text content after deletion.
3. The method for hierarchically classifying long text network information according to claim 2, characterized in that: The step S2 specifically includes: When the length of the long text network information exceeds the position coding limit of the NLP model, calling a preset first model prompt word format to generate a corresponding first model prompt sentence according to the preliminary text information, and inputting the first model prompt sentence into the large language model to extract text summary information; The obtained text summary is used as the input text, and the input text and the selected keyword attributes are combined according to the preset second model prompt word format to generate a corresponding second model prompt sentence, and the second model prompt sentence is input into the large language model to extract multiple keywords in the input text to form a scene keyword group corresponding to the input text.
4. The method for hierarchically classifying long text network information according to claim 3, characterized in that: The text classification model is based on the Ernie model, and a fully connected layer is used in the output layer of the Ernie model, where the output dimension corresponds to the number of categories required for classification of a specific task.
5. The method for hierarchically classifying long text network information according to claim 4, characterized in that: The text classification model uses the Focal Loss loss function, which is: FL(p t )=-α t (1-p t ) γ log(p t ), where p t It is the probability value of the result predicted by the model and calculated by the softmax function, α t It is the category weight coefficient and is a vector whose length is equal to the number of categories. It is used to store the weight of each category.
6. The method for hierarchically classifying long text network information according to claim 5, characterized in that: It also includes using an Xgboost model to predict a correct label from multiple candidate labels predicted by a text classification model, and using the correct label as a multi-level classification result of the sample, wherein the training process of the Xgboost model specifically includes the following: Construct the features of the Xgboost model, predict the sample data through the text classification model, select the samples whose maximum probability predicted by the text classification model is lower than the set threshold, obtain the top N prediction results and corresponding probabilities of each sample, and arrange them in descending order according to the prediction probability of each candidate label; segment all the texts in the dataset based on the Jieba word segmentation library, count the high-frequency words in the dataset, count the K popular words in the dataset and construct K features; for the text after extracting the summary, extract the hidden state of the model output as the semantic information of the sample, and use it as part of the input features of Xgboost. Select samples whose prediction probability is lower than the set threshold in the text classification model, predict the top N candidate tags, and construct the ranking IDs and corresponding prediction probabilities of the top N candidate tags, the hidden state output of the text classification model, and the features of popular words; The sample label is the position of the correct label among the N candidate labels. If the correct label is not in the TopN labels, the label is zero. The above samples and sample labels are used as training sets to train the Xgboost model.
7. The method for hierarchically classifying long text network information according to claim 6, characterized in that: Also includes: For the summaries corresponding to all samples in the training set, use the Embedding model to obtain the Embedding vector corresponding to each sample and store it in the milvus vector library; For the test set samples, obtain the summary and key information of the sample, use the Embedding model to calculate the Embedding vector of the summary information, and recall the labels corresponding to the top N samples that are most similar to the Embedding vector of the test sample in the miluvs vector library; The multiple candidate labels recalled in the milvus vector library and the corresponding recall probabilities are supplemented as features of the Xgboot model.
8. A system for hierarchical classification of long text network information, characterized in that: The steps include: A data cleaning module is used to clean the acquired long text network information to be processed to obtain preliminary text information after preprocessing; An information extraction module, used to call a preset model prompt word format to generate a corresponding model prompt sentence according to the preliminary text information, input the preliminary text information into the first model to perform summary extraction and text-specified keyword extraction, and obtain a text summary and a scene keyword group; The classification and labeling module is used to use the trained text classification model to perform multi-level classification and labeling according to the text summary and scene keyword group, and select the candidate label with the largest prediction probability as the multi-level classification result of the sample.
9. A server comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Natural language processing-based multi-language analysis method and device
CN108197109A
Text content classification method and device, electronic equipment and storage medium
CN114328919A
Medium and long text classification method and system based on abstract extraction and keyword extraction
CN115408523A
Text classification model training method, text classification method and device
CN116049400A
Nursing text hierarchical multi-label classification method and device, equipment and storage medium
CN117574230A
Cited By
Long document multi-dimensional text classification method and system based on scene learning
CN119513319A
Coal industry lexicon classification method
CN119513321A
Short text clustering method and device based on large language model
CN119669476A
Zero-annotation text hierarchical classification method, device and equipment based on large language model
CN120561309A
Large language model-based zero-labeled text hierarchical classification method, device and equipment
CN120561309B
