Emotion detection method, emotion detection device and computer storage medium

By generating perturbation text and constructing causal reasoning graphs, and utilizing large language models and graph attention networks, the problem of low emotion recognition accuracy in existing technologies is solved, and high-accuracy emotion detection is achieved, which is suitable for fields such as social opinion analysis and emotional trend analysis.

CN120763333APending Publication Date: 2025-10-10HARBIN INSTITUTE OF TECHNOLOGY (SHENZHEN) (INSTITUTE OF SCIENCE AND TECHNOLOGY INNOVATION HARBIN INSTITUTE OF TECHNOLOGY SHENZHEN)
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510839346.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-20
Publication Date
2025-10-10

AI Technical Summary

Technical Problem

Existing text emotion recognition technology, which uses pre-trained model fine-tuning, has the problem of low accuracy in inferring causes from effects, making it difficult to accurately analyze the causes of emotions.

Method used

By generating perturbed text and constructing a causal reasoning graph, utilizing a large language model and graph attention network, introducing news element features, and enhancing text structure knowledge, we can achieve sentiment detection by inferring the cause from the effect.

Benefits of technology

It improves the accuracy of emotion detection and can more accurately analyze the causes of readers' emotions. It is suitable for fields such as social opinion analysis and emotion trend analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120763333A_ABST
    Figure CN120763333A_ABST
Patent Text Reader

Abstract

The invention provides an emotion detection method, an emotion detection device and a computer storage medium. The emotion detection method comprises the following steps: respectively extracting text elements of a clause text and a disturbance text; splicing each clause text and the corresponding text element, and encoding to obtain a first text encoding vector; splicing each disturbance text and the corresponding text element, and encoding to obtain a second text encoding vector; generating clause nodes according to the first text coding vector and the second text coding vector; generating an emotion node according to the emotion coding vector of the to-be-detected emotion; constructing a causal reasoning graph according to all the clause nodes and the emotion nodes; and inputting an emotion detection model to obtain an emotion reason text. Through the emotion detection method, the text element features are introduced, and auxiliary information is provided for accurate analysis of emotion detection; a disturbance mode is introduced for model reasoning, so that the model is helped to understand the causal relationship between the text and the emotion, and the emotion detection accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and in particular to an emotion detection method, an emotion detection device, and a computer storage medium. Background Art

[0002] Text sentiment analysis (TSA) is a key task in natural language processing, aiming to identify and analyze the emotional tendencies expressed in text. With the rapid growth of text data from social media, online reviews, product evaluations, and feedback, sentiment recognition has become a key technology in applications such as information retrieval, public opinion monitoring, and user sentiment analysis. For example, on internet operating platforms, sentiment recognition in user feedback text can effectively help understand the operational status of target services or products. Improving the accuracy of text sentiment recognition is a current research focus in this field.

[0003] The current paradigm of text emotion recognition, which directly utilizes pre-trained models for fine-tuning, suffers from the drawback of inferring causes from effects. The problem with identifying the cause of emotion is actually a reverse reasoning process from effects: given the reader's stated emotions, the cause of that emotion is analyzed. However, inferring causes from effects is difficult, while reverse reasoning based on this process is more common sense, resulting in lower accuracy in inferring results from effects. Summary of the Invention

[0004] To solve the above technical problems, the present application proposes an emotion detection method, an emotion detection method, an emotion detection device and a computer storage medium.

[0005] To solve the above technical problems, the present application proposes an emotion detection method, which includes:

[0006] Acquire a text to be detected and an emotion to be detected, wherein the text to be detected includes a plurality of clause texts;

[0007] For each clause text, generate at least one perturbation text;

[0008] extracting text elements of the clause text and the disturbance text respectively;

[0009] splicing each clause text with its corresponding text element and then encoding them to obtain a first text encoding vector;

[0010] Each disturbed text is concatenated with its corresponding text element and then encoded to obtain a second text encoding vector;

[0011] generating a clause node according to the first text encoding vector and the second text encoding vector;

