Text emotion classification method and device, equipment, medium and product

By combining global embedding and contextual embedding, a recurrent neural network is used for text sentiment classification, which solves the problem of insufficient feature extraction capability in traditional methods and achieves more accurate sentiment classification results. It is suitable for applications such as social media and public opinion monitoring.

CN120994827APending Publication Date: 2025-11-21INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511098876.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-06
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

In existing text sentiment classification methods, traditional machine learning relies on cumbersome manual feature engineering and has limited feature extraction capabilities, while deep learning methods struggle to fully mine global semantic information, resulting in insufficient classification accuracy.

Method used

We use a combination of global embedding and contextual embedding to obtain dual-channel word vector sequences, perform contextual semantic modeling and feature enhancement through recurrent neural networks, and fuse the dual-channel feature matrices to generate a sentiment feature fusion matrix, thereby achieving more accurate sentiment classification.

Benefits of technology

By integrating multi-dimensional information, the semantic information of words is fully captured, improving the accuracy of text sentiment classification and system performance. It is applicable to scenarios such as social media analysis and public opinion monitoring.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120994827A_ABST
    Figure CN120994827A_ABST
Patent Text Reader

Abstract

The invention provides a text emotion classification method and device, equipment, a medium and a product, and relates to the field of big data. According to the method, to-be-classified sentences are obtained, and global embedding and context embedding processing is carried out on the to-be-classified sentences, so that a two-channel word vector sequence is obtained; and performing context semantic modeling and feature enhancement processing on the dual-channel word vector sequence to obtain a dual-channel feature matrix. And performing fusion processing on the dual-channel feature matrix to obtain an emotion feature fusion matrix of the to-be-classified sentences. And based on the emotion feature fusion matrix, generating a category result of the to-be-classified sentence. According to the method, multiple technical means are comprehensively utilized, semantic features are extracted and enhanced from different angles, sentence emotion information can be accurately captured, and the accuracy of emotion classification is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of big data, and in particular to a method, apparatus, device, medium, and product for classifying text sentiment. Background Technology

[0002] With the rapid development of the internet, social media, e-commerce platforms, and other online platforms generate massive amounts of text data daily, containing rich user sentiment information. Sentiment classification of this text helps understand user needs and feedback, optimize products and services, and facilitates the analysis of public opinion trends on social media platforms. Accurate and efficient text sentiment classification has become an important task in the field of natural language processing, with significant application value in business decision-making and public opinion monitoring.

[0003] Currently, text sentiment classification technology is mainly based on traditional machine learning and deep learning. Traditional machine learning methods, such as Support Vector Machines and Naive Bayes, rely on manually designed feature engineering to convert text into numerical vectors before classification. Among deep learning methods, Recurrent Neural Networks (RNNs) can process sequential data and capture temporal dependencies in text; Convolutional Neural Networks (CNNs) extract local features through convolutional kernels.

[0004] Traditional machine learning relies on manual feature engineering, a cumbersome process with limited feature extraction capabilities, making it difficult to capture complex semantics. While CNN models can extract local features, they don't fully explore global semantic information. Most methods offer only a single text representation, processing only at the word vector level, resulting in limited semantic information and impacting classification accuracy. Summary of the Invention

[0005] This application provides a method, apparatus, device, medium, and product for classifying text sentiment, in order to solve the problem that the lack of rich semantic information in text in the prior art affects the accuracy of text sentiment classification.

[0006] Firstly, this application provides a method for classifying textual sentiment, including:

[0007] Obtain the sentence to be classified, and perform global embedding and context embedding processing on the sentence to be classified to obtain a dual-channel word vector sequence;

[0008] The dual-channel word vector sequence is subjected to contextual semantic modeling and feature enhancement processing to obtain a dual-channel feature matrix;

[0009] The dual-channel feature matrix is ​​fused to obtain the sentiment feature fusion matrix of the sentence to be classified.

[0010] Based on the sentiment feature fusion matrix, the category results of the sentence to be classified are generated.

[0011] Secondly, this application provides a text sentiment classification device, comprising:

[0012] The acquisition module is used to acquire the sentence to be classified and to perform global embedding and context embedding processing on the sentence to be classified to obtain a dual-channel word vector sequence;

[0013] The processing module is used to perform contextual semantic modeling and feature enhancement processing on the dual-channel word vector sequence to obtain a dual-channel feature matrix;

[0014] The processing module is used to perform fusion processing on the dual-channel feature matrix to obtain the sentiment feature fusion matrix of the sentence to be classified.

[0015] The generation module is used to generate the category result of the sentence to be classified based on the sentiment feature fusion matrix.

[0016] Thirdly, this application provides an electronic device, including: a processor, and a memory communicatively connected to the processor;

