A Text Data Classification Method Based on Graph Kernels
By extracting textual and structural information from documents, and using an improved graph kernel method and SVM model for text classification, the problem of insufficient accuracy in existing technologies is solved, achieving efficient and low-resource-consumption text classification results.
Patent Information
- Application Number
- CN202310069841.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-07
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-02-07
AI Technical Summary
Existing graph kernel-based text classification methods fail to fully utilize the textual and structural information of documents, resulting in insufficient classification accuracy and failing to meet users' demands for high accuracy and high operational efficiency.
By extracting textual and structural information from documents, an improved graph kernel method is used to measure document similarity. Document similarity analysis is performed by combining adjacency matrix and diagonal matrix, and text classification is performed using an SVM model.
It achieves high-accuracy text classification, reduces computational resource consumption, improves user experience, and meets users' needs for high accuracy and low storage consumption.
Smart Images

Figure CN116340508B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing, and more specifically to a text data classification method based on graph kernels. Background Technology
[0002] Text classification is a crucial task in natural language processing. It is widely applied in fields such as news text analysis, sentiment analysis, and spam detection. A key focus in text classification is how to better identify the text users need and the text they don't. Text classification utilizes labeled data (data with known category information) for model training to ultimately classify unknown text. Typically, this operation involves comparing the similarity between two documents, making document similarity a vital aspect of this field. We can use graph structures to capture both textual and structural information within documents, and then measure similarity using graph kernels to help users obtain the news text they need or block spam.
[0003] Using graph kernel techniques for document classification has become a common approach in text classification in recent years. By representing a document as a word graph, we can better capture its textual information (such as the frequency of a word's occurrence) and structural information (such as the relationship between two words), thus enabling us to model these relationships. In a word graph, each word is represented as a node, and the relationships between words are represented by edges between nodes. By using improved graph kernel methods, we can measure the similarity between two documents. Simultaneously, we can transform the word graph into adjacency matrices and diagonal matrices to present the document's feature information to the user, allowing them to more intuitively understand the degree of association and importance of words within the document. The key to using graph kernels for document similarity measurement is capturing sufficient textual and structural information. However, some existing graph kernel methods do not fully utilize this information. Past graph kernel-based methods only focused on the word graph itself, without utilizing the word graph to store textual and structural information, resulting in accuracy rates that did not fully meet user needs. Furthermore, as users increasingly focus on user experience, some existing high-precision methods are no longer adequately meeting these needs. Summary of the Invention
[0004] The main objective of this invention is to provide a text data classification method based on graph kernels. The algorithm saves the textual and structural information of documents into a word graph, and proposes a new graph kernel method to measure the similarity of documents, thereby meeting users' requirements for high accuracy, high operating efficiency, and low storage consumption in text classification.
[0005] According to a first aspect of the present invention, a text data classification method based on graph kernels is provided, characterized in that it includes:
[0006] Step S10: Preprocess the original document collection.
[0007] Step S20: Extract the text information of the document, including steps S21-S22.
[0008] Step S21: Extract the entropy-based weighted value, i.e., the BDC value, for each word.
[0009]
[0010] Where t is a word, |C| is the number of categories, and p(t|c) is the number of categories. i ) is the word t in category c i The percentage it accounts for.
[0011] Step S22: Construct a dictionary with one-to-one correspondence between words and BDC values using descending order.
[0012] Step S30: Extract the document's structural information, including steps 31-32.
[0013] Step S31: Based on the word co-occurrence window W, convert the document into a word graph G = (V, E), where V = {v1, v2, ..., v...} n Let E = {e1, e2, ..., e} represent the set of vertices transformed from words. n} represents the set of edges between vertices.
[0014] Step S32: Assign values to the edges in set E. Among them, ne i Representing edge e i The number of times a word appears in the word graph G, max(ne1,ne2,…,ne…). n () represents the edge that appears most frequently.
[0015] Step S40: Based on the text information and structural information, perform document similarity analysis based on the graph kernel, including steps 41-42.
[0016] Step 41: Transform the word graph G into an adjacency matrix A and a diagonal matrix D. A stores the edge values of G, i.e. ME values, and D stores the vertex values of G, i.e. BDC values of words.
[0017] Step 42: Calculate the document similarity between word graph G1 = (V1, E1) and word graph G2 = (V2, E2) using the improved graph kernel method.
[0018]
[0019] Where norm = ||A1+D1|| F ×‖A2+D2‖F The matrix A1 and A2 are used to normalize the obtained graph kernel values; A1 and A2 are the adjacency matrices of graphs G1 and G2, storing the structural information of the two word graphs; D1 and D2 are the diagonal matrices of graphs G1 and G2, storing the text information of the two word graphs. F It is the F-norm of the matrix. The k-norm between two word graphs is calculated using the values in diagonal matrices D1 and D2. node Value. If vertex v i and vertex v j If they are the same word, then and Represents vertex v i and v j The degree of a vertex in graphs G1 and G2 (i.e., how many vertices it is connected to). and Represents vertex v i and v j The BDC value of vertex v. i and vertex v j If they are not the same word, then k node (v i ,v j ) = 0.
[0020] Calculate the k-value between two word graphs using the values in adjacency matrices A1 and A2. edge Value, if edge e i Connecting two vertices v m and v n With edge e j Connect the two vertices v′ m and v′ n If the words are the same, then If edge e i The word connecting the two vertices and the edge e j If the words of the two connected vertices are different, then k edge (e i ,e j ) = 0.
[0021] Step S50: Based on the document similarity matrix, perform text classification using the SVM model.
[0022] Furthermore, the text data classification method based on graph kernel provided by the present invention is characterized in that step S10 includes: loading the dataset, obtaining the tags and content of the document, and removing punctuation marks, stop words, and words with excessively high or low frequency from the content.
[0023] Furthermore, the text data classification method based on graph kernel provided by the present invention is characterized in that step S50 includes: training an SVM model based on the document similarity matrix of the training document set, saving the trained SVM model and the optimal penalty parameter P; and classifying documents using the SVM model according to the optimal penalty parameter P.
[0024] According to a second aspect of the present invention, a computer device is provided, characterized in that it comprises:
[0025] A memory for storing instructions; a processor for calling the instructions stored in the memory to execute the graph kernel-based text data classification method of the first aspect.
[0026] According to a third aspect of the present invention, a computer-readable storage medium is provided, characterized in that it stores instructions that, when executed by a processor, perform the graph kernel-based text data classification method of the first aspect.
[0027] Compared with the prior art, the above-mentioned technical solution conceived in this invention has at least the following beneficial effects:
[0028] (1) The text data classification method based on graph kernel of the present invention is applicable to various types of text classification, which helps to realize different text classification models according to different user needs, and helps users obtain the text they need more accurately and block spam text, thus meeting users' needs for spam information blocking and news text analysis.
[0029] (2) The improved graph kernel method used in this invention can meet the needs of users more quickly and conveniently, with low requirements for users' computer hardware configuration, less computer resources occupied, and a better user experience.
[0030] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description
[0031] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0032] Figure 1 This is a flowchart illustrating a graph kernel-based text data classification method according to an exemplary embodiment.
[0033] Figure 2 This is a word weight graph of a graph kernel-based text data classification method illustrated according to an exemplary embodiment.
[0034] Figure 3This is a classification effect diagram illustrating a graph kernel-based text data classification method according to an exemplary embodiment.
[0035] Figure 4 This is a document diagram illustrating the storage requirements of a graph kernel-based text data classification method according to an exemplary embodiment.
[0036] Figure 5 This is a runtime graph illustrating a graph kernel-based text data classification method according to an exemplary embodiment.
[0037] Figure 6 This is a memory usage graph of a kernel-based text data classification method illustrated according to an exemplary embodiment. Detailed Implementation
[0038] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0039] This invention provides a text data classification method based on graph kernels. The algorithm saves the textual and structural information of documents into a word graph, and proposes a new graph kernel method to measure the similarity of documents, meeting users' needs for high accuracy, high running efficiency and low storage consumption in text classification.
[0040] According to a first aspect of the present invention, a text data classification method based on graph kernels is provided, such as... Figure 1 As shown, the feature is that it includes:
[0041] Step S10: Preprocess the original document collection.
[0042] Step S20: Extract the text information of the document, including steps S21-S22.
[0043] Step S21: Extract the entropy-based weighted value, i.e., the BDC value, for each word.
[0044]
[0045] Where t is a word, |C| is the number of categories, and p(t|c) is the number of categories. i ) is the word t in category c i The percentage it accounts for.
[0046] Step S22: Construct a dictionary with one-to-one correspondence between words and BDC values using descending order, such as... Figure 2 As shown.
[0047] In step 20, after preprocessing the text data and dividing it into two lists—tags and document content—the BDC formula is used to calculate the weights of the vocabulary corresponding to the document set, and these weights are saved in dictionary form. Users can then visually view the weights of each word in the document set, understanding the importance of each word. The word weights are as follows: Figure 2 As shown.
[0048] Step S30: Extract the document's structural information, including steps 31-32.
[0049] Step S31: Based on the word co-occurrence window W, convert the document into a word graph G = (V, E), where V = {v1, v2, ..., v...} n Let E = {e1, e2, ..., e} represent the set of vertices transformed from words. n} represents the set of edges between vertices.
[0050] In some embodiments, the user can set the word co-occurrence window W to a size of 2, and convert the document into a word graph by sliding the window W. All constructed word graphs are stored in a list.
[0051] Step S32: Assign values to the edges in set E. Among them, ne i Representing edge e i The number of times a word appears in the word graph G, max(ne1,ne2,…,ne…). n () represents the edge that appears most frequently. The BDC value is assigned to each word in the vertex set V by looking it up in the dictionary.
[0052] Step S40: Based on the text information and structural information, perform document similarity analysis based on the graph kernel, including steps 41-42.
[0053] Step 41: Transform the word graph G into an adjacency matrix D and a diagonal matrix D. Store the edge values of G, i.e. ME values, in A, and store the vertex values of G, i.e. BDC values of words, in D.
[0054] Step 42: Calculate the document similarity between word graph G1 = (V1, E1) and word graph G2 = (V2, E2) using the improved graph kernel method.
[0055]
[0056] Where norm = ||A1+D1|| F ×‖A2+D2‖ FThe matrix A1 and A2 are used to normalize the obtained graph kernel values; A1 and A2 are the adjacency matrices of graphs G1 and G2, storing the structural information of the two word graphs; D1 and D2 are the diagonal matrices of graphs G1 and G2, storing the text information of the two word graphs. F It is the F-norm of the matrix. The k-norm between two word graphs is calculated using the values in diagonal matrices D1 and D2. node Value. If vertex v i and vertex v j If they are the same word, then and Represents vertex v i and v j The degree of a vertex in graphs G1 and G2 (i.e., how many vertices it is connected to). and Represents vertex v i and v j The BDC value of vertex v. i and vertex v j If they are not the same word, then k node (v i ,v j ) = 0.
[0057] Calculate the k-value between two word graphs using the values in adjacency matrices A1 and A2. edge Value, if edge e i Connecting two vertices v m and v n With edge e j Connect the two vertices v′ m and v′ n If the words are the same, then If edge e i The word connecting the two vertices and the edge e j If the words of the two connected vertices are different, then k edge (e i ,e j ) = 0.
[0058] Step S50: Based on the document similarity matrix, perform text classification using the SVM model.
[0059] In some embodiments, step S10 includes: loading the dataset, obtaining the tags and content of the document, and removing punctuation marks, stop words, and words with excessively high or low frequency from the content.
[0060] In some embodiments, step S50 includes: training an SVM model based on the document similarity matrix of the training document set, saving the trained SVM model and the optimal penalty coefficient P; and using the SVM model to classify documents according to the optimal penalty coefficient P.
[0061] In some embodiments, the data is selected from a subclass R8 of the REUTERS-21578 dataset, which is widely used for text classification tasks. R8 has 8 classes and a total of 7674 documents. Suppose a user wants to use our tool to obtain the news data they need and filter out the data they don't want.
[0062] After using the SVM model for text classification, users can obtain results such as... Figure 3 The classification effect diagram shown illustrates the results. Precision represents the text classification accuracy, recall represents the text classification recall, F1-score represents the F1 score, and accuracy represents the text classification precision. These are four general metrics for evaluating text classification performance. Using these four metrics, users can more intuitively understand the classification accuracy of the documents they need, simultaneously obtaining the news documents they require and filtering out unnecessary ones. For example, a user can obtain the documents belonging to the "trade" category and save them to their computer. Figure 4 As shown. Meanwhile, as Figure 5 and 6 As shown, our method occupies less memory, runs more efficiently, and provides a better user experience.
[0063] In some embodiments, users can also filter out spam messages and only obtain the information they need. If a user wants to learn about medical data related to a certain disease, they can also use this method to obtain it.
[0064] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the claims.
[0065] It should be understood that the present invention is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A text data classification method based on graph kernels, characterized in that, include: Step S10: Preprocess the original document collection; Step S20: Extract the text information of the document, including steps S21-S22; Step S21: Extract the entropy-based weighted value, i.e., the BDC value, for each word. Where t is a word, |C| is the number of categories, and p(t|c) is the number of categories. i ) is the word t in category c i The percentage it accounts for; Step S22: Construct a dictionary with one-to-one correspondence between words and BDC values using descending order; Step S30: Extract the document's structural information, including steps S31-S32; Step S31: Based on the word co-occurrence window W, convert the document into a word graph G = (V, E), where V = {v1, v2, ..., v...} n Let E = {e1, e2, ..., e} represent the set of vertices transformed from words. n } represents the set of edges between vertices; Step S32: Assign values to the edges in set E. Among them, ne i Representing edge e i The number of times a word appears in the word graph G, max(ne1, ne2, ..., ne...). n () represents the edge that appears most frequently; Step S40: Based on textual and structural information, perform document similarity analysis using graph kernels, including steps 41-42; Step 41: Transform the word graph G into an adjacency matrix A and a diagonal matrix D. A stores the edge values of G, i.e. ME values, and D stores the vertex values of G, i.e. BDC values of words. Step 42: Calculate the document similarity between word graph G1 = (V1, E1) and word graph G2 = (V2, E2) using the improved graph kernel method. Where norm=||A1+D1|| F ×||A2+D2|| F The matrix A1 and A2 are used to normalize the obtained graph kernel values; A1 and A2 are the adjacency matrices of graphs G1 and G2, storing the structural information of the two word graphs; D1 and D2 are the diagonal matrices of graphs G1 and G2, storing the text information of the two word graphs. F It is the F-norm of the matrix; calculate the k between the two word graphs using the values in D1 and D2. node Value, if vertex v i and vertex v j If they are the same word, then and Represents vertex v i and v j The degree of a vertex in graphs G1 and G2, i.e., how many vertices it is connected to. and Represents vertex v i and v j The BDC value, if vertex v i and vertex v j If they are not the same word, then k node (v i v j ) = 0; Calculate the k-value between two word graphs using the values in adjacency matrices A1 and A2. edge Value, if edge e i Connecting two vertices v m and v n With edge e j Connect the two vertices v′ m and v′ n If the words are the same, then If edge e i The word connecting the two vertices and the edge e j If the words of the two connected vertices are different, then k edge (e i e j ) = 0; Step S50: Based on the document similarity matrix, perform text classification using the SVM model.
2. The text data classification method based on graph kernels according to claim 1, characterized in that, Step S10 includes: Load the dataset, obtain the document's tags and content, and remove punctuation marks, stop words, and words with excessively high or low frequency from the content.
3. The text data classification method based on graph kernels according to claim 1, characterized in that, Step S50 includes: Train an SVM model based on the document similarity matrix of the training document set, and save the trained SVM model and the optimal penalty parameter P. The document is classified using an SVM model based on the optimal penalty parameter P.
4. A computer device, characterized in that, include: Memory, used to store instructions; A processor is configured to invoke instructions stored in the memory to execute the graph kernel-based text data classification method as described in any one of claims 1-3.
5. A computer-readable storage medium, characterized in that, The system stores instructions that, when executed by a processor, perform the graph kernel-based text data classification method as described in any one of claims 1-3.
Citation Information
Patent Citations
Text feature quantification method based on comentropy, text feature quantification device based on comentropy, text classification method and text classification device
CN105224695A
Construction method of material knowledge graph, material knowledge graph and application
CN114896408A