[0012] Generate an emotion node according to the emotion coding vector of the emotion to be detected;

[0013] Constructing a causal reasoning graph based on all clause nodes and the emotion nodes;

[0014] The causal reasoning graph is input into a pre-trained emotion detection model to obtain emotion cause text.

[0015] The step of generating at least one disturbed text for each clause text includes:

[0016] For each clause text, generating a counterfactual perturbation text; wherein the textual semantics of the counterfactual perturbation text is opposite to the textual semantics of the clause text;

[0017] and / or, generating a restated perturbation text for each clause text; wherein the textual semantics of the restated perturbation text is the same as the textual semantics of the clause text;

[0018] And / or, for each clause text, generate a masked perturbation text.

[0019] The step of generating at least one disturbed text for each clause text includes:

[0020] Inputting each clause text and disturbance prompt information into the large language model to generate the at least one disturbance text;

[0021] The disturbance prompt information is used to indicate the disturbance type of the generated disturbance text.

[0022] The extracting of text elements of the clause text and the disturbance text respectively includes:

[0023] identifying first dimension text elements of the clause text or the perturbation text;

[0024] When the first-dimensional text element belongs to a preset text element, continue to identify the second-dimensional text element of the clause text or the disturbance text;

[0025] The first-dimensional text elements and the second-dimensional text elements are fused to obtain text elements of the clause text or the disturbance text.

[0026] Among them, the text elements of the first dimension include: time, place, people, and events;

[0027] The text elements of the second dimension include: cause, process, and result.

[0028] The step of inputting the causal reasoning graph into a pre-trained emotion detection model to obtain emotion cause text includes:

[0029] Inputting the causal reasoning graph into a graph attention network to update node features of the causal reasoning graph;

[0030] The updated node features are input into a pre-trained emotion detection model to obtain an emotion reason clause to be determined as the emotion reason text.

[0031] The step of inputting the updated node features into a pre-trained emotion detection model and obtaining the emotion cause clause to determine as the emotion cause text includes:

[0032] Input the updated node features into the pre-trained emotion detection model to obtain the predicted probability of the target emotion category corresponding to each clause text;

[0033] The clause text whose predicted probability of the target emotion category is higher than a preset threshold is determined as the emotion cause text.

[0034] The emotion detection method further includes:

[0035] Acquire a training sample, wherein the training sample includes emotion detection text, emotion detection clauses, and reader emotion categories;

[0036] generating a disturbance detection clause corresponding to the emotion detection clause;

[0037] Replacing the disturbance detection clause with the emotion detection clause in the emotion detection text;

[0038] Construct a training causal reasoning graph based on the replaced emotion detection text;

[0039] Inputting the trained causal reasoning graph into the emotion detection model to be trained to obtain an emotion prediction value;

[0040] Generating a training loss value based on the emotion prediction value and the true emotion category;

[0041] The emotion detection model is trained using the training loss value.

[0042] To solve the above technical problems, the present application also proposes an emotion detection device, which includes a memory and a processor coupled to the memory; wherein the memory is used to store program data, and the processor is used to execute the program data to implement the emotion detection method as described above.

[0043] In order to solve the above technical problems, the present application also proposes a computer storage medium, which is used to store program data. When the program data is executed by a computer, it is used to implement the above emotion detection method.

[0044] Compared with the existing technology, the beneficial effects of the present application are: through the above-mentioned emotion detection method, the text elements are introduced to enhance the text structure knowledge by using the characteristics of the text itself, providing auxiliary information for accurate analysis of emotion detection; a variety of perturbation methods are introduced to construct an innovative model reasoning structure to realize emotion detection from effect to cause, and the reverse reasoning process of emotion detection is realized by perturbation processing of the text, thereby achieving high-accuracy emotion detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0046] in:

[0047] Figure 1 This is a schematic diagram of an embodiment of the reader emotion cause extraction task provided by this application;

[0048] Figure 2 This is a flow chart of an embodiment of the emotion detection method provided by the present application;