[0017] The memory stores computer-executed instructions;

[0018] The processor executes computer execution instructions stored in the memory to implement the text sentiment classification method as described in the first aspect and various possible implementations of the first aspect above.

[0019] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions thereon, which, when executed by a processor, are used to implement the text sentiment classification method as described in the first aspect and various possible implementations of the first aspect.

[0020] Fifthly, this application provides a program product, including a computer program, which, when executed by a processor, implements the text sentiment classification method described above.

[0021] This application provides a method, apparatus, device, medium, and product for classifying text sentiment. The method employs both global embedding and contextual embedding to process the sentence to be classified, comprehensively capturing the semantic information of words in the sentence and constructing a dual-channel word vector sequence. This considers both the position of words in the overall semantic space and their dynamic meaning in specific contexts. Next, contextual semantic modeling is performed on the dual-channel word vector sequence to deeply explore the semantic relationships between words. Key sentiment features are highlighted through feature enhancement processing, resulting in a dual-channel feature matrix. Then, the feature matrices from these two channels are fused, integrating sentiment information from different perspectives to form a more discriminative sentiment feature fusion matrix. Finally, the sentiment category result of the sentence to be classified is generated based on this fusion matrix, achieving more accurate sentiment classification. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0023] Figure 1 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 1 ;

[0024] Figure 2 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 2 ;

[0025] Figure 3 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 3 ;

[0026] Figure 4 A schematic diagram of the structure of a text sentiment classification device provided in this application;

[0027] Figure 5 This is a schematic diagram of the structure of an electronic device provided in this application.

[0028] The accompanying drawings have illustrated specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to specific embodiments. Detailed Implementation

[0029] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.

[0030] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, storage, use, processing, transmission, provision, disclosure, and application of the relevant data all comply with relevant laws, regulations, and standards, necessary confidentiality measures have been taken, they do not violate public order and good morals, and corresponding operation portals are provided for users to choose to authorize or refuse.

[0031] Furthermore, the technical solution involved in this application, which involves big data analysis of user information (including but not limited to personal biometrics, identity data, consumption data, asset data, electronic terminal operation data, etc.) and the use of artificial intelligence technology for automated decision-making, and makes decisions that have a significant impact on personal rights based on the results of automated decision-making, provides users with corresponding operation entry points for users to choose to agree to or reject the results of automated decision-making; if the user chooses to reject, the process will proceed to the expert decision-making process.

[0032] It should be noted that the text sentiment classification method, apparatus, device, medium and product provided in this application can be used in the field of big data, or in any field other than big data. The application field of the text sentiment classification method, apparatus, device, medium and product in this application is not limited.

[0033] First, let's explain the terms used in this application:

[0034] Convolutional Neural Networks (CNNs): A type of feedforward neural network that includes convolutional computations and has a deep structure; it is one of the representative algorithms of deep learning.

[0035] Word vectors: A collective term for a set of language modeling and feature learning techniques in natural language processing, in which words or phrases from the vocabulary are mapped to vectors of real numbers. Conceptually, it involves mathematical embeddings from a one-dimensional space for each word to a continuous vector space with lower dimensions.

[0036] Multi-head self-attention mechanism: A commonly used attention mechanism in natural language processing to capture long-distance dependencies in an input sequence. Its core idea is to calculate the attention weight at each position in the input sequence, and then sum these weights with the input sequence in a weighted manner to obtain the output sequence.

[0037] In the digital age, massive amounts of text data are emerging, encompassing social media comments, product reviews, news information, and more. Accurately identifying the sentiment (positive, negative, or neutral) of this text is crucial for understanding user feedback and optimizing product services. Text sentiment classification, as one of the core tasks in natural language processing, aims to automatically determine the emotional attitude expressed in text through algorithmic models. However, with the increasing complexity and diversity of text content, traditional sentiment classification methods face numerous challenges and struggle to meet the demands for high accuracy and strong adaptability in practical applications.

[0038] Currently, common techniques for text sentiment classification mainly include machine learning-based methods and deep learning-based methods. Machine learning-based methods typically require manually designed features to convert the text into numerical vectors before classification. Deep learning-based methods, such as Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs), can automatically learn feature representations from text. CNNs excel at capturing local features, extracting local semantic information by sliding convolutional kernels across the text; RNN models, on the other hand, can process sequential data, capturing long-range dependencies in the text and mining global semantic information.

