Text emotion recognition method and device, electronic device, and storage medium
By combining the text emotion recognition model of the orderly long and short-term memory network and the multi-head self-attention mechanism network, the problem of difficulty in accurate identification in short text emotion classification is solved, and effective mining of syntactic structure information and accurate improvement of emotional recognition is achieved.
Patent Information
- Application Number
- CN202210593767.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-27
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2042-05-27
AI Technical Summary
The prior art is difficult to accurately identify in short text emotion classification, mainly due to its dependence on feature engineering, poor robustness, and the inability to effectively mine syntactic structure information.
By establishing a text emotion recognition model that includes an ordered long and short-term memory network and a multi-head self-attention mechanism network. This model extracts sentence meaning characteristics and hierarchical information through syntax hierarchical sorting and context encoding, and uses the multi-head self-attention mechanism to perform in-depth information fusion.
It realizes more accurate recognition of short text emotions, improves the robustness of the model and the ability to explore deep information of sentences, and improves the accuracy of emotional recognition.
Smart Images

Figure CN114911940B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of text sentiment classification, and in particular to a text sentiment recognition method and device, electronic equipment, and storage medium. Background Art
[0002] In recent years, intelligent customer service systems have invaded every aspect of people's lives. All conceivable customer service scenarios, such as online shopping returns and exchanges, mobile phone package changes, and user complaints, have the shadow of intelligent customer service behind them. In order to enable intelligent customer service to better serve users and make the responses it generates more humane, the user's emotional state is an important reference indicator, so it is particularly important to analyze the user's emotional state through the text entered by the user.
[0003] In the field of intelligent customer service, the texts input by users are all at the sentence level, and there are very few long texts. Therefore, they contain little information. In addition, natural language expressions are diverse, and the same word may express different emotions in different contexts. These difficulties make it difficult to accurately classify the emotions of short texts.
[0004] In the early days, people mostly used traditional machine learning methods to classify sentiment. However, these methods are extremely dependent on feature engineering, which is time-consuming and laborious. They not only require a lot of domain knowledge, but also have poor robustness and are prone to overfitting. With the development of deep learning, it does not require artificially designed features and can automatically learn to extract features, making it the mainstream. Researchers began to use various network structures of deep learning to solve sentiment classification problems and achieved certain results, but there are still some problems. For example, the current network structure can encode context well using structures such as LSTM (Long Short-Term Memory) or transformer (multi-head attention mechanism), but it still cannot explore deeper internal connections, such as syntactic structures. Syntactic structure plays an important role in understanding the semantics of sentences. Because although language looks like a sequence, it actually has a complex hierarchical structure. Even if the same sequence, different internal hierarchical structures will bring semantic differences. Although we can use syntactic analysis tools or train a model to analyze the hierarchical structure of sentences and then input them as features into the sentiment classification model, the split of the model will bring certain instability. Therefore, it is necessary to provide a text emotion recognition method and device, electronic device, and storage medium. Summary of the invention
[0005] In view of the above-mentioned shortcomings of the prior art, the present invention provides a text emotion recognition method and device, an electronic device, and a storage medium to solve the above-mentioned technical problems.
[0006] The text emotion recognition method provided by the present invention comprises:
[0007] Get sample data;
[0008] Labeling the sample data, and classifying the labeled sample data according to the emotion category to obtain a sample data set;
[0009] Establishing a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set;
[0010] According to the output result of the first network model and the classification processing result, a second network model is established, and the second network model is trained to obtain a text emotion recognition model, wherein the text emotion recognition model includes the first network model and the trained second network model connected in sequence;
[0011] The text data to be recognized is input into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized.
[0012] In one embodiment of the present invention, after acquiring the sample data, the sample data is preprocessed, and the preprocessing includes the following steps:
[0013] Performing text standardization processing on the sample data to obtain standardized sample data, wherein the text standardization processing includes number normalization, English capitalization unification, character encoding standardization and / or Chinese traditional and simplified unification;
[0014] Performing text cleaning on the standardized sample data to remove non-text content and obtain cleaned sample data;
[0015] Text error correction is performed on the cleaned sample data to obtain preprocessed sample data.
[0016] In one embodiment of the present invention, the step of inputting the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized includes:
[0017] Inputting the text data to be recognized into the text emotion recognition model, extracting the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and constructing a sentence feature matrix;
[0018] The sentence feature matrix is input into the second network model to obtain the probability value that the text data to be recognized belongs to each preset emotion category, and the emotion category with the highest probability value is used as the emotion recognition result of the text data to be recognized.
[0019] In one embodiment of the present invention, the first network model is an ordered long short-term memory network, and the second network model is a multi-head self-attention mechanism network.
[0020] In one embodiment of the present invention, the text data to be recognized is input into the text emotion recognition model, sentence features and context encoding information of the text data to be recognized are extracted through the first network model, and a sentence feature matrix is constructed, including:
[0021] Converting the text data to be recognized into a feature matrix;
[0022] The feature matrix is input into the second network model, hierarchical information in the feature matrix is extracted, and a sentence feature matrix is obtained.
[0023] In one embodiment of the present invention, the sentence feature matrix is input into the second network model, the probability values of the text data to be recognized belonging to each preset emotion category are obtained, and the emotion category with the highest probability value is used as the emotion recognition result of the text data to be recognized, including:
[0024] According to a preset attention mechanism operation, the sentence feature matrix input to the second network model is processed to obtain an attention matrix;
[0025] By setting a multi-hop connection of the attention matrix, obtaining the attention matrix output by the last attention layer of the second network model;
[0026] The features in the attention matrix output by the last attention layer are classified, and the classification results are matched with the labels, and the classification results of the sample data are obtained according to the matching rate of the text sentiment category.
[0027] In one embodiment of the present invention, the sentence feature matrix is input into the second network model, and the attention matrix is obtained according to the preset attention mechanism operation, including:
[0028] Perform dot multiplication of the sentence feature matrix with the preset query vector weight matrix, key vector weight matrix, and value vector weight matrix of the current head in the second network model, respectively, to obtain a query vector matrix, a key vector matrix, and a value vector matrix, and construct a sentence vector feature matrix of the current head;
[0029] The sentence vector feature matrices of each head are concatenated to obtain a concatenated feature matrix;
[0030] The attention matrix is obtained by summing and normalizing the concatenated feature matrix and the sentence feature matrix.
[0031] In one embodiment of the present invention, the text emotion recognition model is obtained by jointly training the first network model and the second network model. The acquisition of the text emotion recognition model includes: inputting the output result of the first network model into the second network model, obtaining the classification result of each sample data in the sample data set, and based on the classification result and the label of the sample data, jointly training the first network model and the second network model, updating the parameters of the text emotion recognition model according to the classification result, and obtaining a trained text emotion recognition model.
[0032] In one embodiment of the present invention, updating the parameters of the text emotion recognition model according to the classification result includes:
[0033] Obtaining current parameter values of the text emotion recognition model;
[0034] According to the preset parameter update rules, the loss value of the classification result is obtained, and the new parameter value is obtained according to the loss value and the current parameter value.
[0035] In one embodiment of the present invention, a text emotion recognition device is also provided, the device comprising:
[0036] A sample data acquisition module configured to acquire sample data;
[0037] A sample data set making module is configured to label the sample data and classify the labeled sample data according to the emotion category to obtain a sample data set;
[0038] A first network model building module is configured to build a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set;
[0039] A text emotion recognition model acquisition module is configured to establish a second network model according to the output result of the first network model and the classification processing result, and train the second network model to obtain a text emotion recognition model, wherein the text emotion recognition model includes the first network model and the trained second network model connected in sequence;
[0040] The text emotion recognition module is configured to input the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized.
[0041] In one embodiment of the present invention, there is also provided an electronic device, comprising:
[0042] one or more processors;
[0043] A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the electronic device implements any of the above-mentioned text emotion recognition methods.
[0044] In one embodiment of the present invention, a computer-readable storage medium is further provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes any of the above-mentioned text emotion recognition methods.
[0045] Beneficial effects of the present invention: In the present invention, a new network structure of a text emotion recognition model is designed according to the correlation between the previous and next words between sentences, so that the text emotion recognition model can automatically mine and utilize the deep information of the sentence. The underlying network of the model is constructed based on the first network model, and the grammatical hierarchy sorting and context encoding of the input sample data are performed, so that the first network model can obtain syntactic messages without adding prior knowledge, which is beneficial for the model to mine the deep information of the sentence. On the other hand, the method uses the second network model to construct a high-level encoding network of the model, and at the same time integrates the syntactic information obtained by the first network model into the input of the second network model, so as to make full use of the extracted deep information and obtain richer text feature information to improve the model effect.
[0046] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] The drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present application, and together with the specification, are used to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0048] Figure 1 is a schematic diagram of an implementation environment of a text emotion recognition method shown in an exemplary embodiment of the present application;
[0049] Figure 2 is a network structure diagram of a text emotion recognition method shown in an exemplary embodiment of the present application;
[0050] Figure 3 is a flowchart of a text emotion recognition method shown in an exemplary embodiment of the present application;
[0051] Figure 4 is a flow chart of a preprocessing method shown in an exemplary embodiment of the present application;
[0052] Figure 5 yes Figure 3 Step S350 in the illustrated embodiment is a flow chart in an exemplary embodiment;
[0053] Figure 6 yes Figure 5 Step S510 in the illustrated embodiment is a flow chart in an exemplary embodiment;
[0054] Figure 7 yes Figure 5 Step S520 in the illustrated embodiment is a flow chart in an exemplary embodiment;
[0055] Figure 8 yes Figure 7 Step S710 in the illustrated embodiment is a flow chart in an exemplary embodiment;
[0056] Fig. 9 is a flow chart of a parameter updating method shown in an exemplary embodiment of the present application;
[0057] Fig.10 is a block diagram of a text emotion recognition device shown in an exemplary embodiment of the present application;
[0058] Fig.11 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION
[0059] The following will describe the embodiments of the present invention with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention, not for limiting the scope of protection of the present invention.
[0060] It should be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present invention, and thus the drawings only show components related to the present invention rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.
[0061] In the following description, numerous details are discussed to provide a more thorough explanation of the embodiments of the present invention. However, it is obvious to those skilled in the art that the embodiments of the present invention can be implemented without these specific details. In other embodiments, well-known structures and devices are shown in the form of block diagrams rather than in detail to avoid making the embodiments of the present invention difficult to understand.
[0062] It should be noted that text sentiment recognition is the process of analyzing, processing, summarizing and reasoning subjective text with emotional color. The Internet (such as blogs and forums and social service networks such as Dianping) has generated a large amount of valuable comment information on people, events, products, etc. with the participation of users. These comment information expresses people's various emotional colors and emotional tendencies, such as joy, anger, sadness, happiness, criticism, praise, etc. Based on this, potential users can understand the public opinion on a certain event or product by browsing these subjective comments.
[0063] Figure 1 1 is a schematic diagram of the implementation environment of the text emotion recognition method shown in an exemplary embodiment of the present application. The smart terminal 110 shown can be a terminal device that recognizes any text emotion category, such as a smart phone, a car computer, a tablet computer, a laptop computer or a wearable device, but is not limited to this. The recognition server 120 is a navigation server, for example, it can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, etc., which are not limited here. The smart terminal 210 can communicate with the recognition server 120 through wireless networks such as 3G (third generation mobile information technology), 4G (fourth generation mobile information technology), and 5G (fifth generation mobile information technology), which is not limited here.
[0064] See also Figure 3 , Figure 3 is a flowchart of a text emotion recognition method shown in an exemplary embodiment of the present application. The method can be applied to Figure 1 The implementation environment shown is specifically executed by the smart terminal 110 in the implementation environment. It should be understood that the method can also be applied to other exemplary implementation environments and be specifically executed by devices in other implementation environments. This embodiment does not limit the implementation environment to which the method is applicable.
[0065] like Figure 2 and Figure 3 As shown, Figure 2 : is a network structure diagram of a text emotion recognition method shown in an exemplary embodiment of the present application. In an exemplary embodiment, the text emotion recognition method at least includes steps S310 to S350, which are described in detail as follows:
[0066] Step S310, obtaining sample data.
[0067] In this embodiment, the sample data can be selected from an open source text sample data set or a text sample data set independently created by a user based on collected situational sentences in a specific scenario, which is not limited here. The sample data is sentence-level text extracted from a corpus of a specific application scenario, and can usually cover various types of text in the corpus.
[0068] Step S320: label the sample data, and classify the labeled sample data according to the emotion category to obtain a sample data set.
[0069] In this embodiment, different labels can be annotated to the sample data according to the needs of text emotion recognition in the current application scenario, and the labels are used to represent the emotion categories of the sample data. For example, when identifying the dynamic emotions of a user in a vehicle, it is usually necessary to classify the emotions into multiple different categories such as "happy", "frustrated", "angry", and "sad". For the sample data "the weather is so good", the label of the sample data can be annotated as "happy", and for the sample data "it's really unlucky today", the label of the sample data can be annotated as "frustrated", etc. After the labeling is completed, the sample data is classified and processed according to the label category of the sample data, so as to obtain a sample data set. Exemplarily, the sample data labeled "sad" is placed in one folder, and the sample data labeled "happy" is placed in another folder, so as to facilitate the hierarchical extraction of sample data from folders of different label categories in the subsequent training process. It should be noted that this embodiment does not specifically limit the specific content of the label, and those skilled in the art can adaptively select the corresponding label content according to the actual text emotion recognition scenario.
[0070] Step S330, establishing a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set.
[0071] In this embodiment, since the sample data are all composed of sentence-level texts, the words before and after the sentence texts have a certain correlation. If a convolutional neural network is simply used, the correlation information between the words is easily lost after the pooling layer, resulting in a decrease in the subsequent recognition rate. Therefore, it is necessary to sort the sample data set by grammatical hierarchy and context encoding, and the first network model obtained protects the integrity of the correlation between the words before and after the word order, reduces the learning difficulty, and thus improves the accuracy of sentence emotion recognition.
[0072] Step S340, establishing a second network model according to the output result of the first network model and the classification processing result, and training the second network model to obtain a text emotion recognition model, wherein the text emotion recognition model includes the first network model and the trained second network model connected in sequence.
[0073] In this embodiment, the first network model is used to extract the grammatical hierarchy information of the input text sentence and the contextual association information between the previous and next words, so as to realize the preliminary feature extraction of the input text sentence. The information output by the first network model and the classification processing result are input into the second network model for iterative training, so as to obtain a text emotion recognition model. The text emotion recognition model is used to perform emotion recognition on the text sentence and obtain the emotion category corresponding to the text sentence.
[0074] Step S350: input the text data to be recognized into a text emotion recognition model to obtain a text emotion recognition result of the text data to be recognized.
[0075] In this embodiment, the text data to be identified is a sentence issued by the user, which can be a sentence in text form or a sentence in voice form, and is converted into a text sentence by voice-to-text conversion, which is not limited here. Since the present invention is applied to the emotion recognition of sentence-level text, the text data to be identified should include multiple words to form a complete sentence to facilitate the identification of its emotion. Then, according to the content of the text data to be identified, text standardization processing methods such as character encoding standardization, English uppercase and lowercase unification, traditional and simplified unification, and digital normalization can be selected to unify the expression form of the text. Then, it is determined whether the text data to be identified contains non-text content. If it does, text cleaning is required to filter out the non-text content. Finally, sentence correction is performed to correct spelling errors, grammatical errors, or errors in voice-to-text conversion, and preprocessing of the text data to be identified is achieved to obtain the preprocessed text data to be identified. The preprocessed text data to be identified is input into the above-mentioned trained text emotion recognition model, and the probability of different emotion categories of the text sentence is obtained by the softmax (logistic regression) function, and the emotion category with the highest probability is selected as the emotion category of the current text data to be identified.
[0076] Figure 4 FIG. 1 is a flowchart of a preprocessing method shown in an exemplary embodiment of the present application. Figure 4 As shown, after obtaining the sample data, the sample data is further preprocessed. The preprocessing process may include steps S410 to S430, which are described in detail as follows:
[0077] Step S410, performing text standardization processing on the sample data to obtain standardized sample data, wherein the text standardization processing includes number normalization, English uppercase and lowercase unification, character encoding standardization and / or Chinese traditional and simplified unification.
[0078] In this embodiment, since the sample data contains various noises and is not pure text data, it is necessary to first perform text standardization on the sample data to obtain standardized sample data. Text standardization is the process of converting different text variants into a standard form. Specifically, according to the different noises contained in the sample data, one or more text standardization processing methods such as number normalization, English uppercase and lowercase unification, character encoding standardization and / or traditional and simplified Chinese unification can be selected.
[0079] Specifically, digital normalization refers to mapping all numbers appearing in the sample data to an interval in the range of [0,1] so that the data can be processed quickly. English uppercase and lowercase unification refers to converting English letters into uppercase English letters or lowercase English letters. Character encoding standardization refers to unifying the full-width and half-width text information. As an example, full-width English characters and Arabic numerals can be converted into half-width to correspond to Chinese characters that are all full-width characters. Traditional and simplified unification refers to converting Chinese text content into simplified Chinese characters or traditional Chinese characters. It can be understood that the above-mentioned text standardization processing method does not perform each text standardization processing method for each sample data, but adaptively selects the corresponding text standardization processing method according to the text expression form of the sample data. For example, for a text sentence containing English characters, English uppercase and lowercase unification processing is required, and if there is no traditional Chinese character in the text sentence, it is not necessary to perform traditional and simplified unification, thereby improving the efficiency of preprocessing.
[0080] Step S420, performing text cleaning on the standardized sample data to remove non-text content to obtain cleaned sample data.
[0081] In this embodiment, text cleaning refers to deleting non-text characters contained in the standardized sample data, wherein the non-text characters include but are not limited to punctuation marks, special symbols, and useless tags. Among them, the punctuation marks in this embodiment can be various symbols of auxiliary text recording languages such as commas, periods, colons, question marks, and special symbols can be space characters, tab characters, unit symbols, arrow symbols, various emoticons, etc., and useless tags refer to HTML (Hyper Text Markup Language) or URL (Uniform Resource Locator) tags contained in the crawled text data, such as lt, >, etc. By cleaning the text data, various non-Chinese characters can be removed from the standardized sample data, thereby greatly improving the recognition efficiency of the model, so as to quickly identify the emotional category of the current text data.
[0082] Step S430, performing text error correction on the cleaned sample data to obtain preprocessed sample data.
[0083] In this embodiment, considering that the cleaned sample data is pure text data, there may be grammatical errors, word spelling errors, etc., so it is necessary to perform text error correction on the cleaned sample data to obtain accurate text content as the pre-processed sample data. Text error correction is an important technology for realizing automatic inspection and automatic error correction of text sentences, so as to improve the correctness of language and reduce labor costs. As an example, the cleaned sample data can be identified by a built-in English vocabulary, and some common spelling errors can be pre-stored in the English vocabulary, such as some common place names, names, etc. For example, "Chana" can be corrected to "China", etc. The cleaned sample data is pre-processed by this text error correction method, so that the pre-processed sample data can be more accurate.
[0084] Figure 5 yes Figure 3 Step S350 in the illustrated embodiment is a flow chart of an exemplary embodiment. Figure 5 As shown, the process of inputting the to-be-recognized text data into the text emotion recognition model to obtain the text emotion recognition result of the to-be-recognized text data may include steps S510 to S520, which are described in detail as follows:
[0085] Step S510: input the text data to be recognized into the text emotion recognition model, extract the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and construct a sentence feature matrix.
[0086] In this embodiment, the first network model is an ordered long short-term memory network, and the second network model is a multi-head self-attention mechanism network. The underlying network of the model is constructed based on ON-LSTM (Ordered Neurons Long Short-Term Memory), so that syntactic messages can be obtained without adding prior knowledge, which is conducive to the model to mine deep sentence information. By using ON-LSTM (i.e., the first network model) to construct the underlying network of the model, ON-LSTM is used to perform preliminary context encoding on the input text data to be recognized: h1, h2..., hn, and sentence features are obtained at the same time: i1, i2..., in, and a sentence feature matrix is constructed based on the context encoding information and sentence features.
[0087] Step S520, input the sentence feature matrix into the second network model, obtain the probability value of the text data to be recognized belonging to each preset emotion category, and take the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized.
[0088] In this embodiment, the sentence feature matrix is input into the second network model (i.e., the multi-head self-attention mechanism network), and the output of the last multi-head attention layer is used for maximum pooling and average pooling to obtain two sentence vector representations of each text sentence in the sentence feature matrix. The probability value of the text data to be recognized belonging to different emotion categories is obtained by the softmax function, and the emotion category with the highest probability value is selected as the emotion recognition result of the text data to be recognized.
[0089] Figure 6 yes Figure 5 Step S510 in the illustrated embodiment is a flow chart of an exemplary embodiment. Figure 6 As shown, the process of inputting the text data to be recognized into the text emotion recognition model, extracting the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and constructing the sentence feature matrix may include steps S610 to S620, which are described in detail as follows:
[0090] Step S610: converting the text data to be recognized into a feature matrix.
[0091] Since the ON-LSTM network does not contain loop and convolution operations, in order to obtain the sequence information of the text data to be recognized, it is necessary to mark the position of each word in the text data to be recognized and add position encoding information so that more attention can be paid to the corresponding position information in the text data to be recognized during the training process. At the same time, considering that the text data to be recognized may contain multiple words, when these words are input into the text emotion recognition model for training, the variables corresponding to these words have multiple different dimensions, resulting in a large number of parameters and calculations of the text emotion recognition model. Therefore, it is necessary to map the text data to be recognized to a lower dimension through word embedding in order to achieve faster recognition. Then, the text data to be recognized after word embedding is positionally encoded to obtain a feature matrix. Since position encoding is performed by embedding the text data to be recognized, the embedding vector plus the position vector of the text data to be recognized is added as the final output, thereby ensuring that when the same word appears in different positions in the sentence, the word vector corresponding to the word is represented differently, thereby ensuring the order of the sentences input into the ON-LSTM network. As an example, for the sentence "Turn on the left turn signal", the position coding method can adopt the relative position coding method, where the position coding of "turn on" is 1, the position coding of "left" is 2, and the position coding of "turn signal" is 3, thereby obtaining the relative order relationship between the words.
[0092] It can be understood that this embodiment only exemplifies a method of position encoding, but the method of position encoding is not limited to the method described in this embodiment. Those skilled in the art should understand that for different text data to be identified, various relative position encoding or absolute position encoding methods can be adaptively adopted, and no limitation is made here.
[0093] Step S620: input the feature matrix into the second network model, extract the hierarchical information in the feature matrix, and obtain the sentence feature matrix.
[0094] In this embodiment, it is considered that in the language structure, the lower the level, the smaller the structure of the granularity in the language, and the higher the level, the coarser the structure of the granularity. For example, in a Chinese sentence, "character" can be considered as the lowest level structure, followed by words, and above that are phrases, phrases, etc. The higher the level, the coarser the granularity, and the larger its span in the sentence. When the first network model is ON-LSTM, in the ON-LSTM network structure, high-level information may be retained for a considerable distance, and low-level information may be updated at each step of input, so the hierarchical structure is embedded through information classification. Group update is realized, so that the higher group information is transmitted with a larger span, and the lower group span is smaller. These different spans form the hierarchical structure of the input sequence. Thereby, the hierarchical content of the text data to be identified in the input feature sequence can be better identified. The ON-LSTM network adds the ability to extract text syntactic information based on the LSTM (Long Short-Term Memory) network. Therefore, the present invention uses ON-LSTM to construct the underlying network of the model, uses ON-LSTM to perform preliminary context encoding on the information of the input feature matrix, and obtains syntax-related information at the same time. This context encoding information and syntax-related information together constitute a sentence feature matrix. That is, the sentence feature matrix not only has the correlation information between the previous and next words in the text sentence sequence, but also has the dynamic order information of the text sentence sequence after being encoded by ON-LSTM.
[0095] Figure 7 yes Figure 5 Step S520 in the illustrated embodiment is a flow chart of an exemplary embodiment. Figure 7 As shown, the process of inputting the sentence feature matrix into the second network model, obtaining the probability values of the text data to be recognized belonging to each preset emotion category, and taking the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized may include steps S710 to S730, which are described in detail as follows:
[0096] Step S710, according to the preset attention mechanism operation, the sentence feature matrix input to the second network model is processed to obtain an attention matrix.
[0097] In this embodiment, since the second network model is a multi-head self-attention mechanism network, it includes six multi-head attention layers, each of which includes six attention heads with the same structure. By splicing the results of the six attention heads and then using a multi-hop connection method, the extraction and analysis of text information is achieved. Since each attention head focuses on different semantic information, the multi-head self-attention mechanism network can pay attention to more semantic dimensions. At the high level of the model, the multi-head self-attention mechanism is combined with the extracted syntactic information to enable the model to be effectively modeled, thereby making up for the shortcomings of the traditional multi-head attention model in capturing the implicit semantics and structural information of the sentence. After the sentence feature matrix is input into the multi-head self-attention mechanism network, the scale dot product self-attention mechanism operation method is used to obtain the attention matrix. Specifically, for the sentence feature matrix X, each row represents a word vector in a text sentence in the sentence feature matrix, and the sentence feature matrix and the query vector weight matrix W in the multi-head self-attention mechanism network are combined. Q , key vector weight matrix W K , value vector weight matrix W V After dot multiplication, the corresponding query vector matrix Q, key vector matrix K and value vector matrix V are obtained. The query vector weight matrix, key vector weight matrix and value vector weight matrix parameters in each header are not shared, so that multiple different features that do not interfere with each other can be obtained. Specifically, in one embodiment of the present invention, the query vector weight matrix W Q , key vector weight matrix W K , value vector weight matrix W V The parameter calculation formula is shown in formula (1):
[0098]
[0099] Among them, Linear is the fully connected layer of the neural network; I is the sentence feature matrix, I T is the transpose of the sentence feature matrix. After the obtained features are summed and normalized and other attention mechanism operations are performed, the attention matrix can be obtained. Among them, in one embodiment of the present invention, before the sentence feature matrix and the query vector weight matrix, key vector weight matrix, and value vector weight matrix in the multi-head autonomous attention mechanism are dot-multiplied in sequence, it also includes: initializing the query vector weight matrix, the key vector weight matrix, and the value vector weight matrix, so as to obtain the initialized matrix parameters that can be dot-multiplied with the sentence feature matrix.
[0100] Step S720, by setting a multi-hop connection of the attention matrix, obtain the attention matrix output by the last attention layer of the second network model.
[0101] In this embodiment, the attention matrix of the current layer is residually connected with the attention matrix of the previous layer as the input of the next attention layer, and the above method is used to perform operations in each attention layer until the attention mechanism output by the last attention layer is obtained. Through this multi-hop connection method, compared with the ordinary serial structure, long-distance dependencies can be obtained on a shorter path, so that each multi-head attention layer can pay attention to historical information. The self-attention mechanism used in the present invention can effectively alleviate the phenomenon of gradient disappearance, and at the same time can better pay attention to contextual information, thereby enhancing the robustness of the model.
[0102] Step S730, classify the features in the attention matrix output by the last attention layer, match the classification results with the labels, and obtain the emotion recognition result of the text data to be recognized according to the matching rate of the text emotion category.
[0103] In this embodiment, the attention matrix output by the attention layer of the last layer contains the syntactic features of the text data to be recognized. These syntactic features are subjected to maximum pooling and average pooling to obtain two different sentence vector representations of the syntactic features, and the two sentence vectors are input into the fully connected layer in a spliced manner. Softmax is used to select the label with the highest matching rate as the emotion recognition result of the text data to be recognized. Among them, the softmax function is shown in formula (2):
[0104]
[0105] Among them, z i represents the probability that the text data to be identified matches the i-th label, z j Represents the probability that the text data to be recognized matches the jth label.
[0106] Figure 8 yes Figure 7 Step S710 in the illustrated embodiment is a flow chart of an exemplary embodiment. Figure 8 As shown, the sentence feature matrix is input into the second network model, and the process of obtaining the attention matrix according to the preset attention mechanism operation may include steps S810 to S830, which are described in detail as follows:
[0107] Step S810, perform dot multiplication of the sentence feature matrix with the preset query vector weight matrix, key vector weight matrix, and value vector weight matrix of the current head in the second network model, obtain the query vector matrix, key vector matrix, and value vector matrix, and construct the sentence vector feature matrix of the current head.
[0108] In this embodiment, for the text data to be recognized after position encoding and word embedding, each word in the text data to be recognized will obtain a word vector representation, and the word vector representations of each word will be merged to form a sentence feature matrix. Exemplarily, the text data is "turn on the fog lights", the word vector representation of "turn on" is X1, and the word vector representation of "fog lights" is X2. X1 and X2 together constitute the sentence feature matrix X. For each attention head in each layer of the multi-head attention mechanism network, the sentence feature matrix is multiplied with the query vector weight matrix, key vector weight matrix, and value vector weight matrix of the attention head, and the matrices after the dot product are spliced to obtain the sentence vector feature matrix of the current head. Exemplarily, after the sentence feature matrix is calculated with the first head of the first layer of the multi-head attention mechanism, the first sentence vector feature matrix X is obtained. 11 After the sentence feature matrix is calculated with the second head of the first-layer multi-head attention mechanism, the second sentence vector feature matrix X is obtained. 12 .
[0109] Step S820, concatenate the sentence vector feature matrices of each head to obtain a concatenated feature matrix.
[0110] In this embodiment, the sentence vector feature matrix of each head after splicing is spliced again to obtain a spliced feature matrix. For example, for a network with six attention heads, the second sentence vector feature matrix X 12 Concatenated to the first sentence vector feature matrix X 11 Later, the third sentence vector feature matrix X 13 The concatenation is done later, and so on, to obtain the concatenated feature matrix.
[0111] Step S830, obtaining an attention matrix by summing and normalizing the concatenated feature matrix and the sentence feature matrix.
[0112] In this embodiment, the concatenated feature matrix is added to the sentence feature matrix to obtain a summed attention matrix. By adding the text information in the sentence feature matrix, the historical information can be read. Then, the summed attention matrix is normalized to achieve the standardization of the data in the model, which facilitates the model to quickly read the various parameters therein.
[0113] In one embodiment of the present invention, the text emotion recognition model is obtained by jointly training the first network model and the second network model. The acquisition of the text emotion recognition model includes: inputting the output result of the first network model into the second network model, obtaining the classification result of each sample data in the sample data set, and based on the classification result and the label of the sample data, jointly training the first network model and the second network model, updating the parameters of the text emotion recognition model according to the classification result, and obtaining a trained text emotion recognition model.
[0114] In this embodiment, the first network model used is an ordered long short-term memory network, and the second network model is a multi-head self-attention mechanism network. After the sentence feature matrix is input into the second network model of the text emotion recognition model, the output of the last multi-head attention layer is used for maximum pooling and average pooling to obtain two sentence vector representations of each text sentence in the sentence feature matrix. The two sentence vector representations are spliced together and input into the fully connected layer, and the probability that the current sentence belongs to different emotion categories is output through the softmax function. The one with the largest probability is selected as the classification result of the current sentence of the sample data, and then according to the classification result and the label of the sample data, the parameters of the second network model and the first network model are continuously updated by the gradient descent method and the back propagation method. Through this continuous iterative training, a trained text emotion recognition model can be finally obtained. As an example, after several iterative trainings, the verification set consisting of part of the preprocessed sample data is input into the multiple text emotion recognition models completed by the above training, and the model with the best robustness is selected as the trained text emotion recognition model.
[0115] Fig. 9 FIG. 1 is a flow chart of a parameter updating method shown in an exemplary embodiment of the present application. Fig. 9 As shown, the process of updating the parameters of the text emotion recognition model according to the classification results may include steps S910 to S920, which are described in detail as follows:
[0116] Step S910, obtaining current parameter values of the text emotion recognition model.
[0117] In this embodiment, during each iterative training process, the current parameters of ON-LSTM in the text emotion recognition model and the current parameters of the multi-head self-attention mechanism network are saved, for example, in the training log, so that the specific numerical information of these parameters can be extracted in time during the next training. Among them, the parameters include but are not limited to the learning rate value, the weight value of each network layer, the weight value of the query vector weight matrix, the key vector weight matrix, and the value vector weight matrix in the multi-head self-attention mechanism.
[0118] Step S920, according to the preset parameter update rule, obtain the loss value of the classification result, and obtain a new parameter value according to the loss value and the current parameter value.
[0119] In this implementation, according to the preset parameter update rules, the classification result is obtained through the softmax function, and the loss value is obtained through the loss function according to the classification result and the label of the corresponding text sentence in the sample data, and then the parameters of the text emotion recognition model are continuously updated by back propagation. Among them, considering that the sentence-level emotion classification task belongs to the classification task in deep learning, the cross entropy function is selected as the loss function Loss during training in this embodiment, and its formula is shown in formula (3):
[0120]
[0121] Among them, pi is the sample with the label of emotion category i; q i is the probability that the sample data is predicted to be emotion category i. Further, in this embodiment, the parameter update rule is: derivative according to the chain derivation rule. Specifically, the error back propagation gradient calculation formula is: Gradp = ((w p-1 ) T Gradp p-1 )δ, where δ is the current loss value, Gradp is the error back propagation gradient of the pth layer, and w p-1 is the weight of the text emotion recognition model during the p-1th iteration training. According to the back propagation gradient, the parameter update value is calculated using the following formula: p =w p-1 -ε·Gradp, where ε is the learning rate and w p Represents the parameters of the current text sentiment recognition model.
[0122] In the present invention, a new network structure of a text emotion recognition model is designed based on an ordered long short-term memory network and an attention mechanism, so that the text emotion recognition model can automatically mine and utilize the deep information of sentences. The underlying network of the model is constructed based on an ordered long short-term memory network, so that it can obtain syntactic information without adding prior knowledge, which is beneficial for the model to mine the deep information of sentences. On the other hand, this method constructs a high-level encoding network of the model based on the attention mechanism, and at the same time integrates the syntactic information obtained by the ordered long short-term memory network into the attention mechanism, so as to make full use of the extracted deep information and obtain richer text feature information to improve the model effect.
[0123] Machine Learning (ML) is a multi-disciplinary subject that involves probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance. Among them, machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and teaching learning.
[0124] Based on the powerful learning ability of machine learning, through the machine learning process for a large number of historical trajectories, the machine learning model can be used to calculate the statistics of the correlation between each word in the text sentence, and estimate the sentiment category of the text sentence based on the relevant words and the various parameters in the trained model. Exemplarily, the machine learning model may include a supervised model based on a neural network, such as a binary classification machine learning model, and the machine learning model is trained by using a large number of text sentence data sets so that the machine learning model adjusts the model parameters during the training process, so that the adjusted model parameters have a comprehensive prediction performance for the sentiment category of the text sentence.
[0125] Fig.10 is a block diagram of a text emotion recognition device shown in an exemplary embodiment of the present application. The device can be applied to Figure 1 The implementation environment shown is specifically configured in the intelligent terminal 110. The device may also be applicable to other exemplary implementation environments and specifically configured in other devices. This embodiment does not limit the implementation environment applicable to the device.
[0126] like Fig.10 As shown, the exemplary text emotion recognition device includes:
[0127] The sample data acquisition module 1001 is configured to acquire sample data; the sample data set production module 1002 is configured to annotate the sample data and classify the annotated sample data according to the emotion category to obtain the sample data set; the first network model construction module 1003 is configured to establish a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set; the text emotion recognition model acquisition module 1004 is configured to establish a second network model according to the output result of the first network model and the classification processing result, and train the second network model to obtain a text emotion recognition model, wherein the text emotion recognition model includes a first network model and a trained second network model connected in sequence; the text emotion recognition module 1005 is configured to input the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized.
[0128] In another exemplary embodiment, the text emotion recognition module 1005 includes:
[0129] The sentence feature matrix acquisition unit is configured to input the text data to be recognized into the text emotion recognition model, extract the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and construct a sentence feature matrix.
[0130] The emotion recognition result acquisition unit is configured to input the sentence feature matrix into the second network model, obtain the probability value that the text data to be recognized belongs to each preset emotion category, and take the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized.
[0131] In another exemplary embodiment, the sentence feature matrix acquisition unit includes:
[0132] The feature matrix acquisition subunit is configured to convert the text data to be recognized into a feature matrix; the sentence feature matrix acquisition subunit is configured to input the feature matrix into the second network model, extract the hierarchical information in the feature matrix, and obtain the sentence feature matrix.
[0133] In another exemplary embodiment, the emotion recognition result acquisition unit includes:
[0134] The attention matrix acquisition subunit is configured to input the sentence feature matrix into the multi-head self-attention mechanism network, and obtain the attention matrix according to the preset attention mechanism operation; the last layer attention matrix acquisition subunit is configured to perform multi-hop connections on the attention matrix to obtain the attention matrix output by the last layer of attention layer of the multi-head attention mechanism network; the text emotion result acquisition subunit is configured to classify each feature in the attention matrix output by the last layer of attention layer, match the classification results with each label, select the text emotion category with the highest matching rate, and obtain the emotion recognition result of the text data to be recognized.
[0135] It should be noted that the model training device provided in the above embodiment and the text emotion recognition method provided in the above embodiment belong to the same concept, and the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment and will not be repeated here. In practical applications, the model training device provided in the above embodiment can distribute the above functions to different functional modules as needed, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here.
[0136] An embodiment of the present application also provides an electronic device, comprising: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the electronic device implements the road condition refresh method provided in the above-mentioned embodiments.
[0137] Fig.11 The structure diagram of the computer system suitable for implementing the electronic device of the embodiment of the present application is shown. It should be noted that: Fig.11 The computer system 1100 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0138] like Fig.11As shown, the computer system 1100 includes a central processing unit (CPU) 1101, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1102 or the program loaded from the storage part 1108 to the random access memory (RAM) 1103, such as executing the method described in the above embodiment. In the RAM 1103, various programs and data required for system operation are also stored. The CPU 1101, the ROM 1102 and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0139] The following components are connected to the I / O interface 1105: an input section 1106 including a keyboard, a mouse, etc.; an output section 1107 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to the I / O interface 1105 as needed. A removable medium 1111, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1110 as needed so that a computer program read therefrom is installed into the storage section 1108 as needed.
[0140] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 1109, and / or installed from a removable medium 1111. When the computer program is executed by a central processing unit (CPU) 1101, various functions defined in the system of the present application are executed.
[0141] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal can take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0142] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the 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 flowchart, and the combination of boxes in the block diagram or flowchart 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.
[0143] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0144] Another aspect of the present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the road condition refreshing method as described above is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0145] Another aspect of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the road condition refreshing method provided in each of the above embodiments.
[0146] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present invention. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A text emotion recognition method, characterized in that: The process includes: Get sample data; Labeling the sample data, and classifying the labeled sample data according to the emotion category to obtain a sample data set; Establishing a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set; According to the output result of the first network model and the classification processing result, a second network model is established, and the second network model is trained to obtain a text emotion recognition model, wherein the text emotion recognition model includes the first network model and the trained second network model connected in sequence; Inputting the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized; The first network model is an ordered long short-term memory network, and the second network model is a multi-head self-attention mechanism network; For the multi-head self-attention mechanism network: the attention matrix of the current layer is residually connected with the attention matrix of the previous layer as the input of the next attention layer; The step of inputting the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized includes: Inputting the text data to be recognized into the text emotion recognition model, extracting the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and constructing a sentence feature matrix; Inputting the sentence feature matrix into the second network model, obtaining the probability value of the text data to be recognized belonging to each preset emotion category, and taking the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized; The step of inputting the sentence feature matrix into the second network model, obtaining probability values of the text data to be recognized belonging to each preset emotion category, and taking the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized, comprises: According to a preset attention mechanism operation, the sentence feature matrix input to the second network model is processed to obtain an attention matrix; By setting a multi-hop connection of the attention matrix, obtaining the attention matrix output by the last attention layer of the second network model; The features in the attention matrix output by the last attention layer are classified, and the classification results are matched with the labels, and the emotion recognition results of the text data to be recognized are obtained according to the matching rate of the text emotion category.
2. The text emotion recognition method according to claim 1, characterized in that: After obtaining the sample data, the sample data is preprocessed, and the preprocessing includes the following steps: Performing text standardization processing on the sample data to obtain standardized sample data, wherein the text standardization processing includes number normalization, English capitalization unification, character encoding standardization and / or Chinese traditional and simplified unification; Performing text cleaning on the standardized sample data to remove non-text content and obtain cleaned sample data; Text error correction is performed on the cleaned sample data to obtain preprocessed sample data.
3. The text emotion recognition method according to claim 1, characterized in that: The step of inputting the text data to be recognized into the text emotion recognition model, extracting sentence features and context encoding information of the text data to be recognized through the first network model, and constructing a sentence feature matrix includes: Converting the text data to be recognized into a feature matrix; The feature matrix is input into the first network model, hierarchical information in the feature matrix is extracted, and a sentence feature matrix is obtained.
4. The text emotion recognition method according to claim 1, characterized in that: The step of inputting the sentence feature matrix into the second network model and calculating according to a preset attention mechanism to obtain an attention matrix includes: Perform dot multiplication of the sentence feature matrix with the preset query vector weight matrix, key vector weight matrix, and value vector weight matrix of the current head in the second network model, respectively, to obtain a query vector matrix, a key vector matrix, and a value vector matrix, and construct a sentence vector feature matrix of the current head; The sentence vector feature matrices of each head are concatenated to obtain a concatenated feature matrix; The attention matrix is obtained by summing and normalizing the concatenated feature matrix and the sentence feature matrix.
5. The text emotion recognition method according to claim 1, characterized in that: The text emotion recognition model is obtained by jointly training the first network model and the second network model. The acquisition of the text emotion recognition model includes: inputting the output result of the first network model into the second network model, obtaining the classification result of each sample data in the sample data set, and based on the classification result and the label of the sample data, jointly training the first network model and the second network model, updating the parameters of the text emotion recognition model according to the classification result, and obtaining a trained text emotion recognition model.
6. The text emotion recognition method according to claim 5, characterized in that: The updating of the parameters of the text emotion recognition model according to the classification result includes: Obtaining current parameter values of the text emotion recognition model; According to the preset parameter update rules, the loss value of the classification result is obtained, and the new parameter value is obtained according to the loss value and the current parameter value.
7. A text emotion recognition device, characterized in that: The device comprises: A sample data acquisition module configured to acquire sample data; A sample data set production module is configured to annotate the sample data and classify the annotated sample data according to the emotion category to obtain a sample data set; A first network model building module is configured to build a first network model by performing grammatical hierarchy sorting and context encoding on the sample data set; A text emotion recognition model acquisition module is configured to establish a second network model according to the output result of the first network model and the classification processing result, and train the second network model to obtain a text emotion recognition model, wherein the text emotion recognition model includes the first network model and the trained second network model connected in sequence; The text emotion recognition module is configured to input the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized; The first network model is an ordered long short-term memory network, and the second network model is a multi-head self-attention mechanism network; For the multi-head self-attention mechanism network: the attention matrix of the current layer is residually connected with the attention matrix of the previous layer as the input of the next attention layer; The step of inputting the text data to be recognized into the text emotion recognition model to obtain the text emotion recognition result of the text data to be recognized includes: Inputting the text data to be recognized into the text emotion recognition model, extracting the sentence meaning features and context encoding information of the text data to be recognized through the first network model, and constructing a sentence feature matrix; Inputting the sentence feature matrix into the second network model, obtaining the probability value of the text data to be recognized belonging to each preset emotion category, and taking the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized; The step of inputting the sentence feature matrix into the second network model, obtaining probability values of the text data to be recognized belonging to each preset emotion category, and taking the emotion category with the highest probability value as the emotion recognition result of the text data to be recognized, comprises: According to a preset attention mechanism operation, the sentence feature matrix input to the second network model is processed to obtain an attention matrix; By setting a multi-hop connection of the attention matrix, obtaining the attention matrix output by the last attention layer of the second network model; The features in the attention matrix output by the last attention layer are classified, and the classification results are matched with the labels, and the emotion recognition results of the text data to be recognized are obtained according to the matching rate of the text emotion category.
8. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the text emotion recognition method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is enabled to execute the text emotion recognition method according to any one of claims 1 to 6.