Chinese short text classification method based on graph attention network
By constructing a graph network using the Word vector fusion-Bert-GAT model and integrating syntactic dependency relations and text co-occurrence graphs, the problems of polysemy and long-range relevance in existing technologies are solved, thereby improving the performance of legal text classification tasks.
Patent Information
- Application Number
- CN202410907715.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-08
- Publication Date
- 2024-10-15
AI Technical Summary
Existing text embedding techniques cannot effectively solve the problems of polysemy and long-range relevance. Pre-trained models are limited by text length. Graph neural networks suffer from overfitting in deep information mining. Traditional deep learning methods are inadequate in legal text classification tasks.
The Word vector fusion-Bert-GAT model is adopted, which captures information between words by constructing a graph network. It combines syntactic dependency relations, text co-occurrence and latent topics, and uses a graph attention network for feature fusion and classification.
It improves the performance of legal text classification tasks, effectively captures word representations in the semantic context of sentences, solves the problems of long-range correlation and polysemy, and alleviates the overfitting phenomenon of graph neural networks.
Smart Images

Figure CN118779453A_ABST
Abstract
Description
Technical Field
[0001] The present invention focuses on case descriptions in the legal field, and pays attention to independent sentence units with periods as natural division units. Through a series of syntactic analysis methods, the example sentences are classified into primary or secondary sentence pattern categories recognized by the Chinese academic community, such as subject-predicate sentence structures or non-subject-predicate sentence structures. Background Art
[0002] Among the feature vectors input by traditional deep learning networks, there are the TextCNN model applied to text classification by the CNN network, the TextRNN model from the RNN network, the TextRCNN model that introduces the context environment based on word embedding, and the deep convolutional DPCNN model. The performance of such models depends on the quality of the input text embedding. Common text embedding technologies such as Word2vector and Glove have obvious limitations. Word2Vec cannot solve the problem of polysemy of a word, and although they all take the context into consideration, they still lack the long-range correlation of features for long texts at the chapter level. Therefore, the improvement of key technologies for semantic feature extraction of chapter texts is a key issue and difficulty to be solved.
[0003] Due to model limitations, the Transformer-based pre-trained model limits the length of a string to 512 characters. In text classification tasks, the maximum text length is generally set to 128 or 256. In addition, the Transformer method lacks non-continuous word semantic features and global relations of the corpus. This makes the pre-trained model insufficient to process the text information of a case.
[0004] There are few methods for text construction as graph data. The current idea of "text -> graph data" is still based on simple statistical methods. Cora scientific citation dataset, where each node represents a chapter and the edge is the connection of the citation. TextGCN constructs text graphs in the form of "chapter-word" co-occurrence heterogeneous graphs. The early scientific citation Cora dataset contains 2708 scientific publications, 5429 edges, and a total of 7 categories. Each chapter node in the dataset is described by a word vector containing 0 / 1 values, indicating the absence / presence of the corresponding word in the dictionary. The dictionary consists of 1433 non-repeated words that appear in the dataset. This means that each chapter is composed of 1433 features, each of which is represented by only 0 / 1. The schematic diagram of Cora composition is as follows.
[0005] The TextGCN model proposes a general text composition scheme. The graph contains all chapters and words as two-level heterogeneous nodes, and each node feature is embedded using one-hot. TF-idf is used to construct the edge weights of chapter nodes and word nodes; for the relationship between words, the point-by-point mutual information between word nodes is used to calculate the PMI value. Try to place similar words and documents close to each other in the graph.
[0006] Based on the text in a specific field, how to extract information and construct more effective graph data is the premise for us to apply graph methods to solve downstream problems. Graph neural networks can be divided into spectral domain graph networks and frequency domain graph networks. The current migration of text classification and reasoning tasks to graph problems is generally described as a "node classification" task. The mathematical essence of the spectral domain graph neural network suitable for such tasks is Laplace smoothing. When the number of layers is greater than 2, over-smoothing and overfitting will occur. The extremely limited number of layers is not enough to mine deeper graph data. Therefore, how to alleviate the overfitting phenomenon of spectral domain graph neural networks and mine deep graph information is a difficult problem that needs to be solved.
[0007] Traditional deep learning methods use semantic embedding features, and the current semantic embedding representation technology of text cannot meet the practical needs of long-range correlation and polysemy. The pre-trained model is also limited by the number of model token units and the length of the processed text. In addition, the cost of improvement is high. The present invention solves the problem of text classification reasoning in the legal field and achieves better performance in the legal text classification reasoning scenario. Summary of the invention
[0008] In order to solve the above problems, we proposed the Word vector fusion-Bert-GAT (WBGAT) model to overcome the fact that semantic embedding representation technology cannot meet the practical needs of long-range correlation, polysemy, and the number of model token units. The algorithm model proposed in this invention uses the graph network model framework to capture and transmit the intrinsic information between words by constructing a graph network, thereby learning a new word representation that can better reflect the semantic context of the entire sentence. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] Figure 1 :Word Vector fusion-Bert-GAT (WBGAT) algorithm flow chart Figure 2 : Example diagram of sentence storage according to law Figure 3 : Syntax analysis principle diagram Figure 4 : Schematic diagram of syntactic relations.
[0010] Figure 5 :Node embedding combination diagram Figure 6 :Schematic diagram of text co-occurrence graph construction Figure 7 : Part of the dataset text Figure 8:Topic extraction structure Fig. 9 For: Word-Chapter-Theme Text Diagram DETAILED DESCRIPTION
[0011] The present invention will be further described below in conjunction with the accompanying drawings.
[0012] The algorithm model proposed in the present invention uses the graph network model framework to capture and transmit the intrinsic information between words by constructing a graph network, thereby learning a new word representation that can better reflect the semantic context of the entire sentence. The legal text is analyzed, the text is split into single sentences according to commas, and then three graphs are constructed: word co-occurrence, legal sentence existence, and chapter-theme. Through a fusion function, the three graphs are adaptively fused into a word vector, and then GAT is introduced for classification.
[0013] Specific methods
[0014] Step 1: Construct a sentence existence diagram
[0015] The sentence existence method can accurately reveal the syntactic relationship between words in the text and the syntactic structure of the entire text. Therefore, this paper uses the dependency syntax interpreter to extract the syntactic relationship of the legal text.
[0016] The biaffine attention model is used to obtain the syntactic dependency structure in the sentence. This algorithm is based on the dependency syntactic analysis principle of graph theory. It parses the sentence step by step from left to right. For each lexical unit in the sentence, its core task is to determine the connection between the word and its corresponding head word, which is specifically manifested in finding the dependency arc from the current word to its head word, and at the same time identifying the dependency type represented by this arc. In other words, the algorithm mainly solves two key problems at the same time: which two word nodes have a dependency connection and what is the label attribute attached to this connection.
[0017] The biaffine attention mechanism is an extension and innovation of the traditional affine classifier formula. The difference lies in the weight matrix and bias term. When processing the output of Stacked LSTM, this mechanism replaces the original with a linear transformation operation of dimension . At the same time, the original bias term b is replaced by a linear transformation of dimension , as shown in formulas (1) and (2).
[0018] s i =Wr i +b (1)
[0019]
[0020] The type of dependency relationship between head (central word) and dep (dependent word) is fixed, so this is a classification problem with clear categories. In this regard, the following formula (3) is used to calculate the scores of each type of label.
[0021]
[0022] In a sentence containing N words, there are N+1 words including the virtual root node ROOT. For each word in the sentence, we need to calculate the scores of all possible dependencies. Considering that the number of words in a sentence is not fixed, this means that this is a classification problem with non-fixed categories. The traditional multi-layer perceptron (MLP) performs well in dealing with fixed category classification tasks. However, in the face of the uncertainty of the number of words in a sentence, the traditional method needs to be adaptively adjusted. Therefore, in order to solve the non-deterministic category classification task, two separate multi-layer perceptrons (MLPs) are used to re-encode the hidden layer output vectors generated by the BILSTM network, as shown in formulas (4) and (3-5). Then, the two vectors processed by MLP are applied to a formula structure similar to formula (2), and the calculation formula (6) for the dependency score is obtained. Here, the two MLPs are respectively for dep (dependent word) and head (center word) in the dependency relationship. MLP compresses the BILSTM hidden layer output vector into a more compact representation through dimensionality reduction. The advantage of this is that it can filter out irrelevant information because the original BILSTM hidden layer state contains information for predicting dependency arc labels, which is not necessary for predicting head words.
[0023]
[0024] The input is the set of LSTM hidden state vectors at each time step, and the output is the normalized vector representation at each time step. Like other graph-based models, during the training phase, the model predicts each word to be attached to the head word with the highest score to build a parse tree (although during the testing phase, the minimum spanning tree (MST) algorithm is used to ensure that the constructed parse tree structure is legal and reasonable).
[0025] It is straightforward to model the relationship between the prior probability of a word receiving any dependency in the second term and the probability of receiving a specific dependency in the first term. A bi-affine classifier is also used to predict the given head or the corresponding dependency label.
[0026] In dependency grammar analysis, dependency relations are used to describe the connections between words within a sentence, usually by connecting them with lines and marking the relationships. In a typical sentence, there is usually a verb that plays a core role, which forms a dependency relationship with other words.
[0027] For example, in the sentence: "Fourth, the end time of the real estate sales project and the time of Di's resignation have not been clarified.", we can get the dependency structure as follows Figure 2 .
[0028] Use the syntactic dependency parser to extract the modification relationship of each text in the text, construct text edges based on the syntactic relationship, and use each word in the text as a node of the graph. Then use the graph attention model described later to obtain the word embedding representation in the text graph. Finally, in the pooling stage, we will input the node embedding pool as a feature of the entire text into the classifier. The specific text graph is as follows Figure 3 , Figure 4 .
[0029] The initial modification relationship of the dependency parser is directional. In this paper, we remove it and change it to an undirected edge. If a node in a syntactic relationship is not connected to another node, the weight assigned to the edge is 0. In the combination of text features, "movie" will have more features such as "one", "attractive", and "iconic", while "continuously" is the second-order domain of "movie". There is no direct syntactic relationship between the two, and they are connected through the feature words in the first-order domain, so the resulting semantic features will be relatively few. Due to the relationship of the undirected edge, the features of "movie" and "continuously" can be combined to learn node embedding.
[0030] The update of the entire node embedding is calculated using GAT, as shown in (7) and (8).
[0031]
[0032] In the formula, is the text node embedding, is the number of updates, is the linear transformation, is the weight between nodes, and is the neighbor node of the node. Figure 4 , "movie" will calculate the weights between "one", "attractive" and "iconic". If "movie", "attractive" and "iconic" have higher weights, the features of the new "movie" will include the features of "movie", "attractive" and "iconic". The weight calculation formula is shown in (8). After linear transformation, the node features are concatenated and then multiplied by a weight vector, which is then activated by a LeakyReLU function and finally the weight is calculated by softmax.
[0033] In the original node embedding, we use the biRNN architecture to obtain the feature information before and after each word. The RNN part uses the gated recurrent unit (GRU), and the calculation method is shown in formula (9):
[0034] x 0 =[h0,h1,...,h n ]=biRNN(w0,w1,...,w n ) (9)
[0035] Where is the conversion vector of Word2vec in the text and is the length of the text.
[0036] For the legal dataset built by this paper, according to the visualization of the syntactic analysis results of DDpasrser, there are at most second-order neighborhood connections between text words, so when L=2, the second-order neighborhood is sufficient to obtain text features. When L=0, the "movie" node has not obtained other node features. When L=1, it has node features in the first-order domain, but L is too large to bring more noise. The process of node embedding combination is as follows: Figure 5 ,In R8 and R52, obtaining root words and modifying root word text features have reached the limit of classification; in MR, more modifier features may be needed, and these modifiers are related to emotions, so more levels of L are needed.
[0037] Step 2: Construct a text co-occurrence graph
[0038] After preprocessing the legal text, we will get individual sentences, and the set of individual sentences is n = (n1, n2, ... n m ), the specific construction steps are as follows:
[0039] (1) Set the size of the sliding window to m.
[0040] (2) Divide each sentence in the sentence set into several words, using W = {w1,w2,…w n} represents its word set, each word w in the set i Each is a single node.
[0041] (3) The window starts to slide in a certain direction (from left to right). If and exist in a sliding window, an undirected edge is connected between the two words, and the number of co-occurrences of the two words in the sliding window is used as the weight of the undirected edge, represented by . The specific calculation formula is shown in (10):
[0042]
[0043] Take the sentence "Xiao Ming is a football star and he has won many honors" as an example. Figure 6An example of text co-occurrence graph construction is given.
[0044] In addition to the characteristic information of characters, words, and sentences in the text, each text may have one or more potential topics. Therefore, this chapter uses the topic model NVDM-GSM (Gaussian-Softmax) to mine potential topics K, thereby enriching the semantics of short texts. Each topic (representing vocabulary) is represented by the probability distribution of words. The NVDM-GSM model uses the bag-of-words (BOW) representation of the document as input features. Given that the topic distribution should follow the normalization characteristics of the probability distribution, after the model samples the Gaussian random variables representing the topic from the latent space, it also needs to normalize them to ensure that the generated topic distribution can meet the requirements of the probability distribution. To this end, NVDM-GSM adopts the strategy of the Softmax function layer. By applying the Softmax operation to the sampled Gaussian variables, the extracted topic vectors are effectively normalized and converted into probabilistic topic distributions that can be used for subsequent analysis. The specific formula is as follows:
[0045] z~Ν(μ(x),σ(x) 2 )(11)
[0046] θ=Softmax(W l T z) (12)
[0047] The normalized vector θ (K-dimensional) obtained in this way is used as the topic distribution vector of the document, and the reconstructed document is obtained after being imported into the decoder P(x|z). The weight parameter ρ in the decoder K*V This is the topic-word distribution matrix. Let θ take the one-hot vector with the kth dimension as 1 and import it into the decoder to get the topic-word distribution of the kth topic. In this chapter, the number of topics is set to 20, and the classifier is selected as HanLP, which is used in actual self-built data, such as Figure 7 shown.
[0048] After 600 epochs, the extracted keywords are as follows: Figure 8 :
[0049] like Figure 8 As shown in the figure, the topic diversity is 0.67, which means that there are many repeated words or the distinction between topics is not enough. The main reason is the problem of the VAE encoding and decoding architecture in the model. However, it can still be seen that the focus of the topics in the dataset.
[0050] For each short text, it is necessary to assign the topic with the highest probability, that is, the topic most relevant to the text, in order to express the semantics of the text more accurately and appropriately.
[0051] After obtaining the relationship between words through the sliding window, combined with the potential topics of the text mined in this section, a three-level heterogeneous graph structure with words, chapters, and topics as nodes is constructed. The specific structure is as follows: Fig. 9 shown.
[0052] Step 3: Text Graph Embedding Representation
[0053] Through sliding windows, DDparser and neural topic models, we constructed three text graphs, namely text co-occurrence graph G1=(V,E1), syntactic dependency graph G2=(V,E2) and word-topic-text graph G3=(V,E3).
[0054] The three constructed text graphs are respectively used to learn their topological structures through the graph attention network, and the word nodes of the text graph are vectorized. The formula is as follows:
[0055] H M =σ(A M ,H M ,W M ) (13)
[0056] H L =σ(A L ,H L ,W L ) (14)
[0057] H D =σ(A D ,H D ,W D ) (15)
[0058] In the formula, H i (i=M,L,D) represents three graph embedding matrices, where the first layer input of the graph attention network is H L 0 =X,X∈R N×L , N represents the number of word nodes, and L represents the embedding dimension of word nodes. A∈R N×N It is the adjacency matrix, and the edge weight is each element value in the matrix, which is between 0 and 1, representing the weight parameter matrix, which represents the nonlinear activation function.
[0059] Step 4: Graph Pooling Operation
[0060] After the operation of the graph attention layer, an embedded representation is successfully generated for each word node in the text. In order to further capture the semantic information of the text as a whole and convert it into a single vector suitable for document-level classification, the embedding vectors of these word nodes need to be aggregated and integrated. This process involves the soft attention mechanism and possible hybrid pooling technology. In the soft attention mechanism, a two-layer multi-layer perceptron (MLP) is used for processing steps: first, one of the MLPs is used to perform a nonlinear transformation on the text word embedding vector to extract higher-level features; then, another MLP is used to calculate the attention weight coefficients corresponding to each word vector in the text. These coefficients directly reflect the importance level of each word in the document context. The calculation process is as follows:
[0061]
[0062] Among them, σ represents the activation function, mlp1, mlp2, mlp3, mlp4, mlp5, mlp6 represent multi-layer perceptrons, mlp1, mlp3, mlp5 calculate weight coefficients, mlp2, mlp4, mlp6 perform nonlinear transformation on node representation; h L Represents the embedding vector of each node in the text co-occurrence graph, h M represents the embedding vector of each node in the syntactic dependency graph, h D Represents the embedding vector of each node in the word-chapter-topic graph.
[0063] By combining the advantages of average pooling and maximum pooling, the dimension of text graph features can be effectively reduced, and the effective extraction of key information can be further ensured. Therefore, when performing aggregation operations on each node, average pooling and maximum pooling are used simultaneously. The specific formula is as follows.
[0064]
[0065] where h1,h2,…,h ν Represents the embedding representation of the text word node, with "+" as the dividing line. The part before the dividing line indicates that the node is average pooled, and the part after the dividing line indicates that the node is max pooled.
[0066] Step 5: Feature Adaptive Fusion
[0067] The text features of the text graph are vectorized using the graph attention network. However, how to effectively integrate these three types of feature vectors and ensure that the features with higher importance are given greater weights during the fusion process has become a core issue. To solve this problem, a feature-adaptive feature fusion algorithm is proposed. This algorithm enables the model to fuse text graph features pairwise and dynamically learn the importance weights of various features based on the characteristics of different data sets. The following is the calculation formula to achieve this fusion process:
[0068] h1'=a*h G1 +(1-a)h G2 (twenty two)
[0069] h=a*h G3 +(1-a)h1' (23)
[0070] In the formula, It is a variable parameter that will be automatically adjusted to the optimal parameter as the model is trained.
[0071] Step 6: Softmax classification
[0072] Because the Softmax function is used in the text classification layer of the present invention to convert the text feature vector h obtained after fusion into probability, the classification prediction of Chinese sentence patterns is completed, and the specific formula is shown in (24).
[0073] y=softmax(Wh+b) (24)
[0074] In the formula, W represents the parameter matrix that maps the classification features to the output domain, b is the bias term, and y is the classification result predicted by the model.
[0075] The loss function used in the present invention is the minimum cross entropy loss function
[0076]
Claims
1. A Chinese short text classification method based on graph attention network, characterized by The following steps are involved: Step 1: Construct a sentence existence law graph. The sentence existence law can accurately reveal the syntactic relationship between words in the text and the syntactic structure of the entire text. Therefore, this paper uses a dependency syntax interpreter to extract the syntactic relationship of the legal text. The biaffine attention model is used to obtain the syntactic dependency structure in the sentence. This algorithm is based on the dependency syntax analysis principle of graph theory. It parses the sentence step by step from left to right. For each lexical unit in the sentence, its core task is to determine the connection relationship between the word and its corresponding head word, which is specifically manifested in finding the dependency arc from the current word to its head word, and at the same time identifying the dependency relationship type represented by this arc. Step 2: Constructing a text co-occurrence graph In addition to the feature information of characters, words, and sentences, each text may have one or more potential topics. Therefore, this chapter uses the topic model NVDM-GSM (Gaussian-Softmax) to mine potential topics K, thereby enriching the semantics of short texts. Each topic (representing vocabulary) is represented by the probability distribution of words. The NVDM-GSM model uses the bag-of-words (BOW) representation of the document as input features. Given that the topic distribution should follow the normalization characteristics of the probability distribution, the model needs to normalize the Gaussian random variables representing the topic after sampling from the latent space to ensure that the generated topic distribution can meet the requirements of the probability distribution. To this end, NVDM-GSM adopts the strategy of the Softmax function layer. By applying the Softmax operation to the sampled Gaussian variables, the extracted topic vectors are effectively normalized and converted into probabilistic topic distributions that can be used for subsequent analysis. Step 3: Text graph embedding representation. Through sliding windows, DDparser and neural topic models, we constructed three types of text graphs, namely text co-occurrence graph, syntactic dependency graph and word-topic-text graph. The topological structures of the three constructed text graphs are learned through the graph attention network, and the word nodes of the text graphs are vectorized. Step 4: Graph pooling operation. After the operation of the graph attention layer, an embedded representation is successfully generated for each word node in the text. In order to further capture the semantic information of the text as a whole and convert it into a single vector suitable for document-level classification, the embedding vectors of these word nodes need to be aggregated and integrated. This process involves a soft attention mechanism and possible hybrid pooling technology. In the soft attention mechanism, a two-layer multi-layer perceptron (MLP) is used for processing steps: first, one of the MLPs is used to perform a nonlinear transformation on the text word embedding vector to extract higher-level features; then, another MLP is used to calculate the attention weight coefficients corresponding to each word vector in the text. These coefficients directly reflect the importance level of each word in the document context. Step 5: Adaptive feature fusion, using the graph attention network to vectorize the text features of the text graph. However, how to effectively integrate these three types of feature vectors and ensure that the more important features are given greater weights during the fusion process has become a core issue. To solve this problem, a feature-adaptive feature fusion algorithm is proposed. This algorithm enables the model to fuse text graph features pairwise and dynamically learn the importance weights of various features based on the characteristics of different data sets. Step 6: Softmax classification. In the text classification layer of the present invention, the Softmax function is used to convert the text feature vector h obtained after fusion into probability, thereby completing the classification prediction of Chinese sentence patterns.
2. The method according to claim 1, characterized in that: In step one, the biaffine attention model is used to obtain the syntactic dependency structure in the sentence.
3. The method according to claim 1, characterized in that: In step 2, the topic model NVDM-GSM (Gaussian-Softmax) is used to mine potential topics K to enrich the semantics of short texts. Each topic (representing vocabulary) is represented by the probability distribution of words.
4. The method according to claim 1, characterized in that: In step three, the topological structure is learned through the graph attention network, and the word nodes of the text graph are vectorized.
5. The method according to claim 1, characterized in that: In step 4, a soft attention mechanism and possible mixed pooling techniques are used. In the soft attention mechanism, a two-layer multi-layer perceptron (MLP) is used for processing.
6. The method according to claim 1, characterized in that: In step 5, a feature-adaptive feature fusion algorithm is used to enable the model to fuse text-graph features pairwise and dynamically learn the importance weights of various features according to the characteristics of different data sets.
Citation Information
Patent Citations
Text classification method based on graph neural network topic model
CN114186062A
Cited By
Text classification method and system based on natural language processing
CN119691179A
A text classification method and system based on natural language processing
CN119691179B