[0039] Machine learning-based methods heavily rely on manual feature engineering, which is not only time-consuming and labor-intensive but also struggles to capture all valuable sentiment information in text, thus limiting classification performance. While deep learning-based methods can automatically learn features, they also have shortcomings. CNNs can capture local sentiment features, but they don't fully explore global semantic information, making it difficult to understand the overall sentiment context of the text. RNN models, while capable of handling sequence dependencies, are prone to vanishing or exploding gradients when dealing with long texts and have low computational efficiency. Furthermore, most of these methods use a single text representation method, failing to comprehensively and richly express text semantics, making it difficult to further improve classification accuracy.

[0040] To address the aforementioned issues, this application provides a text sentiment classification method. This method aims to improve the text sentiment classification effect through multi-dimensional information fusion. It uses global embedding and contextual embedding to obtain dual-channel word vectors of the sentence to be classified, taking into account both the overall semantic position of words and the contextual meaning. Contextual semantic modeling is performed on the dual-channel word vector sequence to strengthen key sentiment features and obtain a dual-channel feature matrix. Then, the feature matrices of the two channels are fused to integrate sentiment information from different perspectives, forming a more discriminative sentiment feature fusion matrix. Finally, sentiment category results are generated based on this matrix, achieving more accurate sentiment classification.

[0041] This application can be applied to customer service scenarios, analyzing the emotional tone of customer feedback sentences to quickly identify customer dissatisfaction, enabling timely measures to resolve issues and improve customer experience.

[0042] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0043] Figure 1 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 1 .like Figure 1 As shown, the text sentiment classification method provided in this embodiment can be implemented by, for example, a classification system, including:

[0044] S101: Obtain the sentence to be classified, and perform global embedding and context embedding on the sentence to be classified to obtain a dual-channel word vector sequence.

[0045] Understandably, sentences to be categorized can come from various sources, such as comments on social media platforms or websites. The methods for obtaining sentences can be to scrape data from specific web pages or data interfaces, or to directly read pre-collected sentence data from existing databases.

[0046] Once the sentences to be classified are obtained, global embedding and contextual embedding can be performed. Global embedding can capture the general semantic information of words in the sentence across the entire corpus. Taking the Word2vec model as an example, it learns the co-occurrence relationships between each word and other words by training on a large amount of text data, thus mapping words into a low-dimensional vector space. In this space, semantically similar words are mapped to similar positions, so each word has a vector representation that can represent its semantics. In this way, the classification system can understand the basic meaning of words, providing a foundation for subsequent sentiment analysis.

[0047] Contextual embedding focuses more on the semantics of words within a specific sentence. Taking the GloVe model as an example, it considers the context of a sentence. By analyzing the collocation of words within a sentence, it can generate word vectors that better fit the sentence's context. For instance, the same word may have different meanings in different sentences; contextual embedding can capture these subtle differences, allowing word vectors to more accurately reflect the actual semantics of the word in the current sentence. After these two embedding processes, the classification system obtains dual-channel word vector sequences based on the Word2vec and GloVe models respectively, providing rich semantic information for subsequent feature extraction and analysis.

[0048] S102: Perform contextual semantic modeling and feature enhancement processing on the dual-channel word vector sequence to obtain the dual-channel feature matrix.

[0049] Understandably, after obtaining the dual-channel word vector sequence, contextual semantic modeling can be performed on the word vector sequence in each channel to deeply explore the semantic relationships and sentence structure information between words in the word vector sequence.

[0050] For example, recurrent neural networks (RNNs) or their variants (such as Long Short-Term Memory Networks (LSTM) and Gated Recurrent Units (GRUs)) can be used for modeling. RNNs can process sequential data and capture the temporal dependencies between words through recurrent units, thereby understanding the order of words and semantic coherence in a sentence.

[0051] Feature enhancement can also be performed during contextual semantic modeling. Feature enhancement aims to highlight features that have a significant impact on sentiment classification while suppressing irrelevant or interfering features. This can be achieved through attention mechanisms. Attention mechanisms can automatically assign different weights to different words in a word vector sequence, making the classification system pay more attention to those words that play a key role in sentiment expression.

[0052] For example, in sentences expressing positive emotions, words like "like" and "satisfied" might be given higher weights, while irrelevant modifiers might be given lower weights. In this way, the classification system can strengthen important semantic features and improve the accuracy of sentiment classification. After contextual semantic modeling and feature enhancement, the classification system obtains a dual-channel feature matrix, which contains rich and optimized semantic feature information.

[0053] S103: The dual-channel feature matrix is ​​fused to obtain the sentiment feature fusion matrix of the sentence to be classified.

[0054] Understandably, the dual-channel feature matrix extracts semantic features of a sentence from two different perspectives: Word2vec and GloVe. To fully utilize the information from these two channels, they can be fused. The goal of this fusion process is to combine the features from both channels to form a more comprehensive and accurate representation of sentiment characteristics.