[0049] Figure 3 This is a schematic diagram of a framework for discovering reader emotion causes based on graph reasoning provided by this application;

[0050] Figure 4 This is a schematic diagram of the causal diagram for extracting emotional causes provided by this application;

[0051] Figure 5 yes Figure 2 A flow chart of specific sub-steps of step S13 of the emotion detection method is shown;

[0052] Figure 6 yes Figure 2 Schematic diagram of the flow of specific sub-steps of step S19 of the emotion detection method shown;

[0053] Figure 7 This is a flow chart of another embodiment of the emotion detection method provided by the present application;

[0054] Figure 8 This is a schematic diagram of an embodiment of the causal reasoning graph reasoning stage provided by this application;

[0055] Figure 9 This is a structural diagram of an embodiment of an emotion detection device provided by the present application;

[0056] Figure 10It is a structural diagram of an embodiment of a computer storage medium provided by this application. DETAILED DESCRIPTION

[0057] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0058] The terms "first," "second," "third," "fourth," etc. (if any) in the specification and claims of the present application and in the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential sequence. It should be understood that the numbers used in this way are interchangeable where appropriate, so that the embodiments of the present application described herein can, for example, be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having," and any variations thereof, are intended to cover non-exclusive inclusions, for example, a process, method, system, product, or apparatus comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or apparatus.

[0059] The technical terms involved in the emotion detection method of this application include but are not limited to the following:

[0060] Extracting Reader Emotions and Their Causes: Unlike conventional author sentiment (which expresses the emotions expressed in a text), reader sentiment refers to the emotions triggered by a reader after reading a given sentence. This information often lacks explicit emotional subtext. The goal of discovering reader causes is to analyze the underlying causes of reader emotions that are triggered by the text but not explicitly expressed. Mining reader emotions and analyzing their causes helps us uncover the underlying reasons behind emotions, which is crucial for subsequent tasks such as monitoring public opinion and tracing the source of emotions.

[0061] Please refer to the following for details: Figure 1 , Figure 1 This is a schematic diagram of an embodiment of the reader emotion cause extraction task provided by this application.

[0062] Figure 1 The example shown is a news article. The goal of extracting reader emotion causes is to analyze and extract the sentences that trigger the reader's emotions, namely, c4, c5, and c7. It should be noted that the text types used in this application for analyzing user emotion text include, but are not limited to, news articles, Weibo posts and comments, and short novels.

[0063] A pre-trained language model (such as BERT[1], RoBERTa[2]) is a pre-trained language representation model. In natural language processing, a language model is trained with the help of a large amount of text corpus. This model can be fine-tuned on the data of a specific natural language processing task and applied to systems such as text classification and question answering. It uses the TransformerEncoder block for connection and is a typical bidirectional encoding model. At the same time, it uses a new masked language model (MLM) to generate deep bidirectional language representation. The input of the model is a text sequence X = {x1, x2,…, x n}, the output is a vector sequence Good at handling text classification tasks.

[0064] Large Language Models (LLMs) are pre-trained models that are trained on extensive training data and typically have a large number of parameters. LLMs typically have millions or even billions of parameters, enabling them to learn rich linguistic expressions and semantic structures, and possess strong text understanding and generation capabilities. Some of the most prominent large language models include GPT-3, Baichuan, and ChatGLM. The emergence of LLMs has led to significant progress and innovation in the field of natural language processing, achieving state-of-the-art results on many natural language processing tasks, such as machine translation, text generation, and question-answering systems.

[0065] GAT Graph Attention Network: The Graph Attention Network (GAT) is a neural network designed for processing graph-structured data. It uses an attention mechanism to assign different weights to the neighbors of each node in the graph, aggregating neighbor information to update node features. It can automatically learn the importance relationships between nodes. With its unique attention mechanism and excellent performance, the GAT network plays a vital role in many fields involving graph-structured data.

