A sentiment analysis method based on text-atlas joint reasoning and bidirectional interaction
By employing a language model and graph neural network within a multi-layered fusion module, and through a bidirectional interaction mechanism for text and knowledge graph embedding, this technique addresses problems that have not been effectively solved in existing technologies. It achieves high-efficiency sentiment analysis by implementing the innovative methods employed in the aforementioned techniques, thereby resolving issues that have not been effectively addressed in existing technologies.
Patent Information
- Application Number
- CN202510190545.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-20
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2045-02-20
AI Technical Summary
In existing sentiment analysis methods, the interaction between GNN and LM is simple and lacks deep integration, resulting in low knowledge-text matching and failure to fully utilize knowledge graph information. Furthermore, GNN fails to effectively capture the characteristics of nodes themselves in sentiment analysis tasks, affecting the accuracy of sentiment classification and the model's generalization ability.
By employing a multi-layer fusion module, combining a pre-trained language model and a graph neural network, and using a bidirectional interaction mechanism to iteratively update the embedding of text and knowledge graph, a self-loop mechanism and edge attribute encoding are introduced to optimize the GNN structure, thereby achieving deep fusion and dynamic adjustment of knowledge and text.
It improves the accuracy and robustness of sentiment analysis, enhances the model's ability to model complex emotional relationships, and improves the fine-grained analysis capability of sentiment analysis and the model's adaptability in different scenarios.
Smart Images