[0055] One fusion method is concatenation, which involves concatenating the feature matrices of the Word2vec and GloVe channels along a specific dimension, resulting in a fused matrix that contains all the feature information from both channels. This method is simple and direct, preserving the original features of both channels.

[0056] Another fusion method is weighted fusion, which assigns different weights to the feature matrices of the two channels and then sums them using weighted summation. The weights can be dynamically adjusted based on the performance of the two channels in the sentiment classification task. Weighted fusion can balance the features of the two channels, making the fused feature matrix more suitable for sentiment classification.

[0057] S104: Generate category results for sentences to be classified based on the sentiment feature fusion matrix.

[0058] Understandably, once the sentiment feature fusion matrix is ​​obtained, the category results of the sentence to be classified can be generated based on this matrix. This process can usually be achieved using a classifier.

[0059] Training a classifier requires a large amount of labeled sentence data. This data includes the text content of the sentences and their corresponding sentiment category labels. By inputting the sentiment feature fusion matrix and the corresponding labels into the classifier for training, the classifier can learn how to accurately determine the sentiment category of a sentence based on the feature matrix. During training, the classifier can continuously adjust its parameters to minimize the error between the predicted results and the true labels.

[0060] Once the classifier is trained, it can be applied to sentences to be classified. The sentiment feature fusion matrix of the sentence to be classified is input into the trained classifier, which outputs a probability distribution. Based on this probability distribution, the final sentiment category of the sentence can be determined.

[0061] Optionally, the specific steps for generating the category results for the sentence to be classified include:

[0062] The emotion feature fusion matrix is ​​mapped to obtain the initial score for each preset category.

[0063] Understandably, the sentiment feature fusion matrix includes rich semantic information of sentences, but this information exists in vector form and needs to be mapped to convert it into an initial score for each preset category.

[0064] Mapping is typically achieved using a linear transformation layer. This layer can be viewed as a weight matrix, which is multiplied by the sentiment feature fusion matrix. Each element in the weight matrix is ​​learned from a large amount of training data and reflects the degree of association between features and different sentiment categories. For example, if sentiment classification pre-defines three categories—positive, negative, and neutral—then the linear transformation layer will map the sentiment feature fusion matrix onto these three dimensions, resulting in three initial scores.

[0065] During the mapping process, a Dropout mechanism can be incorporated. Dropout is a commonly used regularization technique that randomly discards some neurons in a neural network with a certain probability. In the mapping stage, Dropout can mask some features in the sentiment feature fusion matrix, preventing the model from over-relying on certain specific features during training. This prevents the model from overfitting to the training set and improves its generalization ability. In other words, mapping optimized with Dropout yields more robust initial scores, allowing the model to accurately calculate reasonable initial scores even when faced with new or unseen sentences.

[0066] The initial scores are processed using the softmax function to obtain the probability distribution results.

[0067] Understandably, after obtaining the initial scores for each preset category, these scores reflect the relative magnitude of the sentence belonging to each category, but their value range and meaning are not intuitive, making it difficult to determine the final category result. Therefore, the initial scores can be probabilistically transformed based on the softmax function.

[0068] The softmax function is a function that transforms a set of real numbers into a probability distribution. The softmax function normalizes the initial scores of all classes so that their sum is 1, and the probability value for each class is between 0 and 1.

[0069] After the probability transformation using the softmax function, the probability distribution result is obtained. This probability distribution result shows the likelihood of a sentence belonging to each preset category.

[0070] Based on the probability distribution results, the category results are determined, and the category results are those with a probability value greater than other categories.

[0071] Understandably, the probability distribution results already reflect the likelihood of a sentence belonging to each category. Choosing the category with the highest probability value is equivalent to choosing the category most likely to match the sentiment of the sentence.

[0072] For example, if the probability of positive sentiment is 0.7, the probability of negative sentiment is 0.2, and the probability of neutral sentiment is 0.1, then the sentence is more likely to belong to the positive sentiment category. The probability distribution results not only provide a basis for determining the final category, but also make the classification results more interpretable.

[0073] This embodiment provides a text sentiment classification method. It obtains the sentence to be classified and performs global embedding and context embedding processing on the sentence to be classified, resulting in a dual-channel word vector sequence. Contextual semantic modeling and feature enhancement processing are then performed on the dual-channel word vector sequence to obtain a dual-channel feature matrix. The dual-channel feature matrix is ​​then fused to obtain a sentiment feature fusion matrix for the sentence to be classified. Based on the sentiment feature fusion matrix, the classification result of the sentence to be classified is generated. This method comprehensively utilizes multiple models and techniques to extract and enhance semantic features from different perspectives, accurately capturing sentence sentiment information and effectively improving the accuracy of sentiment classification. It can be widely applied in scenarios such as social media analysis, public opinion monitoring, and product evaluation analysis, providing a reliable basis for relevant decision-making.

