Sparse sentiment classification method and device, equipment, medium and program product
A sparse emotion classification method that combines multi-channel emotional text representation and multi-head self-attention mechanism, using long short-term memory neural network and sparse mechanism, solves the problems of obscure and diverse classification of emotional text in the existing technology, and improves classification accuracy. performance and model efficiency.
Patent Information
- Application Number
- CN202410784366.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-08-27
AI Technical Summary
Existing sparse emotion classification models have difficulty learning effective features when dealing with obscure emotional expressions and diverse emotional texts, resulting in reduced classification accuracy, high model complexity, and high computational costs.
A sparse emotion classification method that combines multi-channel emotional text representation and multi-head self-attention mechanism is adopted. Through long short-term memory neural network and sparse mechanism, it captures time dependence and performs emotion classification, reducing model complexity and computational cost.
It improves the accuracy and robustness of emotional text classification, reduces the resource requirements and computational costs of model training, overcomes the over-fitting problem, and determines emotional polarity more accurately.
Smart Images

Figure CN118551052A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of cloud computing or artificial intelligence, and more specifically to a sparse sentiment classification method, device, equipment, medium and program product. Background Art
[0002] Sparse sentiment classification has a wide range of application scenarios, including but not limited to social media analysis, public opinion analysis, financial analysis, and intelligent customer service. In these scenarios, sparse sentiment classification can help companies and organizations better understand user needs and emotional tendencies, thereby improving products and services and increasing customer satisfaction. However, sparse sentiment classification also faces some challenges. For example, most texts do not contain clear emotional labels or the emotional expressions are relatively obscure, making it difficult for the model to learn effective emotional feature representations during training. In addition, due to the diversity and complexity of emotional expressions, this also causes certain difficulties for the model in identifying and understanding emotions. Summary of the invention
[0003] In view of the above problems, embodiments of the present disclosure provide a sparse sentiment classification method, apparatus, device, medium and program product.
[0004] According to the first aspect of the present disclosure, a sparse sentiment classification method is provided, the method comprising: obtaining sentiment text; mapping the sentiment text into different vector spaces to obtain multi-channel numerical vectors; utilizing a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to perform feature extraction on the multi-channel numerical vectors to capture time dependencies and obtain multi-head attention representations; and based on the time dependencies of the multi-head attention representations, performing sentiment classification on the sentiment text.
[0005] According to an embodiment of the present disclosure, the method also includes: introducing a sparse mechanism in the long short-term memory neural network; and using the sparse mechanism to sparse the parameters or connections of the long short-term memory neural network to reduce the complexity of the long short-term memory neural network.
[0006] According to an embodiment of the present disclosure, the numerical vector includes a first numerical vector and a second numerical vector, and the multi-channel includes a first channel and a second channel; mapping the emotional text into different vector spaces to obtain a multi-channel numerical vector includes: processing the emotional text through a first word embedding method, converting the emotional text into the corresponding first numerical vector, and the first numerical vector constitutes the first channel; and processing the emotional text through a second word embedding method, converting the emotional text into the corresponding second numerical vector, and the second numerical vector constitutes the second channel.
[0007] According to an embodiment of the present disclosure, the use of a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to perform feature extraction on the numerical vectors of multiple channels to capture time dependencies and obtain a multi-head attention representation includes: sending the numerical vectors of multiple channels as different input sequences into the long short-term memory neural network for processing, capturing the time dependencies within each channel, and outputting a hidden state sequence; splitting the hidden state sequence through the multi-head self-attention mechanism, and calculating the self-attention weight of each head; and weighted summing the self-attention weight and the input sequence to obtain the multi-head attention representation.
[0008] According to an embodiment of the present disclosure, the use of the sparsification mechanism to sparsify the parameters or connections of the long short-term memory neural network includes: evaluating the importance of the parameters or connections of the long short-term memory neural network based on preset evaluation conditions to obtain evaluation results; setting a pruning threshold based on the evaluation results; and removing the parameters or connections whose importance is lower than the pruning threshold from the long short-term memory neural network to achieve the sparsification of the long short-term memory neural network.
[0009] According to an embodiment of the present disclosure, the sentiment classification of the sentiment text based on the time dependency of the multi-head attention representation includes: inputting the multi-head attention representation into a pre-trained sentiment classifier to identify and determine the sentiment category of the sentiment text.
[0010] According to an embodiment of the present disclosure, the method further includes: preprocessing the emotion text; and segmenting the preprocessed emotion text to split the emotion text into independent vocabulary units.
[0011] The second aspect of the present disclosure provides a sparse sentiment classification device, including: an acquisition module for acquiring sentiment text; a mapping module for mapping the sentiment text into different vector spaces to obtain multi-channel numerical vectors; an extraction module for using a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to perform feature extraction on the multi-channel numerical vectors to capture time dependencies and obtain multi-head attention representations; and a classification module for performing sentiment classification on the sentiment text based on the time dependencies of the multi-head attention representations.
[0012] A third aspect of the present disclosure provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the above-mentioned sparse sentiment classification method.
[0013] The fourth aspect of the present disclosure further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned sparse sentiment classification method are implemented.
[0014] The fifth aspect of the present disclosure also provides a computer program product, including a computer program, which implements the steps of the above-mentioned sparse sentiment classification method when executed by a processor.
[0015] In the embodiments of the present disclosure, a multi-head self-attention mechanism is introduced into a long short-term memory neural network to increase the importance of sentiment polarity words in sentiment texts, thereby capturing key sentiment features and improving the accuracy of classification. In addition, sentiment texts are vectorized in multiple channels to more comprehensively understand the content of sentiment texts and more accurately judge the sentiment polarity of sentiment texts. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The above contents and other objects, features and advantages of the present disclosure will become more apparent through the following description of the embodiments of the present disclosure with reference to the accompanying drawings, in which:
[0017] Figure 1 A diagram schematically shows an application scenario of a sparse sentiment classification method, apparatus, device, medium, and program product according to an embodiment of the present disclosure;
[0018] Figure 2 A flowchart of a sparse sentiment classification method according to an embodiment of the present disclosure is schematically shown;
[0019] Figure 3 A flowchart of a method for extracting features from a multi-channel numerical vector according to an embodiment of the present disclosure is schematically shown;
[0020] Figure 4 A structural block diagram of a sparse sentiment classification device according to an embodiment of the present disclosure is schematically shown; and
[0021] Figure 5 A block diagram of an electronic device according to a sparse sentiment classification method according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0022] Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present disclosure. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of the embodiments of the present disclosure. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of the concepts of the present disclosure.
[0023] The terms used herein are only for describing specific embodiments and are not intended to limit the present disclosure. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.
[0024] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.
[0025] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).
[0026] In the technical solution of the present invention, the user information (including but not limited to user personal information, user image information, user device information, such as location information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved are all information and data authorized by the user or fully authorized by all parties, and the collection, storage, use, processing, transmission, provision, disclosure and application of the relevant data comply with relevant laws, regulations and standards, take necessary confidentiality measures, do not violate public order and good morals, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0027] Figure 1 The application scenario diagram of the sparse sentiment classification method, apparatus, device, medium and program product according to the embodiments of the present disclosure is schematically shown.
[0028] like Figure 1 As shown, the application scenario 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0029] The user can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only for example).
[0030] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0031] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for websites browsed by users using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0032] It should be noted that the sparse sentiment classification method provided in the embodiment of the present disclosure can generally be executed by the server 105. Accordingly, the sparse sentiment classification device provided in the embodiment of the present disclosure can generally be set in the server 105. The sparse sentiment classification method provided in the embodiment of the present disclosure can also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Accordingly, the sparse sentiment classification device provided in the embodiment of the present disclosure can also be set in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.
[0033] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0034] First, the technical terms described in this article are explained and described as follows.
[0035] Long Short-Term Memory (LSTM): A time-recurrent neural network designed specifically to solve the long-term dependency problem of general RNNs (recurrent neural networks). All RNNs have a chain form of repeated neural network modules.
[0036] Word2Vec and Glove: A group of related models for generating word embeddings. These models are shallow, two-layer neural networks trained to reconstruct linguistic word texts.
[0037] Word embedding: A general term for a set of language modeling and feature learning techniques in natural language processing, in which words or phrases from a vocabulary are mapped to vectors of real numbers. Conceptually, it involves mathematical embedding from a one-dimensional space for each word to a continuous vector space with lower dimensions.
[0038] Multi-head self-attention mechanism: A commonly used attention mechanism in the field of natural language processing to capture long-distance dependencies in the input sequence. Its core idea is to calculate the attention weight of each position in the input sequence, and then weighted sum these weights with the input sequence to obtain the output sequence.
[0039] The following will be based on Figure 1 The scene described by Figure 2 and Figure 3 The sparse sentiment classification method of the embodiment of the present disclosure is described in detail.
[0040] Figure 2 The flowchart of the sparse sentiment classification method according to an embodiment of the present disclosure is schematically shown.
[0041] like Figure 2 As shown, the sparse sentiment classification method of this embodiment includes operations S210 to S240.
[0042] In operation S210, the emotion text is acquired.
[0043] In an embodiment of the present disclosure, before acquiring the emotion text, the user's consent or authorization is obtained. For example, before operation S210, a request to acquire the emotion text is issued to the user. When the user agrees or authorizes that the emotion text can be acquired, the operation S210 is performed.
[0044] In operation S220, the emotional text is mapped into different vector spaces to obtain multi-channel numerical vectors.
[0045] In operation S230, a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism are used to perform feature extraction on the numerical vectors of multiple channels to capture time dependencies and obtain a multi-head attention representation.
[0046] In operation S240, sentiment classification is performed on the sentiment text based on the temporal dependency of the multi-head attention representation.
[0047] In the embodiment of the present disclosure, a corresponding operation entry is provided for the user to choose to agree or reject the automated decision result. That is, before the emotional text is subjected to emotional classification processing / decision based on the time dependency relationship represented by the multi-head attention, an instruction of the user to agree or reject the processing / decision input through the corresponding operation entry is obtained. If the user agrees to perform the processing / decision, the emotional text is subjected to emotional classification processing / decision, that is, step S240 is executed. If the user refuses to perform the processing / decision, the expert decision process is entered.
[0048] The inventor has found through research that when performing sentiment classification in related technologies, the neural network training process is prone to overfitting, and the key sentiment features are unevenly distributed throughout the text, which easily leads to the loss of key sentiment features. In addition, the single text representation results in the lack of rich text semantic information, which all lead to the problem of reduced classification accuracy. In addition, the resource requirements and computing costs of recurrent neural networks in processing time series prediction problems are also high. The disclosed embodiment overcomes the shortcomings of the prior art and provides a sparse sentiment classification method that integrates multi-channel features and a multi-head self-attention mechanism.
[0049] Specifically, in the initial stage of sentiment classification, we first need to obtain sentiment texts from various sources to be classified, such as social media posts, product reviews, and news articles. At the same time, although sentiment texts contain rich sentiment information, they are also accompanied by noise and irrelevant content, which can be processed through the following corresponding steps.
[0050] Optionally, the method further includes: preprocessing the emotional text; and segmenting the preprocessed emotional text to split the emotional text into independent vocabulary units.
[0051] In some exemplary embodiments, preprocessing may include cleaning and normalizing the sentiment text, removing stop words, and processing punctuation marks. Among them, text cleaning involves deleting HTML tags, special characters, URL links, etc. in the text, which are not helpful for sentiment classification and may interfere with subsequent processing steps. Text normalization is to convert all text to lowercase letters to avoid semantic differences caused by different cases. In addition, lemmatization or stemming can be performed to reduce the diversity of vocabulary by restoring words to their basic forms. Stop words refer to words that frequently appear in the text but contribute little to the meaning of the text, such as "de", "shi", and "zai", etc. Removing stop words can reduce the dimensionality of the text and improve the efficiency of subsequent processing. In addition, since punctuation marks play a role in separating and emphasizing in the text, but may not be necessary in sentiment classification. Therefore, punctuation marks can be regarded as delimiters to split the text into independent sentences or phrases.
[0052] Furthermore, in Chinese text, since there are no obvious delimiters (such as spaces) between words, word segmentation is particularly important. The quality of word segmentation directly affects the accuracy of subsequent feature extraction and sentiment classification. Word segmentation is to split continuous natural language text (the preprocessed sentiment text) into independent lexical units. In this process, a pre-built dictionary can be used for word segmentation. The dictionary contains a large number of words and phrases. By matching the text with the dictionary, the lexical units in the text can be identified. Statistical machine learning methods can also be used to segment the text. This method does not require a pre-built dictionary, but segments the text by learning the lexical boundary information in the text.
[0053] It can be understood that by preprocessing and segmenting the text, the semantic and sentiment information in the text can be captured more accurately, making subsequent text processing and feature extraction more accurate and effective, thereby improving the accuracy and robustness of sentiment classification.
[0054] After obtaining the emotional text and processing the emotional text, the text is mapped to the numerical vector space so that the computer can process and understand it. In this process, the quality of the text representation has a crucial impact on the final classification result. In order to more accurately capture the emotional information in the text, the embodiment of the present disclosure adopts a variety of different numerical vector (word vector) technologies to enrich the text representation, that is, using a multi-channel method to map the text to different vector spaces, and using different embedding techniques to generate multiple numerical vectors, each of which reflects the characteristics of the text from different angles. Then, these vectors are processed using a pre-trained long short-term memory neural network (LSTM) to capture the temporal dependencies in the text, that is, the order and dependencies between words. At the same time, in order to further improve the performance of the model, a multi-head self-attention mechanism is introduced, so that the model learns different attention weights in multiple different representation subspaces, that is, to enhance the importance of emotional polarity words in text representation, thereby more comprehensively capturing the key information in the text. Finally, sentiment classification is performed based on the multi-head attention representation.
[0055] It should be noted that when training the LSTM neural network, existing knowledge bases and sentiment dictionaries are used to enrich the representation of sentiment information. These resources contain a large number of sentiment words, sentiment phrases, and the relationships between them, which can effectively supplement the sentiment information in the text. By integrating these resources into the LSTM neural network, the sentiment polarity in the text can be more accurately identified and the subtle differences between different sentiments can be captured.
[0056] It can be understood that by adopting a multi-channel approach, different semantic and emotional features in emotional text are captured and used in combination, thus providing a more comprehensive and detailed text representation and providing richer input for subsequent feature extraction and sentiment classification. In addition, the importance of sentiment polarity words is enhanced by using a multi-head self-attention mechanism, which overcomes the problem of uneven distribution of key sentiment features throughout the text and improves the accuracy of classification.
[0057] In an embodiment of the present disclosure, the method also includes: introducing a sparse mechanism in the long short-term memory neural network; and using the sparse mechanism to sparse the parameters or connections of the long short-term memory neural network to reduce the complexity of the long short-term memory neural network.
[0058] Specifically, a sparse mechanism is introduced into the long short-term memory neural network, and the implementation method is to first introduce the sparse mechanism into the gated recurrent unit (i.e., GRU), and then combine the sparse GRU with the sparse mechanism with the long short-term memory neural network. GRU is a simplified variant of LSTM, which also has the ability to capture long-term and short-term dependencies in a sequence, but has a simpler structure. In the embodiment of the present disclosure, when the sparse GRU is combined with the LSTM, a pruned GRU is connected after each channel, that is, after the feature extraction of each channel, a lighter, sparse GRU is used to process these features, so that while extracting long-term and short-term dependencies, the neural connection can be greatly shortened, and ultimately the model training speed is greatly improved.
[0059] It is understandable that by utilizing the sparsity mechanism, the number of parameters of the long short-term memory neural network is reduced, the resource requirements and computational costs for processing sparse sentiment classification are saved, the model training speed is greatly improved, and the accuracy loss is reduced. In addition, sparsification also helps prevent overfitting because fewer parameters mean fewer degrees of freedom to fit the noise in the training data.
[0060] Furthermore, the use of the sparsification mechanism to sparse the parameters or connections of the long short-term memory neural network includes: evaluating the importance of the parameters or connections of the long short-term memory neural network based on preset evaluation conditions to obtain evaluation results; setting a pruning threshold according to the evaluation results; and removing the parameters or connections whose importance is lower than the pruning threshold from the long short-term memory neural network to achieve the sparsification of the long short-term memory neural network.
[0061] In some exemplary embodiments, pruning is performed so that a portion of weights or connections become zero, thereby achieving network sparseness.
[0062] The specific process of sparse GRU is as follows: Pruning the GRU network is regarded as an optimization problem.
[0063] Given the original dataset , sliding window size ,in , x (t) represents the observation value or data point at time point t, and n is the total number of data points in the data set D. Through slider processing, a new data dimension m=n-s+1 can be obtained, that is, the number of data points obtained after sliding window processing, and a time series data set can be formed , in the time series data set D T In, X (t) represents the tth data block, , and X (t) The corresponding target value or label 。
[0064] There are two specific gate structures in the structure of the gated recurrent neural network GRU, namely the forget gate and the reset gate:
[0065] (1)
[0066] (2)
[0067] where σ is the activation function (i.e., for example, the sigmoid function), h(t - 1) is the hidden state at time t - 1, and W z and W r are both parameter matrices of dimension p * q (0 < p < m, 0 < q < s). As a variant of the RNN, GRU also inherits the following structure in its composition:
[0068] (3)
[0069] (4)
[0070] where g is the activation function, such as ReLU and tanh. In the embodiments of the present disclosure, GRU will be defined as a mapping relationship completed by iterative calculation for ease of understanding and calculation:
[0071] (5)
[0072] where W is the combination of the parameter matrices of the three linear operations in the GRU model (i.e., W z , W r , W h ), and ŷ is the predicted value at time t. Substitute the parameter matrix W into formula (5) to obtain the pruning threshold e,
[0073] (6)
[0074] where s' is the sensitivity factor used to control the threshold e, and W_ is the mean value after taking the absolute value of the weights. Given the sparsity level k, where k represents the number of non-zero weights that are desired to be retained in the neural network, there are model constraint conditions generated:
[0075] (7)
[0076] To ensure that the pruned connections will not be revived through backpropagation, an auxiliary index variable is introduced. Corresponding to the parameter matrix, there is a mask matrix .
[0077] (8)
[0078] At this time, the optimization problem is transformed into:
[0079] (9)
[0080] Here, L is the loss function. The mask matrix C is the key factor to ensure single-shot pruning. It not only removes the weights at the corresponding positions during the forward propagation process, but also prevents the discarded weights from being revived during the training phase.
[0081] Finally, the overview and implementation steps of the entire optimization process are as follows: First, pre-train the network to obtain a set of initial weights W. For all weights W, calculate their absolute values and calculate the ε associated with the regularization term. Then, use a do loop to traverse all weights, and for each weight, decide whether to prune it according to the preset conditions. If the pruning conditions are met, the corresponding weight is set to 0 (i.e., pruned), otherwise the weight is retained. After all weights are processed according to the pruning conditions, the weights of the updated model are the pruned weights W'.
[0082] It is understandable that pruning can achieve the sparsification of long short-term memory neural networks, which can significantly reduce the model size and computational complexity while maintaining model performance, thereby improving the efficiency, robustness, and interpretability of the model.
[0083] In an embodiment of the present disclosure, the numerical vector includes a first numerical vector and a second numerical vector, and the multi-channel includes a first channel and a second channel; mapping the emotional text into different vector spaces to obtain a multi-channel numerical vector includes: processing the emotional text by a first word embedding method, converting the emotional text into the corresponding first numerical vector, and the first numerical vector constitutes the first channel; and processing the emotional text by a second word embedding method, converting the emotional text into the corresponding second numerical vector, and the second numerical vector constitutes the second channel.
[0084] Exemplarily, the first word embedding method is the word2vec method, which is a neural network model for learning word vectors. It learns the meaning of each word in the context by training a large amount of text data, and represents each word as a high-dimensional vector. In the first channel, the word2vec method is used to process the preprocessed input text after word segmentation. Specifically, each word in the text is converted into a corresponding word2vec vector, and these vectors are combined into a long vector according to the order of the words in the text as the first numerical vector of the first channel.
[0085] Exemplarily, the second word embedding method is the glove method, which combines global statistical information and local context information to learn word vectors. Compared with word2vec, glove can better utilize the global statistical information of the text and consider the co-occurrence relationship of words during training. In the second channel, the same input text is processed using the glove method. Similar to word2vec, each word in the text is converted into a corresponding glove vector, and these vectors are combined into a long vector as the second numerical vector of the second channel.
[0086] It can be understood that by constructing multi-channel numerical vectors through different word embedding methods, the sentiment information in the text can be captured from multiple angles, thereby improving the accuracy and robustness of sentiment analysis.
[0087] Figure 3 The flowchart schematically shows a method for extracting features from multi-channel numerical vectors according to an embodiment of the present disclosure.
[0088] like Figure 3 As shown, the method utilizes a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to perform feature extraction on the numerical vectors of multiple channels to capture time dependencies and obtain a multi-head attention representation, including: sending the numerical vectors of multiple channels as different input sequences to the long short-term memory neural network for processing, capturing the time dependencies within each channel, and outputting a hidden state sequence; splitting the hidden state sequence through the multi-head self-attention mechanism, and calculating the self-attention weight of each head; and performing weighted summation of the self-attention weight and the input sequence to obtain the multi-head attention representation.
[0089] Specifically, the numerical vector sequence of each channel is fed into the LSTM network. Through the processing of the LSTM network, the numerical vector sequence in each channel is converted into a series of hidden state vectors, which contain the information of each position in the sequence and the temporal dependency between them. After obtaining the hidden state sequence output by the LSTM, the multi-head self-attention mechanism is introduced to further extract key information. The multi-head self-attention mechanism splits the hidden state sequence into multiple "heads" and independently calculates the self-attention weight on each head, so that multiple positions in the sequence can be paid attention to in parallel. In the multi-head self-attention mechanism, the LSTM model obtains the self-attention weight by calculating a triple called "query", "key" and "value". For each head, each position in the hidden state sequence is regarded as a query, and all positions are also regarded as keys and values. The model calculates the dot product of each query and all keys and converts it into a probability distribution, namely the self-attention weight, through the softmax function. After obtaining the self-attention weight, the model performs a weighted summation with the corresponding value to obtain a new representation of each head. Finally, the representations of all heads are concatenated or averaged to form a new representation containing multiple channel information as well as temporal dependencies and key information, namely the multi-head attention representation.
[0090] It can be understood that the multi-head self-attention mechanism allows the LSTM model to learn different attention weights in multiple different representation subspaces, thereby more comprehensively capturing the key information in the text. By applying this mechanism to the sentiment classification task of the embodiment of the present disclosure, the model pays more attention to words or phrases that are critical to the judgment of sentiment polarity, thereby improving the accuracy and robustness of classification.
[0091] Furthermore, the sentiment classification of the sentiment text based on the time dependency of the multi-head attention representation includes: inputting the multi-head attention representation into a pre-trained sentiment classifier to identify and determine the sentiment category of the sentiment text.
[0092] After obtaining the multi-head attention representations, since these representations have captured the temporal dependencies and key sentiment features in the text, they can be used as effective classification basis for sentiment classification.
[0093] Specifically, the multi-head attention representation is input into a sentiment classifier, which has been trained with a large amount of labeled data and is able to extract sentiment features from text and predict sentiment categories. In the sentiment classifier, the multi-head attention representation is further processed and transformed through a series of layers (such as fully connected layers and activation functions). Finally, the classifier calculates the activation value of the network output layer and applies the softmax function to output a probability distribution, in which each element represents the probability that the sentiment text belongs to a certain sentiment category. Among them, the softmax function converts the activation value of the output layer into a probability distribution so that the sum of the probabilities of all categories is 1. According to the probability distribution output by the sentiment classifier, the sentiment category with the highest probability can be selected as the final classification result, such as the positive category, that is, the sentiment expressed by the text is positive and optimistic, such as joy, satisfaction, praise, etc., and the negative category, that is, the sentiment expressed by the text is negative and pessimistic, such as anger, sadness, disappointment, etc., and the neutral category, that is, the sentiment expressed by the text has no obvious positive or negative tendency, or contains both positive and negative elements, resulting in an unclear overall sentiment tendency.
[0094] It can be understood that by utilizing sentiment classifiers for sentiment classification, the emotional tendency of texts can be understood more accurately and provide valuable support for various application scenarios.
[0095] Figure 4 The structural block diagram of a sparse sentiment classification device according to an embodiment of the present disclosure is schematically shown.
[0096] like Figure 4 As shown, the sparse sentiment classification device 400 according to this embodiment includes an acquisition module 410 , a mapping module 420 , an extraction module 430 and a classification module 440 .
[0097] The acquisition module 410 is used to acquire the emotional text. In one embodiment, the acquisition module 410 can be used to perform the operation S210 described above, which will not be described in detail here.
[0098] The mapping module 420 is used to map the emotional text into different vector spaces to obtain multi-channel numerical vectors. In one embodiment, the mapping module 420 can be used to perform the operation S220 described above, which will not be described in detail here.
[0099] The extraction module 430 is used to use the pre-trained long short-term memory neural network and the introduced multi-head self-attention mechanism to perform feature extraction on the numerical vector of the multi-channel to capture the time dependency and obtain the multi-head attention representation. In one embodiment, the extraction module 430 can be used to perform the operation S230 described above, which will not be repeated here.
[0100] The classification module 440 is used to perform sentiment classification on the sentiment text based on the temporal dependency of the multi-head attention representation. In one embodiment, the classification module 440 can be used to perform the operation S240 described above, which will not be repeated here.
[0101] In an embodiment of the present disclosure, the extraction module 430 can also be used to: introduce a sparse mechanism into the long short-term memory neural network; and use the sparse mechanism to sparse the parameters or connections of the long short-term memory neural network to reduce the complexity of the long short-term memory neural network.
[0102] In an embodiment of the present disclosure, the numerical vector includes a first numerical vector and a second numerical vector, and the multi-channel includes a first channel and a second channel; the mapping module 420 is specifically used to: process the emotion text through a first word embedding method, convert the emotion text into the corresponding first numerical vector, and the first numerical vector constitutes the first channel; and process the emotion text through a second word embedding method, convert the emotion text into the corresponding second numerical vector, and the second numerical vector constitutes the second channel.
[0103] In an embodiment of the present disclosure, the extraction module 430 is specifically used to: send the numerical vectors of multiple channels as different input sequences into the long short-term memory neural network for processing, capture the time dependency within each channel, and output a hidden state sequence; split the hidden state sequence through the multi-head self-attention mechanism, and calculate the self-attention weight of each head; and perform weighted summation of the self-attention weight and the input sequence to obtain the multi-head attention representation.
[0104] In an embodiment of the present disclosure, the extraction module 430 may also be used to: evaluate the importance of the parameters or connections of the long short-term memory neural network based on preset evaluation conditions to obtain an evaluation result; set a pruning threshold according to the evaluation result; and remove the parameters or connections whose importance is lower than the pruning threshold from the long short-term memory neural network to achieve sparsification of the long short-term memory neural network.
[0105] In an embodiment of the present disclosure, the classification module 440 is specifically used to: input the multi-head attention representation into a pre-trained sentiment classifier to identify and determine the sentiment category of the sentiment text.
[0106] In the embodiment of the present disclosure, the acquisition module 410 may also be used to: pre-process the emotion text; and segment the pre-processed emotion text to split the emotion text into independent vocabulary units.
[0107] According to an embodiment of the present disclosure, any multiple modules of the acquisition module 410, the mapping module 420, the extraction module 430 and the classification module 440 can be combined in one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present disclosure, at least one of the acquisition module 410, the mapping module 420, the extraction module 430 and the classification module 440 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the acquisition module 410, the mapping module 420, the extraction module 430 and the classification module 440 can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.
[0108] Figure 5 A block diagram of an electronic device according to a sparse sentiment classification method according to an embodiment of the present disclosure is schematically shown.
[0109] like Figure 5 As shown, the electronic device 500 according to an embodiment of the present invention includes a processor 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 to a random access memory (RAM) 503. The processor 501 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 501 may also include an onboard memory for caching purposes. The processor 501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.
[0110] In RAM 503, various programs and data required for the operation of electronic device 500 are stored. Processor 501, ROM 502 and RAM 503 are connected to each other via bus 504. Processor 501 performs various operations of the method flow according to the embodiment of the present invention by executing the program in ROM 502 and / or RAM 503. It should be noted that the program can also be stored in one or more memories other than ROM 502 and RAM 503. Processor 501 can also perform various operations of the method flow according to the embodiment of the present invention by executing the program stored in the one or more memories.
[0111] According to an embodiment of the present invention, the electronic device 500 may further include an input / output (I / O) interface 505, which is also connected to the bus 504. The electronic device 500 may further include one or more of the following components connected to the input / output (I / O) interface 505: an input portion 506 including a keyboard, a mouse, etc.; an output portion 507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 508 including a hard disk, etc.; and a communication portion 509 including a network interface card such as a LAN card, a modem, etc. The communication portion 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the input / output (I / O) interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that the computer program read therefrom is installed into the storage portion 508 as needed.
[0112] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.
[0113] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 502 and / or RAM 503 described above and / or one or more memories other than ROM 502 and RAM 503.
[0114] The embodiment of the present disclosure also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the sparse sentiment classification method provided by the embodiment of the present disclosure.
[0115] The above functions defined in the system / device of the embodiment of the present disclosure are performed when the computer program is executed by the processor 501. According to the embodiment of the present disclosure, the system, device, module, unit, etc. described above can be implemented by a computer program module.
[0116] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 509, and / or installed from the removable medium 511. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0117] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the processor 501, the above functions defined in the system of the embodiment of the present disclosure are performed. According to the embodiment of the present disclosure, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.
[0118] According to an embodiment of the present disclosure, the program code for executing the computer program provided by the embodiment of the present disclosure can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (for example, using an Internet service provider to connect through the Internet).
[0119] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0120] It will be appreciated by those skilled in the art that the features described in the various embodiments of the present disclosure may be combined and / or combined in a variety of ways, even if such combinations or combinations are not explicitly described in the present disclosure. In particular, without departing from the spirit and teachings of the present disclosure, the features described in the various embodiments of the present disclosure may be combined and / or combined in a variety of ways. All of these combinations and / or combinations fall within the scope of the present disclosure.
[0121] The embodiments of the present disclosure are described above. However, these embodiments are only for illustrative purposes and are not intended to limit the scope of the present disclosure. Although the embodiments are described above, this does not mean that the measures in the various embodiments cannot be used in combination to advantage. Without departing from the scope of the present disclosure, those skilled in the art may make a variety of substitutions and modifications, which should all fall within the scope of the present disclosure.
Claims
1. A sparse sentiment classification method, characterized in that: The method comprises: Get emotional text; Mapping the emotional text into different vector spaces to obtain multi-channel numerical vectors; Using a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism, feature extraction is performed on the numerical vectors of multiple channels to capture time dependencies and obtain a multi-head attention representation; and Based on the temporal dependency of the multi-head attention representation, sentiment classification is performed on the sentiment text.
2. The method according to claim 1, characterized in that The method further comprises: Introducing a sparse mechanism into the long short-term memory neural network; and The sparsification mechanism is used to sparse the parameters or connections of the long short-term memory neural network to reduce the complexity of the long short-term memory neural network.
3. The method according to claim 1 or 2, characterized in that: The numerical vector includes a first numerical vector and a second numerical vector, and the multi-channel includes a first channel and a second channel; Mapping the emotional text to different vector spaces to obtain multi-channel numerical vectors includes: Processing the sentiment text by a first word embedding method, converting the sentiment text into a corresponding first numerical vector, wherein the first numerical vector constitutes the first channel; and The sentiment text is processed by a second word embedding method to convert the sentiment text into the corresponding second numerical vector, and the second numerical vector constitutes the second channel.
4. The method according to claim 1 or 2, characterized in that: The method of using a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to extract features from the numerical vectors of multiple channels to capture time dependencies and obtain a multi-head attention representation includes: Sending the numerical vectors of multiple channels as different input sequences to the long short-term memory neural network for processing, capturing the time dependency within each channel, and outputting a hidden state sequence; Splitting the hidden state sequence through the multi-head self-attention mechanism, and calculating the self-attention weight of each head; and The self-attention weight is weightedly summed with the input sequence to obtain the multi-head attention representation.
5. The method according to claim 2, characterized in that: The utilizing the sparse mechanism to sparse the parameters or connections of the long short-term memory neural network includes: Evaluating the importance of the parameters or connections of the long short-term memory neural network based on preset evaluation conditions to obtain an evaluation result; According to the evaluation result, setting a pruning threshold; and The parameters or connections whose importance is lower than the pruning threshold are removed from the long short-term memory neural network to achieve sparseness of the long short-term memory neural network.
6. The method according to claim 1 or 2, characterized in that: The sentiment classification of the sentiment text based on the time dependency relationship represented by the multi-head attention comprises: The multi-head attention representation is input into a pre-trained sentiment classifier to identify and determine the sentiment category of the sentiment text.
7. The method according to claim 1, characterized in that The method further comprises: Preprocessing the emotional text; and The preprocessed sentiment text is segmented to separate the sentiment text into independent vocabulary units.
8. A sparse sentiment classification device, characterized in that: The device comprises: An acquisition module is used to acquire emotional text; A mapping module, used for mapping the emotional text into different vector spaces to obtain multi-channel numerical vectors; An extraction module, for performing feature extraction on the numerical vectors of multiple channels using a pre-trained long short-term memory neural network and an introduced multi-head self-attention mechanism to capture temporal dependencies and obtain a multi-head attention representation; and A classification module is used to perform sentiment classification on the sentiment text based on the temporal dependency relationship represented by the multi-head attention.
9. An electronic device, comprising: one or more processors; a storage device for storing one or more computer programs, It is characterized in that when the one or more programs are executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 7.
10. A computer-readable storage medium having executable instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor executes the method according to any one of claims 1 to 7.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Aspect-level sentiment classification method and system based on dependency perception graph convolutional network
CN113987167A
Text aspect level emotion recognition method based on bidirectional LSTM (Long Short Term Memory) and multi-head attention mechanism
CN114648031A
Text classification method and device based on convolutional neural network multi-channel feature representation
CN115034299A
Network model pruning method and device, electronic equipment and storage medium
CN115496199A