[0066] Examples: These examples are intended to give the large model a certain understanding of the task paradigm so that it can imitate and generate responses that meet the requirements. Large models have strong zero-shot and few-shot generation capabilities, that is, when no examples are provided or a small number of examples are provided.

[0067] Counterfactual: In causal models, in addition to factual scenarios, there's also a hypothetical scenario called a counterfactual. A counterfactual is a situation that didn't actually happen, but we want to know what the outcome would be if it did. For example, a bankrupt seller might want to know how their sales would have changed if they had purchased advertising services (i.e., an intervening variable). This hypothetical scenario is a counterfactual.

[0068] Causal reasoning: Causal reasoning is the process of exploring the cause-and-effect relationships between events. Drawing on existing knowledge, observations, and data, it analyzes the factors that lead to a particular outcome and the mechanisms that link cause and effect. Using hypotheses and comparisons, it helps clarify causal chains, playing a vital role in scientific research, decision-making, and many other fields.

[0069] This application proposes a method and corresponding device for analyzing the causes of reader emotions. First, LLM is used to analyze news elements in a text, obtain corresponding features, and encode them. Secondly, a causal graph reasoning model is constructed, using GAT to capture the intrinsic relationships between clauses. Three perturbation methods are used to construct the reasoning process, and the model ultimately outputs the causes of reader emotions.

[0070] The emotion detection method of the present application can be applied to the reader emotion cause extraction system, and its application scenarios include social opinion analysis, emotion trend analysis system, rumor detection system, etc. Traditional analysis of reader emotion causes usually directly models the text content, that is, using a pre-trained model to obtain text representation to complete the extraction of reader emotion causes. In addition, traditional methods do not fully utilize the information of news article elements, nor do they fully infer and model the process of stimulating emotions. By introducing the scheme of this application, the sentiment analysis system is expected to infer and model the causal process of reader reading and stimulating emotions, and thus more accurately complete the prediction of reader emotion causes.

[0071] Please refer to the following for details: Figure 2 and Figure 3 , Figure 2 This is a flow chart of an embodiment of the emotion detection method provided by this application. Figure 3 This is a schematic diagram of the reader emotion cause discovery framework based on graph reasoning provided by this application.

[0072] The emotion detection method of the present application is applied to an emotion detection device, wherein the emotion detection device of the present application can be a server, a terminal device, or a system comprising a server and a terminal device that cooperate with each other. Accordingly, the various components of the emotion detection device, such as the various units, subunits, modules, and submodules, can be all provided in the server, all provided in the terminal device, or separately provided in the server and the terminal device.

[0073] Furthermore, the server described above may be either hardware or software. When the server is hardware, it may be implemented as a distributed server cluster consisting of multiple servers, or as a single server. When the server is software, it may be implemented as multiple software programs or software modules, such as software or software modules for providing a distributed server, or as a single software program or software module, without further limitation.

[0074] It should be noted that the emotion detection device of the present application can be equipped with Figure 3 The figure shows an intelligent terminal based on a graph reasoning framework for discovering the causes of readers' emotions.

[0075] like Figure 3 As shown, the graph-based reasoning framework for discovering reader emotion causes in this application is divided into four main stages: counterfactual description and restatement generation, news element analysis, sentence encoding, and causal graph reasoning and prediction. The following describes the functions of these four main stages in conjunction with the emotion detection method provided in this application.

[0076] like Figure 2 As shown, the specific steps are as follows:

[0077] Step S11: obtaining the text to be detected and the emotion to be detected, wherein the text to be detected includes several clause texts.

[0078] In the embodiment of the present application, Figure 3 In the counterfactual description and restatement stages shown, the emotion detection method of the present application inputs the text to be detected and outputs the disturbed text generated by different disturbance methods.

[0079] It should be noted that the text to be detected includes multiple clause texts, and the emotion detection device needs to generate a corresponding disturbance text for each clause text.

[0080] Step S12: For each clause text, generate at least one disturbance text.

[0081] In the embodiment of the present application, the counterfactual description and restatement stage refers to rewriting the sentence from the two perspectives of counterfactual and restatement based on the counterfactual reasoning theory to obtain perturbation data, that is, perturbation text.