[0074] Figure 2 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 2 .like Figure 2 As shown, in Figure 1 Based on the embodiments, the process of determining the feature matrix is ​​described in detail, including:

[0075] S201: For any word vector sequence in the dual-channel word vector sequence, perform dimensionality reduction on the word vector sequence to obtain word vector features.

[0076] Understandably, word vector sequences may have high dimensionality and contain a lot of redundant information. High-dimensional data may increase the consumption of computational resources and may also lead to difficulties in model training. Therefore, dimensionality reduction processing can be performed on word vector sequences.

[0077] Word vector sequences can be input into a Bidirectional Long Short-Term Memory (BiLSTM) model. The BiLSTM model effectively handles sequential data and captures dependencies within the sequence. In the BiLSTM model, the input word vector sequence undergoes internal computation and processing to form a word vector matrix with a sentence length of l. Dimensionality reduction using the BiLSTM model removes unnecessary noise while preserving important semantic features, resulting in more compact and representative word vector features.

[0078] S202: Extract contextual semantic features from word vector features to obtain the contextual hidden matrix.

[0079] Understandably, while word vector features contain basic semantic information about words, the semantics of a single word are often incomplete and require context for accurate understanding. The BiLSTM model employs a two-way network structure, processing the input word vector features from the forward and backward directions respectively. The forward network captures semantic information from the beginning of the sentence to the current word, while the backward network captures semantic information from the end of the sentence to the current word.

[0080] By combining the effects of these two networks, the BiLSTM model can consider the context of each word in a sentence, extracting more comprehensive and accurate contextual semantic features. This process yields a contextual hiding matrix. Each element in this matrix contains the semantic information of the corresponding word within its context.

[0081] S203: Divide the context hiding matrix into multiple matrix blocks.

[0082] Understandably, directly processing the context hiding matrix can be quite complex and computationally intensive. Therefore, it's advisable to partition the context hiding matrix into multiple matrix blocks. This partitioning process can be flexibly designed based on actual needs and task characteristics.

[0083] For example, the context hiding matrix can be divided according to the position of words in the sentence, grouping the context hiding vectors corresponding to several adjacent words into a matrix block; alternatively, it can be divided according to semantic units, grouping the context hiding vectors corresponding to words with similar semantic features into the same matrix block. This partitioning process decomposes a large context hiding matrix into multiple relatively smaller matrix blocks, allowing the model to focus more on the semantic relationships within each matrix block. It also facilitates subsequent processing such as multi-head attention mechanisms, improving the system's performance and efficiency.

[0084] S204: For any one of the multiple matrix blocks, perform a linear transformation on the matrix block using a preset weight matrix to generate a query matrix, a key matrix, and a value matrix.

[0085] Understandably, in multi-head attention mechanisms, linear transformations are required for each matrix block to calculate semantic relevance between different positions. This process is achieved using a pre-defined weight matrix. For any given matrix block, the pre-defined weight matrix performs a linear transformation on that block.

[0086] Specifically, three different matrices are generated: a query matrix, a key matrix, and a value matrix. The query matrix represents the semantic information that needs to be focused on, the key matrix represents the semantic information at other locations, and the value matrix contains the actual semantic content. Through this linear transformation, the original matrix blocks can be converted into a matrix form more suitable for attention calculation.

[0087] S205: Determine the similarity between the query matrix and the key matrix.

[0088] Understandably, similarity calculation reflects the degree of correlation between the semantic information represented by the query matrix and the semantic information represented by the key matrix.

[0089] Similarity is typically calculated using methods such as dot product and additive attention. Taking dot product as an example, each query vector in the query matrix is ​​multiplied by each key vector in the key matrix to obtain a similarity score. A higher score indicates greater similarity in semantic information between the query and key vectors. By calculating the similarity scores between all vector pairs in the query and key matrices, a similarity matrix is ​​obtained. Each element in this similarity matrix represents the degree of similarity between corresponding vectors in the query and key matrices, providing crucial information for determining subsequent weighting coefficients.

[0090] S206: The similarity is normalized based on the softmax function to obtain the weight coefficients of the matrix blocks.

[0091] Understandably, since the similarity score can range widely, the softmax function can be used to normalize the similarity score. After processing with the softmax function, the similarity score is converted into weight coefficients. These weight coefficients represent the relative importance of each query vector in the query matrix to all key vectors in the key matrix. The larger the weight coefficient, the more relevant the semantic information represented by the corresponding key vector is to the query vector, and it will be given greater weight in the subsequent weighted summation operation.