Figure CN120031043B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of sentiment analysis, and particularly relates to a sentiment analysis method based on text-graph joint reasoning and bidirectional interaction. BACKGROUND
[0002] At present, the wide application of deep learning in sentiment analysis tasks relies on data-driven supervised learning methods, but due to the bias of data distribution and the complexity of the text itself, it is difficult for traditional methods to accurately understand the implicit sentiment relationship. Therefore, researchers introduce a knowledge graph (KG) to provide structured sentiment association information, and combine a language model (LM) to enhance the sentiment analysis effect. However, the existing knowledge fusion method still has many problems, which limits its performance in real application scenarios.
[0003] The prior art combines an external knowledge graph (KG) for reasoning in the sentiment analysis task, but still has the following key shortcomings and problems:
[0004] The existing method usually encodes the knowledge graph using GNN and inputs the encoded knowledge representation into LM, but the interaction between GNN and LM is relatively simple, and the two lack real bidirectional information fusion in the reasoning process. The current mainstream approach is (1) GNN independently encodes the knowledge graph, and LM processes the text alone, and the two are only combined in the final prediction stage, which makes it difficult for knowledge to affect the semantic modeling of the text; (2) GNN provides structured knowledge representation for LM, but LM cannot adjust the knowledge representation of GNN in the reverse direction, so the matching degree of knowledge and text is low. For example, in some studies, GNN is only used as an additional feature encoder, and LM cannot dynamically adjust the knowledge information in the reasoning process, which leads to the fact that knowledge cannot be fully utilized in the reasoning stage, affecting the accuracy of sentiment classification.
[0005] The current GNN method is mainly based on the standard architecture, which can learn the structural information of the knowledge graph, but is not optimized for sentiment analysis tasks. The expression of sentiment text usually depends on the context, while the information propagation mechanism of GNN mainly depends on the neighbor nodes, and cannot effectively capture the sentiment features of the nodes themselves. In addition, the lack of self-loop mechanism makes it impossible for nodes to retain their own features in the information aggregation process, affecting the modeling ability of complex sentiment expressions.
[0006] The reasons for the above-mentioned shortcomings and problems include:
[0007] The information interaction mechanism of GNN and LM is imperfect: existing methods mostly adopt fixed GNN-Transformer architecture, and fail to realize deep two-way interaction in model structure. The output of GNN is only used as the input of LM, and LM cannot optimize GNN reversely, so that the role of knowledge information in reasoning process is limited, resulting in insufficient fusion depth of knowledge and text.
[0008] Limitations of GNN structure: the design of GNN is usually based on general graph data processing requirements, while the sentiment analysis task has particularity. For example, the sentiment expression of text often depends on context information, while GNN mainly relies on neighbor information for propagation and fails to effectively utilize the features of nodes themselves. In addition, the existing GNN architecture is not optimized for sentiment tasks, and lacks deep modeling of sentiment relationships.
[0009] Insufficient dynamic adjustment ability of knowledge in reasoning stage: the current method mainly introduces knowledge graph in the training stage, while the knowledge utilization mode in the reasoning stage is fixed, and the knowledge representation cannot be dynamically adjusted, so that the model is difficult to fully utilize the information of knowledge graph when processing new text, affecting the generalization ability of the model. SUMMARY
[0010] To solve the above technical problems, the present application provides a sentiment analysis method based on text-graph joint reasoning and two-way interaction to solve the problems existing in the prior art.
[0011] To achieve the above purpose, the present application provides a sentiment analysis method based on text-graph joint reasoning and two-way interaction, comprising:
[0012] processing the text to be analyzed based on a pre-trained language model to obtain text embedding; based on an external knowledge graph, and generating knowledge graph embedding;
[0013] constructing a multi-layer fusion module, inputting the text embedding and the knowledge graph embedding into the multi-layer fusion module, the fusion module iteratively updating the text embedding and the knowledge graph embedding to obtain joint representation of the text embedding and the knowledge graph embedding;
[0014] wherein the multi-layer fusion module comprises several layers, each layer comprising a language model layer, a graph neural network layer and a fusion layer;
[0015] performing sentiment analysis based on the joint representation of the text embedding and the knowledge graph embedding.
[0016] Optionally, input the text to be analyzed into the pre-trained language model to obtain the initial text embedding, add global token to the initial text embedding to obtain the expanded text embedding, and input the expanded text embedding into the Transformer encoder to obtain the text embedding.
[0017] Optionally, the external knowledge graph is initialized to obtain a node embedding matrix, global nodes are introduced into the node embedding matrix to obtain an extended node embedding, and the extended node embedding is input into the graph neural network to obtain a knowledge graph embedding.
[0018] Optionally, the language model layer extracts non-interacted global tokens after encoding and processing the text embedding of the current layer through a Transformer architecture, and the non-interacted global tokens are interacted with non-interacted global nodes through a fusion layer to obtain updated text embedding; during the iterative updating process, the information of the external knowledge graph is transmitted to other tokens through the updated text embedding and an attention mechanism.
[0019] Optionally, the graph attention network framework is improved based on One-hot encoding of edge attributes and a self-loop mechanism to obtain the graph neural network layer.
[0020] Optionally, the graph neural network layer one-hot encodes the attributes of each edge in the knowledge graph to obtain an attribute feature vector, acquires a self-loop feature vector, calculates the attention weight of each node to its neighbor nodes and performs normalization processing after explicitly adding a self-loop to each node in the knowledge graph, aggregates the neighbor node information of each node based on the attention weight, and updates the embedding representation of each node to obtain updated knowledge graph embedding.
[0021] Optionally, the fusion layer splices the non-interacted global tokens and the non-interacted global nodes to form a joint representation, performs fusion operation on the joint representation to generate fused embedding, and separates the fused embedding into new global tokens and global nodes, which are respectively transmitted to the language model layer and the graph neural network layer of the next layer.
[0022] The application also provides a computer device, which comprises a memory, a processor, a computer program stored on the memory and executable on the processor, and the processor executes the computer program to realize the steps of the above method.
[0023] The application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the steps of the above method.
[0024] The application also provides a computer program product, which comprises a computer program, and the computer program is executed by a processor to realize the steps of the above method.
[0025] Compared with the prior art, the application has the following advantages and technical effects:
[0026] The application provides a sentiment analysis method based on text-atlas joint reasoning and bidirectional interaction. Through the bidirectional interaction mechanism, GNN and LM can be deeply integrated in the reasoning process, making the knowledge and text information dynamically adapt, improving the accuracy and robustness of sentiment analysis. Through the self-loop mechanism and edge attribute encoding, the application of GNN in sentiment analysis tasks is optimized, enabling the model to accurately model complex sentiment relationships and improve the ability of fine-grained sentiment analysis. Through the optimization of the knowledge dynamic adjustment mechanism in the reasoning stage, the knowledge representation can be optimized according to the text content, improving the adaptability of the model in different scenarios and making the sentiment analysis more accurate and stable. BRIEF DESCRIPTION OF DRAWINGS
[0027] The accompanying drawings, which form a part of this application, are included to provide a further understanding of the application and are incorporated in and constitute a part of this application. The embodiments of this application, and their
[0028] Figure 1 The joint update learning and fusion structure diagram of the embodiments of the application;
[0029] Figure 2 The fusion module structure diagram of the embodiments of the application. DETAILED DESCRIPTION
[0030] It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict. The present application will be described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
[0031] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from that shown here.
[0032] Embodiment one
[0033] As shown in Figures 1-2 The present embodiment provides a sentiment analysis method based on text-atlas joint reasoning and bidirectional interaction, which includes:
[0034] Based on the pre-trained language model, the text to be analyzed is processed to obtain text embedding; based on the external knowledge atlas, the knowledge atlas embedding is generated;
[0035] Further, the text to be analyzed is input into the pre-trained language model to obtain the initial text embedding, the global token is added to the initial text embedding to obtain the text expansion embedding, and the text expansion embedding is input into the Transformer encoder to obtain the text embedding.
[0036] Further, the external knowledge graph is initialized to obtain a node embedding matrix, global nodes are introduced into the node embedding matrix to obtain extended node embeddings, and the extended node embeddings are input into a graph neural network to obtain knowledge graph embeddings.
[0037] Specifically, each input sentence is pre-encoded by a pre-trained language model to generate an embedding representation of the text, and combined with a specially designed global token to capture global information in the language model representation. At the same time, key nodes of the external knowledge graph are connected to a global node to capture global information in the graph.
[0038] A multi-layer fusion module is constructed to input the text embedding and the knowledge graph embedding into the multi-layer fusion module, and the fusion module iteratively updates the text embedding and the knowledge graph embedding to obtain a joint representation of the text embedding and the knowledge graph embedding.
[0039] The multi-layer fusion module includes a plurality of layers, each layer including a language model layer, a graph neural network layer, and a fusion layer, as shown in Figure 2 .
[0040] Further, the language model layer encodes and processes the text embedding of the current layer through the Transformer architecture to extract non-interacted global tokens; the non-interacted global tokens and the non-interacted global nodes are interacted through the fusion layer to obtain updated text embedding; during the iterative updating process, the information of the external knowledge graph is transmitted to other tokens through the updated text embedding and the attention mechanism.
[0041] Further, the graph attention network framework is improved based on One-hot encoding of edge attributes and self-loop mechanism to obtain the graph neural network layer.
[0042] Further, the graph neural network layer one-hot encodes the attributes of each edge in the knowledge graph to obtain an attribute feature vector; a self-loop feature vector is obtained, and after explicitly adding a self-loop to each node in the knowledge graph, the attention weight of each node to its neighbor nodes is calculated and normalized; based on the attention weight, the neighbor node information of each node is aggregated, and the embedding representation of each node is updated to obtain updated knowledge graph embeddings.
[0043] Further, the fusion layer concatenates the non-interacted global tokens and the non-interacted global nodes to form a joint representation; performs a fusion operation on the joint representation to generate a fused embedding; separates the fused embedding into new global tokens and global nodes, and respectively transmits them to the language model layer and the graph neural network layer of the next layer.
[0044] In particular, for the language model, the input text embedding from the Mth layer of the pre-encoding structure will be further processed by an additional transformer language model encoder block. The text embedding of the (M+l+1)th layer is updated by the following process:
[0045]
[0046] In the current layer, refers to the global token that has not yet been interacted with. The encoded text global token will interact with the global nodes in the knowledge graph, and then in the subsequent layers, the received global structured knowledge can continue to be encoded to realize the fusion of the external knowledge graph and the context token representation, because in the subsequent LM layers, the global token will fully transmit the information from the external graph to the remaining tokens through the attention mechanism.
[0047] Meanwhile, in the fusion module, the above initialized graph representation is sent to the graph neural network layer for updating, which can fully utilize the common sense knowledge and emotional connections between nodes. The embodiment adopts an improved graph attention network framework to learn the graph representation. This framework promotes the learning of node representations between graph neighbors through an iterative message passing process. The invention considers the properties of edges when calculating attention. The standard GAT mainly learns the representation of the graph through node features and their topology, but fails to explicitly utilize the properties of edges. In order to improve the performance of the model, the invention considers not only the connected nodes but also the properties of the edges themselves when updating the graph representation. By one-hot encoding the edge types, a unique representation vector is generated for each type of edge, enriching the input information of the model. After incorporating the features of the edges into the attention mechanism, the model can better handle graphs with rich edge properties, thereby improving the understanding of the graph structure. The invention also explicitly adds self-loops to the graph before calculating the attention coefficients. This allows each node to consider its own features when aggregating neighbor information, thereby improving the node's representation in the context. Specifically, in each layer of the fusion module, the representation of each node is updated by the following method:
[0048]
[0049] wherein, refers to the global node in the current layer that has not yet been interacted with.
[0050] Specifically, for each layer of the N-layer graph neural network, the representation of each node p is updated by the following method
[0051]
[0052] in Let m represent the neighborhood of node p. sp ∈R d α represents the message from each neighbor node s to node p. sp It is an attention weight used to scale each message m from node s to node p. sp Then, the sum of all messages is passed through f. n Process the data and apply batch normalization, f n This represents a two-layer MLP structure.
[0053] In addition, m sp and α sp The specific calculations are as follows:
[0054] Based on various knowledge node types and retrieval edge relationship types, one-hot encoding is performed on each node, with node p encoded as t. p ∈{0,1} |T| The relation is encoded as r sp ∈{0,1} |E| Then, the type embedding t of each node p can be obtained through linear transformation. p And the embedding of the relationship between node s and node p in r sp as follows:
[0055] t p =f type (t p ), r sp =f relation (r sp ,t s ,t p )
[0056] Then calculate each message m from node s to node p. sp :
[0057]
[0058] Among them, f type It is R |T| →R D / 2 linear transformation, f relation It is R |E|+2|T| →R D The two-layer perceptron, f message It is R 2.5|D| →R D The linear change.
[0059] For α spAn attention mechanism is used to capture the strength of the association between two nodes, which should be derived from the node type, relationship, and relevance score of the nodes. First, the relevance score of each node p is encoded as ρ through a two-layer MLP. p This score was obtained during node pruning. The attention weight α between node s and node p is then calculated. sp The query vector is defined as The key vector is defined as follows: Among them, f query and f key Both undergo linear changes, q s ,k p ∈R d The attention weights are then calculated as follows:
[0060]
[0061] After passing through the fusion unit, the global node carries context information and can input text information into the structured representation through node message passing in GAT.
[0062] After updating the text embedding and node embedding using the language model layer and graph neural network layer respectively, this embodiment uses a fusion unit (FU) to perform information fusion, which utilizes a text global token embedding h that captures global text information. glo And graph global node embeddings that capture global information of the knowledge graph glo By not interacting with and By splicing the images together, applying a fusion operation to the joint representations, and then separating the fused embeddings, we obtain the fused global representation.
[0063]
[0064] The fusion unit (FU) employs a multilayer perceptron (MLP). Besides the global token and global nodes, other tokens and nodes do not directly participate in the fusion. Instead, in the next round of encoding, they allocate fused information using an attention mechanism based on information obtained from each other by their respective global units. For text representation, the fused h... glo Along with other text tokens, they are fed into the next layer of the language model, where they undergo another round of modality propagation, allowing them to be fused with commonsense knowledge and specific sentiment knowledge from the knowledge graph. For graph representations, the fused v gloThe nodes, along with others, are fed into the next GAT layer, where their propagation mechanism allows each node to integrate contextual information from the language model. Through this design, LM and GAT form a bidirectional information propagation mechanism, mutually reinforcing each other through joint reasoning and improving the model's sentiment analysis performance.
[0065] Sentiment analysis based on joint representations of text embedding and knowledge graph embedding.
[0066] To verify the effectiveness of this invention, this embodiment was tested on several popular sentiment analysis datasets. The model uses RoBERTa as the basic framework for constructing the Transformer module and GAT as the basic framework for constructing the graph neural network module. Based on the experiments, the GNN structure was designed differently for different datasets: 5-layer GNNs were used for IMDB and Yelp-2 / 5, while 7-layer GNNs were used for other datasets. The hidden dimension was set to 200 for all datasets, and a dropout rate of 0.3 was applied to each GNN module to prevent overfitting. The model was trained using the RAdam optimizer and utilized two GPUs (NVIDIA A30). The batch size was set to 64 (IMDB, Yelp-2 / 5) and 128 (other datasets) for different datasets. The learning rate for the language model module was set to 1e-5 for MR and 5e-5 for the others. The learning rate for the graph neural network module was set to 1e-3. To ensure coverage of more than 90% of the samples, the input sequence length for the IMDB and Yelp-2 / 5 datasets was set to 512, and for other datasets it was set to 128. The experimental results are reported as the average of 5 runs, and the results are shown in the table below.
[0067] Table 1
[0068]
[0069] This invention designs a highly efficient multi-layer fusion unit capable of dynamically exchanging textual information and structured knowledge across different layers, improving the accuracy and efficiency of reasoning. By having the Language Model (LM) update the text representation and the Graph Neural Network (GNN) update the external knowledge graph, synchronous optimization of information is achieved. Simultaneously, global tokens and global nodes are introduced at the end of each layer to ensure full interaction between textual information and knowledge graph representation, optimizing knowledge flow and enabling knowledge to dynamically adapt to text content. This bidirectional information interaction mechanism not only enhances the deep fusion of text and knowledge but also effectively supplements and corrects textual representations during reasoning, making the model more capable of understanding sentiment analysis tasks and significantly improving its generalization ability. Furthermore, the structured knowledge representation utilizes contextual information in the text to provide feedback and adjust the external knowledge representation, ensuring that the knowledge potential is fully explored, rather than merely serving as static auxiliary information input.
[0070] For encoding external knowledge graphs related to sentiment, an improved Graph Attention Network (GAT) is employed, incorporating edge attribute features and enhancing edge representation through one-hot encoding. This allows the GNN to more accurately model the influence of different relationships within the knowledge graph. This invention adds one-hot encoding of edge attributes to the traditional GAT, integrating edge features into the attention mechanism to improve the model's understanding of complex relationship graphs. Simultaneously, a self-loop mechanism is introduced, enabling each node to fully consider its own features when aggregating information. After each encoding layer, a Multilayer Perceptron (MLP) processes the complex feature combinations of global nodes, thereby improving the prediction accuracy and expressiveness of the sentiment analysis model.
[0071] This invention optimizes the depth of text and knowledge fusion while improving the accuracy, robustness, and generalization ability of sentiment analysis tasks, providing key technical support for intelligent text understanding and knowledge-enhanced reasoning.
[0072] The present invention also provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the computer program to implement the steps of the above method.
[0073] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method.
[0074] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the above-described method.
[0075] The above are merely preferred embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method of sentiment analysis based on text-atlas joint reasoning and bidirectional interaction, characterized in that, The method comprises the following steps: processing the text to be analyzed based on a pre-trained language model to obtain a text embedding; and generating a knowledge graph embedding based on an external knowledge graph; a multi-layer fusion module is constructed, and the text embedding and the knowledge graph embedding are input into the multi-layer fusion module; the fusion module iteratively updates the text embedding and the knowledge graph embedding to obtain a joint representation of the text embedding and the knowledge graph embedding; The multi-layer fusion module comprises a plurality of layers, each layer comprising a language model layer, a graph neural network layer and a fusion layer; performing sentiment analysis based on the joint representation of the text embedding and the knowledge graph embedding; The language model layer encodes and processes the text embedding of the current layer through a Transformer architecture to extract non-interacting global tokens; the non-interacting global tokens and the non-interacting global nodes are interacted through the fusion layer to obtain updated text embedding; during the iterative updating process, the information of the external knowledge graph is transmitted to other tokens through the updated text embedding and an attention mechanism; The graph attention network framework is improved based on One-hot encoding of edge attributes and a self-loop mechanism to obtain the graph neural network layer; The graph neural network layer one-hot encodes the attributes of each edge in the knowledge graph to obtain an attribute feature vector; a self-loop feature vector is obtained, and after adding a self-loop to each node of the knowledge graph, the attention weight of each node to its neighbor nodes is calculated and normalized; based on the attention weight, the neighbor node information of each node is aggregated, and the embedding representation of each node is updated to obtain updated knowledge graph embedding; The fusion layer concatenates the non-interacting global tokens and the non-interacting global nodes to form a joint representation; the joint representation is fused to generate a fused embedding; the fused embedding is separated into new global tokens and global nodes, which are respectively transmitted to the language model layer and the graph neural network layer of the next layer.
2. The sentiment analysis method based on text-knowledge graph joint reasoning and bidirectional interaction according to claim 1, wherein the text to be analyzed is input into a pre-trained language model to obtain a text initial embedding, a global token is added to the text initial embedding to obtain a text expanded embedding, and the text expanded embedding is input into a Transformer encoder to obtain a text embedding.
3. The sentiment analysis method based on text-knowledge graph joint reasoning and bidirectional interaction according to claim 2, wherein the external knowledge graph is initialized to obtain a node embedding matrix, a global node is introduced into the node embedding matrix to obtain an expanded node embedding, and the expanded node embedding is input into a graph neural network to obtain a knowledge graph embedding. A memory and a processor to store a computer program stored on the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method of any one of claims 1-3. The computer program is executed by the processor to implement the steps of the method of any one of claims 1-3.
4. A computer apparatus comprising: 5. A computer-readable storage medium having stored thereon a computer program, characterized in that, 6. A computer program product comprising a computer program, characterized in that, The computer program, which is executed by the processor, implements the steps of the method according to any one of claims 1 to 3.
Citation Information
Patent Citations
Description knowledge graph, text graph coding model and graph-based pre-training method
CN117252256A
Triple classification method based on multivariate information embedding
CN118551043A
Online course quality evaluation big data analysis method based on knowledge graph
CN118673161A