[0082] Specifically, the present application introduces perturbations to the causal features, reversing or restating the causal features by making necessary modifications, in the hope of enhancing the effect of causal reasoning and increasing the generalization and robustness of the model when facing unseen examples.

[0083] Please refer to the following for details: Figure 4 , Figure 4This is a schematic diagram of the causal diagram for extracting emotional causes provided by this application. Figure 4 Show the causal reasoning process, where X represents a news clause, T represents its context clause, Y represents the reader's sentiment, and H is the news fusion feature. By perturbing X or T, the predicted Y will be affected, which is called

[0084] Based on inference path analysis, the emotion detection device designed three perturbations for the X->H->Y path:

[0085] (1) The emotion detection device performs counterfactual perturbations on the text to generate clauses that are completely opposite to the text’s semantics. The emotion detection device constructs prompts to allow the LLM to re-express the original sentence using different words and emotions, making the sample semantics opposite and generating counterfactual perturbations.

[0086] (2) The emotion detection device performs restatement perturbation on the text to enhance generalization and robustness. Similarly, LLM is used to re-express the original sentence with different words and emotions, while ensuring that the perturbed sample remains unchanged in terms of semantics and context, to generate restatement perturbation text.

[0087] (3) The emotion detection device performs mask perturbation on the text. Similarly, the original sentence is masked using LLM. You can choose to mask the entire text or partially mask the text to generate mask perturbation text.

[0088] Through the above method, we can obtain the counterfactual perturbation text C, restatement perturbation text R, and mask perturbation text K of clause X.

[0089] This application introduces three data perturbation methods based on the reasoning path: counterfactual generation, restatement generation, and mask generation; by designing prompts, LLM generates corresponding perturbation data for data enhancement.

[0090] Step S13: extracting text elements of the clause text and the disturbance text respectively.

[0091] In the embodiment of the present application, Figure 3 In the news element analysis phase shown, the sentiment detection method of this application inputs the text of each clause and outputs the news element features of each clause text. The news element analysis phase refers to using LLM to analyze and obtain news element features under the sample prompt method.

[0092] This application provides a technical solution for news element analysis. Figure 5 , Figure 5 yes Figure 2 Schematic diagram of the flow of specific sub-steps of step S13 of the emotion detection method.

[0093] like Figure 5 As shown, the specific steps are as follows:

[0094] Step S131: Identify the first dimension text elements of the clause text or the disturbance text.

[0095] In the embodiment of the present application, the six elements of news (that is, narrative elements) include: time, place, people, cause, process, and result of an event. Putting them together means: why someone did something at a certain time and place, and a certain result occurred. A news report, whether it is news, correspondence, or feature, generally contains these factors. The news element features play an important role in the emotion detection device's understanding and analysis of sentences in news articles. Therefore, the present application wants to make full use of the news element features and designs a news element category set M, where M = {M1, M2, ..., M6}.

[0096] In the news element analysis stage, we adopted a hierarchical analysis approach: First, we analyzed the four dimensions of basic information: time M1, place M2, person M3, and event z, and designed prompts to prompt LLM analysis and understanding.

[0097] It should be noted that during the training process of the emotion detection model, the emotion detection device manually annotated the training sample examples with corresponding news elements. This information will serve as context to provide guidance for element analysis.

[0098] Step S132: When the first-dimensional text element belongs to the preset text element, continue to identify the second-dimensional text element of the clause text or the disturbance text.

[0099] In the embodiment of the present application, the clause text identified as event z in step S131 is further analyzed from three perspectives: cause M4, process M5, and result M6.

[0100] Step S133: Fusing the first-dimensional text elements and the second-dimensional text elements to obtain text elements of the clause text or the disturbance text.

[0101] In the embodiment of the present application, the emotion detection device fuses these two levels to obtain the final news element features. If a clause does not belong to an element, it is marked as other.