[0092] The formula for determining the weighting coefficients can be, for example:

[0093]

[0094]

[0095] in, These are the weighting coefficients. The attention score represents the similarity score, where Q is the query vector and K is the key vector.

[0096] S207: The value matrix is ​​weighted and summed based on the weight coefficients to obtain the output matrix of the matrix block.

[0097] As is understandable, the weighted summation process involves multiplying each value vector in the value matrix by its corresponding weight coefficient, and then summing all the results. In this way, semantic information related to the query matrix within the value matrix can be integrated to obtain a more representative output vector.

[0098] The formula for weighted summation can be, for example:

[0099]

[0100] in, Let be a value vector in the value matrix.

[0101] For each query vector in the matrix block, this weighted summation operation is performed, ultimately yielding an output matrix with the same dimensions as the query matrix. This output matrix contains the result of all semantic information in the matrix block processed by the attention mechanism, highlighting the semantic content related to the query vector and providing a more effective feature representation for subsequent feature merging and classification.

[0102] S208: Merge the output matrices of multiple matrix blocks to obtain the feature matrix.

[0103] Understandably, to obtain a complete feature representation, the output matrices of multiple matrix blocks need to be merged. The merging method can be chosen according to actual needs. For example, the output matrices of multiple matrix blocks can be concatenated according to their position order in the original contextual hidden matrix to obtain a larger feature matrix. This feature matrix contains the semantic information of all matrix blocks after processing by the attention mechanism, and is the feature representation of the entire sentence after optimization by the multi-head attention mechanism. Through merging, the local features of each matrix block are integrated into a global feature, enabling the system to more comprehensively understand the semantic information of the sentence.

[0104] This embodiment provides a text sentiment classification method. It extracts word vector features by reducing the dimensionality of a dual-channel word vector sequence, then extracts contextual semantic features to obtain a contextual hidden matrix. After dividing the hidden matrix into multiple matrix blocks, each block is linearly transformed using a preset weight matrix to generate query, key, and value matrices. The similarity between the query and key matrices is determined and normalized using softmax to obtain weight coefficients. The value matrices are then weighted and summed based on these weight coefficients to obtain the output matrix for each matrix block. Finally, the output matrices are merged to obtain the feature matrix. This method reduces redundancy through dimensionality reduction, captures contextual semantics using BiLSTM, and focuses key semantic information through a multi-head attention mechanism. It effectively integrates sentence semantics, improves the classification system's understanding of sentence semantics, provides more accurate and richer feature representations for subsequent tasks, and enhances system performance.

[0105] Figure 3 A flowchart illustrating the text sentiment classification method provided in this application embodiment. Figure 3 .like Figure 3 As shown, in Figure 1 Based on the embodiments, the process of determining the emotion feature fusion matrix is ​​described in detail, including:

[0106] S301: The feature matrix and the context hiding matrix are concatenated to obtain the enhanced feature matrix.

[0107] Understandably, the feature matrix contains key features extracted through multi-head attention mechanisms, while the contextual hiding matrix contains the semantic information of each word in the sentence within its context. Concatenating these two matrices integrates feature information from different sources. For example, the feature matrix might focus more on semantic relationships and importance weights between words, while the contextual hiding matrix provides information on the position and semantic coherence of words within the overall sentence context. The resulting enhanced feature matrix combines the advantages of both, enabling the system to obtain a more comprehensive and richer feature representation.

[0108] S302: Input the enhanced feature matrix into the convolutional neural network to obtain global sentiment features.

[0109] Understandably, Convolutional Neural Networks (CNNs) are highly capable of feature extraction from text data. By inputting the enhanced feature matrix into a CNN, the CNN can extract local feature patterns by sliding its unique convolutional kernels across the feature matrix.

[0110] CNN networks can employ dense connections. This connection method ensures that each layer in the network is connected to all preceding layers, allowing for the reuse of original features. In other words, during feature extraction, not only are features from the current layer used in subsequent calculations, but features from previous layers also continuously participate. This ensures that more features are involved in the model's learning process, avoiding feature loss and waste.

[0111] By employing multi-layer convolution and pooling operations in CNNs, representative global sentiment features can be gradually extracted from the enhanced feature matrix. These global sentiment features can capture the overall sentiment tendency and key sentiment expression patterns in a sentence, providing an important basis for sentiment classification.

[0112] S303: The global sentiment features of the two channels are concatenated to obtain the sentiment feature fusion matrix of the sentence to be classified.

