Text emotion prediction processing method, server, storage medium and program product
By constructing text sequences and attribute word sequences, parsing syntactic structures and using pre-trained language models and attention network models to fuse multi-dimensional relationship features, the problem that traditional sentence-level sentiment analysis cannot handle the different sentiment polarities of multi-attribute words is solved, and higher text sentiment prediction accuracy is achieved.
Patent Information
- Application Number
- CN202510940427.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-08
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2045-07-08
AI Technical Summary
Traditional sentence-level sentiment analysis cannot effectively process sentences containing multiple attribute words with different sentiment polarities, resulting in low accuracy in text sentiment prediction.
By constructing text sequences and attribute word sequences, parsing syntactic structures, determining semantic relationship features, and using pre-trained language models and attention network models to fuse multi-dimensional relationship features, the sentiment classifier finally outputs the sentiment prediction results.
It improves the accuracy of text sentiment prediction, can more accurately capture the semantic associations between attribute words, and improves the accuracy of sentiment prediction.
Smart Images

Figure CN120430316B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a text emotion prediction processing method, server, storage medium, and program product. Background Art
[0002] Sentiment analysis is primarily used to analyze the sentiment polarity of a sentence, such as positive, neutral, or negative. In real-world scenarios, a sentence may contain multiple attributes, and different attributes may have different sentiment polarities. Traditional sentence-level sentiment analysis cannot meet this requirement, so attribute-based sentiment analysis tasks have emerged.
[0003] In related technologies, syntactic dependency trees are used to intuitively present the grammatical relationship between words in a sentence, helping to locate the association between attribute words and sentiment words. However, when dealing with complex semantics such as connection structures, it is difficult to model the relationship between multiple attribute words, which leads to the model's misjudgment of sentiment tendencies and affects the prediction effect of text sentiment. Summary of the Invention
[0004] The present application provides a text emotion prediction processing method, server, storage medium and program product to at least solve the problem of low text emotion prediction accuracy in related technologies.
[0005] The present application provides a text sentiment prediction processing method, comprising: obtaining a text to be analyzed, preprocessing the text to be analyzed to obtain a text sequence and an attribute word sequence, wherein the attribute word sequence includes at least one attribute word; parsing the syntactic structure of the text sequence to obtain the syntactic structure features of each word segment in the text sequence; determining the semantic relationship features between each attribute word based on the attribute word sequence and the syntactic structure features; inputting the text sequence and the attribute word sequence into a pre-trained first language model to output a first semantic feature corresponding to the text sequence; inputting the first semantic feature and the syntactic structure feature into a pre-trained syntactic graph attention network model to obtain the syntactic weighted feature of each word segment; inputting the semantic relationship features between each attribute word, the syntactic weighted feature of each word segment and the first semantic feature corresponding to the text sequence into a pre-trained relationship graph attention network model to obtain a first joint feature that integrates multi-dimensional relationships; inputting the first joint feature into a pre-trained sentiment classifier to output the sentiment prediction result of the text to be analyzed for each attribute word.
[0006] This application also provides a text emotion prediction processing device, comprising:
[0007] The preprocessing module is used to obtain the text to be analyzed, and preprocess the text to be analyzed to obtain a text sequence and an attribute word sequence, wherein the attribute word sequence includes at least one attribute word.
[0008] The syntactic parsing module is used to parse the syntactic structure of the text sequence and obtain the syntactic structure features of each word in the text sequence.
[0009] The relationship analysis module is used to determine the semantic relationship characteristics between attribute words based on the attribute word sequence and syntactic structure characteristics.
[0010] The semantic feature generation module is used to input the text sequence and the attribute word sequence into the pre-trained first language model to output the first semantic feature corresponding to the text sequence.
[0011] The syntactic weighted feature generation module is used to input the first semantic feature and the syntactic structure feature into the pre-trained syntactic graph attention network model to obtain the syntactic weighted features of each word segmentation.
[0012] The relationship joint feature generation module is used to input the semantic relationship features between each attribute word, the syntactic weighted features of each word segmentation and the first semantic feature corresponding to the text sequence into the pre-trained relationship graph attention network model to obtain the first joint feature that integrates multi-dimensional relationships.
[0013] The sentiment classification module is used to input the first joint feature into a pre-trained sentiment classifier and output a sentiment prediction result for each attribute word in the text to be analyzed.
[0014] The present application also provides a server, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned text emotion prediction processing methods when executing the computer program.
[0015] The present application also provides a computer-readable storage medium, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned text emotion prediction processing methods are implemented.
[0016] The present application also provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned text emotion prediction processing methods when executed by a processor.
[0017] The text sentiment prediction processing method, server, storage medium and program product of the present application obtain the text to be analyzed and pre-process it to obtain a text sequence and an attribute word sequence, clarify the target object of sentiment analysis, parse the syntactic structure of the text sequence, construct a grammatical structure tree and generate syntactic structure features, determine the syntactic association path, construct a phrase relationship tree, define neighbor attribute word pairs and mine semantic relationship features based on the attribute word sequence and syntactic structure features, and accurately capture the semantic association between attribute words; use the pre-trained first language model to output the first semantic feature, and then combine the syntactic structure feature to input the syntactic graph attention network model to obtain the syntactic weighted feature, input the semantic relationship feature, the syntactic weighted feature and the first semantic feature into the relationship graph attention network model to obtain the first joint feature, and finally output the sentiment prediction result through the sentiment classifier. The local semantics of each word segment is captured by the syntactic graph attention network, and the relational features of each attribute word are captured by the relationship graph attention network. It can show superiority in the alignment between the attribute word and the word segment that identifies the emotion, thereby improving the accuracy of text sentiment prediction. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in 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.
[0019] Figure 1 This is a diagram of the overall architecture of the sentiment classification prediction model provided in the embodiments of the present application;
[0020] Figure 2 A flowchart of a text sentiment prediction method according to an embodiment of the present invention;
[0021] Figure 3 A schematic diagram of the structure of a text emotion prediction and processing device provided in an embodiment of the present application;
[0022] Figure 4 A schematic diagram of the structure of the server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] The following will be combined with the accompanying 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 them. Based on the embodiments of this application, all other embodiments obtained by ordinary technicians in this field without making any creative work are within the scope of protection of this application.
[0024] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.
[0025] In order to clearly understand the technical solution of the present application, the solution of the prior art is first introduced in detail. Sentiment analysis is an important task in the field of natural language processing, which is mainly used to analyze the sentiment polarity of a sentence, such as positive, neutral or negative. In many application scenarios, a sentence may contain multiple attributes, and the sentiment polarity of different attributes may be different. Traditional sentence-level sentiment analysis cannot meet this demand, so the aspect-based sentiment analysis task came into being. In the related art, the syntactic dependency tree is used to intuitively present the grammatical relationship between words in a sentence, which helps to locate the association between attribute words and sentiment words. However, when dealing with complex semantics such as connection structures, it is difficult to model the relationship between multiple attribute words, which leads to the model's misjudgment of sentiment tendencies and affects the prediction effect of text sentiment.
[0026] In order to solve the above technical problems, the inventors came up with the idea of first constructing the text sequence and attribute word list of the text to be processed, parsing the syntactic structure of the text sequence, mining the syntactic structure features between word segments, anchoring the structural logic for semantic understanding, combining the attribute word sequence and syntactic structure features, sorting out the semantic relationship features between attribute words, extracting the global semantic features of the text with the help of the pre-trained first language model, and then integrating the global semantic features and syntactic structure features through the syntactic graph attention network to strengthen the syntactic weighted features between each word segment. Then, through the relational graph attention network, the semantic relationship features between each attribute word, the syntactic weighted features of each word segment, and the global semantic features corresponding to the text sequence are integrated, and the text relationship is multi-dimensionally mined to generate joint features. Finally, the sentiment classifier accurately determines the sentiment tendency of each attribute word based on the joint features. The syntactic graph attention network captures the local semantics of each word segment, and the relational graph attention network captures the relational features of each attribute word. It can show superiority in the alignment between attribute words and word segments that identify sentiment, thereby improving the accuracy of text sentiment prediction.
[0027] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0028] In conjunction with the specific application environment architecture or specific hardware architecture on which the execution of the text emotion prediction processing method depends, the specific application environment architecture or specific hardware architecture is described here. Figure 1, Figure 1 This is the overall architecture diagram of the sentiment classification prediction model provided in the embodiment of this application. Figure 1 As shown, the architecture includes a first language model, a second language model, a grammatical structure tree, a phrase relationship tree, a semantic spectrum separation model, a syntactic graph attention network model, a relationship graph attention network model and a sentiment classifier. After the text to be analyzed is input into the sentiment classification prediction model provided in the embodiment of the present application, the first language model processes the text to be analyzed to obtain a first semantic feature, the second language model processes the text to be analyzed to obtain a second semantic feature, a grammatical structure tree is obtained according to the syntactic structure of the text to be analyzed, a phrase relationship tree is obtained according to the grammatical structure tree through a preset mapping relationship, the first semantic feature and the grammatical structure tree are input into the syntactic graph attention network model, the syntactic weighted feature of each word is output, the second semantic feature is input into the semantic spectrum separation model, the sentiment association feature of each word is output, the relationship graph attention network model aggregates the sentiment association feature and syntactic weighted feature of each word, as well as the semantic relationship feature between each attribute word corresponding to the phrase relationship tree and the first semantic feature corresponding to the text sequence, outputs a joint feature integrating multi-dimensional relationships, the joint feature is input into the sentiment classifier, and the output is the sentiment prediction result of the text to be analyzed for each attribute word.
[0029] Figure 2 This is a flow chart of the text emotion prediction processing method provided in the embodiment of this application. Figure 2 As shown, the embodiment of the present application provides a text emotion prediction processing method, which is described in detail as follows:
[0030] S201: Acquire a text to be analyzed, and pre-process the text to be analyzed to obtain a text sequence and an attribute word sequence, wherein the attribute word sequence includes at least one attribute word.
[0031] The text to be analyzed can come from movie reviews, electronic product reviews, or comments on social networks.
[0032] Specifically, through standardized processing processes such as text cleaning and word segmentation, the original text to be analyzed is structured into text sequences and attribute word sequences. The text sequence retains complete word order information, and the attribute word sequence uses named entity recognition, domain keyword matching and other technologies to extract core attribute vocabulary related to sentiment prediction in the text to be analyzed, providing a clear target object for sentiment analysis in the attribute dimension.
[0033] S202: Parse the syntactic structure of the text sequence to obtain syntactic structure features of each word in the text sequence.
[0034] Specifically, the method for determining the syntactic structure features of each participle includes Sa1~Sa2:
[0035] Sa1: Construct a syntax structure tree corresponding to the text sequence based on the syntactic structure of the text sequence.
[0036] Specifically, following the syntactic structure of the text sequence, a CRF (Conditional Random Field) component analyzer is used to create a grammatical structure tree in a bottom-up manner. The text sequence consists of several word segments at each level of the phrase structure tree, and each word segment has an independent semantic block.
[0037] Sa2: Generates the syntactic structure features of each word in the text sequence based on the grammatical structure in the grammatical structure tree.
[0038] Specifically, in the grammatical structure tree, based on each layer composed of segmentation, a graph structure is constructed with a sentence as a unit, that is, for the layer l composed of segmentation, the adjacency matrix representing the segmentation connection is defined as In this adjacency matrix In the above example, if any two participles w i and w j In the same statement fragment, the definition is 1, if w i and w j Do not belong to the same statement fragment, then define 0. Determine the syntactic structure features of each word in the text sequence.
[0039] S203: Determine semantic relationship features between attribute words based on the attribute word sequence and syntactic structure features.
[0040] Specifically, the method for determining the semantic relationship features between attribute words includes Sb1 to Sb4:
[0041] Sb1: Determine the syntactic association path of each attribute word based on the syntactic structure characteristics of each participle.
[0042] Specifically, based on the grammatical structure tree, the connection relationship of attribute words in the syntactic hierarchy is sorted out, syntactic features such as part of speech are identified, the grammatical dominance and dependency links between attribute words and other participles are clarified, and the syntactic association path of attribute words in the grammatical structure tree is extracted.
[0043] Sb2: Based on the syntactic association path of each attribute word and the syntactic structure characteristics of each participle, construct a phrase relationship tree corresponding to each attribute word.
[0044] Specifically, the process includes: determining the lowest common ancestor node of any two attribute words in the grammatical structure tree based on the syntactic association path. Extracting the phrase segmentation items of the two attribute words based on the subtree structure characteristics of the lowest common ancestor node. For each phrase segmentation item, the connection weight between the segmentation word and the two attribute words is calculated based on the syntactic structure characteristics. The connection weights of the segmentation word and the two attribute words are weighted and aggregated to obtain the comprehensive connection strength of each phrase segmentation item. Construct a phrase relationship tree with each attribute word as a node, the phrase segmentation item as a connecting edge, and the comprehensive connection strength as the edge weight.
[0045] Specifically, the process of extracting phrase segmentation items of two attribute words includes: judging whether there are internal branches in the subtree structure; if there are internal branches in the subtree structure, extracting the segmentation set in the internal branch as the phrase segmentation item; if there are no internal branches in the subtree structure, taking all segmentation sequences between the two attribute words as phrase segmentation items.
[0046] Sb3: Based on the phrase relationship tree, define neighbor attribute words as pairs of attribute words with adjacent position indices.
[0047] Specifically, in the constructed phrase relationship tree, based on the position indexes of the attribute words, only attribute word pairs with adjacent position indexes are retained.
[0048] Sb4: Determine the semantic relationship features between attribute words based on the attribute word pairs and phrase relationship tree.
[0049] Specifically, based on the phrase relationship tree, the modification and / or restriction relationship between any two attribute word pairs is determined, thereby determining the semantic relationship features between any two attribute word pairs.
[0050] S204: Input the text sequence and the attribute word sequence into a pre-trained first language model to output a first semantic feature corresponding to the text sequence.
[0051] Among them, the first language model is the Bert (Bidirectional Encoder Representations from Transformers) model.
[0052] Specifically, for the i-th sentence s in the text sequence i , prepend a special token [CLS] to s i On the word segmentation, and put the special symbol [SEP] and the attribute word sequence at the end, we get:
[0053]
[0054] Where n represents s i The number of participles in Represents the i-th statement si The text sequence, Represents the attribute word sequence. Then extract the output activation of the last layer corresponding to the [CLS] tag as s i The first semantic feature of .
[0055] S205: Input the first semantic feature and the syntactic structure feature into the pre-trained syntactic graph attention network model to obtain the syntactic weighted features of each word segment.
[0056] Among them, the syntactic graph attention network model is a multi-layer graph attention network model.
[0057] Specifically, the first semantic feature is defined as the initial node feature of the multi-layer graph attention network model; the syntactic structure feature is defined as the graph structure input of the multi-layer graph attention network; the multi-layer graph attention network model, according to the connection relationship of each segmentation defined by the syntactic structure feature, aggregates the neighbor features of each segmentation in turn through each layer of the attention network model to generate the corresponding intermediate features; the intermediate features generated by each layer of the attention network model are fused to obtain the syntactic weighted features of each segmentation.
[0058] Specifically, the constructed syntactic structure features are input into a syntactic graph attention network model composed of a stack of multiple layers of graph attention network models. The syntactic graph attention network model is composed of multiple layers of graph attention network models. Each graph attention network model is applied to the syntactic structure features obtained from a layer of the phrase structure tree. These graph attention network models use a masked self-attention mechanism to aggregate information from neighbors and map the intermediate features to the same semantic space through a fully connected feedforward network to obtain the syntactic weighted features of each word. The syntactic graph attention network model is implemented as follows:
[0059]
[0060]
[0061]
[0062] Where, The updated feature representation of the t-th sentence in the text sequence is obtained by calculating the i-th word in the l-th layer of the graph attention network model. FC is a fully connected feedforward network that maps the input feature vector to a new dimensional space through linear transformation and nonlinear activation, achieving feature conversion and fusion, allowing information from different layers and nodes to better adapt and interact. Represents the t-th sentence, the intermediate feature representation obtained after the i-th word is aggregated through operations such as neighbor information in the l-th layer graph attention network model; Z is the number of attention heads, σ is the activation function, is the neighbor set of node i in the graph structure of the t-th sentence, is the attention weight of node j to node i under the z-th attention head, is the learnable parameter matrix corresponding to the zth attention head; exp is the exponential function, and f is the attention score calculation function. The input of the first-layer graph attention network model is the first semantic feature.
[0063] S206: Input the semantic relationship features between each attribute word, the syntactic weighted features of each word segment, and the first semantic feature corresponding to the text sequence into the pre-trained relationship graph attention network model to obtain the first joint feature that integrates the multi-dimensional relationship.
[0064] Among them, the relational graph attention network model is a multi-layer graph attention network model.
[0065] Specifically, the above-mentioned multi-layer graph attention network model is used as an encoder, and the semantic relationship features between attribute words, the syntactic weighted features of each word segment and the first semantic feature corresponding to the text sequence are taken as input to obtain the relationship enhanced representation of each attribute word, that is, the first joint feature that integrates multi-dimensional relationships.
[0066] S207: Input the first joint feature into a pre-trained sentiment classifier, and output a sentiment prediction result for each attribute word of the text to be analyzed.
[0067] Among them, the sentiment classifier is a linear classifier.
[0068] Specifically, the hidden layer vector obtained by the relationship graph attention network model, that is, the first joint feature of the fusion multi-dimensional relationship, is passed through the linear layer classifier to obtain the probability distribution of the sentiment label:
[0069]
[0070] Where P(r) represents the probability distribution of the sentiment label output for the attribute word r; softmax(·) represents the normalized activation function, which converts the original score after linear transformation into a probability value; Represents the weight matrix of the linear classifier, with dimension , d in is the first joint feature dimension, d out is the number of emotion label categories, is the first joint feature, i.e. the hidden layer vector of the graph attention network model, b p Represents the bias term of the linear classifier, with dimension .
[0071] In summary, the method obtains the text to be analyzed and preprocesses it to obtain a text sequence and an attribute word sequence. The target object of sentiment analysis is then clarified, the syntactic structure of the text sequence is parsed, a grammatical structure tree is constructed, and syntactic structure features are generated. Based on the attribute word sequence and syntactic structure features, the syntactic association path is determined, a phrase relationship tree is constructed, neighbor attribute word pairs are defined, and semantic relationship features are mined to accurately capture the semantic associations between attribute words. The method uses a pre-trained first language model to output the first semantic feature, which is then combined with the syntactic structure feature and input into the syntactic graph attention network model to obtain the syntactic weighted feature. The semantic relationship feature, syntactic weighted feature, and the first semantic feature are then input into the relational graph attention network model to obtain the first joint feature. Finally, the sentiment classifier outputs the sentiment prediction result. By capturing the local semantics of each segmented word through the syntactic graph attention network and the relational graph attention network capturing the relational features of each attribute word, the method demonstrates superiority in aligning attribute words with segmented words that identify sentiment, thereby improving the accuracy of text sentiment prediction.
[0072] In the input vector of the relational graph attention network model provided in the embodiment of the present application, the sentiment association features of each word can also be aggregated. After obtaining the syntactic weighted features of each word, the method further includes:
[0073] S301: Inputting a text sequence and an attribute word sequence into a pre-trained second language model to output a second semantic feature corresponding to the text sequence.
[0074] Among them, the second language model is the XLNet (eXtreme Language Modeling, natural language processing model) model.
[0075] S302: Input the second semantic feature into the pre-trained semantic spectrum separation model, and output the sentiment association feature of each word segment.
[0076] Among them, the semantic spectrum separation model includes a frequency filter based on discrete Fourier transform.
[0077] Specifically, the steps of extracting sentiment-related features of each word segment include Sc1 to Sc3:
[0078] Sc1: Input the second semantic feature into the frequency filter, perform frequency domain transformation on the second semantic feature, and obtain the disentangled semantic feature.
[0079] Specifically, the process of performing the disentanglement operation on the second semantic feature is:
[0080]
[0081] Where, f(·) represents fast Fourier transform; f -1(·) represents the inverse transform of the fast Fourier transform; φ represents the filtering operation, which filters the second semantic feature in the frequency domain. Represents a frequency filter, which outputs the semantic features after filtering in the frequency domain.
[0082] Sc2: Calculate the association scores between each word based on the disentangled semantic features.
[0083] Specifically, the calculation formula for the correlation score between each participle is:
[0084]
[0085] Where, e ij represents the correlation score between the i-th participle and the j-th participle; W i Represents a learnable weight matrix that linearly transforms the semantic features of the i-th word segmentation, W j represents the learnable weight matrix, which linearly transforms the semantic features of the jth word segmentation, h i represents the semantic features of the i-th word, h j Represents the semantic features of the jth word.
[0086] Sc3: Normalize the correlation scores between each segmentation to obtain the sentiment correlation features of each segmentation.
[0087] Specifically, the normalization formula is:
[0088]
[0089] Where C ij represents the sentiment association feature between the i-th participle and the j-th participle; exp(e ij ) represents the exponential transformation of the correlation scores between the i-th participle and the j-th participle.
[0090] S303: Input the sentiment association features of each word segment, the semantic relationship features between each attribute word, the syntactic weighted features of each word segment and the first semantic features corresponding to the text sequence into the pre-trained relationship graph attention network model to obtain the second joint features that integrate multi-dimensional relationships.
[0091] Specifically, the above-mentioned multi-layer graph attention network model is used as an encoder, and the sentiment association features of each segmentation, the semantic relationship features between each attribute word, the syntactic weighted features of each segmentation and the first semantic features corresponding to the text sequence are taken as input to obtain the relationship enhanced representation of each attribute word, that is, the second joint feature that integrates multi-dimensional relationships.
[0092] S304: Input the second joint feature into a pre-trained sentiment classifier, and output a sentiment prediction result of each attribute word in the text to be analyzed.
[0093] Among them, the sentiment classifier is a linear classifier.
[0094] Specifically, the hidden layer vector obtained by the relationship graph attention network model, that is, the second joint feature of the fusion multi-dimensional relationship, is passed through the linear layer classifier to obtain the probability distribution of the sentiment label:
[0095]
[0096] Where P(r) represents the probability distribution of the sentiment label output for the attribute word r; softmax(·) represents the normalized activation function, which converts the original score after linear transformation into a probability value; Represents the weight matrix of the linear classifier, with dimension , d in is the second joint feature dimension, d out is the number of emotion label categories, is the second joint feature, i.e. the hidden layer vector of the graph attention network model, b p Represents the bias term of the linear classifier, with dimension .
[0097] In summary, by extracting the second semantic features through the second language model and passing it through the semantic spectrum separation model, we can capture more detailed sentiment-related features of each word in different frequency bands, thereby improving the ability to understand complex semantics.
[0098] In another embodiment provided by the present application, a process of training the sentiment classification prediction model used in the text sentiment prediction processing method is also included, and the process includes:
[0099] S401: Acquire a text training dataset, where the text training dataset includes multiple text sequences, multiple attribute words, and corresponding marked sentiment polarities.
[0100] Specifically, we collect texts with attribute words and sentiment annotations, and construct a training set of "text sequence + attribute words + sentiment polarity" to provide a basis for the model to learn input-output mapping.
[0101] For example, experiments are conducted on the Laptop, Restaurant, Twitter, and MAMS datasets, and the statistics of the datasets are shown in Table 1.
[0102] Table 1: Dataset statistics
[0103]
[0104] S402: Setting graph comparison learning loss learning rate, cross entropy loss learning rate, preset batch size, and number of training steps.
[0105] Specifically, configure key training parameters, such as the comparison of learning loss learning rate, cross entropy loss learning rate, preset batch size, and number of training steps.
[0106] S403: Initialize the parameters of the first language model, the second language model, the semantic spectrum separation model, the syntactic graph attention network model, the relational graph attention network model and the sentiment classifier.
[0107] Specifically, initial values are assigned to the Bert model, XLNet model, multi-layer graph attention network model and linear classifier.
[0108] S404: Iterate the following steps according to the number of training steps:
[0109] S404a: Randomly sample training data of a preset batch size from the text training dataset.
[0110] S404b: Analyze the syntactic structure of each training data to determine the syntactic structure features of each training data.
[0111] S404c: Determine semantic relationship features of each training data according to the syntactic structure features of each training data.
[0112] S404d: Input the training data into the first language model to obtain a first semantic feature.
[0113] S404e: Input the training data into the second language model to obtain a second semantic feature.
[0114] S404f: Input the first semantic feature and syntactic structure feature of each training data into the syntactic graph attention network model to obtain the syntactic weighted feature of each training data.
[0115] S404g: Input the second semantic feature, syntactic weighted feature, semantic relationship feature and first semantic feature of each training data into the relationship graph attention network model to obtain a joint feature that integrates multi-dimensional relationships.
[0116] S404h: Input the joint features into the sentiment classifier, and output the sentiment prediction results of each attribute word in the corresponding text sequence in each training data.
[0117] Specifically, a set number of batches of data are randomly selected from a constructed text training dataset. For each selected training data point, syntactic analysis is performed to construct a grammatical structure tree, extracting the syntactic structural features of the word segments. Based on the syntactic structural features of the training data, semantic associations between attribute words are further explored. By constructing a phrase relationship tree, syntactic association paths and neighboring attribute word pairs are found. Semantic relationships between attribute word pairs, such as modification and qualification, are analyzed and converted into features that can be processed by the model. The training data is then fed into a first language model, converting the text sequence into a first semantic feature represented by a vector. The training data is then fed into a second language model to obtain a second semantic feature. The first semantic feature and the syntactic structural features obtained from the previous analysis are then fed into a syntactic graph attention network model. This model utilizes a graph attention mechanism to aggregate the features of each word's neighbors layer by layer based on the word segmentation connections defined by the syntactic structural features. The outputs of the multi-layer network are then fused to obtain syntactically weighted features that incorporate both semantic information and syntactic structural weights. The second semantic feature, syntactically weighted features, semantic relationship features, and the first semantic feature are then fed into the relationship graph attention network model. The model aggregates multidimensional features through a multi-layer graph attention network to generate joint features that incorporate multidimensional relationships within the text. These joint features are then fed into a linear classifier. The classifier uses linear transformations and softmax operations to map the features to the probability distribution of different sentiment labels. The classifier then outputs sentiment predictions for each attribute word in the corresponding text sequence in the training data, simulating the actual sentiment classification process.
[0118] S405: Calculate the cross entropy loss and graph contrast learning loss based on the sentiment prediction results of each training data and the sentiment polarity of the corresponding label.
[0119] Specifically, we calculate the cross-entropy loss and graph contrastive learning loss based on the emotion prediction results of the training data and the true emotion polarity of the corresponding labels in the dataset. The cross-entropy loss measures the difference between the predicted emotion probability distribution and the true emotion polarity, while the graph contrastive learning loss is used to optimize the learning of graph structure features.
[0120] Specifically, the calculation method of the graph contrastive learning loss function is as follows: taking the syntactically weighted features as negative sample vectors; taking the joint features as positive sample vectors; mapping the positive sample vectors to the scalar scores of the positive sample vectors through a preset linear projection function; mapping the negative sample vectors to the scalar scores of the negative sample vectors through a preset linear projection function; constructing a contrastive learning loss function based on the scalar scores of the positive sample vectors and the scalar scores of the negative sample vectors; and calculating the graph contrastive learning loss based on the contrastive learning loss function.
[0121] Specifically, the sentiment label is used as the supervisory signal for the supervised loss. The hidden layer vector obtained by the syntactic graph attention network model is used as the negative vector, and the hidden layer vector obtained by the relational graph attention network model is used as the positive vector. The scalar score of the true vector is required to be higher than the scalar score of the negative vector, and contrastive learning is used to enhance the relationship representation between attribute words. is a linear projection used to transform the vector Converted to a scalar score, the image contrast loss is:
[0122]
[0123] Where, Represents the preset linear projection function, represents the positive sample vector, represents the jth negative sample vector, B represents the number of negative samples, Indicates the preset interval parameter.
[0124] Specifically, the cross entropy loss is used for training, which is defined as the cross entropy loss between the sentiment polarity labels and the predicted result distribution of all attribute words:
[0125]
[0126] Where, Represents the current model parameters, s represents the text sequence in the training data, represents the attribute word set in the text sequence s, p(r) represents the predicted sentiment probability distribution, y(r) represents the true sentiment label distribution, represents the cross entropy loss of any text sequence, Represents any attribute word.
[0127] S406: Determine the mini-batch loss of the training data based on the cross entropy loss and the graph contrast learning loss.
[0128] Specifically, the mini-batch loss of training data is:
[0129]
[0130] Where, represents the mini-batch loss of the training data, represents the graph contrastive learning loss, represents the cross entropy loss, Represents a graph comparing learning loss and learning rate; represents the cross entropy loss learning rate.
[0131] S407: Determine whether the small batch loss meets the preset loss minimization condition.
[0132] Specifically, check whether the small batch loss meets the preset loss minimization conditions, such as whether the loss value is less than the preset value, the loss decrease tends to be stable, and reaches the set minimum loss threshold.
[0133] S408: If the preset loss minimization condition is not met, the parameters of the first language model, the second language model, the semantic spectrum separation model, the syntactic graph attention network model, the relational graph attention network model and the sentiment classifier are updated according to the mini-batch loss.
[0134] Specifically, if the mini-batch loss does not meet the minimization condition, the gradient of the parameter update is calculated based on the loss, and an optimization algorithm such as Adam is used to adjust the parameters of the first language model, second language model, syntactic graph attention network model, relational graph attention network model, and sentiment classifier, so that the model is closer to the correct sentiment classification rules in subsequent training.
[0135] S409: If the preset loss minimization condition is met, the iteration is terminated.
[0136] Specifically, when the small batch loss meets the preset loss minimization condition, it means that the model has achieved good learning effect after training and the parameter optimization has become stable. At this time, the iterative training is stopped to obtain a trained model that can be used for text sentiment prediction.
[0137] For the trained models that can be used for text sentiment prediction, we study the effects of different model combinations on text sentiment prediction. Table 2 shows the experimental results of different model combinations on different public datasets.
[0138] Table 2: Experimental results of different model combinations on different public datasets
[0139]
[0140] Acc represents the accuracy of the sentiment classification model, and F1 represents the macro-average metric for evaluating the performance of the sentiment classification model. Model1 represents a sentiment classification prediction model that uses a first language model, a second language model, a semantic spectral separation model, a syntactic graph attention network model, and a sentiment classifier. Model2 represents a sentiment classification prediction model that uses a first language model, a syntactic graph attention network model, a relational graph attention network model, and a sentiment classifier. Model3 represents a sentiment classification prediction model that uses a first language model, a second language model, a semantic spectral separation model, a syntactic graph attention network model, a relational graph attention network model, and a sentiment classifier.
[0141] In addition, comparative experiments were conducted to evaluate the effectiveness of the sentiment classification prediction model provided in the embodiments of this application. These models were compared with other baseline models, including attention-based models such as IAN, RAM, MGAN, and GCNet; grammar-based models such as ASGCN, CDT, BiGCN, R-GAT, DGEDT, DualGCN, SSEGCN, IDGNN, DAGCN, and LD2G; and pre-trained models such as BERT-SPC, IPOS-BERT, and ACLT. Accuracy and macro-average F1 were used as evaluation criteria for comparison with other baseline models. Table 3 shows the results of experimental comparisons with various models on four public datasets.
[0142] Table 3: Experimental comparison results of different models on four datasets
[0143]
[0144] In summary, the sentiment classification prediction model provided by the embodiment of the present application achieved an accuracy of 87.45%, 81.36%, 78.28% and 85.73% on the Restaurant, Laptop, Twitter and MAMS datasets, respectively, and the macro-average F1 reached 82.63%, 78.69%, 76.83% and 84.45% respectively. Therefore, the sentiment classification prediction model provided by the embodiment of the present application can fully extract the features related to attribute words in the aspect-level sentiment analysis task and enhance them. Compared with the attention-based methods of IAN, RAM, MGAN and GCNet, the difference in accuracy index on the Restaurant dataset is 3.88%-8.85%, and the difference in accuracy index on the Laptop dataset is 3.26%-9.26%. The sentiment classification prediction model provided by the embodiment of the present application has obvious advantages. Compared with the grammar-based methods of ASGCN, CDT, BiGCN, R-GAT, IDGNN, DGEDT, DualGCN, SSEGCN, DAGCN and LD2G, the accuracy index on the Restaurant dataset differs by 1.47%-6.68%, and the accuracy index on the Laptop dataset differs by 0.8%-5.81%. The sentiment classification prediction model provided in the embodiment of the present application also has a good effect. Compared with the pre-trained models of BERT-SPC, IPOS-BERT, and ACLT, the accuracy index on the Restaurant dataset differs by 1.74%-2.99%, and the accuracy index on the Laptop dataset differs by 0.8%-2.37%. The sentiment classification prediction model provided in the embodiment of the present application has better performance.
[0145] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.
[0146] Figure 3 This is a schematic diagram of the structure of the text emotion prediction processing device provided in the embodiment of the present application. Figure 3 As shown, an embodiment of the present application also provides a text sentiment prediction processing device, including: a preprocessing module 301, a syntactic parsing module 302, a relationship parsing module 303, a semantic feature generation module 304, a syntactic weighted feature generation module 305, a relationship joint feature generation module 306 and a sentiment classification module 307.
[0147] A preprocessing module 301 is used to obtain a text to be analyzed, and preprocess the text to be analyzed to obtain a text sequence and an attribute word sequence, wherein the attribute word sequence includes at least one attribute word;
[0148] Syntactic analysis module 302, used to parse the syntactic structure of the text sequence and obtain the syntactic structure features of each word in the text sequence;
[0149] The relationship analysis module 303 is used to determine the semantic relationship characteristics between attribute words based on the attribute word sequence and syntactic structure characteristics;
[0150] A semantic feature generation module 304 is configured to input a text sequence and an attribute word sequence into a pre-trained first language model to output a first semantic feature corresponding to the text sequence;
[0151] The syntactic weighted feature generation module 305 is used to input the first semantic feature and the syntactic structure feature into the pre-trained syntactic graph attention network model to obtain the syntactic weighted feature of each word segmentation;
[0152] The relational joint feature generation module 306 is used to input the semantic relationship features between each attribute word, the syntactic weighted features of each word segment, and the first semantic feature corresponding to the text sequence into the pre-trained relational graph attention network model to obtain a first joint feature that integrates multi-dimensional relationships;
[0153] The sentiment classification module 307 is configured to input the first joint feature into a pre-trained sentiment classifier and output a sentiment prediction result for each attribute word of the text to be analyzed.
[0154] In a possible embodiment, the device also includes a semantic spectrum separation module, which is used to input a text sequence and an attribute word sequence into a pre-trained second language model to output a second semantic feature corresponding to the text sequence; input the second semantic feature into the pre-trained semantic spectrum separation model to output the sentiment association feature of each segmented word; input the sentiment association feature of each segmented word, the semantic relationship feature between each attribute word, the syntactic weighted feature of each segmented word and the first semantic feature corresponding to the text sequence into a pre-trained relationship graph attention network model to obtain a second joint feature that integrates multi-dimensional relationships; input the second joint feature into a pre-trained sentiment classifier to output the sentiment prediction result of each attribute word in the text to be analyzed.
[0155] In one possible implementation, the semantic spectrum separation module is specifically used to input the second semantic feature into a frequency filter, perform frequency domain transformation on the second semantic feature, and obtain a disentangled semantic feature; calculate the association score between each participle based on the disentangled semantic feature; and normalize the association score between each participle to obtain the sentiment association feature of each participle.
[0156] In one possible implementation, the syntactic weighted feature generation module 305 is specifically used to define the first semantic feature as the initial node feature of the multi-layer graph attention network model; define the syntactic structure feature as the graph structure input of the multi-layer graph attention network; the multi-layer graph attention network model, according to the connection relationship of each segmentation defined by the syntactic structure feature, aggregates the neighbor features of each segmentation in turn through each layer of the attention network model to generate corresponding intermediate features; and fuses the intermediate features generated by each layer of the attention network model to obtain the syntactic weighted features of each segmentation.
[0157] In a possible implementation, the syntax parsing module 302 is specifically configured to construct a syntax structure tree corresponding to the text sequence according to the syntax structure of the text sequence; and generate syntax structure features of each word in the text sequence based on the syntax structure in the syntax structure tree.
[0158] In one possible implementation, the relationship analysis module 303 is specifically used to determine the syntactic association path of each attribute word based on the syntactic structure characteristics of each participle; construct a phrase relationship tree corresponding to each attribute word based on the syntactic association path of each attribute word and the syntactic structure characteristics of each participle; define neighbor attribute words as attribute word pairs with adjacent position indexes based on the phrase relationship tree; and determine the semantic relationship characteristics between each attribute word based on the attribute word pairs and the phrase relationship tree.
[0159] In a possible implementation, the relationship parsing module 303 is further specifically used to determine the lowest common ancestor node of any two attribute words in the grammatical structure tree based on the syntactic association path; extract the phrase segmentation items of the two attribute words based on the subtree structure characteristics of the lowest common ancestor node; for the segmentation words in each phrase segmentation item, based on the syntactic structure characteristics, calculate the connection weight of the segmentation word and the two attribute words; perform weighted aggregation on the connection weights of the segmentation word and the two attribute words to obtain the comprehensive connection strength of each phrase segmentation item; and construct a phrase relationship tree with each attribute word as a node, the phrase segmentation item as a connecting edge, and the comprehensive connection strength as the edge weight.
[0160] In one possible implementation, the relationship parsing module 303 is further specifically used to determine whether the subtree structure has internal branches; if the subtree structure has internal branches, the word set in the internal branches is extracted as phrase segmentation items; if the subtree structure does not have internal branches, all word sequences between the two attribute words are used as phrase segmentation items.
[0161] In a possible embodiment, the device also includes a training module, which is used to obtain a text training data set, which includes multiple text sequences, multiple attribute words and corresponding marked sentiment polarities; set a graph contrast learning loss learning rate, a cross entropy loss learning rate, a preset batch size and a training step number; initialize the parameters of the first language model, the second language model, the semantic spectrum separation model, the syntactic graph attention network model, the relationship graph attention network model and the sentiment classifier; according to the training step number, iteratively perform the following steps: randomly sample training data of a preset batch size from the text training data set; parse the syntactic structure of each training data to determine the syntactic structure features of each training data; determine the semantic relationship features of each training data based on the syntactic structure features of each training data; input the training data into the first language model to obtain the first semantic feature; input the training data into the second language model to obtain the second semantic feature; the first semantic feature of each training data is input into the second language model to obtain the second semantic feature; The features and syntactic structure features are input into the syntactic graph attention network model to obtain the syntactic weighted features of each training data; the second semantic features, syntactic weighted features, semantic relationship features and first semantic features of each training data are input into the relational graph attention network model to obtain the joint features integrating multi-dimensional relationships; the joint features are input into the sentiment classifier to output the sentiment prediction results of each attribute word in the corresponding text sequence in each training data; the cross entropy loss and graph contrast learning loss are calculated according to the sentiment prediction results of each training data and the sentiment polarity of the corresponding mark; the mini-batch loss of the training data is determined according to the cross entropy loss and graph contrast learning loss; it is judged whether the mini-batch loss meets the preset loss minimization condition; if the preset loss minimization condition is not met, the parameters of the first language model, the second language model, the semantic spectrum separation model, the syntactic graph attention network model, the relational graph attention network model and the sentiment classifier are updated according to the mini-batch loss; if the preset loss minimization condition is met, the iteration is terminated.
[0162] In one possible implementation, the training module is specifically used to use syntactically weighted features as negative sample vectors; use joint features as positive sample vectors; map the positive sample vectors to the scalar scores of the positive sample vectors through a preset linear projection function; map the negative sample vectors to the scalar scores of the negative sample vectors through a preset linear projection function; construct a contrastive learning loss function based on the scalar scores of the positive sample vectors and the scalar scores of the negative sample vectors; and calculate the graph contrastive learning loss based on the contrastive learning loss function.
[0163] In one possible implementation, the contrastive learning loss function in the training module is:
[0164]
[0165] Where, Represents the preset linear projection function, represents the positive sample vector, represents the jth negative sample vector, B represents the number of negative samples, Indicates the preset interval parameter.
[0166] In one possible implementation, the formula for calculating the cross entropy loss in the training module is:
[0167]
[0168] Where, Represents the current model parameters, s represents the text sequence in the training data, represents the attribute word set in the text sequence s, p(t) represents the predicted sentiment probability distribution, y(t) represents the true sentiment label distribution, represents the cross entropy loss of any text sequence, Represents any attribute word.
[0169] For the description of the features in the embodiment corresponding to the text emotion prediction processing device, please refer to the relevant description of the embodiment corresponding to the text emotion prediction processing method, and no further details will be given here.
[0170] Figure 4 This is a schematic diagram of the structure of the server provided in the embodiment of the present application. Figure 4 As shown, the server provided in this embodiment includes: at least one processor 401 and a memory 402. Optionally, the server also includes a communication component 403. The processor 401, the memory 402 and the communication component 403 are connected via a bus.
[0171] In a specific implementation process, at least one processor 401 executes the computer-executable instructions stored in the memory 402 , so that the at least one processor 401 executes the above-mentioned text emotion prediction processing method embodiment.
[0172] The specific implementation process of the processor 401 can be found in the above method embodiment. Its implementation principle and technical effects are similar and will not be repeated here in this embodiment.
[0173] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly executed by a hardware processor or by a combination of hardware and software modules within the processor.
[0174] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage.
[0175] A bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus. Buses can be categorized as address buses, data buses, and control buses. For ease of illustration, the buses in the drawings of this application are not limited to just one bus or just one type of bus.
[0176] An embodiment of the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above-mentioned text emotion prediction processing method embodiments when running.
[0177] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0178] An embodiment of the present application further provides a computer program product, including a computer program, which implements the steps of any of the above-mentioned text emotion prediction processing method embodiments when the computer program is executed by a processor.
[0179] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned text emotion prediction processing method embodiments.
[0180] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0181] The above is a detailed introduction to the text emotion prediction processing method, server, storage medium, and program product provided by this application. This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
Claims
1. A text sentiment prediction processing method, characterized in that: include: Acquire a text to be analyzed, and preprocess the text to be analyzed to obtain a text sequence and an attribute word sequence, wherein the attribute word sequence includes at least one attribute word; Constructing a grammatical structure tree corresponding to the text sequence according to the syntactic structure of the text sequence, and generating syntactic structure features of each word in the text sequence; Determining the syntactic association path of each attribute word according to the syntactic structure characteristics of each participle; Based on the syntactic association paths of the attribute words and the syntactic structure features of the segmented words, a phrase relationship tree corresponding to the attribute words is constructed; wherein the nodes of the phrase relationship tree are the attribute words, the edges are the phrase segmentation items connecting the attribute words, and the weights of the edges are the comprehensive connection strengths between the phrase segmentation items and the attribute words; According to the phrase relationship tree, defining neighbor attribute words as pairs of attribute words with adjacent position indexes; Determining semantic relationship features between the attribute words based on the attribute word pairs and the phrase relationship tree; inputting the text sequence and the attribute word sequence into a pre-trained first language model to output a first semantic feature corresponding to the text sequence; Inputting the first semantic feature and the syntactic structure feature into a pre-trained syntactic graph attention network model, so that the syntactic graph attention network model obtains syntactic weighted features of each word based on the connection relationship of each word defined by the syntactic structure feature, and the syntactic graph attention network model is a multi-layer graph attention network model; Inputting the semantic relationship features between the attribute words, the syntactic weighted features of the segmented words, and the first semantic feature corresponding to the text sequence into a pre-trained relational graph attention network model to obtain a first joint feature that integrates multi-dimensional relationships; The first joint feature is input into a pre-trained sentiment classifier, and a sentiment prediction result of each attribute word in the text to be analyzed is output.
2. The text emotion prediction processing method according to claim 1, characterized in that: After obtaining the syntactic weighted features of each word, the method further includes: Inputting the text sequence and the attribute word sequence into a pre-trained second language model to output a second semantic feature corresponding to the text sequence; Inputting the second semantic feature into a pre-trained semantic spectrum separation model, and outputting the sentiment association feature of each word segment; Inputting the sentiment association features of each segmentation, the semantic relationship features between each attribute word, the syntactic weighted features of each segmentation, and the first semantic feature corresponding to the text sequence into a pre-trained relational graph attention network model to obtain a second joint feature that integrates multi-dimensional relationships; The second joint feature is input into a pre-trained sentiment classifier, and the sentiment prediction results of each attribute word in the text to be analyzed are output.
3. The text emotion prediction processing method according to claim 2, characterized in that: The semantic spectrum separation model includes a frequency filter; Accordingly, the step of inputting the second semantic feature into a pre-trained semantic spectrum separation model and outputting the sentiment-related features of each word segmentation includes: Inputting the second semantic feature into the frequency filter, performing frequency domain transformation on the second semantic feature, and obtaining a deentangled semantic feature; Calculating the correlation scores between the participles according to the disentangled semantic features; The correlation scores between the segmented words are normalized to obtain the sentiment correlation features of the segmented words.
4. The text emotion prediction processing method according to claim 1, characterized in that: The step of inputting the first semantic feature and the syntactic structure feature into a pre-trained syntactic graph attention network model so that the syntactic graph attention network model obtains the syntactic weighted features of each word based on the connection relationship of each word defined by the syntactic structure feature, including: defining the first semantic feature as the initial node feature of the multi-layer graph attention network model; Defining the syntactic structure feature as the graph structure input of the multi-layer graph attention network; The multi-layer graph attention network model, according to the connection relationship of each word defined by the syntactic structure feature, aggregates the neighbor features of each word in turn through each layer of the attention network model to generate corresponding intermediate features; The intermediate features generated by the attention network models of each layer are fused to obtain the syntactic weighted features of each word segmentation.
5. The text emotion prediction processing method according to claim 1, characterized in that: Generating syntactic structure features of each word in the text sequence, including: Based on the grammatical structure in the grammatical structure tree, a syntactic structure feature of each word in the text sequence is generated.
6. The text emotion prediction processing method according to claim 1, characterized in that: The step of constructing a phrase relationship tree corresponding to each attribute word according to the syntactic association path of each attribute word and the syntactic structure features of each participle includes: Determining the lowest common ancestor node of any two attribute words in the grammatical structure tree according to the syntactic association path; Extracting phrase segmentation items of the two attribute words according to the subtree structure characteristics of the lowest common ancestor node; For each segmentation item of a phrase, based on the syntactic structure feature, a connection weight between the segmentation item and the two attribute words is calculated; Performing weighted aggregation on the connection weights of the segmentation word and the two attribute words to obtain the comprehensive connection strength of each phrase segmentation item; The phrase relationship tree is constructed with the attribute words as nodes, the phrase segmentation items as connecting edges, and the comprehensive connection strength as edge weight.
7. The text emotion prediction processing method according to claim 6, characterized in that: The step of extracting phrase segmentation items of the two attribute words according to the subtree structural features of the lowest common ancestor node includes: Determine whether the subtree structure has an internal branch; If the subtree structure has an internal branch, extracting a word segmentation set in the internal branch as the phrase segmentation item; If the subtree structure does not have an internal branch, all word segmentation sequences between the two attribute words are used as the phrase segmentation items.
8. The text sentiment prediction processing method according to claim 1, characterized in that: Before obtaining the text to be analyzed, the method further includes: Acquire a text training dataset, wherein the text training dataset includes multiple text sequences, multiple attribute words, and corresponding marked sentiment polarities; Setting graph comparing learning loss learning rate, cross entropy loss learning rate, preset batch size, and number of training steps; Initialize the parameters of the first language model, second language model, semantic spectrum separation model, syntactic graph attention network model, relational graph attention network model and sentiment classifier; According to the number of training steps, the following steps are iteratively performed: Randomly sampling training data of a preset batch size from the text training dataset; Parsing the syntactic structure of each training data to determine the syntactic structure features of each training data; Determining semantic relationship features of each training data according to the syntactic structure features of each training data; Inputting the training data into a first language model to obtain a first semantic feature; Inputting the training data into a second language model to obtain a second semantic feature; Inputting the first semantic feature and the syntactic structure feature of each training data into the syntactic graph attention network model to obtain the syntactic weighted feature of each training data; Inputting the second semantic feature, syntactic weighted feature, semantic relationship feature and the first semantic feature of each training data into the relationship graph attention network model to obtain a joint feature integrating multi-dimensional relationships; Input the joint features into the sentiment classifier, and output the sentiment prediction results of each attribute word in the corresponding text sequence in each training data; Calculate the cross entropy loss and graph contrast learning loss based on the sentiment prediction results of each training data and the sentiment polarity of the corresponding label; determining a mini-batch loss for the training data based on the cross entropy loss and the graph contrastive learning loss; Determining whether the small batch loss meets a preset loss minimization condition; If the preset loss minimization condition is not met, updating the parameters of the first language model, the second language model, the semantic spectrum separation model, the syntactic graph attention network model, the relational graph attention network model, and the sentiment classifier according to the mini-batch loss; If the preset loss minimization condition is met, the iteration is terminated.
9. The text emotion prediction processing method according to claim 8, characterized in that: The graph contrast learning loss calculation method includes: Using the syntactic weighted features as negative sample vectors; Taking the joint feature as a positive sample vector; Mapping the positive sample vector to a scalar score of the positive sample vector by a preset linear projection function; Mapping the negative sample vector to a scalar score of the negative sample vector by using the preset linear projection function; Constructing a contrastive learning loss function based on the scalar score of the positive sample vector and the scalar score of the negative sample vector; Based on the contrastive learning loss function, the graph contrastive learning loss is calculated.
10. The text sentiment prediction processing method according to claim 9, characterized in that: The contrastive learning loss function is: Where, represents the preset linear projection function, represents the positive sample vector, represents the jth negative sample vector, B represents the number of negative samples, Indicates the preset interval parameter.
11. The text sentiment prediction processing method according to claim 8, characterized in that: The calculation formula of the cross entropy loss is: Where, Represents the current model parameters, s represents the text sequence in the training data, represents the attribute word set in the text sequence s, p(t) represents the predicted sentiment probability distribution, y(t) represents the true sentiment label distribution, represents the cross entropy loss of any text sequence, Represents any attribute word.
12. A server, characterized in that: include: memory for storing computer programs; A processor, configured to implement the steps of the text emotion prediction method according to any one of claims 1 to 11 when executing the computer program.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the text emotion prediction processing method according to any one of claims 1 to 11 are implemented.
14. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the text emotion prediction processing method according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Text attribute word sentiment classification method and device, equipment and medium
CN116701638A