[0102] Step S14: concatenate each clause text with its corresponding text element and encode them to obtain a first text encoding vector.

[0103] In the embodiment of the present application, Figure 3In the sentence encoding stage shown, the emotion detection method of the present application inputs the clause text X, the news element M and the reader emotion category Y corresponding to the news to which it belongs, and outputs the concatenated text encoding vector.

[0104] Specifically, the emotion detection device uses pre-training to obtain an embedding model. Specifically, it extracts all clauses X, the corresponding news elements M, and the reader emotion categories Y corresponding to the news to which they belong, and then concatenates them to obtain a set of sentence-emotion text [X, M, Y]. The concatenated text is then used to train the RoBERTa model, enabling the model to learn context-independent representations. Finally, the trained model is used as the embedding model to encode each concatenated text:

[0105] E=Embedding([X,M i ])

[0106] Each clause X is encoded as a 768-dimensional text encoding vector.

[0107] It should be noted that the emotion detection device can pre-encode the reader's emotion category Y using the initial RoBERTa model. In subsequent use, it is only necessary to extract the pre-encoded and stored emotion code.

[0108] Step S15: Each disturbed text is concatenated with its corresponding text element and then encoded to obtain a second text encoding vector.

[0109] In the embodiment of the present application, similar to the text encoding shown in the above step S14, the emotion detection device encodes the counterfactual description sentence C, restatement sentence R and mask sentence K generated in the first stage using the above method to obtain corresponding encoding vectors respectively.

[0110] Step S16: Generate a clause node according to the first text encoding vector and the second text encoding vector.

[0111] In the embodiment of the present application, Figure 3 In the causal graph reasoning stage shown, the emotion detection method of the present application inputs the encoded representation of the news clause X, emotion category Y, news element M, counterfactual description sentence C, mask sentence K and restatement sentence R, and outputs a causal reasoning graph.

[0112] Step S17: Generate an emotion node according to the emotion coding vector of the emotion to be detected.

[0113] In an embodiment of the present application, the emotion detection device designs two types of nodes in the construction of the causal reasoning graph, namely clause nodes and emotion nodes.

[0114] Specifically, the emotion detection apparatus regards each news clause as an independent node, and sets the reader emotion corresponding to the news as an emotion node.

[0115] Step S18: constructing a causal reasoning graph according to all clause nodes and emotion nodes.

[0116] In the embodiment of the present application, the emotion detection apparatus connects all clause nodes to each other in view of the fact that there are often explicit or implicit correlations between different news clauses; meanwhile, the emotion detection apparatus also establishes a connection relationship between each clause node and the emotion node, thereby constructing a causal reasoning graph.

[0117] Step S19: inputting the causal reasoning graph into a pre-trained emotion detection model to obtain emotion cause text.

[0118] In the embodiment of the present application, the emotion detection apparatus inputs the causal reasoning graph generated in step S18 into a pre-trained emotion detection model, inputs the clause features in the causal reasoning graph into a Softmax classifier through a multilayer perceptron (MLP) of the emotion detection model, and extracts clauses with a prediction probability greater than one-half from the Softmax classifier, which are emotion cause clauses obtained through prediction.

[0119] The present application provides a technical solution of causal reasoning graph reasoning, and specific reference is made to Figure 6 , Figure 6 is Figure 2 a flowchart of a specific substep of step S19 of the emotion detection method.

[0120] As shown in Figure 6 , the specific steps are as follows:

[0121] Step S191: inputting the causal reasoning graph into a graph attention network to update the node features of the causal reasoning graph.

[0122] In the embodiment of the present application, the emotion detection apparatus can also capture the internal relationship between clauses by means of a graph attention network (GAT), thereby updating the node features of the causal reasoning graph.

[0123] Specifically, the emotion detection apparatus updates the process of the node v i in the forward propagation to the (l+1)th layer as follows:

[0124]

[0125] wherein respectively represent the node features of the lth layer and the (l+1)th layer, v iThe neighbors of the lth layer, the weight matrix and bias term are W (l) and b (l) , σ represents the activation function.