[0113] Understandably, after the aforementioned processing, both channels yield corresponding global sentiment features. These two channels' weighted sentiment features reflect the emotional information of the sentence from different angles or aspects. Concatenating the global sentiment features of the two channels integrates them into a unified feature representation. Through concatenation, the unique sentiment features extracted from each channel, along with the shared sentiment information they express, can be fused together. The resulting sentiment feature fusion matrix combines the advantages of both channels, providing a more comprehensive and accurate representation of the sentiment features of the sentence to be classified.

[0114] This embodiment provides a text sentiment classification method that enhances feature information by concatenating a feature matrix with a contextual hidden matrix. The enhanced feature matrix is ​​then input into a densely connected convolutional neural network to fully extract global sentiment features and effectively utilize the original features. Finally, the global sentiment features from the two channels are concatenated to obtain a sentiment feature fusion matrix, enabling the classification system to capture sentence sentiment more comprehensively and accurately, thus improving the accuracy and reliability of sentiment classification.

[0115] Figure 4 This is a schematic diagram of the structure of a text sentiment classification device provided in this application. Figure 4 As shown, this application provides a text sentiment classification device, the text sentiment classification device 400 including:

[0116] The acquisition module 401 is used to acquire the sentence to be classified and to perform global embedding and context embedding processing on the sentence to be classified to obtain a dual-channel word vector sequence.

[0117] Processing module 402 is used to perform contextual semantic modeling and feature enhancement processing on the dual-channel word vector sequence to obtain a dual-channel feature matrix;

[0118] Processing module 402 is used to perform fusion processing on the dual-channel feature matrix to obtain the sentiment feature fusion matrix of the sentence to be classified;

[0119] The generation module 403 is used to generate the category result of the sentence to be classified based on the sentiment feature fusion matrix.

[0120] Optionally, the processing module 402 is specifically used to perform dimensionality reduction processing on any one of the word vector sequences of the dual-channel word vector sequence to obtain word vector features; to perform context semantic feature extraction processing on the word vector features to obtain a context hiding matrix; and to perform feature enhancement processing on the context hiding matrix based on a multi-head attention mechanism to obtain a feature matrix.

[0121] Optionally, the processing module 402 is specifically used to divide the context hiding matrix to obtain multiple matrix blocks; for any one of the multiple matrix blocks, perform a linear transformation on the matrix block using a preset weight matrix to generate a query matrix, a key matrix, and a value matrix; determine the weight coefficients of the matrix block based on the query matrix and the key matrix; perform a weighted summation on the value matrix based on the weight coefficients to obtain the output matrix of the matrix block; and merge the output matrices of the multiple matrix blocks to obtain the feature matrix.

[0122] Optionally, the processing module 402 is specifically used to determine the similarity between the query matrix and the key matrix; and to normalize the similarity based on the softmax function to obtain the weight coefficients of the matrix blocks.

[0123] Optionally, the processing module 402 is specifically used to concatenate the feature matrix and the context hiding matrix to obtain an enhanced feature matrix; input the enhanced feature matrix into a convolutional neural network to obtain global sentiment features; and concatenate the global sentiment features of the two channels to obtain the sentiment feature fusion matrix of the sentence to be classified.

[0124] Optionally, the generation module 403 is specifically used to map the emotion feature fusion matrix to obtain an initial score for each preset category; perform probability transformation on the initial scores based on the softmax function to obtain a probability distribution result; and determine the category result based on the probability distribution result, wherein the category result is the category with a probability value greater than other categories.

[0125] The text emotion classification device provided in this application embodiment is similar in principle and technical effect to the implementation of each part of the aforementioned text emotion classification method, and will not be described again here.

[0126] Figure 5 This is a schematic diagram of the structure of an electronic device provided in this application. Figure 5 As shown, this application provides an electronic device 500, which includes: a receiver 501, a transmitter 502, a processor 503, and a memory 504.

[0127] Receiver 501 is used to receive instructions and data;

[0128] Transmitter 502 is used to send commands and data;

[0129] Memory 504 is used to store instructions executed by the computer;

[0130] Processor 503 is used to execute computer execution instructions stored in memory 504 to implement the various steps of the text sentiment classification method in the above embodiments. For details, please refer to the relevant descriptions in the foregoing embodiments of the text sentiment classification method.

[0131] Optionally, the memory 504 can be either standalone or integrated with the processor 503.

[0132] When the memory 504 is set up independently, the electronic device also includes a bus for connecting the memory 504 and the processor 503.

[0133] The implementation principle and technical effects of the electronic device provided in this embodiment can be found in the foregoing embodiments, and will not be repeated here.

[0134] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the method described in any of the foregoing embodiments.

[0135] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the methods described in any of the foregoing embodiments.

[0136] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.

[0137] It should be further noted that although the steps in the flowchart are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.

