Document Emotion Cause Extraction Method Based on Edge-Weighted Graph Neural Network and Document Segmentation
By splitting the document into sub-documents of clause pairs and using edge features to enhance the graph neural network method, the confusion and classification task problems in emotional cause extraction are solved, the accuracy and efficiency of emotional cause relationships are improved, and the extraction accuracy is achieved.
Patent Information
- Application Number
- CN202310098522.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-10
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2043-02-10
AI Technical Summary
The existing emotional reasons for the extraction task have problems in which long-distance emotional searches are confused by multiple emotions, emotional relationship extraction tasks are regarded as classification tasks rather than relationship modeling, and imbalance in emotional assumption clauses and document lengths, resulting in insufficient extraction efficiency and accuracy.
The graph neural network and document segmentation method based on edge features are used to split the document into sub-documents of clause pairs, and a fully connected graph is constructed through node vectors and edge feature vectors. A bidirectional gating network and linear classifier are used to predict emotional cause relationships, and combined with local distance information and edge feature enhancement, improving the accuracy of relationship modeling.
The efficiency and accuracy of emotional cause classification are improved, the confusing effect of long-distance emotional search is reduced, and the ability to directly extract emotional cause relationships is enhanced. The experimental results show accuracy, recovery and F1 scores of 72.64%, 76.75% and 74.55% on the ECPE dataset.
Smart Images