[0126] Step S192: Input the updated node features into the pre-trained emotion detection model, obtain the emotion reason clause and determine it as the emotion reason text.

[0127] Please continue reading Figure 7 , for the emotion detection model used in the above-mentioned emotion detection method embodiment, the present application also provides a model training method, wherein, Figure 7 This is a flow chart of another embodiment of the emotion detection method provided by the present application.

[0128] like Figure 7 As shown, the specific steps are as follows:

[0129] Step S21: obtaining training samples, wherein the training samples include emotion detection text, emotion detection clauses, and reader emotion categories.

[0130] Step S22: Generate a disturbance detection clause corresponding to the emotion detection clause.

[0131] Step S23: replacing the emotion detection clause in the emotion detection text with the disturbance detection clause.

[0132] In the embodiment of the present application, the emotion detection device is designed with three disturbance methods: first, performing a mask operation on the news clause X; second, replacing the news clause X with its corresponding counterfactual description sentence C; third, replacing the news clause X with its restatement sentence R.

[0133] Step S24: Construct a training causal reasoning graph based on the replaced emotion detection text.

[0134] Step S25: input the trained causal reasoning graph into the emotion detection model to be trained to obtain the emotion prediction value.

[0135] In the embodiments of this application, please refer to Figure 8 , Figure 8 This is a schematic diagram of an embodiment of the causal reasoning graph inference stage provided by this application. The emotion detection device conducts reasoning on these three disturbance modes respectively, and then obtains three emotion prediction values

[0136] Step S26: Generate a training loss value based on the emotion prediction value and the true emotion category.

[0137] In the embodiment of the present application, the emotion detection device uses the three emotion prediction values ​​of step S25 as follows: Compare it with the true emotion category Y to calculate the loss value.

[0138] Step S27: Use the training loss value to train the emotion detection model.

[0139] This application proposes an innovative architecture based on causal reasoning graph construction and the introduction of three perturbation methods for model training and reasoning. This can clearly present the causal relationship within the text, helping researchers and models to better understand the relationship between text structure and sentiment, and facilitating subsequent analysis and improvement. The introduction of perturbations can effectively improve the robustness of the model and reduce the risk of inaccurate predictions of emotional causes due to subtle changes in the text.

[0140] Existing related methods fail to fully consider news structure information during the analysis process. This application introduces news element features, which can provide powerful assistance for accurately analyzing the cause clauses of emotions.

[0141] Discovering the causes of emotions is essentially a process of inferring causes from effects. That is, given the reader's stated emotions, we analyze the causes of those emotions. However, inferring causes from effects is quite difficult, while inverse reasoning is more common sense. Based on this, this application proposes a method for reasoning based on causal graphs and introduces three perturbation methods to build an innovative model training and reasoning architecture.

[0142] Those skilled in the art will understand that in the above-mentioned method of the specific implementation method, the writing order of each step does not mean a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.

[0143] In order to implement the above emotion detection method, this application also proposes an emotion detection device, please refer to Figure 9 , Figure 9 It is a structural diagram of an embodiment of the emotion detection device provided by this application.

[0144] The emotion detection device 400 of this embodiment includes a processor 41 , a memory 42 , input and output devices 43 , and a bus 44 .

[0145] The processor 41 , the memory 42 , and the input / output device 43 are respectively connected to a bus 44 . The memory 42 stores program data, and the processor 41 is used to execute the program data to implement the emotion detection method described in the above embodiment.

[0146] In the embodiment of the present application, the processor 41 may also be referred to as a CPU (Central Processing Unit). The processor 41 may be an integrated circuit chip having signal processing capabilities. The processor 41 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor may be a microprocessor, or the processor 41 may be any conventional processor.

[0147] This application also provides a computer storage medium, please continue to refer to Figure 10 , Figure 10 1 is a schematic structural diagram of an embodiment of a computer storage medium provided in the present application. The computer storage medium 600 stores a computer program 61. When the computer program 61 is executed by a processor, it is used to implement the emotion detection method of the above embodiment.