[0138] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation. For example, multiple units, modules, or components may be combined, or integrated into another system, or some features may be ignored or not executed.

[0139] Furthermore, unless otherwise specified, the functional units / modules in the various embodiments of this application can be integrated into one unit / module, or each unit / module can exist physically separately, or two or more units / modules can be integrated together. The integrated units / modules described above can be implemented in hardware or as software program modules.

[0140] When integrated units / modules are implemented in hardware, the hardware can be digital circuits, analog circuits, etc. The physical implementation of the hardware structure includes, but is not limited to, transistors, memristors, etc. Unless otherwise specified, the processor can be any suitable hardware processor, such as a CPU, GPU, FPGA, DSP, and ASIC, etc. Unless otherwise specified, the storage unit can be any suitable magnetic or magneto-optical storage medium, such as Resistive Random Access Memory (RRAM), Dynamic Random Access Memory (DRAM), Static Random Access Memory (SRAM), Enhanced Dynamic Random Access Memory (EDRAM), High-Bandwidth Memory (HBM), Hybrid Memory Cube (HMC), etc.

[0141] If the integrated unit / module is implemented as a software program module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, 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. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.

[0142] In the above embodiments, the descriptions of each embodiment have their own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments. The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as the combination of these technical features does not contradict each other, it should be considered within the scope of this specification.

[0143] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.

[0144] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A method for classifying textual sentiment, characterized in that, include: Obtain the sentence to be classified, and perform global embedding and context embedding on the sentence to be classified to obtain a dual-channel word vector sequence; The dual-channel word vector sequence is subjected to contextual semantic modeling and feature enhancement processing to obtain a dual-channel feature matrix; The dual-channel feature matrix is ​​fused to obtain the sentiment feature fusion matrix of the sentence to be classified. Based on the sentiment feature fusion matrix, the category results of the sentence to be classified are generated.

2. The method according to claim 1, characterized in that, The process of performing contextual semantic modeling and feature enhancement on the dual-channel word vector sequence to obtain a dual-channel feature matrix includes: For any word vector sequence in the dual-channel word vector sequence, the word vector sequence is subjected to dimensionality reduction processing to obtain word vector features; The word vector features are subjected to contextual semantic feature extraction processing to obtain the contextual hiding matrix; The context hiding matrix is ​​enhanced using a multi-head attention mechanism to obtain a feature matrix.

3. The method according to claim 2, characterized in that, The feature matrix obtained by performing feature enhancement processing on the context hiding matrix based on the multi-head attention mechanism includes: The context hiding matrix is ​​divided into multiple matrix blocks; For any one of the plurality of matrix blocks, a linear transformation is performed on the matrix block using a preset weight matrix to generate a query matrix, a key matrix, and a value matrix; Based on the query matrix and the key matrix, determine the weight coefficients of the matrix blocks; The value matrix is ​​weighted and summed based on the weight coefficients to obtain the output matrix of the matrix block. The output matrices of the multiple matrix blocks are merged to obtain the feature matrix.

4. The method according to claim 3, characterized in that, Determining the weight coefficients of the matrix blocks based on the query matrix and the key matrix includes: Determine the similarity between the query matrix and the key matrix; The similarity is normalized using the softmax function to obtain the weight coefficients of the matrix blocks.

5. The method according to claim 2, characterized in that, The process of fusing the dual-channel feature matrix to obtain the sentiment feature fusion matrix of the sentence to be classified includes: The feature matrix and the context hiding matrix are concatenated to obtain the enhanced feature matrix. The enhanced feature matrix is ​​input into a convolutional neural network to obtain global sentiment features; The global sentiment features from the two channels are concatenated to obtain the sentiment feature fusion matrix of the sentence to be classified.

6. The method according to claim 1, characterized in that, The step of generating the category result of the sentence to be classified based on the sentiment feature fusion matrix includes: The emotional feature fusion matrix is ​​mapped to obtain an initial score for each preset category; The initial score is subjected to probability transformation based on the softmax function to obtain the probability distribution result; Based on the probability distribution results, the category results are determined, and the category results are those with a probability value greater than other categories.

7. A text sentiment classification device, characterized in that, include: The acquisition module is used to acquire the sentence to be classified and to perform global embedding and context embedding processing on the sentence to be classified to obtain a dual-channel word vector sequence; The processing module is used to perform contextual semantic modeling and feature enhancement processing on the dual-channel word vector sequence to obtain a dual-channel feature matrix; The processing module is used to perform fusion processing on the dual-channel feature matrix to obtain the sentiment feature fusion matrix of the sentence to be classified. The generation module is used to generate the category result of the sentence to be classified based on the sentiment feature fusion matrix.

8. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.

10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 6.