Figure CN116069930B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of natural language processing, and relates to a graph neural network with edge features and a method for extracting emotion-cause pairs in document segmentation. Background Technique
[0002] In recent years, machine learning-based sentiment analysis has become a popular direction in natural language processing. Emotion Cause Extraction (ECE) is an emerging direction in sentiment analysis, whose goal is to given a document containing an emotion clause, find out the cause clause that causes the emotion. Although the ECE task has attracted some attention in the field of sentiment analysis, this task requires the labels of emotion clauses to be manually annotated, which is very difficult to achieve in practice. To solve this problem, a new non-annotated task - Emotion Cause Pair Extraction (ECPE) has been proposed. Different from the Emotion Cause Extraction (ECE) task, Emotion Cause Pair Extraction regards the emotion clause and its corresponding cause clause as a pair, called an emotion-cause pair, and extracts both in the document. This solves the annotation problem, and this task has attracted extensive attention in recent research.
[0003] The extraction of emotion-cause pairs is a more difficult task than extracting the cause of a specific emotion. Previous studies on emotion-cause pair extraction mainly fall into two categories: pipeline models and end-to-end models. The pipeline model consists of two parts: in the first stage, an algorithm is designed to extract emotion sentences and cause sentences respectively, and in the second stage, the emotion sentences extracted in the first stage are matched with the cause sentences. However, a serious disadvantage of the pipeline model is that its performance is limited because the errors generated in the first stage will spread and affect the performance of the second stage. To solve this problem, an end-to-end algorithm for emotion-cause pairs has been proposed. Most existing end-to-end models use a two-dimensional representation for emotion-cause pairs and make predictions based on different neural models.
[0004] An example of the ECPE task extracting in a document is as Figure 1 shown. The document contains multiple emotion sentences. Among them, (C i , C i-1 ) is an emotion-cause pair, containing the emotion "sad", and its cause is "lost wallet". (C i+2 , C i+3 ) represents another emotion-cause pair. For long-distance search, adjacent emotions may confuse the extraction of the cause. In addition, the accuracy of the ECPE task may be affected by fuzzy emotion expressions that only express emotions, which we call emotion hypothesis clauses.
[0005] Current research has improved the performance of emotion-cause pair extraction, but there are still the following problems:
[0006] (1) Long-distance emotion search may be confused by multiple emotions, which exists in multiple emotion expressions in the emotion expression document, and some emotion expressions have no reasons.
[0007] (2) The emotion cause relationship extraction task is mostly considered as a classification task (classifying after pairing emotion clauses and cause clauses). If the extraction task can model the relationship, then this method can extract the corresponding cause of the emotion more directly, rather than the binary classification of emotion-cause pairs.
[0008] (3) Existing work generally encodes the relative positions or generates a position matrix according to the true emotion causes, which may be affected by the multiple emotion expressions mentioned in (1), or affected by the imbalance between the emotion hypothesis clauses (only expressing emotions but without cause expressions) and the length of the document. Summary of the Invention
[0009] To solve the above problems and improve the efficiency and accuracy of emotion cause search.
[0010] To achieve the above object, according to some embodiments of the present application, a document emotion cause extraction method based on a graph neural network with edge features and document segmentation includes:
[0011] Split a document containing multiple clauses into sub-documents with the lengths of the front and back clauses of a sentence.
[0012] Obtain node vectors according to the clauses in the sub-documents.
[0013] Obtain emotion node factors and cause node factors according to the node vectors.
[0014] Pair the emotion node factors and cause node factors pairwise to obtain edge feature vectors.
[0015] Construct a fully connected graph through the node feature vector matrix and the edge feature vector matrix.
[0016] Update the node features according to the fully connected graph, pair the updated node features pairwise, splice the paired node pairs with the edge features, and update the spliced result to obtain updated edge features.
[0017] The updated edge features pass through a linear classifier to obtain an emotion cause relationship classification result, and the emotion cause relationship classification result is used as an emotion cause relationship prediction result label.
[0018] A method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The step of obtaining node vectors according to the clauses in the sub-document includes, for the clauses in the sub-document, converting the vocabulary of the clauses in the sub-document into BERT vectors.
[0019] A method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The step of obtaining sentiment node factors and reason node factors according to the node vectors includes:
[0020] Use a word-level BERT network to learn the word context information at the clause level in the sub-document;
[0021] Generate a vector representation for each clause and regard the vector representation as the initial representation of the node;
[0022] The sentiment reason relationship generates a learnable distance vector for the clause information in the sub-document through a random number, concatenates the distance vectors corresponding to different clause information, and the concatenated distance vector is used as the node vector representation of the clause with distance information;
[0023] Input the obtained node vector representation with distance information into a sentence-level bidirectional gated network to learn the context sentence information in the sub-document and obtain the node vectors for constructing the sentiment reason relationship;
[0024] After the node vectors for constructing the sentiment reason relationship pass through a linear layer, generate the node vector factors of the sentiment reason relationship, and obtain the sentiment node factors containing sentiment information for the first time through the bidirectional gated network and the linear layer;
[0025] The node vectors for constructing the sentiment reason relationship pass through the bidirectional gated network for the second time. The output of the bidirectional gated network is used as the initialization result of the sub-graph nodes. The matrix of the initialized nodes is represented by the node feature vector matrix. After the initialized nodes pass through a linear layer, generate the reason node factors containing reason information.
[0026] A method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The word context information at the clause level in the sub-document is represented by the following formula:
[0027] hj = BERT(c j ) j=1,···,n
[0028] where hj represents the word context information at the clause level in the document, c j represents the clause whose vocabulary is converted into BERT vectors, and n represents the number of vocabularies.
[0029] A method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The context sentence information in the sub-document is represented by the following formula:
[0030]
[0031] where hj represents the context sentence information in the sub-document, BiGRU represents a bidirectional gated network, softmax represents, and W e represents the weight of the network, and b e represents the bias of the network, h j represents the word context information at the clause level in the document, and d ij represents that the sentiment reason relationship generates a learnable distance vector for the clause information in the sub-document through random numbers.
[0032] A method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The sentiment node factor is represented by the following formula:
[0033]
[0034] where g e represents the sentiment factor, BiGRU represents a bidirectional gated network, softmax represents the softmax mechanism, and W e represents the weight of the network, h j represents the context sentence information in the sub-document, d ij represents that the sentiment reason relationship generates a learnable distance vector for the clause information in the sub-document through random numbers, and b e represents the bias of the network;
[0035] The reason node factor is represented by the following formula:
[0036]
[0037] where g c represents the reason factor, BiGRU represents a bidirectional gated network, h j represents the context sentence information in the sub-document, represents the sentiment node factor.
[0038] A method for extracting document emotion reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The step of pairing the emotion node factors and the reason node factors pairwise to obtain edge feature vectors includes: pairwise pairing the emotion node factors and the reason node factors through the corresponding multiplication of matrix elements, so that each initialized node has a bidirectional connection of emotion-reason relationships, and obtaining the edge feature vectors. The formula is expressed as follows:
[0039]
[0040] Where e i represents the edge feature, softmax represents the softmax mechanism, represents the emotion factor, represents the reason factor, and i represents the numbering of the edge features.
[0041] A method for extracting document emotion reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The step of constructing a fully connected graph through the node feature vector matrix and the edge feature vector matrix includes using the node feature vectors to construct a node feature vector matrix, using the edge feature vectors to construct an edge feature vector matrix, and constructing a fully connected graph G = <V, E> through the node feature vector matrix V and the edge feature vector matrix E. The fully connected graph G = <V, E> is a subgraph with local distance information.
[0042] A method for extracting document emotion reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application. The step of updating the node features according to the fully connected graph is expressed by the following formula:
[0043]
[0044] Where represents, f n represents the node update network, represents the aggregation of edge features, represents the aggregation of the emotion-reason relationships between the neighbor nodes of the entire subgraph starting from node j and node j. j represents h j is the j-th node in the document, h k represents h j is a certain neighbor node of h j (t) represents, is the connection operation, represents the aggregation of edge features, represents the node vector, represents the learnable parameter;
[0045] The above steps pair the updated node features pairwise. The paired node pairs are concatenated with the edge features, and the concatenated result is updated to obtain the updated edge features, which are expressed by the following formula:
[0046]
[0047] where represents the updated edge features, f e represents the edge feature enhancement network, represents the pairing of two interconnected node pairs or the pairing of a node with itself, represents the edge features before update, and θ e represents the learnable parameters.
[0048] According to the method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to some embodiments of the present application, edge features are used to represent and predict the sentiment reason relationship between two sentence nodes, which is expressed by the following formula:
[0049]
[0050] where y ec represents the predicted sentiment reason label, σ represents the fully connected layer, represents the hth j and the hth k updated edge features at the tth connection.
[0051] According to the above solution, the beneficial effects that the present invention can have are as follows:
[0052] (1) The present invention segments the document, and according to the characteristics of sentiment reason expression, obtains the sentiment node factor and the reason node factor, solves the problem that long-distance sentiment search may be confused by multiple sentiments, and improves the efficiency of sentiment reason classification.
[0053] (2) The present invention uses edge features for relationship modeling. Compared with simple node pairing, it adds a relationship learning module between nodes, can more directly extract the reasons corresponding to sentiments, rather than a binary classification task of sentiment reason pairs, and improves the accuracy of sentiment reason extraction.
[0054] (3) The present invention uses the distance vector to reduce the influence of multiple sentiment expressions and reduce the influence of the imbalance between the length of the sentiment hypothesis clause and the document.
[0055] (4) The effectiveness of the model of the present invention was tested on the ECPE dataset, and it was proven that the accuracy of the proposed model was improved compared to the baseline. The experimental results of the present invention are represented by accuracy (P), recall (R), and F1-score, and the three indicators are 72.64%, 76.75%, and 74.55% respectively. Description of the Drawings
[0056] Figure 1 It is an example of the distribution of document sentiment reasons for the ECPE task
[0057] Figure 2 It is a flowchart of the sentiment-cause pair extraction algorithm based on the edge feature graph neural network of the present invention.
[0058] Figure 3 It is a schematic diagram of the module structure of the sentiment-cause pair extraction algorithm based on the edge feature graph neural network of the present invention.
[0059] Figure 4 It is a schematic diagram of the example document content in the embodiment. Detailed Description of the Embodiments
[0060] Embodiments of the present application will be described in detail below with reference to the accompanying drawings, and examples of the embodiments are shown in the drawings.
[0061] Embodiment 1: A method for extracting document sentiment-cause pairs based on a graph neural network with edge features and document segmentation, comprising the following steps:
[0062] S101. Segment the document: For a document containing multiple clauses, split the document into sub-documents of length n; to improve the extraction efficiency, the document can be split into sub-documents with the length of the first and second clauses of a sentence, that is, the length of the split sub-documents is n = 5. It should be specifically noted that for a document with less than 5 clauses, no splitting process is performed, and a sub-graph is directly constructed.
[0063] Specifically, for a document D = {c1, c2,..., c n}, the document D can be split into sub-documents Di = {c j-2 , c j-1 , c j , c j+1 , c j+2}.
[0064] S102. Clause Node Representation Learning: For the clauses in the sub-document, convert the vocabulary of the clauses in the sub-document into BERT vectors (referred to as clause vectors); use the vocabulary-level BERT network to learn the word context information at the clause level in the sub-document (the context information between different vocabularies of the clauses); in this step, by generating the vector representation of each clause (node vector), the purpose is to regard the vector representation as the node initialization representation;
[0065] hj = BERT(c j ) j=1,···,n
[0066] The emotional cause relationship generates a learnable distance vector d for the clause information in the sub-document through random position information (using clause distance representation) ij , concatenate the distance vectors corresponding to different clause information, and the concatenated distance vector is used as the node vector representation of the clause with distance information and added to the node h i and h j Local distance information d ij , and learn the distance information of neighbors for each clause node through the random distance vector to better fuse the context semantics.
[0067] Input the obtained node vector representation with distance information into the sentence-level bidirectional gated network (Bi-GRU) to learn the context sentence information in the sub-document (the context information between different clauses, used to construct the node vector of the emotional cause relationship):
[0068]
[0069] where hj represents the context sentence information in the sub-document, BiGRU represents the bidirectional gated network, softmax represents, W e represents the weight of the network, b e represents the bias of the network, h j represents the word context information at the clause level in the document, d ij represents that the emotional cause relationship generates a learnable distance vector for the clause information in the sub-document by generating a random position vector.
[0070] After passing through the linear layer, the node vector used to construct the emotional cause relationship generates the node vector factor of the emotional cause relationship, and the emotional node factor containing emotional information obtained for the first time through Bi-GRU and the linear layer Where:
[0071]
[0072] Where g edenotes the emotional factor, BiGRU denotes the bidirectional gated network, softmax is used to indicate the use of the attention mechanism, W e denotes the weight of the network, h j denotes the context sentence information in the sub-document, d ij denotes that the emotional cause relationship generates a learnable distance vector for the clause information in the sub-document through random numbers, b e denotes the bias of the network.
[0073] The node vector for constructing the emotional cause relationship passes through the bidirectional gated network (Bi-GRU) for the second time, and the output of the bidirectional gated network (Bi-GRU) is used as the initialization result h of the subgraph node j (0), and the matrix for initializing the node uses the node feature vector matrix V = {v i} i=1,…,n denotes that after the initialized node passes through the linear layer, a cause node factor containing cause information is generated Where:
[0074]
[0075] Where g c denotes the cause factor, BiGRU denotes the bidirectional gated network, h j denotes the context sentence information in the sub-document, denotes the emotional node factor.
[0076] S103. Generate the subgraph edge feature representation matrix: Through the corresponding multiplication of matrix elements, pair the node vector factors generated in step S102 and in pairs to model the emotional cause relationship, aiming to enable each initialized node to have a bidirectional connection of the emotional cause relationship. (It should be specially noted that the bidirectional connection of the initialized node itself is completed by constructing a self-loop edge) to obtain the edge feature, and the edge feature can be expressed as e i , where the edge feature is obtained by learning the attention mechanism for the element-wise product vector of the emotional factor and the cause factor and is expressed by the following formula:
[0077]
[0078] Where e i denotes the edge feature, softmax indicates the use of the attention mechanism, denotes the emotional factor, denotes the cause factor. Here, i represents the numbering of the edge feature rather than the number of the edge connecting two nodes. For the subgraph to be constructed, to obtain the matrix containing all edge features, the edge feature vector matrix It is shown that the number of edge features is the square of the number of nodes n (the sum of the numbers of bidirectionally connected edge features and self-loop edge features).
[0079] S104. Construct a subgraph with local distance information: For the node feature vector matrix V and edge feature vector matrix E generated in the above steps, construct a fully connected graph G = <V, E> through the node feature vector matrix V and edge feature vector matrix E, and the fully connected graph is the subgraph to be constructed.
[0080] S105. Emotion-cause pair extraction based on edge features: Use a node learning network that combines edge features to update the node features for the subgraph with local distance information to obtain the updated node features; specifically, the node learning network is constructed by a convolutional neural network (CNN). Since the dimension of the clause vector composed of text is low, the structure of the node learning network is to use Conv1d and LayerNorm layers to construct a graph convolutional neural network (GCN) network.
[0081] Among them, the update of node features incorporates the semantic relationship of learning neighbor emotion-cause relationships from edge features, and the formula is as follows:
[0082]
[0083] Among them denotes, f n denotes the node update network, denotes the aggregation of edge features, denotes the aggregation of the emotion-cause relationships between the neighbor nodes of the entire subgraph starting from node j and node j, where j is the j-th node in the document, k represents a certain neighbor node of j, and h
[0084] denotes, j (t) denotes, is the concatenation operation, denotes the aggregation of edge features, h k (t) denotes the node vector, is a learnable parameter. Pair the updated node features pairwise, and splice the paired node pair m jk (t) with the edge features. The spliced result is updated through an edge feature emotion-cause relationship strengthening network to obtain the updated edge features. The update of the edge features is represented by using two interconnected node features to strengthen the emotion-cause or non-emotion-cause relationship, and the formula is as follows:
[0085]
[0086] Among them denotes the updated edge features, f e denotes the edge feature strengthening network, Represents a pair of two interconnected nodes or the pairing of a node with itself, represents the edge feature before update, θ e which is a learnable parameter.
[0087] Specifically, the node learning network is constructed by a convolutional neural network (CNN). Since the edge feature is generated by the product of the corresponding elements of the clause vectors and has a high dimension, the structure of the relationship strengthening network is to use Conv1d and LayerNorm layers to construct a graph convolutional neural network (GCN) network.
[0088] The edge feature after multiple updates passes through a linear classifier to obtain the classification result of the emotion cause relationship, and the classification result of the emotion cause relationship is used as the final label y of the emotion cause relationship prediction result.
[0089] Using the edge feature representation to predict the emotion cause relationship between two sentence nodes, the formula is as follows:
[0090]
[0091] where y ec represents the predicted emotion cause label, σ represents the fully connected layer, represents node h j and h k represents the edge feature after the t-th update of the connection between them.
[0092] Preferably, the method for extracting document emotion cause pairs based on the graph neural network with edge features and document segmentation further includes:
[0093] S106. In previous tasks related to emotion cause extraction, there are two auxiliary tasks, namely the separate classification of the emotion and cause of the nodes. The role of the auxiliary tasks is to improve the accuracy of the main task of emotion cause relationship extraction.
[0094] For the separate classification of the emotion and cause of the nodes, training is performed using the cross-entropy loss for the classification task. The training Loss formula is as follows:
[0095]
[0096] where L pair represents the Loss for the separate classification of the nodes.
[0097] The algorithm training Loss formula is as follows:
[0098]
[0099] where L pair represents the Loss for the prediction of the edge feature emotion cause relationship.
[0100] For the main task and the auxiliary task, the overall training Loss formula is as follows:
[0101] L all = λL sub + L pair
[0102] Where λ is an adjustable parameter.
[0103] The beneficial effects of the present invention are as follows: The present invention models the emotion cause extraction task as a kind of relationship. To improve efficiency, the document is segmented into sub-documents within the scope of the previous and subsequent two sentences for sub-graph construction, and the emotion cause relationship between two sentence nodes is represented by constructing edge features. Subsequently, by constructing position information, node update, and edge feature enhancement, the emotion causes in the document are extracted, which can improve the emotion cause search efficiency and construct a graph structure to improve the accuracy of the extracted emotion-cause pairs. The loss function used in the present invention can also alleviate problems such as label imbalance.
[0104] In this embodiment, the present invention also proposes an extraction system for a graph neural network with edge features and an emotion cause pair extraction method for document segmentation, including the following modules:
[0105] Document segmentation module: For each clause in the document, extract the previous and subsequent two clauses as sub-documents, where the possibility of expressing the emotion cause in the sub-document is the greatest, and regard the sub-document as the basic unit of the emotion cause extraction training data;
[0106] Sub-graph feature learning module: For the semantic information in the clauses in the sub-graph and the context information of the neighbor nodes in the sub-graph. In addition, an attention mechanism is added to generate the emotion factor representation of the clause nodes; the cause factor representation of the clause is generated by splicing the emotion factor with the clause node, completing the node embedding feature learning of the sub-graph; the edge features are obtained by learning the element-wise product vector of the emotion factor and the cause factor through the attention mechanism;
[0107] Node feature update and edge feature enhancement module: Node feature update is to strengthen the emotion cause or non-emotion cause relationship representation with two connected edge features; edge feature enhancement uses two node features to learn the emotion cause or non-emotion cause relationship representation, so as to obtain the final emotion cause relationship representation;
[0108] Sub-graph position information embedding module: Used to generate position information so that the node features have the ability to learn position information;
[0109] Construction of the related sub-graph: Generate a fully connected bipartite graph with the size of the previous and subsequent two clauses of a node, and initialize the edges with node pairs;
[0110] Edge feature pair extraction module: used to extract emotion-cause pairs, passing the edge features through a fully connected layer to obtain the final label representation.
[0111] Embodiment 2: An emotion-cause pair extraction method based on a graph neural network with edge features and document segmentation, comprising the following steps:
[0112] S201. Document segmentation: Since long-distance information is not very helpful for emotion cause mining, for a document with multiple sentences, it is split to improve the efficiency of emotion cause search. According to emotion expression statistics, the range of reasons causing written emotions is within the distance of two clauses. Therefore, the document can be split into the size of the first and second clauses, that is, the size of 5 clauses. For documents with less than 5 clauses, no splitting is performed.
[0113] S202. Sub-clause node representation learning: For the sub-clauses in the subgraph, word segmentation is performed. For each sentence in the sentence, it is input into the BERT network for semantic learning between sentences, and thus transformed into a BERT vector. Using the word-level BERT network to learn the association information of the words within the sub-clauses in the subgraph, the emotional semantic information in the sentence can be roughly preprocessed, and thus the vector representation of each sub-clause is obtained. The obtained sentence vectors are input into the sentence-level bidirectional gated network (Bi-GRU) and attention network to learn the context sentence information in the subgraph, generating a node vector g that can be used to construct an emotional relationship e , which is called the emotion node factor; again, through a cause information learning network composed of a bidirectional gated network, a node vector g that can be used to construct a cause relationship is obtained c , which is called the cause node factor. At the same time, the emotion factor representation can be regarded as the initial representation of the node table in the S4 graph construction step.
[0114] S203. Generate the subgraph edge feature representation matrix: The node vector emotion factor and cause factor are input into a linear module for pairwise pairing, and each node in the subgraph is bidirectionally connected. The edge feature can be regarded as the emotion cause relationship to be predicted between any two nodes. It should be particularly noted that since a sentence may itself contain an emotion and the cause of the emotion, a self-loop edge is constructed for the node itself to obtain a relationship representation. Finally, the obtained edge features are represented by the matrix E.
[0115] S204. Construct a sub - graph with local distance information: There are mainly two mature methods proposed previously for using graph structures in the task of emotion - cause extraction. 1) Placing the task focus on node classification, without modeling edge features, simply using the graph for context and semantic information propagation. However, this method still requires pairing nodes and re - extracting relationships. 2) Modeling node pairs, taking two candidate sentence pairs as nodes for classifying different relationship nodes.
[0116] The method used in the present invention is as follows: For the node matrix V = {v i} i=1,…,n and edge matrix construct a fully - connected graph G = <V, E> based on node features and edge features. For the sub - graph with n = 5 nodes used in the present invention, there are 25 edge features respectively representing the relationships between two nodes (the relationships include emotion - cause relationship and cause - emotion relationship). Further, through a linear network, a learnable distance vector d ij is generated for each node v, and after concatenating the distance vector with the node vector h j , a node vector representation with distance information of node features is obtained.
[0117] S205. Emotion - cause pair extraction based on edge features: For the constructed sub - graph, use a node learning network combined with edge features to update node features. The specific approach is to take the aggregation of the edge features of the current node and its neighbors as relationship reinforcement information, fuse it with the node features, and finally obtain the updated node
[0118]
[0119] with global emotion - cause information at the t - th update. n where f represents the node update network, and the node update network is a graph convolutional neural network (GCN) built by a 1 - D convolutional network (CNN), is the connection operation, is a learnable parameter, j is the j - th node in the document, k represents a certain neighbor node of j,
[0120] represents the aggregation of the emotion - cause relationships between the neighbor nodes of the entire sub - graph starting from node j and node j. Further, use an attention - based network and node feature concatenation to update edge features. The specific approach is to concatenate the node pair composed of the two nodes connected by the edge feature with the edge feature for learning the relationship between the two nodes. After t updates, the edge feature
[0121]
[0122] Among them, represents a pair of two interconnected nodes or a pairing of a node with itself, f e represents an edge feature enhancement network, and the edge feature enhancement network is a graph convolutional neural network (GCN) built by a 2D convolutional network (CNN), θ e is a learnable parameter.
[0123] Furthermore, the fully connected layer can be used as the final predicted label for the emotional cause relationship:
[0124] y ec = σ(w ec e jk + b ec ) or y ce = σ(w ce e kj + b ce )
[0125] Among them, w ec is the trainable parameter of the emotional cause extraction layer, b ec is the emotional cause extraction bias vector, e jk and e kj respectively represent the relationship between the emotional cause direction and the cause emotion direction. y ec is the predicted label obtained after mapping it to the (0, 1) space. Since the label distribution of the emotional causes in the subgraph is uneven, the focal-Loss commonly used in the field of image classification to solve the problem of uneven label distribution is used in this invention for the training of emotional cause extraction to solve the problem of uneven label distribution of the emotional cause relationships in each sub-document after document segmentation. The calculation formula is as follows:
[0126]
[0127] Among them, L pair is the loss of the emotional cause pair extraction task, α is a regulation factor used to balance the importance of positive and negative samples, control the weights of difficult-to-classify and easy-to-classify samples, and γ regulates the weight reduction rate of simple samples. γ > 0 will reduce the loss of easy-to-classify samples and make the model pay more attention to difficult-to-classify and misclassified samples.
[0128] Furthermore, for the classification of node emotional causes in the subgraph, the emotional classification is obtained by sending the node into a linear classifier:
[0129] y e = σ(w e h j + b e )
[0130] Among them, w e is the trainable parameter of the emotion classification layer, and b e is the bias vector of emotion classification. The classification of cause nodes is obtained using the same method:
[0131] y c = σ(w c h j + b c )
[0132] Among them, the training Loss of the auxiliary task can be expressed as:
[0133]
[0134] The above label results will be compared with the true labels during training to obtain the final accuracy of the entire emotion cause extraction and emotion and cause classification. Among them, the classification result of the emotion cause can be used as a reference for emotion cause extraction. This reference should conform to a positive effect, that is, the more accurate the classification result, the more accurate the extraction result. The overall training Loss can be expressed as:
[0135] L all = λL sub + L pair
[0136] Among them, λ is an adjustable parameter used to adjust the proportion of the auxiliary task's role in the main task during training.
[0137] The present invention proposes a document emotion cause extraction system based on edge features and document segmentation. As Figure 2 shown, it includes:
[0138] Document segmentation module: used to count each document, divide each clause in the document into two clauses before and after. Documents with a length less than 5 are not divided. The formula is as follows:
[0139] D = {D i} i=1,···,L-n+1
[0140] Among them, n represents the length of a document
[0141] Node feature initialization module: used to learn the context information of sentences in the sub-document, train using the BERT network, and generate the sentence embedding of the clause after splicing the learnable position vector. In addition, emotion factors are generated through a bidirectional gated network and an attention mechanism, and cause factors are generated by splicing the emotion factors and passing through the bidirectional gated network again.
[0142] Edge feature initialization module: used to complete the initialization of the edge features of the subgraph. The edge features are paired using emotion factors and reason factors and obtained through a linear network. It can be initially considered that the edge features contain the emotion-reason information between two nodes.
[0143] Graph construction module: used to generate a fully connected graph containing all nodes and bidirectional connections.
[0144] Relationship learning module: used for the update of node features and edge features and relationship learning. Among them, the update of nodes uses edges to aggregate the neighbor emotion-reason relationships and maps them through the GCN network to obtain node features with relationship information; for the enhancement of edge features, the pairing of two nodes with emotion-reason relationships connected by an edge is concatenated with the edge features and learned through GCN to obtain the edge features after relationship learning.
[0145] Emotion-reason extraction: Use the edge features after t updates to judge whether it is an emotion-reason relationship through a linear classifier.
[0146] Node emotion-reason classification: used to obtain the emotion or reason or non-emotion-reason classification of nodes, and classify the nodes after t updates through a linear classifier.
[0147] The present invention divides the document, forms nodes from partial sentences, and at the same time constructs the relationship between two sentences with edges, and constructs a subgraph in combination with the habit of emotion expression. Combining relative position embedding and multi-attention mechanism for representation learning of the subgraph to extract the emotion-reason relationship represented by the edge. The present invention combines the graph neural network and the attention mechanism, improves the accuracy of emotion and reason extraction, and achieves good results in the public dataset.
[0148] Example 3: As Figure 2 shown, a method for extracting document emotion-reason based on a graph neural network model with edge features and document segmentation, the method includes the following steps:
[0149] A. Document segmentation: For a document with a length L greater than or equal to 5, it is segmented into sub-documents with a number of L - n + 1, and a graph structure is modeled in the sub-documents, so that the learning of emotion-reason relationships can be carried out under the same parameters. For a document with a length less than 5, a graph relationship model is directly modeled, and the classification result is used as a reference for other results. For these graphs with a smaller length, empty nodes can be used instead.
[0150] B. Node feature initialization: including lexical-level embedding learning of sentences and sentence-level emotion-reason learning.
[0151] The method for lexical-level embedding learning is as follows: First, convert the vocabulary into BERT word vectors, use the BERT-Chinese model to learn the context information of the vocabulary in the clause, generate a sentence embedding with an attention mechanism and a size of 768 dimensions, so that the sentence has preliminary emotional cause relationship information.
[0152] The method for sentence-level embedding learning is as follows: Send the sentence embedding obtained above into a bidirectional gated network (Bi-GRU) at the sentence level, and use the attention mechanism to learn the context to generate an emotional factor; splice the emotional factor into the initial node, and obtain the emotional factor again through the Bi-GRU.
[0153] Among them, the semantics-specific sentence embedding refers to the use of two Bi-GRU models. Although the network structures of these two networks are the same, different weight parameters are randomly initialized to calculate the emotional factor or the cause factor, and the attention mechanism is added to the emotional factor to make the sentence pay more attention to the emotional information.
[0154] C. Edge feature initialization: Based on node initialization, the emotional factor and the cause factor are used for pairing to model two relationships (emotional cause relationship and cause-emotional relationship) between two nodes, and a softmax mechanism is used to initialize the edge features.
[0155] D. Graph structure construction and relationship learning: Construct a graph with n nodes, construct a graph containing n nodes and n 2 edges. For the nodes, use the edge to aggregate the emotional cause relationship information of the neighbor nodes to update the node features, use GCN to update the node features, for the edges, use the connected nodes to learn the emotional cause relationship of the edge features, and use GCN to strengthen the relationship between the sentences contained in the edge features.
[0156] E. Emotional cause extraction based on edge features: Classify each edge to obtain a bidirectional relationship classification, that is, emotional cause relationship classification and cause-emotional relationship classification. And classify the nodes. The classifier uses a linear classifier, but the parameters and activation functions of each linear classifier are different.
[0157] In a specific example, assume that a document is input, and the content in the document is: "A video about a man falling asleep in a fish spa and 'eating' small fish alive has attracted wide attention. On January 25, a woman from Guangdong filmed a video of her father falling asleep in a fish spa. During that time, small fish even ran into his mouth. Ironically, the father didn't even react. Some netizens joked that he ate the staff alive."
[0158] Document segmentation
[0159] For document segmentation, after removing the punctuation in the document first, 8 sub-clauses can be obtained, namely: a: A video of a man falling asleep in a fish spa and swallowing small fish alive has drawn wide attention; b: January 25th; c: A woman in Guangdong filmed a video of her father falling asleep in a fish spa; d: During that time, small fish even ran into his mouth; e: What's even more hilarious is; f: This father involved didn't show any reaction at all; g: Some netizens joked; h: and swallowed the staff alive
[0160] After segmenting and combining these sub-clauses, five sub-documents <a, b, c, d, e>, <b, c, d, e, f>, <c, d, e, f, g>, <d, e, f, g, h> are obtained, and modeling is carried out for the five sub-graphs respectively.
[0161] Initialization of node features and edge features
[0162] For each sub-clause in the sub-document, after word segmentation, it is replaced with a BERT word vector, and each word in the sub-clause corresponds to a word embedding with a dimension of 768. For the transformed sentence c j , if there are n words in the sentence. First, use the BERT network algorithm at the lexical level to learn the word context information at the sub-clause level in the sub-document, and its formula is as follows:
[0163] hj = BERT(c j ) j=1,···,n
[0164] hj represents the word context information at the sub-clause level in the document
[0165] To learn different features of emotion and reason statements, two statement-level feature learning networks are introduced to learn the context information between sub-clauses in the sub-document. It should be noted that different from the reason network, the attention mechanism is used in the network structure of emotion learning, aiming to make the statement pay more attention to the learning of emotion information. Since the reason must have a certain relationship with the emotion information, the reason learning can use the emotion information. In addition, although the bidirectional gated networks in the two networks use the same structure, different weights are used. Among them, the node vector h is obtained after the node passes through emotion learning j , and its formula is as follows:
[0166]
[0167] Context sentence information in the sub-document (node vector for constructing emotion-reason relationship)
[0168] After passing through the linear layer, the emotion factor can be expressed as The node is passed through the reason feature learning network again to obtain the initial representation h j (0), and its formula is as follows:
[0169]
[0170] where represents the splicing operation, and h j (0) can be used as the initialization result of the node. Again, h j (0) passes through the linear layer
[0171] to obtain the cause factor
[0172] The initialization of the edge features is performed using the emotion factor and the cause factor. For the emotion factor and the cause factor, the corresponding multiplication of matrix elements is performed. This can represent that a relationship modeling has been performed between two nodes respectively, and thus the edge features are obtained as follows:
[0173]
[0174] Emotion-Cause Extraction Based on Edge Features
[0175] This method not only considers the emotion-cause relationship between nodes, but also considers the cause-emotion relationship between nodes. This enables the nodes to more clearly know whether the neighbor is an emotion towards the node or the node is a cause for the neighbor. Node n j needs to aggregate the semantic information and the emotion-cause relationship information from the neighbor node n k . The directed edge features are used to represent whether the node is an emotion or a cause, and the node information relationship is completed. Then, after the node features are updated t times, the formula is as follows:
[0176]
[0177] where is a learnable parameter, and f n represents the node update network. Since the node dimension is relatively low, the structure of the node learning network is a graph convolutional neural network (GCN) network built using Conv1d and LayerNorm layers.
[0178] The enhancement of the edge features requires two interconnected node features to strengthen the relationship representation of emotion-cause or non-emotion-cause. Because the graph structure is a fully connected graph, we can take each pair of two nodes in the graph as the node pair features for relationship enhancement. Therefore, for nodes v j and v k , the update of the connected edge features is as follows:
[0179]
[0180] where θ e is a learnable parameter, and fe Denote the edge feature emotion cause relationship strengthening network, which is composed of GCN. Due to the high dimension of the edge features, the structure of the relationship strengthening network is a graph convolutional neural network (GCN) network built using Conv2d and LayerNorm layers.
[0181] Use the edge features updated t times to extract the emotion cause relationship, and obtain the prediction result y of the emotion cause relationship by passing the edge features through a linear classifier. ec Or the prediction result y of the cause emotion relationship. ce , and its formula is as follows:
[0182] y ec =σ(w ec e jk +b ec )
[0183] y ce =σ(w ce e kj +b ce )
[0184] Among them, w ec is the trainable parameter of the emotion cause extraction layer, b ec is the emotion cause extraction bias vector, and e jk and e kj represent the relationships of the emotion cause direction and the cause emotion direction respectively.
[0185] The value of t is determined by experiments. The experimental results are shown in the following table, where the accuracy is represented by accuracy (P), recall (R), and F1 score, and the best number of updates is 1 time:
[0186]
[0187] The Loss formula for algorithm training is as follows:
[0188]
[0189] Emotion cause classification of nodes
[0190] Use the nodes updated t times for emotion cause classification. For node n j , different linear classifiers are used for classification respectively:
[0191] y e =σ(w e h j +b e )
[0192] y c =σ(w c hj +b c )
[0193] It should be noted that the present invention mainly focuses on the accuracy of emotion cause modeling. The classification result of the clause node itself can be used as an auxiliary task to improve the performance of emotion cause relationship extraction. The overall training Loss is as follows:
[0194] L all = λL sub + L pair
[0195] This application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to this application. It should be understood that each process and / or block in the flowchart and / or block diagram, and the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0196] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means implement the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0197] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process. Thus, the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one process Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.
[0198] Obviously, those skilled in the art can make various changes and modifications to this application without departing from the spirit and scope of this application. Thus, if these modifications and variations of this application fall within the scope of the claims of this application and their equivalent technologies, this application is also intended to include these changes and variations.
Claims
1. A method for extracting document sentiment cause pairs based on a graph neural network with edge features and document segmentation, characterized in that, Including: Splitting a document containing multiple clauses into sub-documents with the lengths of the front and back clauses of a single sentence; Obtaining node vectors according to the clauses in the sub-documents; Obtaining emotional node factors and causal node factors according to the node vectors; Pairing the emotional node factors and the causal node factors pairwise to obtain edge feature vectors; Constructing a fully connected graph through a node feature vector matrix and an edge feature vector matrix; Updating the node features according to the fully connected graph, pairing the updated node features pairwise, splicing the paired node pairs with the edge features, and updating the spliced result to obtain updated edge features; The updated edge features pass through a linear classifier to obtain an emotional cause relationship classification result, and the emotional cause relationship classification result is used as an emotional cause relationship prediction result label.
2. The method for extracting document emotion cause pairs based on a graph neural network with edge features and document segmentation according to claim 1, wherein The step of obtaining node vectors according to the clauses in the sub-documents includes, for the clauses in the sub-documents, converting the words in the clauses of the sub-documents into BERT vectors.
3. The method for extracting document emotion causes based on a graph neural network with edge features and document segmentation according to claim 2, characterized in that, The step of obtaining emotional node factors and causal node factors according to the node vectors includes: Using a word-level BERT network to learn the word context information at the clause level in the sub-documents; Regarding the vector representation generated for each clause as the initial representation of the node by generating the vector representation; The emotional cause relationship generates a learnable distance vector for the clause information in the sub-documents through random numbers, splices the distance vectors corresponding to different clause information, and the spliced distance vector is used as the node vector representation of the clause with distance information; Inputting the obtained node vector representation with distance information into a sentence-level bidirectional gated network to learn the context sentence information in the sub-documents and obtain node vectors for constructing the emotional cause relationship; After the node vectors for constructing the emotional cause relationship pass through a linear layer, node vector factors of the emotional cause relationship are generated, and the emotional node factors containing emotional information obtained for the first time through the bidirectional gated network and the linear layer; The node vectors for constructing the emotional cause relationship pass through the bidirectional gated network for the second time. The output of the bidirectional gated network is used as the initialization result of the subgraph nodes. The matrix of the initialized nodes is represented by a node feature vector matrix. After the initialized nodes pass through a linear layer, causal node factors containing causal information are generated.
4. The method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to claim 3, wherein The word context information at the clause level in the sub-documents is represented by the following formula: hj = BERT(c j ) j=1,···,n where hj represents the word context information at the clause level in the document, c j represents the clause for converting the vocabulary into BERT vectors, and n represents the number of vocabularies.
5. The method for extracting document emotional cause pairs based on a graph neural network with edge features and document segmentation according to claim 4, wherein The context sentence information in the sub-documents is represented by the following formula: h j = BiGRU(softmax(W e (h j ⊕ d ij ) + b e ) Among them, hj represents the context sentence information in the sub-document, BiGRU represents the bidirectional gated network, softmax represents, and W e represents the weight of the network, and b e represents the bias of the network, and h j represents the word context information at the clause level in the document, and d ij represents that the emotional cause relationship generates a learnable distance vector for the clause information in the sub-document through random numbers.
6. The method for extracting document emotional cause pairs based on a graph neural network with edge features and document segmentation according to claim 5, wherein Emotional node factor The formula is expressed as follows: g e = BiGRU(softmax(W e (h j ⊕ d ij ) + b e ) where g e represents the sentiment factor, BiGRU represents the bidirectional gated network, softmax represents the softmax mechanism, W e represents the weight of the network, h j represents the context sentence information in the sub-document, d ij represents that the emotion cause relationship generates a learnable distance vector for the clause information in the sub-document through random numbers, b e represents the bias of the network; Cause node factor The formula is expressed as follows: where g c represents the causal factor, BiGRU represents the bidirectional gated network, and h j represents the context sentence information in the sub-document, represents the emotion node factor.
7. The method for extracting document sentiment reasons based on a graph neural network with edge features and document segmentation according to claim 6, characterized in that, The step of pairing the emotional node factors and the causal node factors pairwise to obtain edge feature vectors includes: pairwise pairing the emotional node factors and the causal node factors through element-wise multiplication of matrices, enabling a bidirectional connection with emotional cause relationships for each initialized node, and obtaining the edge feature vectors, which are represented by the following formula: where e i represents the edge feature, and softmax represents the softmax mechanism, represents the sentiment factor, represents the cause factor, and i represents the numbering of the edge feature.
8. The method for extracting document sentiment cause pairs based on a graph neural network with edge features and document segmentation according to claim 7, wherein The above steps construct a fully connected graph through the node feature vector matrix and the edge feature vector matrix, including constructing the node feature vector matrix using node feature vectors, constructing the edge feature vector matrix using edge feature vectors, and constructing a fully connected graph G = <V, E> through the node feature vector matrix V and the edge feature vector matrix E. The fully connected graph G = <V, E> is a subgraph with local distance information.
9. The method for extracting document sentiment cause pairs based on the graph neural network with edge features and document segmentation according to claim 8, wherein The above steps update the node features according to the fully connected graph, and the formula is as follows: Among them denotes f n denotes the node update network denotes the aggregation of edge features denotes the aggregation of the emotional cause relationship between the neighbor nodes of the entire subgraph starting from node j and node j, where j denotes h j is the j-th node in the document, h k denotes h j a certain neighbor node of h j (t) denotes that ⊕ is the concatenation operation denotes the aggregation of edge features denotes the node vector denotes the learnable parameter The above steps pair the updated node features pairwise, splice the paired node pairs with the edge features, and update the spliced result to obtain the updated edge features. The formula is as follows: Among them represents the updated edge feature, f e represents the edge feature enhancement network represents two pairs of interconnected nodes or the pairing of a node with itself represents the edge feature before update, θ e represents the learnable parameter 10. The method for extracting document emotion cause pairs based on a graph neural network with edge features and document segmentation according to claim 9, characterized in that Use the edge features to represent and predict the emotional cause relationship between two sentence nodes. The formula is as follows: where y ec represents the predicted emotion cause label, and σ represents the fully connected layer, represents node h j and h k is the edge feature after the t-th update of the connection between them.
Citation Information
Patent Citations
Emotion-reason pair extraction method and system based on multiple labels
CN111382565A
Emotional reason pair extraction method based on multi-round machine reading and understanding
CN113988048A