[0148] When the embodiments of the present application are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0149] The above description is only an implementation method of the present application and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the description and drawings of this application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A method for emotion detection, characterized in that: The emotion detection method comprises: Acquire a text to be detected and an emotion to be detected, wherein the text to be detected includes a plurality of clause texts; For each clause text, generate at least one perturbation text; extracting text elements of the clause text and the disturbance text respectively; splicing each clause text with its corresponding text element and then encoding them to obtain a first text encoding vector; Each disturbed text is concatenated with its corresponding text element and then encoded to obtain a second text encoding vector; generating a clause node according to the first text encoding vector and the second text encoding vector; Generate an emotion node according to the emotion coding vector of the emotion to be detected; Constructing a causal reasoning graph based on all clause nodes and the emotion nodes; The causal reasoning graph is input into a pre-trained emotion detection model to obtain emotion cause text.

2. The emotion detection method according to claim 1, characterized in that The step of generating at least one perturbation text for each clause text includes: For each clause text, generating a counterfactual perturbation text; wherein the textual semantics of the counterfactual perturbation text is opposite to the textual semantics of the clause text; and / or, generating a restated perturbation text for each clause text; wherein the textual semantics of the restated perturbation text is the same as the textual semantics of the clause text; And / or, for each clause text, generate a masked perturbation text.

3. The emotion detection method according to claim 2, characterized in that The step of generating at least one perturbation text for each clause text includes: Inputting each clause text and disturbance prompt information into the large language model to generate the at least one disturbance text; The disturbance prompt information is used to indicate the disturbance type of the generated disturbance text.

4. The emotion detection method according to claim 1, wherein: The extracting text elements of the clause text and the disturbance text respectively includes: identifying first dimension text elements of the clause text or the perturbation text; When the first-dimensional text element belongs to a preset text element, continue to identify the second-dimensional text element of the clause text or the disturbance text; The first-dimensional text elements and the second-dimensional text elements are fused to obtain text elements of the clause text or the disturbance text.

5. The emotion detection method according to claim 4, characterized in that: The first dimension of text elements includes: time, place, people, and events; The text elements of the second dimension include: cause, process, and result.

6. The emotion detection method according to claim 1, characterized in that Inputting the causal reasoning graph into a pre-trained emotion detection model to obtain emotion cause text includes: Inputting the causal reasoning graph into a graph attention network to update node features of the causal reasoning graph; The updated node features are input into a pre-trained emotion detection model to obtain an emotion reason clause to be determined as the emotion reason text.

7. The emotion detection method according to claim 6, characterized in that: The step of inputting the updated node features into a pre-trained emotion detection model and obtaining the emotion cause clause to be determined as the emotion cause text includes: Input the updated node features into the pre-trained emotion detection model to obtain the predicted probability of the target emotion category corresponding to each clause text; The clause text whose predicted probability of the target emotion category is higher than a preset threshold is determined as the emotion cause text.

8. The emotion detection method according to claim 1, wherein: The emotion detection method further includes: Acquire a training sample, wherein the training sample includes emotion detection text, emotion detection clauses, and reader emotion categories; generating a disturbance detection clause corresponding to the emotion detection clause; Replacing the disturbance detection clause with the emotion detection clause in the emotion detection text; Construct a training causal reasoning graph based on the replaced emotion detection text; Inputting the trained causal reasoning graph into the emotion detection model to be trained to obtain an emotion prediction value; Generating a training loss value based on the emotion prediction value and the true emotion category; The emotion detection model is trained using the training loss value.

9. An emotion detection device, characterized in that: The emotion detection device includes a memory and a processor coupled to the memory; The memory is used to store program data, and the processor is used to execute the program data to implement the emotion detection method according to any one of claims 1 to 8.

10. A computer storage medium, characterized in that The computer storage medium is used to store program data, and when the program data is executed by a computer, it is used to implement the emotion detection method according to any one of claims 1 to 8.